/**
 * CasePreloader
 *
 **********
 *
 * Håndterer preloading af cases.
 */
function CasePreloader(){
	// Klargør variabler
	this.pageIsLoaded=false;
	this.casesIsLoaded=false;
	this.preloaded=0;

	// Håndter preloading af cases
	this.preloadCase();

	// Opdater status
	this.updateStatus();
}

/**
 * preloadCase
 *
 **********
 *
 * Håndter preloading af den pågældende case
 */
CasePreloader.prototype.preloadCase=function(){
	// Denne funktion kan kun køres, hvis alle cases ikke er preloadet endnu
	if(this.preloaded>=casesHandler.length) return;

	// Klargør variabler
	this.imgsPreloaded=0;
	this.ts=new Date().getTime();

	// Indlæs listen over billeder
	this.imgs=casesHandler[this.preloaded].container.getElementsByTagName('img');
	var i=this.imgs.length; var j=i;
	
	if(i>0)do{
		// Er billedet indlæst?
		if(this.imgs[j-i].complete) this.imgsPreloaded++;

		// Ellers håndteres det ved onload
		else{
			this.imgs[j-i].onload=function(){casePreloader.onComplete();}
			this.imgs[j-i].onabort=function(){casePreloader.onComplete();}
			this.imgs[j-i].onerror=function(){casePreloader.onComplete();}
		}
	}while(--i);

	// Er alle billederne preloadede?
	if(this.imgsPreloaded>=this.imgs.length){
		// Opdater status
		this.preloaded++;
		this.updateStatus();

		// Preload af en case skal tage minimum 100ms
		setTimeout(function(){casePreloader.preloadCase();},100);
	}
}

/**
 * onComplete
 *
 **********
 *
 * Køres når et billede er preloadet.
 */
CasePreloader.prototype.onComplete=function(){
	// Opdater antal preloadede billeder
	this.imgsPreloaded++;
	
	// Er alle billederne preloadede?
	if(this.imgsPreloaded>=this.imgs.length){
		// Opdater status
		this.preloaded++;
		this.updateStatus();

		// Preload af en case skal tage minimum 100ms
		setTimeout(function(){casePreloader.preloadCase();},Math.max(1,100-(new Date().getTime()-this.ts)));
	}
}

/**
 * updateStatus
 *
 **********
 *
 * Opdater preloading status.
 */
CasePreloader.prototype.updateStatus=function(){
	// Opdater status
	var status=Math.round(this.preloaded/(casesHandler.length+3)*190);
	document.getElementById('preload_status').style.width=status+'px';
	document.getElementById('preload_status2').style.left=status+'px';
	document.getElementById('preload_status2').style.width=(190-status)+'px';

	// Afslut preloading!
	if(this.preloaded==casesHandler.length){
		// Er siden fuldstændig loadet?
		if(this.pageIsLoaded) this.done();
		else this.casesIsLoaded=true;
	}
}

CasePreloader.prototype.done=function(){
	// Scroll til toppen!
	window.scrollTo(0,0);

	// Klargør caselisten
	caseList=new CaseList();

	// Håndter preloader-baren
	setTimeout(function(){
		var status=Math.round((casesHandler.length+1)/(casesHandler.length+3)*190);
		document.getElementById('preload_status').style.width=status+'px';
		document.getElementById('preload_status2').style.left=status+'px';
		document.getElementById('preload_status2').style.width=(190-status)+'px';
	},300);
	setTimeout(function(){
		var status=Math.round((casesHandler.length+2)/(casesHandler.length+3)*190);
		document.getElementById('preload_status').style.width=status+'px';
		document.getElementById('preload_status2').style.left=status+'px';
		document.getElementById('preload_status2').style.width=(190-status)+'px';
	},600);
	setTimeout(function(){
		document.getElementById('preload_status').style.width='190px';
		document.getElementById('preload_status2').style.left='190px';
		document.getElementById('preload_status2').style.width='0px';
	},900);
	setTimeout(function(){
		var tmp=document.getElementById('preloader_container');
		tmp.parentNode.removeChild(tmp);
	},1000);
}

/**
 * CaseList
 *
 **********
 *
 * Håndterer oversigten over cases.
 */
function CaseList(){
	// Indlæs en reference til wrapperen
	this.wrapper=document.getElementById('case_wrapper');

	// Klargør variabler
	this.inAnimation=false;
	this.inSlideAnimation=false;
	this.isDragging=false;
	this.caseOpen=false;
	this.speed=0;

	// Udregn hvor mange cases, der befinder sig 'udenfor' skærmen
	var caseWidth=220+220*casesHandler.length;
	var winWidth=window.innerWidth||document.documentElement.clientWidth||document.body.clientWidth;

	// Håndter bredde og maks-scroll
	this.wrapper.style.width=(1100*casesHandler.length+20)+'px';
	this.maxScroll=-Math.max(1100,Math.ceil((caseWidth-winWidth-1100)/220)*220);

	// Fade logoer ind!
	setTimeout(function(){
		var i=casesHandler.length; var j=i;
		if(i>0)do{
			casesHandler[j-i].container.style.background='url('+document.getElementsByTagName('base')[0].href+'templates/view/da_DK/default/images/border.png) repeat-y';
			casesHandler[j-i].logo.style.visibility='visible';
		}while(--i);

		new Effect(function(p){var i=casesHandler.length; var j=i; if(i>0)do{var tmp=casesHandler[j-i].logo_img; tmp.style.opacity=p; tmp.style.filter='progid:DXImageTransform.Microsoft.Alpha(opacity='+Math.round(100*p)+')'; tmp=null;}while(--i);
	},{duration:1.5});},1000);

	// Indlæs hash-adresse
	var hash=window.location.hash.split('#').join('');

	// Hvis der ikke er valgt en case, vises introen
	if(hash.substring(0,5)!='case='){
		// Slide in
		this.introAnimation=true;
		var wrapper=this.wrapper;
		setTimeout(function(){new Effect(function(p){wrapper.style.left=(-1000*p)+'px'; if(p==1){caseList.introAnimation=false; wrapper=null;}},{duration:1.5,ease:true});},1000);

	// Ellers åbnes casen
	}else{
		// Gennemgå listen over cases og find den valgte
		var i=casesHandler.length; var j=i; var x=-1;
		if(i>0)do{
			if(casesHandler[j-i].caseID==hash.substring(5,hash.length)){
				x=j-i;
				break;
			}
		}while(--i);

		// Vis casen
		if(x>-1){
			this.introAnimation=true;
			var tmp=casesHandler[x]; var z=0;
			setTimeout(function(){
				new Effect(function(p){
					// Udregn scroll
					var left=Math.round((x-1)*200*p);

					// Er der mere end 2 cases i venstre side?
					while(z-left<=-1000){
						// Indlæs en reference til den første case
						var tmp3=casesHandler[0];

						// Indlæs en reference til case-afslutningen
						var end=caseList.wrapper.getElementsByTagName('div');
						end=end[end.length-1];

						// Flyt den første case til sidst visuelt
						caseList.wrapper.insertBefore(tmp3.container,end);
						z+=200;

						// Flyt den første case til sidst i hukommelsen
						casesHandler.splice(0,1);
						casesHandler[casesHandler.length]=tmp3;

						// Ryd hukommelsen
						tmp3=null; end=null;
					}

					// Er der mindre end 2 cases i venstre side?
					while(z-left>=-200){
						// Indlæs en reference til den første case
						var tmp3=casesHandler[casesHandler.length-1];

						// Flyt den første case til sidst visuelt
						caseList.wrapper.insertBefore(tmp3.container,caseList.wrapper.getElementsByTagName('div')[0]);
						z-=200;

						// Flyt den første case til sidst i hukommelsen
						casesHandler.splice(casesHandler.length-1,1);
						casesHandler.splice(0,0,tmp3);

						// Ryd hukommelsen
						tmp3=null;
					}

					// Scroll!
					caseList.wrapper.style.left=(z-left)+'px';

					// Fadein
					if(p==1){
						var tmp2=tmp; var slogan=document.getElementById('slogan');
						setTimeout(function(){tmp2.over(); new Effect(function(p){slogan.style.opacity=(1-p); slogan.style.filter='alpha(opacity='+(100-p*100)+')'; if(p==1){slogan=null;}},{duration:0.15,ease:false});},200);
						setTimeout(function(){tmp2.expand(); tmp2=null; caseList.introAnimation=false;},900);
						tmp=null;
					}
				},{duration:1.5,ease:true});
			},1000);

		// Vis introen, hvis ingen case blev fundet
		}else{
			// Slide in
			this.introAnimation=true;
			var wrapper=this.wrapper;
			setTimeout(function(){new Effect(function(p){wrapper.style.left=(-1000*p)+'px'; if(p==1){caseList.introAnimation=false; wrapper=null;}},{duration:1.5,ease:true});},1000);
		}
	}
}

