if(browser.indexOf('Firefox')>-1) {
	document.write('<style type="text/css">.inputButton { margin-top:1px }</style>');
}

function process_hashed_url(url) {
	var res = url.match(/#(.+)$/);
	if (!res) {
		//return;	/* Skip if not "hash" link */
		var date = new Date();
		var hash = date.getFullYear();
	} else {
		var hash = res[1];
		window.location.hash=hash;
	}
	seeArchive(hash);
}
var pageLoaded=false;
window.onload=function() {
	if (document.getElementById('newsArchive')) {
		process_hashed_url(document.location.href);	/* See if current location has a hash */
	}
	var pageLink=document.getElementsByTagName('a');
	for (i=0;i<pageLink.length;i++) {
		pageLink[i].href=pageLink[i].href.replace("(at)","@");
		pageLink[i].innerHTML=pageLink[i].innerHTML.replace("(at)","@");
	}
	pageLoaded=true;
}
function seeArchive(year) {
	if (document.getElementById('archives')) {
		archiveDivs=document.getElementById('archives').getElementsByTagName('div');
		for (i=0;i<archiveDivs.length;i++) {
			archiveDivs[i].style.display='none';
		}
		archiveLinks=document.getElementById('newsArchive').getElementsByTagName('a');
		for (i=0;i<archiveLinks.length;i++) {
			archiveLinks[i].className='';
			hash=archiveLinks[i].toString().split('#');
			if (hash[1]==year) {
				archiveLinks[i].className='active';
			}
		}
		if (document.getElementById(year)) {
			document.getElementById(year).style.display='inline';
		}
	}
}
function clearOnFocus(obj) {	
	obj.defaultValue=obj.value;
	obj.onblur=function() {
		if (this.value=='') {
			this.value=this.defaultValue;
		}
	}
	obj.onfocus=function() {
		if (this.value==this.defaultValue) {
			this.value='';
		}
	}
	obj.value='';		
}
if(document.getElementById) {
	window.alert = function(txt) {
		message(txt);
	}
}
function message(txt) {
	if (!document.getElementById('alertContainer')) {
		alertContainer=document.createElement('div');
		alertContainer.id='alertContainer';
		document.body.appendChild(alertContainer);
	} else {
		alertContainer=document.getElementById('alertContainer');
	}
	alertBox ='<table cellpadding="0" cellspacing="0" border="0" width="375"><tr><td width="9" height="9"><img src="/css/images/gfx-alert-shadow-bg-tl.png" width="9" height="9" /></td><td width="357" height="9"><img src="/css/images/gfx-alert-shadow-bg.png" width="357" height="9" /></td><td><img src="/css/images/gfx-alert-shadow-bg-tr.png" width="9" height="9" /></td></tr>';
	alertBox+='<tr><td width="9" background="/css/images/gfx-alert-shadow-bg.png">&nbsp;</td><td style="background-color:#FFF; border:1px solid #444;"><span id="messageTitle">Massarde A/S</span><span id="messageText">'+txt+'</span><span id="messageClose"><input type="button" class="inputButton" value="'+labelClose+'" onclick="closeMessage()" /></span></td><td width="9" background="/css/images/gfx-alert-shadow-bg.png">&nbsp;</td></tr>';
	alertBox+='<tr><td width="9" height="9"><img src="/css/images/gfx-alert-shadow-bg-bl.png" width="9" height="9" /></td><td width="357" height="9"><img src="/css/images/gfx-alert-shadow-bg.png" width="357" height="9" /></td><td><img src="/css/images/gfx-alert-shadow-bg-br.png" width="9" height="9" /></td></tr></table>';
	alertContainer.innerHTML=alertBox;
	
	var messageTitle=document.getElementById('messageTitle');
	messageTitle.style.backgroundImage='url(/css/images/gfx-alert-title-bg.gif)';
	messageTitle.style.display='block';
	messageTitle.style.borderBottom='1px solid #ce2020';
	messageTitle.style.color='#fff';
	messageTitle.style.fontSize='1.2em';
	messageTitle.style.padding='3px 9px';
	
	var messageText=document.getElementById('messageText');
	messageText.style.display='block';
	messageText.style.padding='3px 9px';
	messageText.style.fontSize='1.1em';
	
	var messageClose=document.getElementById('messageClose');
	messageClose.style.display='block';
	messageClose.style.backgroundColor='#f0f0f0';
	messageClose.style.borderTop='1px solid #d5d5d5';
	messageClose.style.padding='8px 9px';
	messageClose.style.textAlign='right';
	//messageClose.style.lineHeight='37px';
	if (window.innerWidth) {
		windowWidth=window.innerWidth;
		windowHeight=window.innerHeight;
	} else {
		windowWidth=document.documentElement.clientWidth;
		windowHeight=document.documentElement.clientHeight;
	}
	alertContainer.style.zIndex=10000;
	alertContainer.style.position='fixed';
	alertContainer.style.top=(windowHeight/2)-(alertContainer.getElementsByTagName('table')[0].offsetHeight/2)+"px";
	alertContainer.style.left=(windowWidth/2)-(alertContainer.getElementsByTagName('table')[0].offsetWidth/2)+"px";
	//alertContainer.style.
}

function closeMessage() {
	alertContainer=document.getElementById('alertContainer');
	alertContainer.parentNode.removeChild(alertContainer);
}
function ScreenDumpSlideshow(images) {
	var content=document.getElementById('content');
	var myNewContent=content.innerHTML.split('<script language="text/javascript">')[0]+'<div id="slideshowContainer'+images+'"></div>'+content.innerHTML.split('</script>')[1];
	var imageArray=images.split(";");
	var currentImage=-1;
	content.innerHTML=myNewContent.replace('undefined','');
	var slideshowContainer=document.getElementById('slideshowContainer'+images);
	slideshowContainer.style.width='575px';
	slideshowContainer.style.height='300px';
	slideshowContainer.style.backgroundPosition='101px 23px';
	slideshowContainer.style.display='block';
	slideshowContainer.style.cursor='pointer';
	var slideshowOverlay=document.createElement('img');
	slideshowOverlay.src='/css/images/screendump-frame.png';
	slideshowOverlay.style.position='absolute';
	slideshowOverlay.style.width='575px';
	slideshowOverlay.style.height='300px';
	slideshowOverlay.style.zIndex=10;
	slideshowOverlay.style.display='block';
	slideshowContainer.appendChild(slideshowOverlay);
	if (imageArray.length>1) {
		var altText=document.createElement('div');
		altText.style.position='absolute';
		altText.id='altText';
		altText.style.marginTop='-18px';
		altText.style.width='575px';
		altText.style.height='25px';
		altText.style.backgroundRepeat='no-repeat';
		altText.style.backgroundPosition='center top';
		altText.style.textAlign='center';
		altText.style.display='block';
		altText.style.zIndex=11;
		altText.style.color='#fff';
		altText.style.paddingTop='1px';
		altText.style.fontSize='12px';
		altText.style.backgroundImage='url(/css/images/gfx-alttext.png)';
		altText.innerHTML='Klik for flere billeder';
		slideshowContainer.appendChild(altText);
		$("#altText").fadeOut(0.01);
		setTimeout("$(\"#altText\").fadeIn(500).fadeTo(5000,1).fadeOut(250)",1000);
	}
	
	var imageContainer=document.createElement('img');
	imageContainer.id='imageContainer';
	imageContainer.width=375;
	imageContainer.height=235;
	imageContainer.style.position='relative';
	imageContainer.style.top='23px';
	imageContainer.style.left='101px';
	imageContainer.style.zIndex=9;
	slideshowContainer.appendChild(imageContainer);
	
	this.loadImage = function() {
		currentImage++;
		if (currentImage>=imageArray.length) currentImage=0;
		$("#imageContainer").hide();
		imageContainer.onload = $("#imageContainer").fadeIn(250);
		imageContainer.src=imageArray[currentImage];
	}
	if (imageArray.length>1)
	slideshowContainer.onclick = this.loadImage;
	this.loadImage(imageArray[currentImage]);
}
function goingToScene(sceneNo) {
	window.location.hash="/"+sceneNo;
	if (pageLoaded) {
		pageTracker._trackPageview(document.location.href.replace("http://"+document.domain,""));
	}
}