/**
 * resize
 *
 **********
 *
 * Udregner ny maks-scroll ved resize.
 */
CaseList.prototype.resize=function(){
	// Udregn hvor mange cases, der befinder sig 'udenfor' skærmen
	var caseWidth=220+220*casesHandler.length;
	var winWidth=window.innerWidth||document.documentElement.clientWidth||document.body.clientWidth;

	// Opdater maks-scroll
	this.maxScroll=-Math.max(1100,Math.ceil((caseWidth-winWidth-1100)/220)*220);

	// Opdater scroll
//	this.wrapper.style.left=Math.max(this.wrapper.offsetLeft,this.maxScroll)+'px';
}

/**
 * initDrag
 *
 **********
 *
 * Klargører drag'n'drop-scrolling af oversigten.
 *
 **********
 *
 * Parametre:
 * e (eventinfo)						Indeholder informationer om brugerens inputs.
 */
CaseList.prototype.initDrag=function(e){
	// Indlæs informationer om brugerens inputs.
	this.x=e.clientX||e.pageX;

	// Vis rigtig cursor
	if(!this.inSlideAnimation) document.body.style.cursor='url("'+document.getElementsByTagName('base')[0].href+'templates/view/da_DK/default/cursors/hand2.cur"), url("'+document.getElementsByTagName('base')[0].href+'templates/view/da_DK/default/cursors/hand2.gif"), move';
	document.getElementById('cursorbox').style.visibility='hidden';
	document.getElementById('cursorbox').cursorState=1;

	// Angiv at drag'n'drop er aktiveret
	this.isDragging=true;
	this.inSlideAnimation=true;
	this.speed=[];

	// Fade logoer ned
	new Effect(function(p){
		var i=casesHandler.length; var j=i;
		if(i>0)do{
			if(document.all) casesHandler[j-i].logo_img.style.filter='progid:DXImageTransform.Microsoft.Alpha(opacity='+Math.round(100-50*p)+')';
			else casesHandler[j-i].logo_img.style.opacity=1-0.5*p;
		}while(--i);
	},{duration:0.15,ease:false});

	// Afbryd eventet
	stopEvent(e);
}

/**
 * drag
 *
 **********
 *
 * Håndterer drag'n'drop-scrolling af oversigten.
 *
 **********
 *
 * Parametre:
 * e (eventinfo)						Indeholder informationer om brugerens inputs.
 */
CaseList.prototype.drag=function(e){
	// Indlæs informationer om brugerens inputs
	var x=this.x-(e.clientX||e.pageX);

	// Trækkes der mod højre eller venstre?
	this.dir=(e.clientX||e.pageX)>this.x;

	// Udregn gennemsnits hastighed
	this.speed[this.speed.length]=[this.x-(e.clientX||e.pageX),new Date().getTime()];
	if(this.speed.length>5) this.speed.splice(0,1);

	// Gem musens placering
	this.x=e.clientX||e.pageX;

	// Udregn placering
	var x=(this.wrapper.offsetLeft-x);
//	x=Math.max(this.maxScroll,Math.min(0,x));

	// Er der mere end 2 cases i venstre side?
	while(x<=-600){
		// Indlæs en reference til den første case
		var tmp=casesHandler[0];

		// Indlæs en reference til case-afslutningen
		var end=this.wrapper.getElementsByTagName('div');
		end=end[end.length-1];

		// Flyt den første case til sidst visuelt
		this.wrapper.insertBefore(tmp.container,end);
		x+=200;

		// Flyt den første case til sidst i hukommelsen
		casesHandler.splice(0,1);
		casesHandler[casesHandler.length]=tmp;

		// Ryd hukommelsen
		tmp=null; end=null;
	}

	// Er der mindre end 2 cases i venstre side?
	while(x>=-200){
		// Indlæs en reference til den første case
		var tmp=casesHandler[casesHandler.length-1];

		// Flyt den første case til sidst visuelt
		this.wrapper.insertBefore(tmp.container,this.wrapper.getElementsByTagName('div')[0]);
		x-=200;

		// Flyt den første case til sidst i hukommelsen
		casesHandler.splice(casesHandler.length-1,1);
		casesHandler.splice(0,0,tmp);

		// Ryd hukommelsen
		tmp=null;
	}

	// Scroll!
	this.wrapper.style.left=x+'px';

	// Afbryd eventet
	stopEvent(e);
}

/**
 * endDrag
 *
 **********
 *
 * Afslutter drag'n'drop-scrolling af oversigten.
 *
 **********
 *
 * Parametre:
 * e (eventinfo)						Indeholder informationer om brugerens inputs.
 */
CaseList.prototype.endDrag=function(e){
	// Håndter easing
	if(this.speed.length){
		// Udregn gennemsnitshastigheden
		var i=this.speed.length;var x=0; var z=0;
		if(i>0)do{
			x+=this.speed[i-1][0]*i;
			z+=i;
		}while(--i);
		x/=z;

		// Udregn tidsintervallet
		var z=Math.max(0.25,(new Date().getTime()-this.speed[0][1])/this.speed.length/50);
		x=x/z*4;

		// Tilpas til grid
		if(this.dir) var x=this.wrapper.offsetLeft-Math.round((this.wrapper.offsetLeft-x+55)/200)*200;
		else var x=this.wrapper.offsetLeft-Math.round((this.wrapper.offsetLeft-x-55)/200)*200;

		// Tilføj easing
		var wrapper=this.wrapper; var z=this.wrapper.offsetLeft;
		new Effect(function(p){
			// Tjek om der er påbegyndt et nyt drag
			if(caseList.isDragging) wrapper=null;

			// Håndter scrolling
			if(wrapper){
				// Er der mere end 2 cases i venstre side?
				while(z-x*p<=-600){
					// Indlæs en reference til den første case
					var tmp=casesHandler[0];

					// Indlæs en reference til case-afslutningen
					var end=wrapper.getElementsByTagName('div');
					end=end[end.length-1];

					// Flyt den første case til sidst visuelt
					wrapper.insertBefore(tmp.container,end);
					z+=200;

					// Flyt den første case til sidst i hukommelsen
					casesHandler.splice(0,1);
					casesHandler[casesHandler.length]=tmp;

					// Ryd hukommelsen
					tmp=null; end=null;
				}

				// Er der mindre end 2 cases i venstre side?
				while(z-x*p>=-200){
					// Indlæs en reference til den første case
					var tmp=casesHandler[casesHandler.length-1];

					// Flyt den første case til sidst visuelt
					wrapper.insertBefore(tmp.container,wrapper.getElementsByTagName('div')[0]);
					z-=200;

					// Flyt den første case til sidst i hukommelsen
					casesHandler.splice(casesHandler.length-1,1);
					casesHandler.splice(0,0,tmp);

					// Ryd hukommelsen
					tmp=null;
				}

				// Scroll!
				wrapper.style.left=(z-x*p)+'px';
				
				// Afslut scrolling
				if(p==1){
					wrapper=null;
					setTimeout("document.getElementById('cursorbox').cursorState=2;",100);
				}
			}
		},{duration:0.75,ease:true});
	}else
		document.getElementById('cursorbox').cursorState=2;

	// Fade logoer op
	var fader=true;
	setTimeout(function(){
		new Effect(function(p){
			if(caseList.isDragging) fader=false;

			if(fader){
				var i=casesHandler.length; var j=i;
				if(i>0)do{
					if(document.all) casesHandler[j-i].logo_img.style.filter='alpha(opacity='+Math.round(50+50*p)+')';
					else casesHandler[j-i].logo_img.style.opacity=0.5+0.5*p;
				}while(--i);

				if(p==1){
					document.body.style.cursor='url("'+document.getElementsByTagName('base')[0].href+'templates/view/da_DK/default/cursors/hand.cur"), url("'+document.getElementsByTagName('base')[0].href+'templates/view/da_DK/default/cursors/hand.gif"), move';
					caseList.inSlideAnimation=false;
				}
			}
		},{duration:0.15,ease:false});
	},((this.speed.length && x)?500:10));

	// Angiv at der ikke dragges mere
	this.isDragging=false;

	// Afbryd eventet
	stopEvent(e);
}

/**
 * display
 *
 **********
 *
 * Viser case-listen, hvis en side har været åbnet.
 */
CaseList.prototype.display=function(e){
	// Er en animation i gang? - Så afbrydes funktionen
	if(caseList.introAnimation || caseList.isDragging || caseList.inSlideAnimation || caseList.inAnimation) return false;

	// Hvis der ikke er nogen side åben, afbrydes funktionen
	if(!pageDisplayed) return;

	// Klargør variabler
	var tmp=document.getElementById('page_wrapper');
	var tmp2=document.getElementById('cases');

	// Angiv at en animation startes
	caseList.inAnimation=true;

	// Slide ud
	new Effect(function(p){tmp.style.left=Math.round(-740*p)+'px'; tmp2.style.left=Math.round(941-740*p)+'px'; if(p==1){for(var p in pagesHandler) pagesHandler[p].container.style.display='none'; tmp=null; tmp2=null; document.getElementById('pages').style.display='none'; caseList.inAnimation=false;}},{duration:1,ease:false});

	// Fade slogan ind
	setTimeout(function(){new Effect(function(p){if(document.all) document.getElementById('slogan').style.filter='alpha(opacity='+Math.round(p*100)+')'; else document.getElementById('slogan').style.opacity=p;},{duration:0.2,ease:false});},1000);

	// Opdater menuen
	var list=document.getElementById('pagemenu').getElementsByTagName('a');
	var i=list.length; var j=i;

	if(i>0)do{
		list[j-i].className='';
	}while(--i);

	list[0].className='active'; list=null;
	Cufon.refresh('#pagemenu');

	// Vis den rigtige cursor
	document.body.style.cursor='url("'+document.getElementsByTagName('base')[0].href+'templates/view/da_DK/default/cursors/hand.cur"), url("'+document.getElementsByTagName('base')[0].href+'templates/view/da_DK/default/cursors/hand.gif"), move';

	// Angiv at ingen side er åben
	pageDisplayed=false;

	// Google Analytics
	if(window.pageTracker && window.pageTracker._trackPageview){
		// Indlæs base-url
		var url=window.location.pathname;
		if(url.charAt(url.length-1)!='/') url+='/';

		// Track sideskift!
		window.pageTracker._trackPageview(url);
	}

	// Stop eventet
	stopEvent(e);
}

/**
 * CaseHandler
 *
 **********
 *
 * Denne klasse håndterer en case på Appear.dk.
 *
 **********
 *
 * Parametre:
 * id (string)							Indeholder ID'et på casen.
 * caseID (integer)						Indeholder det eksterne ID på casen.
 */
function CaseHandler(id,caseID){
	// Indlæs en reference til containeren
	this.container=document.getElementById(id);
	this.caseID=caseID;
	this.speed=[];

	// Indlæs reference til logo, info og billeder
	var tmp=this.container.getElementsByTagName('div');
	var i=tmp.length; var j=i;

	if(i>0)do{
		if(tmp[j-i].className.toLowerCase()=='case_logo') this.logo=tmp[j-i];
		else if(tmp[j-i].className.toLowerCase()=='case_info') this.info=tmp[j-i];
		else if(tmp[j-i].className.toLowerCase()=='case_photos') this.photos=tmp[j-i];
	}while(--i);
	tmp=null; delete tmp;

	// Indlæs reference til logo billede
	var tmp=this.logo.getElementsByTagName('div');
	var i=tmp.length; var j=i;
	
	if(i>0)do{
		if(tmp[j-i].className.toLowerCase()=='case_logo_img') this.logo_img=tmp[j-i];
	}while(--i);
	tmp=null; delete tmp;

	var tmp=this.logo.getElementsByTagName('img');
	var i=tmp.length; var j=i;
	
	if(i>0)do{
		if(tmp[j-i].className.toLowerCase()=='case_logo_img') this.logo_img=tmp[j-i];
	}while(--i);
	tmp=null; delete tmp;

	// Indlæs reference til info top + beskrivelse
	var tmp=this.info.getElementsByTagName('div');
	var i=tmp.length; var j=i;

	if(i>0)do{
		if(tmp[j-i].className.toLowerCase()=='case_top') this.info_top=tmp[j-i];
		else if(tmp[j-i].className.toLowerCase()=='case_description') this.info_description=tmp[j-i];
	}while(--i);
	this.info_gradient=this.info_top.getElementsByTagName('div')[0];
	tmp=null; delete tmp;

	// Preload top-billede
	var img=new Image();
	img.src=this.logo.getElementsByTagName('img')[0].src.split('_logo.png').join('_top.jpg');

	// Tilføj over/out-events
	if(document.attachEvent){
		this.logo.getElementsByTagName('div')[0].attachEvent('mouseover',function(e){var e=e||window.event; var src=e.srcElement||e.target; while(!src.handler) src=src.parentNode; if(!src.handler.infoOver) src.handler.over(); src=null; e=null;});
		this.logo.getElementsByTagName('div')[0].attachEvent('mouseout',function(e){var e=e||window.event; var src=e.srcElement||e.target; while(!src.handler) src=src.parentNode; if(src.handler.infoOver) src.handler.out(); src=null; e=null;});
	}else{
		this.logo.getElementsByTagName('div')[0].addEventListener('onmouseover',function(e){var e=e||window.event; var src=e.srcElement||e.target; while(!src.handler) src=src.parentNode; if(!src.handler.infoOver) src.handler.over(); src=null; e=null;},false);
		this.logo.getElementsByTagName('div')[0].addEventListener('onmouseout',function(e){var e=e||window.event; var src=e.srcElement||e.target; while(!src.handler) src=src.parentNode; if(src.handler.infoOver) src.handler.out(); src=null; e=null;},false);
	}

	// Klargør variabler
	this.fadingIn=false;
	this.fadingOut=false;
	this.timer=null;
	this.infoOver=false;
	this.infoOver2=false;
	this.inSlideAnimation=false;

	// Indlæs listen over billeder
	var images=this.photos.getElementsByTagName('div')[0].innerHTML.split('|'); var res=[];
	var i=images.length; var j=i; var caseHeight=-20;
	if(i>0)do{
		// Formater info
		var tmp=images[j-i].split(':');
		res[res.length]={url:tmp[0],height:tmp[1]};
		caseHeight+=parseInt(tmp[1]);
	}while(--i);

	// Gem listen over billeder
	this.images=res; this.preloaded=0;
	this.photos.getElementsByTagName('div')[0].innerHTML='';

	// Udregn hvor mange billeder, der befinder sig 'udenfor' skærmen
	var winHeight=window.innerHeight||document.documentElement.clientHeight||document.body.clientHeight;
	this.maxScroll=Math.min(0,-(caseHeight-winHeight));
	this.caseHeight=caseHeight;

	// Lineback
	this.logo.handler=this;
	this.info.handler=this;
	this.photos.handler=this;
}

/**
 * resize
 *
 **********
 *
 * Udregner ny maks-scroll ved resize.
 */
CaseHandler.prototype.resize=function(){
	// Udregn hvor mange billeder, der befinder sig 'udenfor' skærmen
	var winHeight=window.innerHeight||document.documentElement.clientHeight||document.body.clientHeight;
	this.maxScroll=-(this.caseHeight-winHeight);

	// Opdater scroll
	this.photos.style.top=Math.min(0,Math.max(this.photos.offsetTop,this.maxScroll))+'px';
}

/**
 * over
 *
 **********
 *
 * Håndterer mouseover på logo, og fader info-kolonnen ind.
 */
CaseHandler.prototype.over=function(){
	// Afbryd evt. timer
	clearTimeout(this.timer);

	// Er der en animation igang?
	if(this.fadingIn || (!this.fadingIn && !this.fadingOut && this.infoOver)) return false;
	if(this.fadingOut){
		// Prøv igen om 50 ms
		//var t=this;
		//this.timer=setTimeout(function(){t.over(); t=null;},50);

		// Afbryd funktionen
		return false;
	}

	// Klargør variabler
	var elm=this.info;
	var elm2=this.info_top;

	// Klargør fade-in
	elm.style.opacity=0; elm.style.filter='alpha(opacity=0)';
	elm.style.display='block';

	// Angiv at vi fader
	this.fadingIn=true;
	this.fadingOut=false;
	this.infoOver=true;
	this.infoOver2=true;

	// Fade-in
	new Effect(function(p){if(document.all){elm.style.filter='alpha(opacity='+(p*100)+')';}else{elm.style.opacity=p;}  if(p==1){elm.handler.fadingIn=false; elm=null; elm2=null;}},{duration:(document.all?0.8:0.6),ease:false});

	// Ryd hukommelsen
	e=null;
}

/**
 * out
 *
 **********
 *
 * Håndterer mouseout på info-kolonnen.
 */
CaseHandler.prototype.out=function(){
	// Afbryd evt. timer
	clearTimeout(this.timer);
	this.infoOver2=false;

	// Er der en animation igang?
	if(this.fadingOut || (!this.fadingIn && !this.fadingOut && !this.infoOver)) return false;
	if(this.fadingIn){
		// Prøv igen om 50 ms
		var t=this;
		this.timer=setTimeout(function(){t.out(); t=null;},50);

		// Afbryd funktionen
		return false;
	}

	// Angiv at vi fader
	this.fadingIn=false;
	this.fadingOut=true;
	this.infoOver=false;

	// Fade-out
	var elm=this.info;
	new Effect(function(p){elm.style.opacity=(1-p); elm.style.filter='alpha(opacity='+((1-p)*100)+')'; if(p==1){elm.style.display='none'; elm.handler.fadingOut=false; tmp=null; elm=null;}},{duration:0.6,ease:false});

	// Ryd hukommelsen
	e=null;
}

/**
 * expand
 *
 **********
 *
 * Udvidder en case med flere case-billeder.
 */
CaseHandler.prototype.expand=function(){
	if(document.all) this.expandIE();
	else this.expand2();
}
CaseHandler.prototype.expand2=function(){
	// Slides der? - Så afbrydes funktionen
	if(caseList.inSlideAnimation) return false;

	// Klargør fadein
	caseList.inAnimation=true;
	this.photos.style.display='block';

	// Klargør variabler
	var container=this.photos; var wrapper=this.photos.getElementsByTagName('div')[0]; var x=caseList.wrapper.offsetLeft;
	var top=this.info_top; var description=this.info_description;

	// Slide case-oversigten mod venstre
	var l1=-(this.container.offsetLeft)+220;
	var l2=l1-caseList.wrapper.offsetLeft;
	var l3=-caseList.wrapper.offsetLeft;
	if(l2<0) setTimeout(function(){new Effect(function(p){caseList.wrapper.style.left=(l1-220-Math.round(l2*(1-p)))+'px';},{duration:0.75,ease:true});},1000);
	else if(l2>0) setTimeout(function(){new Effect(function(p){caseList.wrapper.style.left=-Math.round(l3-(l2-220)*p)+'px';},{duration:0.75,ease:true});},400);

	// Fadein + expand
	if(document.all){
		var description2=description;
		setTimeout(function(){description2.style.visibility='hidden'; description2=null;},200);
	}
	new Effect(function(p){top.style.opacity=(1-p); description.style.opacity=(1-p); top.style.filter='alpha(opacity='+Math.round(100-100*p)+')'; if(p==1){top=null; description=null;}},{duration:0.4,ease:false});
	setTimeout(function(){new Effect(function(p){var l=Math.round(220*p); container.parentNode.style.padding='0 '+l+'px 0 '+(1+l)+'px'; wrapper.style.width=(199+2*l)+'px'; if(l2<=0) caseList.wrapper.style.left=(x-l)+'px'; if(p==1){container=null; wrapper=null;}},{duration:0.75,ease:true});},400);

	// Vis den rigtige cursor
	handleCursor('dragv');

	// Angiv at en case er open
	this.isOpen=true;
	this.displayIndex=-1;
	caseList.caseOpen=this;
	document.body.style.cursor='default';

	// Begynd at preloade billederne
	var t=this; var info=this.info;
	setTimeout(function(){t.out();},1750);
	setTimeout(function(){
		// Tilføj baggrund
		t.photos.style.background='url('+document.getElementsByTagName('base')[0].href+'templates/view/da_DK/default/images/casebg.png) repeat-x bottom left';

		// Fade allerede preloadede billeder ind
		caseList.inAnimation=false;
		t.displayImage();

		// Ryd hukommelsen
		t=null;
	},2650);

	// Preload billeder
	t.preloadImage();

	// Håndter hash
	window.location.hash='case='+this.caseID;

	// Google Analytics
	if(window.pageTracker && window.pageTracker._trackPageview){
		// Indlæs base-url
		var url=window.location.pathname;
		if(url.charAt(url.length-1)!='/') url+='/';

		// Tilføj case-url
		url+='case-'+this.caseID;

		// Track sideskift!
		window.pageTracker._trackPageview(url);
	}
}
CaseHandler.prototype.expandIE=function(){
	// Slides der? - Så afbrydes funktionen
	if(caseList.inSlideAnimation) return false;

	// Klargør fadein
	caseList.inAnimation=true;
	this.photos.style.display='block';

	// Klargør variabler
	var container=this.photos; var wrapper=this.photos.getElementsByTagName('div')[0]; var x=caseList.wrapper.offsetLeft;
	var top=this.info_top; var description=this.info_description;

	// Slide case-oversigten mod venstre
	var l1=-(this.container.offsetLeft)+220;
	var l2=l1-caseList.wrapper.offsetLeft;
	var l3=-caseList.wrapper.offsetLeft;
	if(l2<0) setTimeout(function(){new Effect(function(p){caseList.wrapper.style.left=(l1-220-Math.round(l2*(1-p)))+'px';},{duration:1.25,ease:true});},1800);
	else if(l2>0) setTimeout(function(){new Effect(function(p){caseList.wrapper.style.left=-Math.round(l3-(l2-220)*p)+'px';},{duration:1.25,ease:true});},1800);

	// Fadein + expand
	if(document.all){
		var description2=description;
		setTimeout(function(){description2.style.visibility='hidden'; description2=null;},200);
	}
	new Effect(function(p){top.style.opacity=(1-p); description.style.opacity=(1-p); top.style.filter='alpha(opacity='+Math.round(100-100*p)+')'; if(p==1){top=null; description=null;}},{duration:0.8,ease:false});
	setTimeout(function(){new Effect(function(p){var l=Math.round(220*p); container.parentNode.style.padding='0 '+l+'px 0 '+(1+l)+'px'; wrapper.style.width=(199+2*l)+'px'; if(l2<=0) caseList.wrapper.style.left=(x-l)+'px'; if(p==1){container=null; wrapper=null;}},{duration:1,ease:true});},850);

	// Vis den rigtige cursor
	setTimeout("handleCursor('dragv');",3000);

	// Angiv at en case er open
	this.isOpen=true;
	this.displayIndex=-1;
	caseList.caseOpen=this;
	document.body.style.cursor='default';

	// Begynd at preloade billederne
	var t=this; var info=this.info;
	setTimeout(function(){t.out();},3100);
	setTimeout(function(){
		// Tilføj baggrund
		t.photos.style.background='url('+document.getElementsByTagName('base')[0].href+'templates/view/da_DK/default/images/casebg.png) repeat-x bottom left';

		// Fade allerede preloadede billeder ind
		caseList.inAnimation=false;
		t.displayImage();

		// Ryd hukommelsen
		t=null;
	},3900);

	// Preload billeder
	t.preloadImage();

	// Håndter hash
	window.location.hash='case='+this.caseID;

	// Google Analytics
	if(window.pageTracker && window.pageTracker._trackPageview){
		// Indlæs base-url
		var url=window.location.pathname;
		if(url.charAt(url.length-1)!='/') url+='/';

		// Tilføj case-url
		url+='case-'+this.caseID;

		// Track sideskift!
		window.pageTracker._trackPageview(url);
	}
}

/**
 * initDrag
 *
 **********
 *
 * Klargører drag'n'drop-scrolling af case billederne.
 *
 **********
 *
 * Parametre:
 * e (eventinfo)						Indeholder informationer om brugerens inputs.
 */
CaseHandler.prototype.initDrag=function(e){
	// Indlæs informationer om brugerens inputs.
	this.y=e.clientY||e.pageY;

	// Vis rigtig cursor
	if(!this.inSlideAnimation){
		this.photos.style.cursor='url("'+document.getElementsByTagName('base')[0].href+'templates/view/da_DK/default/cursors/hand2.cur"), url("'+document.getElementsByTagName('base')[0].href+'templates/view/da_DK/default/cursors/hand2.gif"), move';
		var list=this.photos.getElementsByTagName('div'); var list2=this.photos.getElementsByTagName('img');
		var i=list.length; var j=i;
		if(i>0)do{
			try{list[j-i].style.cursor='url("'+document.getElementsByTagName('base')[0].href+'templates/view/da_DK/default/cursors/hand2.cur"), url("'+document.getElementsByTagName('base')[0].href+'templates/view/da_DK/default/cursors/hand2.gif"), move';}catch(e){}
			try{list2[j-i].style.cursor='url("'+document.getElementsByTagName('base')[0].href+'templates/view/da_DK/default/cursors/hand2.cur"), url("'+document.getElementsByTagName('base')[0].href+'templates/view/da_DK/default/cursors/hand2.gif"), move';}catch(e){}
		}while(--i);
	}

	// Angiv at drag'n'drop er aktiveret
	this.isDragging=true;
	this.inSlideAnimation=true;
	this.speed=[];

	// Afbryd eventet
	stopEvent(e);
}

/**
 * drag
 *
 **********
 *
 * Håndterer drag'n'drop-scrolling af case billederne.
 *
 **********
 *
 * Parametre:
 * e (eventinfo)						Indeholder informationer om brugerens inputs.
 */
CaseHandler.prototype.drag=function(e){
	// Indlæs informationer om brugerens inputs
	var y=this.y-(e.clientY||e.pageY);

	// Trækkes der mod højre eller venstre?
	this.dir=(e.clientY||e.pageY)>this.y;

	// Udregn gennemsnits hastighed
	this.speed[this.speed.length]=[y,new Date().getTime()];
	if(this.speed.length>5) this.speed.splice(0,1);

	// Gem musens placering
	this.y=e.clientY||e.pageY;

	// Udregn placering
	var y=(this.photos.getElementsByTagName('div')[0].offsetTop-y);
	y=Math.max(this.maxScroll,Math.min(0,y));

	// Scroll!
	this.photos.getElementsByTagName('div')[0].style.top=y+'px';

	// Afbryd eventet
	stopEvent(e);
}

/**
 * endDrag
 *
 **********
 *
 * Afslutter drag'n'drop-scrolling af case billederne.
 *
 **********
 *
 * Parametre:
 * e (eventinfo)						Indeholder informationer om brugerens inputs.
 */
CaseHandler.prototype.endDrag=function(e){
	// Håndter easing
	if(this.speed.length){
		// Udregn gennemsnitshastigheden
		var i=this.speed.length;var y=0; var z=0;
		if(i>0)do{
			y+=this.speed[i-1][0]*i;
			z+=i;
		}while(--i);
		y/=z;

		// Udregn tidsintervallet
		var z=(new Date().getTime()-this.speed[0][1])/this.speed.length/50;
		y=y/z*5.5;

		// Tilpas til grid
		y=this.photos.getElementsByTagName('div')[0].offsetTop-Math.max(this.maxScroll,Math.min(0,Math.round(this.photos.getElementsByTagName('div')[0].offsetTop-y)));

		// Tilføj easing
		var t=this; var z=this.photos.getElementsByTagName('div')[0].offsetTop;
		new Effect(function(p){if(t && t.isDragging) t=null; if(t) t.photos.getElementsByTagName('div')[0].style.top=(z-y*p)+'px'; if(p==1) t=null;},{duration:1,ease:true});
	}

	// Angiv at der ikke dragges mere
	this.isDragging=false;
	this.speed=[];

	// Vis rigtig cursor
	var t2=this;
	setTimeout(function(){
		t2.photos.style.cursor='url("'+document.getElementsByTagName('base')[0].href+'templates/view/da_DK/default/cursors/hand.cur"), url("'+document.getElementsByTagName('base')[0].href+'templates/view/da_DK/default/cursors/hand.gif"), move';
		var list=t2.photos.getElementsByTagName('div'); var list2=t2.photos.getElementsByTagName('img');
		var i=list.length; var j=i;
		if(i>0)do{
			try{list[j-i].style.cursor='url("'+document.getElementsByTagName('base')[0].href+'templates/view/da_DK/default/cursors/hand.cur"), url("'+document.getElementsByTagName('base')[0].href+'templates/view/da_DK/default/cursors/hand.gif"), move';}catch(e){}
			try{list2[j-i].style.cursor='url("'+document.getElementsByTagName('base')[0].href+'templates/view/da_DK/default/cursors/hand.cur"), url("'+document.getElementsByTagName('base')[0].href+'templates/view/da_DK/default/cursors/hand.gif"), move';}catch(e){}
		}while(--i);
		t2.inSlideAnimation=false;
		t2=null;
	},(this.speed.length?1000:10))

	// Afbryd eventet
	stopEvent(e);
}

/**
 * close
 *
 **********
 * Lukker flere case-billeder ned.
 */
CaseHandler.prototype.close=function(){
	// Fade billederne ud
	caseList.inAnimation=true; var t=this;
	var photos=this.photos.getElementsByTagName('img'); var slideup=this.photos.getElementsByTagName('div')[0]; var z=slideup.offsetTop; var timeoutDelay=z?700:10;
	new Effect(function(p){slideup.style.top=Math.round(z-z*p)+'px'; if(p==1) slideup=null;},{duration:0.7,ease:true});
	setTimeout(function(){t.photos.style.background='none'; new Effect(function(p){var i=photos.length; var j=i; if(i>0)do{photos[j-i].style.opacity=(1-p); photos[j-i].style.filter='alpha(opacity='+Math.round(100-100*p)+')';}while(--i); if(p==1){var i=photos.length; var j=i; if(i>0)do{photos[j-i].style.visibility='hidden';}while(--i); photos=null;}},{duration:0.4,ease:false});},timeoutDelay);

	// Fade logo ind
	var info=this.info; info.style.display='block';
	setTimeout(function(){new Effect(function(p){info.style.opacity=p; info.style.filter='alpha(opacity='+Math.round(100*p)+')';},{duration:0.4,ease:false});},700+timeoutDelay);

	// Collapse til 1 kolonnes bredde
	var container=this.photos; var wrapper=this.photos.getElementsByTagName('div')[0]; var t=this; var x=caseList.wrapper.offsetLeft;
	setTimeout(function(){new Effect(function(p){var l=Math.round(220*p); container.parentNode.style.padding='0 '+(220-l)+'px 0 '+(1+220-l)+'px'; wrapper.style.width=(639-2*l)+'px'; caseList.wrapper.style.left=Math.round(x+200*p)+'px'; if(p==1){container.style.display='none'; container=null; wrapper=null;}},{duration:0.7,ease:true});},1300+timeoutDelay);

	// Fade kolonnen helt ud
	setTimeout(function(){new Effect(function(p){info.style.opacity=(1-p); info.style.filter='alpha(opacity='+Math.round(100-100*p)+')'; if(p==1){info.style.display='none'; info.handler.info_top.style.opacity=1; info.handler.info_description.style.opacity=1; info.handler.info_top.style.filter='alpha(opacity=100)'; info.handler.info_description.style.visibility='visible'; info=null; caseList.inAnimation=false;}},{duration:0.4,ease:false});},2200+timeoutDelay);
	setTimeout(function(){t.isOpen=false; caseList.caseOpen=null; document.body.style.cursor='url("'+document.getElementsByTagName('base')[0].href+'templates/view/da_DK/default/cursors/hand.cur"), url("'+document.getElementsByTagName('base')[0].href+'templates/view/da_DK/default/cursors/hand.gif"), move'; handleCursor('dragh'); t=null; if(caseList.onClosed){caseList.onClosed(); caseList.onClosed=null;}},2600+timeoutDelay);

	// Håndter hash
	window.location.hash='collapsed';

	// Google Analytics
	if(window.pageTracker && window.pageTracker._trackPageview){
		// Indlæs base-url
		var url=window.location.pathname;
		if(url.charAt(url.length-1)!='/') url+='/';

		// Track sideskift!
		window.pageTracker._trackPageview(url);
	}
}

/**
 * preloadImage
 *
 **********
 *
 * Preloader et billede i listen.
 */
CaseHandler.prototype.preloadImage=function(){
	// Er alle billeder preloaded?
	if(this.preloaded>=this.images.length || !this.isOpen) return;

	// Opdater antal preloadede billeder
	var preloaded=this.preloaded;

	// Klargør elementer
	var div=document.createElement('div');
	var img=document.createElement('img');

	// Vis preloaderen
	div.style.height=this.images[preloaded].height+'px';
	img.style.height=this.images[preloaded].height+'px';
	img.style.opacity=0;
	img.style.filter='alpha(opacity=0)';

	// Håndter preloading
	var t=this;
	img.onload=function(){div.appendChild(img); div.style.background='none'; t.preloaded++; if(t.displayIndex>-1) t.displayImage(); t.preloadImage(); t=null;}
	img.onerror=function(){div.appendChild(img); div.style.background='none'; img=null; t.preloaded++; if(t.displayIndex>-1) t.displayImage(); t.preloadImage(); t=null;}
	img.onabort=function(){div.appendChild(img); div.style.background='none'; img=null; t.preloaded++; if(t.displayIndex>-1) t.displayImage(); t.preloadImage(); t=null;}

	// Indlæs billedet
	img.src=this.images[preloaded].url;
	this.photos.getElementsByTagName('div')[0].appendChild(div);
}

CaseHandler.prototype.displayImage=function(){
	// Denne funktion må kun køres, hvis en case vises
	if(!this.isOpen) return false;

	// Angiv at billeder må vises
	this.displayIndex=Math.max(0,this.displayIndex);

	// Er der flere billeder at vise?
	if(this.displayIndex>=this.preloaded || this.displayIndex>=this.images.length) return;

	// Indlæs en reference til det billede, der skal vises
	var img=this.photos.getElementsByTagName('img')[this.displayIndex];
	this.displayIndex++;

	// Fadein
	var t=this; img.style.visibility='visible';
	new Effect(function(p){if(!caseList.inAnimation){img.style.opacity=p; img.style.filter='alpha(opacity='+Math.round(100*p)+')';} if(p==1){img=null; t.displayImage(); t=null;}},{duration:0.4,ease:false});
}

/**
 * mouseWheel
 *
 *********
 *
 * Håndterer mousewheel-scrolling af case fotos.
 *
 *********
 *
 * Parametre:
 * e (eventinfo)						Indeholder brugerens inputs.
 */
CaseHandler.prototype.mouseWheel=function(e){
	// Klargør variabler
	if(this.mouseWheelTimer) clearTimeout(this.mouseWheelTimer);
	this.inSlideAnimation=true;

	// Indlæs brugerens inputs
	var e=e||window.event;
	var scroll=e.detail? e.detail*(-120): e.wheelDelta;
	scroll=Math.round(scroll/20);

	// Udregn gennemsnits hastighed
	this.speed[this.speed.length]=[-scroll,new Date().getTime()];
	if(this.speed.length>5) this.speed.splice(0,1);

	// Udregn placering
	var y=this.photos.getElementsByTagName('div')[0].offsetTop+scroll;
	y=Math.max(this.maxScroll,Math.min(0,y));

	// Scroll!
	this.photos.getElementsByTagName('div')[0].style.top=y+'px';

	// Håndter easing af scroll
	var t=this;
	this.mouseWheelTimer=setTimeout(function(){
		// Angiv at der ikke scrolles længere
		t.inSlideAnimation=false;

		// Håndter easing
		if(t.speed.length){
			// Udregn gennemsnitshastigheden
			var i=t.speed.length;var y=0; var z=0;
			if(i>0)do{
				y+=t.speed[i-1][0]*i;
				z+=i;
			}while(--i);
			y/=z;

			// Udregn tidsintervallet
			var z=50/((new Date().getTime()-t.speed[0][1])/t.speed.length);
			y=y/z*7.5;

			// Tilpas til grid
			y=t.photos.getElementsByTagName('div')[0].offsetTop-Math.max(t.maxScroll,Math.min(0,Math.round(t.photos.getElementsByTagName('div')[0].offsetTop-y)));

			// Tilføj easing
			var t2=t; var z=t.photos.getElementsByTagName('div')[0].offsetTop;
			new Effect(function(p){if(t2 && (t2.isDragging || t2.inSlideAnimation)) t2=null; if(t2) t2.photos.getElementsByTagName('div')[0].style.top=(z-y*p)+'px'; if(p==1){if(t2) t2.speed=[]; t2=null;}},{duration:1,ease:true});

			// Ryd hukommelsen
			t=null;
		}
	},30);
}

/**
 * PageHandler
 *
 **********
 *
 * Håndterer indholdssider.
 *
 **********
 *
 * pageID (string)						Indeholder ID'et på siden.
 */
function PageHandler(pageID){
	// Indlæs en reference til containeren
	this.container=document.getElementById(pageID);
	this.link=document.getElementById(pageID+'_link');
	this.url=encodeURIComponent(this.link.innerHTML.split(' ').join('-').toLowerCase());

	// Indlæs referencer til elementer
	var list=this.container.getElementsByTagName('div');
	this.top=list[0];
	this.wrapper=list[1];
	this.bottom=list[list.length-1];

	// Ryd hukommelsen
	list=null;
}

/**
 * display
 *
 **********
 *
 * Viser den valgte side.
 */
PageHandler.prototype.display=function(e){
	// Er en animation i gang? - Så afbrydes funktionen
	if(window.caseList && !caseList.introAnimation && !caseList.isDragging && !caseList.inSlideAnimation && !caseList.inAnimation){
		// Er siden allerede aktiv? - Så afbrydes funktionen
		if(this.link.className.toLowerCase()!='active'){
			// Angiv at en animation er i gang
			caseList.inAnimation=true;

			// Vises en case?
			if(caseList.caseOpen) this.doHideDisplay();
			else if(pageDisplayed) this.doSwitchDisplay();
			else this.doDisplay(false);

			// Angiv at en side vises
			pageDisplayed=true;

			// Google Analytics
			if(window.pageTracker && window.pageTracker._trackPageview){
				// Indlæs base-url
				var url=window.location.pathname;
				if(url.charAt(url.length-1)!='/') url+='/';

				// Tilføj side-url
				url+=this.url;

				// Track sideskift!
				window.pageTracker._trackPageview(url);
			}

			// Stop eventet
			stopEvent(e);
		}
	}
}
PageHandler.prototype.doHideDisplay=function(){
	// Skjul først den åbne case
	var t=this;
	caseList.onClosed=function(){t.doDisplay(false); t=null;}
	caseList.caseOpen.close();

	// Opdater menuen
	var list=document.getElementById('pagemenu').getElementsByTagName('a');
	var i=list.length; var j=i;

	if(i>0)do{
		list[j-i].className='';
	}while(--i);
	list=null;

	this.link.className='active';
	Cufon.refresh('#pagemenu');

	handleCursor('none');
}
PageHandler.prototype.doSwitchDisplay=function(){
	// Klargør variabler
	var tmp=document.getElementById('page_wrapper');
	var tmp2=document.getElementById('cases');

	// Slide først den pt. valgte side ud
	new Effect(function(p){tmp.style.left=Math.round(-740*p)+'px'; tmp2.style.left=Math.round(941-740*p)+'px';},{duration:1,ease:true});

	// Opdater menuen
	var list=document.getElementById('pagemenu').getElementsByTagName('a');
	var i=list.length; var j=i;

	if(i>0)do{
		list[j-i].className='';
	}while(--i);
	list=null;

	this.link.className='active';
	Cufon.refresh('#pagemenu');

	// Slide derefter den nye side ind
	var t=this;
	setTimeout(function(){t.doDisplay(true); t=null;},1200);
}
PageHandler.prototype.doDisplay=function(isSwitch){
	// Klargør variabler
	var tmp=document.getElementById('page_wrapper');
	var tmp2=document.getElementById('cases');

	// Skjul alle sider
	for(var p in pagesHandler) pagesHandler[p].container.style.display='none';

	// Klargør slide-in
	tmp.style.left='-740px';
	document.getElementById('pages').style.display='block';
	this.container.style.display='block';
	document.body.style.cursor='auto';

	// Håndter top/bund margen
	this.top.style.height='0px'; this.bottom.style.height='0px';

	var winHeight=window.innerHeight||document.documentElement.clientHeight||document.body.clientHeight;
	var pageHeight=this.wrapper.offsetHeight+40;

	this.top.style.height=Math.max(0,Math.round((winHeight-pageHeight)/2))+'px';
	this.bottom.style.height=Math.max(0,Math.round((winHeight-pageHeight)/2))+'px';

	// Slide siden ind
	setTimeout(function(){new Effect(function(p){tmp.style.left=Math.round(740*p-740)+'px'; tmp2.style.left=Math.round(740*p+201)+'px'; if(p==1){tmp=null; tmp2=null; caseList.inAnimation=false;}},{duration:1,ease:true});},(!isSwitch?250:1));

	// Fade slogan ud
	if(!isSwitch) new Effect(function(p){if(document.all) document.getElementById('slogan').style.filter='alpha(opacity='+Math.round(100-p*100)+')'; else document.getElementById('slogan').style.opacity=(1-p);},{duration:0.2,ease:false});

	// Opdater menuen
	var list=document.getElementById('pagemenu').getElementsByTagName('a');
	var i=list.length; var j=i;

	if(i>0)do{
		list[j-i].className='';
	}while(--i);
	list=null;

	this.link.className='active';
	Cufon.refresh('#pagemenu');
}

/**
 * handleCursor
 *
 **********
 *
 * Håndterer cursor-boksen.
 *
 **********
 *
 * Parametre:
 * state (string)						Angiv hvilket cursorens state.
 */
function handleCursor(state){
	// Indlæs en reference til cursorboksen
	var tmp=document.getElementById('cursorbox');
	clearTimeout(tmp.delay);

	// Er cursoren allerede i det rigtige state?
	if(!window.cursorboxHandler) return false;
	if(tmp.state==state && (tmp.fadedIn || tmp.fadingIn)) return false;

	// Ellers skifter vi state efter 50 ms
	tmp.delay=setTimeout("handleCursor2('"+state+"');",50);
}
function handleCursor2(state){
	// Indlæs en reference til cursorboksen
	var tmp=document.getElementById('cursorbox');
	var tmp2=document.getElementById('slogan');
	tmp.style.width='auto';
	clearTimeout(tmp.timer); clearTimeout(tmp2.timer);
	clearTimeout(tmp.delay);

	// Fades der ind?
	if(tmp.fadingIn){
		// Prøv igen om 50 ms
		tmp.timer=setTimeout("handleCursor2('"+state+"');",50);
		return;
	}

	// Fades der ud?
	if(!tmp.fadingOut && !tmp.fadedOut){
		// Begynd at fade ud
		new Effect(function(p){tmp.style.opacity=(1-p); tmp.style.filter='alpha(opacity='+(100-p*100)+')'; if(p==1){tmp.fadedOut=true; tmp.fadingOut=false; tmp.className=''; tmp.style.display='none'; tmp=null;}},{duration:0.15,ease:false});
		if(!tmp2.isHidden && state!='none' && state!='dragh'){
			tmp2.isHidden=true;
			new Effect(function(p){tmp2.style.opacity=(1-p); tmp2.style.filter='alpha(opacity='+(100-p*100)+')'; if(p==1){tmp2=null;}},{duration:0.15,ease:false});
		}
		tmp.fadingOut=true;
		tmp.fadedIn=false;
		tmp.fadingIn=false;
	}

	// Er cursoren fadet ud endnu?
	if(!tmp.fadedOut && !tmp.fadedIn){
		// Prøv igen om 50 ms
		tmp.timer=setTimeout("handleCursor2('"+state+"');",50);
		return;
	}

	// Skal der vises en cursor?
	if(state!='none'){
		// Indsæt tekst
		tmp.getElementsByTagName('span')[0].innerHTML=cursorboxHandler[state];
		Cufon.replace('#cursorbox');

		// Vis tooltip'et
		tmp.className=state;
		tmp.style.display='block';
		tmp.style.width='300px';
		tmp.getElementsByTagName('span')[0].style.width='auto';
		tmp.getElementsByTagName('span')[0].style.width=tmp.getElementsByTagName('span')[0].offsetWidth+'px';
		tmp.style.width=tmp.getElementsByTagName('span')[0].offsetWidth+'px';

		// Begynd at fade ind
		if(!tmp.fadedIn && !tmp.fadingIn){
			tmp.timer=new Effect(function(p){tmp.style.opacity=p; tmp.style.filter='alpha(opacity='+(p*100)+')'; if(p==1){tmp.fadedIn=true; tmp.fadingIn=false; tmp=null;}},{duration:0.15,ease:false});
			if((state=='none' || state=='dragh') && tmp2.isHidden){
				tmp2.isHidden=false;
				tmp2.timer=new Effect(function(p){tmp2.style.opacity=p; tmp2.style.filter='alpha(opacity='+(p*100)+')'; if(p==1){tmp2=null;}},{duration:0.15,ease:false});
			}

			tmp.fadingIn=true;
			tmp.fadingOut=false;
			tmp.fadedOut=false;
		}
	}

	tmp.state=state;
}

/**
 * mouseMove
 *
 **********
 *
 * Håndterer mousemove-eventet.
 *
 **********
 *
 * Parametre:
 * e (eventinfo)						Indeholder informationer om brugerens inputs.
 */
function mouseMove(e){
	// Indlæs info om brugerens inputs
	var e=e||window.event;
	var src=e.srcElement||e.target;

	// Flyt cursorboxen
	var tmp=document.getElementById('cursorbox');
	try{
		if(tmp.cursorState!=1){
			tmp.style.left=((e.clientX||e.pageX)+10)+'px';
			tmp.style.top=((e.clientY||e.pageY)+15)+'px';
		}
		if(tmp.cursorState==2){
			tmp.style.visibility='visible';
			tmp.cursorState=0;
		}
	}catch(e){}

	// Afbryd event hvis en side vises
	if(pageDisplayed){
		// Skal der vises en lukke-cursor?
		var casesIsOver=false;
		while(src){if(src && src.id && src.id.toLowerCase()=='cases'){casesIsOver=true; break;} src=src.parentNode;}

		// Vis den rigtige cursor
		if(!casesIsOver) handleCursor('none');
		else handleCursor('close2');		

		// Afbryd yderligere eksekvering af funktionen
		stopEvent(e);
		return false;
	}

	// Afbryd event hvis intro-animationen er igang
	if(window.caseList && caseList.introAnimation){
		stopEvent(e);
		return false;
	}

	// Annuller eventet, hvis musen føres over cursorboksen
	if((src && src.id && src.id.toLowerCase()=='cursorbox') || (src && src.parentNode && src.parentNode.id && src.parentNode.id.toLowerCase()=='cursorbox')){
		stopEvent(e);
		return false;
	}

	// Klargør variabler
	var caseOver=false;
	var photosOver=false;
	var linkOver=false;

	// Er musen over et link?
	var tmp=src;
	while(tmp){if(tmp.tagName && tmp.tagName.toLowerCase()=='a'){linkOver=true; break;} tmp=tmp.parentNode;}

	// Gennemgå listen over cases og håndter mouseover/out
	if(window.caseList && !caseList.isDragging && !caseList.inAnimation){
		var i=casesHandler.length; var j=i;
		if(i>0)do{
			// Er musen over denne case?
			var tmp=src; var over=false; var over2=false;
			while(tmp){
				// Gennemgå og tjek alle child-elementer for, om musen er ført over denne case
				if(tmp==casesHandler[j-i].info || tmp==casesHandler[j-i].logo.getElementsByTagName('div')[0]) over=true;
				if(tmp==casesHandler[j-i].photos) over2=true;

				// Loop
				tmp=tmp.parentNode;
			}
			tmp=null;

			// Håndter mouseover/out
			if(over && !casesHandler[j-i].infoOver && window.caseList && !caseList.caseOpen) casesHandler[j-i].over();
			else if(!over && casesHandler[j-i].infoOver && window.caseList && !caseList.caseOpen) casesHandler[j-i].out();

			// Håndter scrolling
			if(casesHandler[j-i].isDragging) casesHandler[j-i].drag(e);

			// Registrer om musen holdes over photos
			casesHandler[j-i].photosOver=over2;

			// Er musen over nogen af casesne?
			caseOver|=over;
			photosOver|=over2;
		}while(--i);
	}

	// Skal der scrolles i oversigten?
	if(window.caseList && caseList.isDragging && !pageDisplayed) caseList.drag(e);

	// Skal drag'n'drop af case-photos vises?
	if(window.caseList && caseList.caseOpen && (caseList.caseOpen.photosOver || caseList.caseOpen.caseOver) && !pageDisplayed) handleCursor('dragv');

	// Skal 'luk denne case' vises?
	else if(window.caseList && caseList.caseOpen && !linkOver && !pageDisplayed) handleCursor('close');

	// Skal 'vis mere info' vises?
	else if(caseOver && !pageDisplayed) handleCursor('more');

	// Skal drag'n'drop scrolling af cases vises?
	else if(!linkOver && !pageDisplayed) handleCursor('dragh');

	// Ellers skjuler vi tooltippet
	else handleCursor('none');

	// Afbryd eventet
	stopEvent(e);

	// Ryd hukommelsen
	e=null;
	src=null;
	tmp=null;
}

/**
 * mouseDown
 *
 **********
 *
 * Håndterer mousedown-eventet.
 *
 **********
 *
 * Parametre:
 * e (eventinfo)						Indeholder informationer om brugerens inputs.
 */
function mouseDown(e){
	// Afbryd event hvis intro-animationen er igang
	if(window.caseList && caseList.introAnimation){
		stopEvent(e);
		return false;
	}

	// Hvis en animation er igang, afbrydes funktionen
	if(window.caseList && caseList.inAnimation){
		stopEvent(e);
		return;
	}

	// Afbryd event hvis en side vises
	if(pageDisplayed){
		stopEvent(e);
		return false;
	}

	// Indlæs informationer om brugerens inputs.
	var e=e||window.event;
	var src=e.srcElement||e.target;

	// Er musen over et link?
	var tmp=src; var linkOver=false;
	while(tmp){if(tmp.tagName && tmp.tagName.toLowerCase()=='a'){linkOver=true; break;} tmp=tmp.parentNode;}

	// Er musen over en case-info?
	if(!linkOver){
		var i=casesHandler.length; var j=i; var infoOver=false; var photosOver=false;
		if(i>0)do{
			// Er musen over denne case?
			if(casesHandler[j-i].infoOver2) infoOver=true;
			if(casesHandler[j-i].photosOver) photosOver=casesHandler[j-i];
		}while(--i);
	}

	// Tjek om case-oversigten skal drag-droppes
	if(!infoOver && !photosOver && !linkOver && !caseList.caseOpen) caseList.initDrag(e);
	else if(photosOver) photosOver.initDrag(e);
	photosOver=null;

	// Afbryd eventet
	stopEvent(e);

	// Ryd hukommelsen
	src=null;
	e=null;
}

/**
 * mouseUp
 *
 **********
 *
 * Håndterer mouseup-eventet.
 *
 **********
 *
 * Parametre:
 * e (eventinfo)						Indeholder informationer om brugerens inputs.
 */
function mouseUp(e){
	// Afbryd event hvis intro-animationen er igang
	if(window.caseList && caseList.introAnimation){
		stopEvent(e);
		return false;
	}
	
	// Hvis en animation er igang, afbrydes funktionen
	if(window.caseList && caseList.inAnimation){
		stopEvent(e);
		return;
	}
	
	// Afbryd event hvis en side vises
	if(pageDisplayed){
		// Blev der klikket på cases?
		var e=e||window.event;
		var src=e.srcElement||e.target;
		var casesClicked=false;

		while(src){if(src && src.id && src.id.toLowerCase()=='cases'){casesClicked=true; break;} src=src.parentNode;}
		if(casesClicked) caseList.display();

		// Afbryd eventet
		stopEvent(e);
		return false;
	}

	// Indlæs informationer om brugerens inputs.
	var e=e||window.event;
	
	// Er musen over en case-info?
	var i=casesHandler.length; var j=i; var over=false;
	if(i>0)do{
		// Er musen over denne case?
		if(casesHandler[j-i].infoOver2) casesHandler[j-i].expand();
		else if(casesHandler[j-i].isDragging) casesHandler[j-i].endDrag(e);
		else if(casesHandler[j-i].isOpen && !casesHandler[j-i].photosOver) casesHandler[j-i].close();
	}while(--i);
	
	// Skal drag-drop afsluttes i case-oversigten?
	if(caseList.isDragging) caseList.endDrag(e);
	
	// Ryd hukommelsen
	stopEvent(e);
	e=null;
}

/**
 * mouseWheel
 *
 **********
 *
 * Håndter scrolling via mousewheel'et.
 *
 **********
 *
 * Parametre:
 * e (eventinfo)						Indeholder informationer om brugerens inputs.
 */
function mouseWheel(e){
	// Er en case åbn?
	if(!window.caseList || !window.caseList.caseOpen || window.caseList.inAnimation || window.caseList.inSlideAnimation || window.caseList.introAnimation){
		stopEvent(e);
		return false;
	}

	// Håndter scrollingen
	caseList.caseOpen.mouseWheel(e);
	stopEvent(e);
}

/**
 * resize
 *
 **********
 *
 * Håndterer onresize-eventet.
 */
function resize(){
	// Opdater info i case-listen
	try{
		if(!caseList) return;
	}catch(e){
		return;
	}
	caseList.resize();

	// Opdater info i cases
	var i=casesHandler.length; var j=i;
	if(i>0)do{casesHandler[j-i].resize();}while(--i);
}

// Håndter events
if(document.attachEvent){
	document.attachEvent('onmousemove',mouseMove);
	document.attachEvent('onmousedown',mouseDown);
	document.attachEvent('onmouseup',mouseUp);
	window.attachEvent('onresize',resize);
	document.attachEvent('onscroll',stopEvent);
	document.attachEvent('onmousewheel',mouseWheel,false);
}else{
	var mousewheelevt=(/Firefox/i.test(navigator.userAgent))? "DOMMouseScroll" : "mousewheel";
	window.addEventListener('mousemove',mouseMove,false);
	window.addEventListener('mousedown',mouseDown,false);
	window.addEventListener('mouseup',mouseUp,false);
	window.addEventListener('resize',resize,false);
	window.addEventListener('scroll',stopEvent,false);
	document.addEventListener(mousewheelevt,mouseWheel,false);
}

// Klargør tooltip'et
document.getElementById('cursorbox').state='none';
document.getElementById('cursorbox').fadedOut=false;

// Klargør variabler
pageDisplayed=false;
var imgGradient=new Image();
imgGradient.src=document.getElementsByTagName('base')[0].href+'templates/view/da_DK/default/images/casegradient.png';

/**
 * stopEvent
 *
 **********
 *
 * Afbryder et event.
 *
 **********
 *
 * Parametre:
 * e (eventinfo)						Indeholder informationer om brugerens inputs.
 */
function stopEvent(e){
	// Indlæs informationer om brugerens inputs
	var e=e||window.event;

	// Afbryd event
	if(e.preventDefault)e.preventDefault();
	if(e.stopPropagation)e.stopPropagation();
	if(e.stop)e.stop();
	if(document.all&&e.keyCode)try{e.keyCode=0;}catch(e){}
	e.cancelBubble=true;
	e.returnValue=false;
}