// Globals
var intBackgroundMarginMultiplier = 1.1;

var bolPlayerActive = false;
var intPlayerAnimationDuration = 600;
var intPlayerAnimationDelay1 = 200;
var intPlayerAnimationDelay2 = 400;
var intPlayerAnimationDelay3 = 300;
var intPlayerAnimationDelay4 = 1000;
var intPlayerAnimationType1 = Fx.Transitions.lineair;
var intPlayerAnimationType2 = Fx.Transitions.Cubic.easeInOut;

var bolPlayerZoom = false;
var intPlayerZoomTop = 9;

var intSlideDistance = 1000;
var bolSlide = false;

var arrPlayerBlurImages=[], arrPlayerImages=[], arrPlayerThumbs=[], arrPlayerTitles=[], arrPlayerSubTitles=[];

function resizeBackground(strBackground, strDuration, bolScroll){
	
	if($(strBackground) && $(strBackground+'_image')){
	
		// Background Ratio
		var intRatioWidth = objWdkaVariables.intBackgroundWidth;
		var intRatioHeight = objWdkaVariables.intBackgroundHeight;
			
		var intWindowWidth;
		var intWindowHeight;
		
		var intNewWindowWidth = 500;
		var intNewWindowHeight = 500;
		
		if(bolScroll == true){
			intWindowWidth = objWdkaVariables.intWindowWidth;
			intWindowHeight = window.getScrollHeight();
		}
		else{
			intWindowWidth = objWdkaVariables.intWindowWidth;
			intWindowHeight = objWdkaVariables.intWindowHeight;
		}
	
		if((intRatioWidth / intRatioHeight) < (intWindowWidth/intWindowHeight)){
			// scale and reposition background image (vertical)
			intNewWindowWidth = intWindowWidth;
			intNewWindowHeight = intWindowWidth / (intRatioWidth / intRatioHeight);
			
			
			var objBackgroundFX = new Fx.Morph(strBackground, {duration: strDuration});
			objBackgroundFX.start({
				'margin-left': 0, 
				'margin-top': '-'+((intNewWindowHeight - intWindowHeight) / 2)+'px', 
				'width': (intNewWindowWidth * intBackgroundMarginMultiplier), 
				'height': (intNewWindowHeight * intBackgroundMarginMultiplier)
			});
		}
		else{
			// scale and reposition background image  (horizontal)
			intNewWindowHeight = intWindowHeight;
			intNewWindowWidth = (intRatioWidth / intRatioHeight) * intWindowHeight;
			
			var objBackgroundFX = new Fx.Morph(strBackground, {duration: strDuration});
			objBackgroundFX.start({
				'margin-left': '-'+((intNewWindowWidth - intWindowWidth) / 2)+'px', 
				'margin-top': 0, 
				'width': (intNewWindowWidth * intBackgroundMarginMultiplier), 
				'height': (intNewWindowHeight * intBackgroundMarginMultiplier) 
			});
		}
	
		// scale the image itself
		var objBackgroundFX = new Fx.Morph(strBackground+'_image', { duration: strDuration });
		objBackgroundFX.start({
			'width': (intNewWindowWidth * intBackgroundMarginMultiplier),
			'height': (intNewWindowHeight * intBackgroundMarginMultiplier)
		});
		
		if(strBackground == 'background_full'){
			//IE Fix / Shadow
			objWdkaElements.background_full.getElements('div[class=sh_ml]').setStyles({ 'height':  (intNewWindowWidth * intBackgroundMarginMultiplier) });
			objWdkaElements.background_full.getElements('div[class=sh_mr]').setStyles({ 'height': (intNewWindowWidth * intBackgroundMarginMultiplier) });
		}
	}
}

function loadBackground(){
	//	full image if home
	if(objWdkaElements.content_home){
		strBackgroundImageSmall = strBackgroundImageFull;
	}
	objBackgroundImageSmall = new Asset.image(strBackgroundImageSmall, {id: 'background_image', onload: displayBackground });
	objBackgroundImageSmall.inject(objWdkaElements.background,'inside');
}

var bolRunOnce = false; // FIX for mootools, when image is chached, the onload function gets fired twice
function displayBackground(){
	if(bolRunOnce == false){
		
		bolRunOnce = true;	
		// set variables
		var ratioImage = new Image();
		ratioImage.src = strBackgroundImageSmall;
		objWdkaVariables.intBackgroundWidth = ratioImage.width;
		objWdkaVariables.intBackgroundHeight = ratioImage.height;
		
		// set properties to small bg image
		objWdkaElements.background.setStyles({ 'opacity': 0 });
		objWdkaElements.background.setStyles({ 'display': 'block'});
	
		// resize small background image	
		resizeBackground('background', 0, false);
		
		// fade in background (now disabled, just display)
		var objBackgroundSmallFX = new Fx.Morph(objWdkaElements.background, {duration: 0});
		objBackgroundSmallFX.start({'opacity': 1});
		
		// load full res background image
		if(objWdkaElements.background_full){
			objBackgroundImageFull = new Asset.image(strBackgroundImageFull, {id: 'background_full_image'});
			objBackgroundImageFull.inject(objWdkaElements.background_full_container,'inside');
		}
		
		// if player exists
		if(objWdkaElements.player_nav){
			loadPlayerImage();
		}
	}
}

var objPlayerImages;
var intPlayerImageCurrent = 0;
var intPlayerIndexCurrent = 0;

function loadPlayerImage(){
	
	if(strSetId > 0){
		arrPlayerImages = arrCasesImages[strSetId];
		arrPlayerBlurImages = arrCasesBlurImages[strSetId];
		arrPlayerThumbs = arrCasesThumbs[strSetId];
		arrPlayerTitles = arrCasesTitles[strSetId];
	}
	
	if(intPlayerImageCurrent < arrPlayerImages.length){
		// full image
		new Asset.image(arrPlayerImages[intPlayerImageCurrent], {onload: loadPlayerImage});
		
		// blur
		var objPlayerBlur = new Asset.image(arrPlayerBlurImages[intPlayerImageCurrent]);

		// thumb
		var objPlayerThumb = new Asset.image(arrPlayerThumbs[intPlayerImageCurrent], {id:'player_nav_thumb_img_'+intPlayerImageCurrent, 'class': 'player_nav_thumb_img', 'width': 50, 'height': 32 });
		var objPlayerThumbLink = new Element('a', { 'events': {	'click': function(){ swapBackground(this.getProperty('index'), bolSlide, 1); pageStateChange({objplayer: {state: 'open', zoomstate: bolPlayerZoom, image: this.getProperty('index')}}); } },
													'id': 'player_nav_thumb_'+intPlayerImageCurrent, 'index': intPlayerImageCurrent, 'class': 'player_nav_thumb', 'href': 'javascript:void(0);'});
		
		objPlayerThumb.inject(objPlayerThumbLink,'inside');
		objPlayerThumbLink.inject(objWdkaElements.player_nav_thumbs,'inside');
		
		intPlayerImageCurrent++;
		
	}
}

var bolSwapping = false;
function swapBackground(inIndex, bolSlide, intSlideDirection){

	if(bolSwapping == false){
		
		bolSwapping = true;
		
		intPlayerIndexCurrent = inIndex.toInt();
		dumpLog("swapBackground intPlayerIndexCurrent:"+intPlayerIndexCurrent+", "+intPlayerImageCurrent);
		if(objWdkaElements.player_nav_index) objWdkaElements.player_nav_index.innerHTML = (intPlayerIndexCurrent+1)+'/'+intPlayerImageCurrent;
		
		playerHighlightThumb();
		
		// set variables
		var ratioImage = new Image();
		ratioImage.src = arrPlayerImages[intPlayerIndexCurrent];
		objWdkaVariables.intBackgroundWidth = ratioImage.width;
		objWdkaVariables.intBackgroundHeight = ratioImage.height;
	
		var intWindowWidth = objWdkaVariables.intWindowWidth;
		var intWindowHeight = objWdkaVariables.intWindowHeight;
		
		var intRatioWidth = objWdkaVariables.intBackgroundWidth;
		var intRatioHeight = objWdkaVariables.intBackgroundHeight;
	
		// set animate layer
		objWdkaElements.background_animate.setStyles({ 'display': 'block'});
		objWdkaElements.background_animate.setStyles({ 'opacity': 0});
		objWdkaElements.background_animate_container.innerHTML =  '<img src="'+arrPlayerImages[intPlayerIndexCurrent]+'" id="background_animate_image" />';
		
		if(bolPlayerZoom == false){
			resizeBackground('background_animate', 0, false);
		}
		else {
			bolPlayerZoom = false;
			playerZoomOut('background_animate', 0)
		}
		
		var intBgMl1 = objWdkaElements.background_animate.getStyle('margin-left').toInt();
		if((intRatioWidth / intRatioHeight) < (intWindowWidth/intWindowHeight) && bolPlayerZoom == true){
			// scale and reposition background image  (horizontal)
			var intNewBackgroundHeight = intWindowHeight - (intPlayerZoomTop * 2);
			var intNewBackgroundWidth = (intRatioWidth / intRatioHeight) * intNewBackgroundHeight;
			intBgMl1 = ((intWindowWidth - intNewBackgroundWidth) / 2);
		}
		var objShowFX = new Fx.Morph(objWdkaElements.background_animate, {duration: intPlayerAnimationDuration, transition: intPlayerAnimationType2});
		if(bolSlide) objStyle = {'margin-left': [intSlideDistance*intSlideDirection, intBgMl1], 'opacity': 1 };
		else objStyle = {'opacity': 1 };
		objShowFX.start(objStyle);
	
		var intBgMl2 = objWdkaElements.background_full.getStyle('margin-left').toInt();
		if((intRatioWidth / intRatioHeight) > (intWindowWidth/intWindowHeight) && bolPlayerZoom == true){
			// scale and reposition background image  (horizontal)
			var intNewBackgroundHeight = intWindowHeight - (intPlayerZoomTop * 2);
			var intNewBackgroundWidth = (intRatioWidth / intRatioHeight) * intNewBackgroundHeight;
			intBgMl2 = ((intWindowWidth - intNewBackgroundWidth) / 2);
		}
		var objHideFX = new Fx.Morph(objWdkaElements.background_full, {duration: intPlayerAnimationDuration, transition: intPlayerAnimationType2});
		if(bolSlide) objStyle = {'margin-left': [intBgMl2, -intSlideDistance*intSlideDirection], 'opacity': 0 };
		else objStyle = {'opacity': 0 };
		objHideFX.start(objStyle);
	
	
		(function(){
			//load image
			$('background_image').setProperty('src', arrPlayerBlurImages[intPlayerIndexCurrent]);
			$('background_full_image').setProperty('src', arrPlayerImages[intPlayerIndexCurrent]);
			
			strBackgroundImageSmall = arrPlayerBlurImages[intPlayerIndexCurrent];
			strBackgroundImageFull = arrPlayerImages[intPlayerIndexCurrent];
		
			//resize
			if(bolPlayerZoom == false){
				resizeBackground('background_full', 0, false);
			}
			else {
				bolPlayerZoom = false;
				playerZoomOut('background_full', 0)
			}
			
		
			(function(){
				//set subtitles
				var strTitleTemp = arrPlayerTitles[intPlayerIndexCurrent];
				if(strTitleTemp == "") objWdkaElements.player_nav_title.setStyles({'display': 'none'});
				else objWdkaElements.player_nav_title.setStyles({'display': 'inline'});
				objWdkaElements.player_nav_title.innerHTML = "<span style=\"color:#FFFF00;font-weight:bold;\">+</span> " + strTitleTemp;
				if(objWdkaElements.player_thumb){
					objWdkaElements.player_thumb.setProperty('src', arrPlayerThumbs[intPlayerIndexCurrent]);
				}
					
				//reset
				objWdkaElements.background_animate.setStyles({ 'display': 'none'});
				if(bolSlide) objStyle = { 'margin-left': intBgMl1, 'opacity': 0};
				else objStyle = { 'opacity': 0};
				objWdkaElements.background_animate.setStyles(objStyle);
				
				if(bolSlide) objStyle = { 'margin-left': intBgMl2, 'opacity': 1};
				else objStyle = { 'opacity': 1};
				objWdkaElements.background_full.setStyles(objStyle);
				
				bolSwapping = false;
			}).delay(100);
		
		}).delay(intPlayerAnimationDuration);
	}
}

function swapBackgroundNext(){
	var intNewIndex=0;
	if(intPlayerIndexCurrent < (intPlayerImageCurrent-1)){
		// to next		
		intNewIndex=intPlayerIndexCurrent+1
	}
	
	pageStateChange({objplayer: {state: 'open', zoomstate: bolPlayerZoom, image: intNewIndex}})

	swapBackground(intNewIndex, bolSlide, 1);
	
}

function swapBackgroundPrev(){
	var intNewIndex=intPlayerImageCurrent-1;
	if(intPlayerIndexCurrent > 0){
		// to previous
		intNewIndex=intPlayerIndexCurrent-1;
	}
	
	pageStateChange({objplayer: {state: 'open', zoomstate: bolPlayerZoom, image: intNewIndex}})

	swapBackground(intNewIndex, bolSlide, -1);
}

document.addEvent('keyup',function(e){
	if(bolPlayerActive == true){
		swapBackgroundWithArrow(e);
	}
});
function swapBackgroundWithArrow(e){
	var evt = e || window.event;
	var key = evt.keyCode;
	
	//alert(key);
	if(key == 37 || key == 38){
		swapBackgroundPrev();
	}
	else if(key == 39 || key == 40){
		swapBackgroundNext();
	}
}


function playerSwap(){
	if(bolPlayerActive == false){
		playerOpen();
	}
	else{
		playerClose();
	}
}

function playerZoomSwap(){
	if(bolPlayerZoom == false){
		playerZoomOut("background_full", 500);
	}
	else{
		playerZoomIn("background_full", 500);
	}
}

function playerZoomIn(strBackground, strDuration){
	if(bolPlayerZoom == true && bolZooming == false){
		bolPlayerZoom = false;
		bolZooming = true;
		
		resizeBackground(strBackground, strDuration, false);
		
		(function(){ bolZooming = false; }).delay(strDuration);
	}
}

function playerHighlightThumb(){
		var objThumbs = objWdkaElements.player_nav_thumbs.getElements('a[id^=player_nav_thumb_]');
		objThumbs.each(function(thumb){
			thumb.setStyles({'border-bottom': '#000000 solid 2px'});
		});
		//alert('player_nav_thumb_'+intPlayerIndexCurrent);
		if($('player_nav_thumb_'+intPlayerIndexCurrent)) $('player_nav_thumb_'+intPlayerIndexCurrent).setStyles({'border-bottom': '#FFFF00 solid 2px'});
}


var bolZooming = false;
function playerZoomOut(strBackground, strDuration){
	if(bolPlayerZoom == false && bolZooming == false){
		bolPlayerZoom = true;
		bolZooming = true;
		
		var intWindowWidth = objWdkaVariables.intWindowWidth;
		var intWindowHeight = objWdkaVariables.intWindowHeight;
		
		var intRatioWidth = objWdkaVariables.intBackgroundWidth;
		var intRatioHeight = objWdkaVariables.intBackgroundHeight;
	
		if((intRatioWidth / intRatioHeight) < (intWindowWidth/intWindowHeight)){
			// scale and reposition background image  (horizontal)
			var intNewBackgroundHeight = intWindowHeight - (intPlayerZoomTop * 2);
			var intNewBackgroundWidth = (intRatioWidth / intRatioHeight) * intNewBackgroundHeight;
			
			var objBackgroundFX = new Fx.Morph(strBackground, {duration: strDuration});
			objBackgroundFX.start({
				'margin-top': intPlayerZoomTop,
				'margin-left': ((intWindowWidth - intNewBackgroundWidth) / 2)+'px', 
				'width': intNewBackgroundWidth, 
				'height': intNewBackgroundHeight 
			});
		}
		else{
			// scale and reposition background image (vertical)
			var intNewBackgroundWidth = intWindowWidth;
			var intNewBackgroundHeight = intNewBackgroundWidth / (intRatioWidth / intRatioHeight);
		
			var objBackgroundFX = new Fx.Morph(strBackground, {duration: strDuration});
			objBackgroundFX.start({
				'margin-left': 0,
				'margin-top': ((intWindowHeight - intNewBackgroundHeight) / 2)+'px', 
				'width': intNewBackgroundWidth, 
				'height': intNewBackgroundHeight
			});
		}
	
		// scale the image itself
		var objBackgroundFX = new Fx.Morph(strBackground+'_image', {duration: strDuration});
		objBackgroundFX.start({
			'width': (intNewBackgroundWidth)+'px',
			'height': (intNewBackgroundHeight)+'px'
		});
		
		if(strBackground == 'background_full'){
			//IE Fix / Shadow
			objWdkaElements.background_full.getElements('div[class=sh_ml]').setStyles({ 'height':  intNewBackgroundHeight });
			objWdkaElements.background_full.getElements('div[class=sh_mr]').setStyles({ 'height': intNewBackgroundHeight });
		}
		
		(function(){ bolZooming = false; }).delay(strDuration);
	}
}

function playerOpen(){
	if(bolPlayerActive == false && bolZooming == false){
		bolPlayerActive = true;
		bolZooming = true;
			
		//set index
		if(objWdkaElements.player_nav_index) objWdkaElements.player_nav_index.innerHTML = (intPlayerIndexCurrent+1)+'/'+intPlayerImageCurrent;
		
		playerHighlightThumb();
		
		//set subtitles
		var strTitleTemp = arrPlayerTitles[intPlayerIndexCurrent];
		if(strTitleTemp == "") objWdkaElements.player_nav_title.setStyles({'display': 'none'});
		else objWdkaElements.player_nav_title.setStyles({'display': 'inline'});
		objWdkaElements.player_nav_title.innerHTML = "<span style=\"color:#FFFF00;font-weight:bold;\">+</span> " + strTitleTemp;
		
		//set title of article
		if(strSetId > 0){
			objWdkaElements.player_nav_art_title.setStyles({'width':300, 'height':'auto', 'min-height':58});
			objWdkaElements.player_nav_art_title.innerHTML = "<div class=\"player_nav_art_title_title\">"+arrCaseTitle[strSetId]+"</div>"+arrCaseDescription[strSetId];
		}
		else{
			objWdkaElements.player_nav_art_title.setStyles({'width':200, 'height':'58', 'min-height':'auto'});
			objWdkaElements.player_nav_art_title.innerHTML = "<div class=\"player_nav_art_title_title\">"+objWdkaElements.header_block_1.innerHTML+"</div>"+objWdkaElements.header_block_2.innerHTML;
		}
		
		// get window height
		var intWindowWidth = objWdkaVariables.intWindowWidth;
		var intWindowHeight = objWdkaVariables.intWindowHeight;
		
		// set player nav
		objWdkaElements.player_nav.setStyles({ 'width': intWindowWidth, 'height': intWindowHeight});
		
		// remove vertical scrollbars 
		objWdkaElements.html.setStyles({ 'overflow-y': 'hidden', 'width': intWindowWidth, 'height': intWindowHeight});
		objWdkaElements.body.setStyles({ 'overflow-y': 'hidden', 'width': intWindowWidth, 'height': intWindowHeight});
		
		// remove horizontal scrollbars 
		objWdkaElements.html.setStyles({ 'overflow-x': 'hidden', 'width': intWindowWidth, 'height': intWindowHeight});
		objWdkaElements.body.setStyles({ 'overflow-x': 'hidden', 'width': intWindowWidth, 'height': intWindowHeight});
		
		// remove all scrollbars for safari 2
		if(window.webkit419 == true){ //safari 2 fix
			objWdkaElements.html.setStyles({ 'overflow': 'hidden', 'width': intWindowWidth, 'height': intWindowHeight });
			objWdkaElements.body.setStyles({ 'overflow': 'hidden', 'width': intWindowWidth, 'height': intWindowHeight });
		}
		
		// scroll to top is there are no scrollbars
		if(window.ie) { // IE6 & IE7 fix
			var scroll = new Fx.Scroll(objWdkaElements.html, { duration: 200 });
			scroll.toTop();
		}
		else{
			var scroll = new Fx.Scroll(objWdkaElements.body, { duration: 200 });
			scroll.toTop();
		}
		
		// set height
		objWdkaVariables.intWindowWidth = window.getWidth();
		objWdkaVariables.intWindowHeight = window.getHeight();
		resizeBackground('background', 400, false);


		// animate header, content, subnav with a delay 
		(function(){
			//animate logos
			var objHideFX = new Fx.Morph(objWdkaElements.logos, {duration: intPlayerAnimationDuration, transition: intPlayerAnimationType2});
			objHideFX.start({'margin-left': -(intWindowWidth / 4), 'opacity': 0 });
			
			//animate header 1
			var objHideFX = new Fx.Morph(objWdkaElements.header_1, {duration: intPlayerAnimationDuration, transition: intPlayerAnimationType2});
			objHideFX.start({'margin-left': -(intWindowWidth / 2), 'opacity': 0 });
	
			//animate header 2
			var objHideFX = new Fx.Morph(objWdkaElements.header_2, {duration: intPlayerAnimationDuration, transition: intPlayerAnimationType2});
			objHideFX.start({'margin-left': -(intWindowWidth / 2), 'opacity': 0 });
	
			//animate extranav
			var objHideFX = new Fx.Morph(objWdkaElements.extranav, {duration: intPlayerAnimationDuration, transition: intPlayerAnimationType2});
			objHideFX.start({'margin-left': -(intWindowWidth / 4), 'opacity': 0 });
			
			//animate content text
			var objHideFX = new Fx.Morph(objWdkaElements.content, {duration: intPlayerAnimationDuration, transition: intPlayerAnimationType2});
			objHideFX.start({'margin-left': -(intWindowWidth / 2), 'opacity': 0 });
	
			//animate subnav
			var objHideFX = new Fx.Morph(objWdkaElements.subnav, {duration: intPlayerAnimationDuration, transition: intPlayerAnimationType2});
			objHideFX.start({'margin-left': -(intWindowWidth / 2), 'opacity': 0 });
		}).delay(intPlayerAnimationDelay1);
	
		
		// animate menu
		(function(){
			if(window.ie) { // IE Fix (can't animate opacity while position:absolute)
				// animate ie menu
				var arrMenuDivs = new Array("lv1", "lv1_current", "lv2", "lv2_current", "lv2_current_ch", "lv2_f", "lv3", "lv3_current", "lv3_b", "lv3_current_ch", "lv3_item", "lv3_pagn", "lv3_cats", "lv4", "lv4_current", "lv4_h");
				for(var i=0; i<arrMenuDivs.length; i++){
					objWdkaElements.menu.getElements('div[class='+arrMenuDivs[i]+']').each(function(el){
						var objHideFX = new Fx.Morph(el, {duration: (intPlayerAnimationDuration + intPlayerAnimationDelay1), transition: intPlayerAnimationType2});
						objHideFX.start({'opacity': 0});
					});
				}
			
				var objHideFX = new Fx.Morph(objWdkaElements.menu, {duration: (intPlayerAnimationDuration + intPlayerAnimationDelay1), transition: intPlayerAnimationType2});
				objHideFX.start({'margin-left': -(intWindowWidth / 2)});
			}
			else{
				// animate menu
				var objHideFX = new Fx.Morph(objWdkaElements.menu, {duration: (intPlayerAnimationDuration + intPlayerAnimationDelay1), transition: intPlayerAnimationType2});
				objHideFX.start({'margin-left': -(intWindowWidth / 2), 'opacity': 0 });
			}
		}).delay(intPlayerAnimationDelay2);
		
		
		// animate footer with a delay 
		(function(){
			var objHideFX = new Fx.Morph(objWdkaElements.footer, {duration: intPlayerAnimationDuration, transition: intPlayerAnimationType2});
			objHideFX.start({'margin-left': -(intWindowWidth / 2), 'opacity': 0 });
		}).delay(intPlayerAnimationDelay3);


		// crossfade to full background image
		fadeToBackgroundFull.delay(intPlayerAnimationDelay4);

		// animate player with a delay 
		(function(){
			if(arrPlayerTitles.length > 1){
				if($('but_player_prev')) $('but_player_prev').setStyles({ 'display': 'block'});
				if($('but_player_next')) $('but_player_next').setStyles({ 'display': 'block'});
			}
			else{
				if($('but_player_prev')) $('but_player_prev').setStyles({ 'display': 'none'});
				if($('but_player_next')) $('but_player_next').setStyles({ 'display': 'none'});
			}
			
			objWdkaElements.player_nav.setStyles({ 'opacity': 0 });
			objWdkaElements.player_nav.setStyles({ 'display': 'block'});
			
			var objHideFX = new Fx.Morph(objWdkaElements.player_nav, {duration: intPlayerAnimationDuration, transition: intPlayerAnimationType2});
			objHideFX.start({'opacity': 1 });
			
			// fix fo arrows
			if(!window.ie) objWdkaElements.player_disable_arrow.focus();

		}).delay(intPlayerAnimationDelay4);
		
		(function(){ bolZooming = false; if(bolPlayerZoom == false){ playerZoomOut("background_full", 500);} }).delay(intPlayerAnimationDelay4+250);
	}
	
}

function playerClose(){
	if(bolPlayerActive == true && bolZooming == false){
		bolPlayerActive = false;
		
		var intDelay = 0;
		if(bolPlayerZoom == true){
			playerZoomIn("background_full", 500);
			intDelay = 500;
		}

		bolZooming = true;
		(function(){
				  
			// set variables
			var ratioImage = new Image();
			ratioImage.src = strBackgroundImageFull;
			objWdkaVariables.intBackgroundWidth = ratioImage.width;
			objWdkaVariables.intBackgroundHeight = ratioImage.height;
		
			// get window height
			var intWindowWidth = objWdkaVariables.intWindowWidth;
			var intWindowHeight = objWdkaVariables.intWindowHeight;
			
			repositionFooter();
			repositionContent();
			repositionColofon();
			setPageOverflow();

			bolContentExpand = false;
			
			// animate header, content, subnav with a delay 
			(function(){
				//animate logos
				objWdkaElements.logos.setStyles({ 'margin-left': (intWindowWidth / 8)});
				var objHideFX = new Fx.Morph(objWdkaElements.logos, {duration: intPlayerAnimationDuration+200, transition: intPlayerAnimationType2});
				objHideFX.start({'margin-left': 0, 'opacity': 1 });
				
				//animate header 1
				objWdkaElements.header_1.setStyles({ 'margin-left': (intWindowWidth / 4)});
				var objHideFX = new Fx.Morph(objWdkaElements.header_1, {duration: intPlayerAnimationDuration+200, transition: intPlayerAnimationType2});
				objHideFX.start({'margin-left': 0, 'opacity': 1 });
		
				//animate header 2
				objWdkaElements.header_2.setStyles({ 'margin-left': (intWindowWidth / 4)});
				var objHideFX = new Fx.Morph(objWdkaElements.header_2, {duration: intPlayerAnimationDuration+200, transition: intPlayerAnimationType2});
				objHideFX.start({'margin-left': 0, 'opacity': 1 });
		
				//animate content text
				objWdkaElements.content.setStyles({ 'margin-left': (intWindowWidth / 4)});
				var objHideFX = new Fx.Morph(objWdkaElements.content, {duration: intPlayerAnimationDuration+200, transition: intPlayerAnimationType2});
				objHideFX.start({'margin-left': 0, 'opacity': 1 });
		
				//animate extranav
				objWdkaElements.extranav.setStyles({ 'margin-left': (intWindowWidth / 8)});
				var objHideFX = new Fx.Morph(objWdkaElements.extranav, {duration: intPlayerAnimationDuration+200, transition: intPlayerAnimationType2});
				objHideFX.start({'margin-left': 0, 'opacity': 1 });
		
				//animate subnav
				objWdkaElements.subnav.setStyles({ 'margin-left': (intWindowWidth / 4)});
				var objHideFX = new Fx.Morph(objWdkaElements.subnav, {duration: intPlayerAnimationDuration+200, transition: intPlayerAnimationType2});
				objHideFX.start({'margin-left': 0, 'opacity': 1 });
			}).delay(intPlayerAnimationDuration);
		
			
			// animate menu
			(function(){
				objWdkaElements.menu.setStyles({ 'margin-left': (intWindowWidth / 4)});
				if(window.ie) { // IE6 & IE7 Fix (can't animate opacity while position:absolute)
					// animate ie menu
					var arrMenuDivs = new Array("lv1", "lv1_current", "lv2", "lv2_current", "lv2_f", "lv3", "lv3_current", "lv3_b", "lv3_current_ch", "lv3_item", "lv3_pagn", "lv3_cats", "lv4", "lv4_current", "lv4_h");
					for(var i=0; i<arrMenuDivs.length; i++){
						objWdkaElements.menu.getElements('div[class='+arrMenuDivs[i]+']').each(function(el){
							var objHideFX = new Fx.Morph(el, {duration: (intPlayerAnimationDuration + intPlayerAnimationDelay1), transition: intPlayerAnimationType2});
							objHideFX.start({'opacity': 1});
						});
					}
				
					var objHideFX = new Fx.Morph(objWdkaElements.menu, {duration: (intPlayerAnimationDuration + intPlayerAnimationDelay1), transition: intPlayerAnimationType2});
					objHideFX.start({'margin-left': 0});
				}
				else{
					// animate menu
					var objHideFX = new Fx.Morph(objWdkaElements.menu, {duration: (intPlayerAnimationDuration + intPlayerAnimationDelay1), transition: intPlayerAnimationType2});
					objHideFX.start({'margin-left': 0, 'opacity': 1 });
				}
			}).delay(intPlayerAnimationDuration+intPlayerAnimationDelay2);
			
			
			// animate footer with a delay 
			(function(){
				objWdkaElements.footer.setStyles({ 'margin-left': (intWindowWidth / 4)});
				var objHideFX = new Fx.Morph(objWdkaElements.footer, {duration: intPlayerAnimationDuration, transition: intPlayerAnimationType2});
				objHideFX.start({'margin-left': 0, 'opacity': 1 });
				

			}).delay(intPlayerAnimationDuration+intPlayerAnimationDelay3);
	
	
			// crossfade to full background image
			fadeToBackgroundSmall.delay(intPlayerAnimationDelay1-intPlayerAnimationDelay1);
			
			// animate player with a delay 
			(function(){
				var objHideFX = new Fx.Morph(objWdkaElements.player_nav, {duration: intPlayerAnimationDuration, transition: intPlayerAnimationType2});
				objHideFX.start({'opacity': 0 });
			}).delay(intPlayerAnimationDelay1-intPlayerAnimationDelay1);
			
			(function(){ bolZooming = false; }).delay(intPlayerAnimationDelay4);
			
		}).delay(intDelay);
	}
}

function fadeToBackgroundSmall(){
	resizeBackground('background', 0, false);

	// fade in
	var objBackgroundSmallFX = new Fx.Morph(objWdkaElements.background, {duration: (intPlayerAnimationDuration*2), fps:24, transition: intPlayerAnimationType2});
	objBackgroundSmallFX.start({'opacity': 1});

	(function(){ objWdkaElements.background_full.setStyles({ 'display': 'none'}); }).delay((intPlayerAnimationDuration*2));

}

function fadeToBackgroundFull(){
	// set bg image properties
	objWdkaElements.background_full.setStyles({ 'opacity': 1 });
	objWdkaElements.background_full.setStyles({ 'display': 'block'});

	// scale background image
	resizeBackground('background_full', 0, false);

	// fade in
	var objBackgroundSmallFX = new Fx.Morph(objWdkaElements.background, {duration: intPlayerAnimationDuration, fps:24, transition: intPlayerAnimationType2});
	objBackgroundSmallFX.start({'opacity': 0});
	
}

function updatePlayerState(strPlayerState, strZoomState, strImageNumber){
	/*
	triggered when a history state change occurs and if the page is loaded with the correct hash values
	*/
	
	dumpLog("in updatePlayerState: "+strPlayerState+", "+strZoomState+", "+strImageNumber);
	
	//convert the variables to strings
	strZoomState=strZoomState+'';
	strImageNumber=strImageNumber+'';
	
	//update image zoom state if the page is loades from the cache
	// TODO !!!
	
	//load the new background if it's not currently in the browser window
	if(strImageNumber.toInt() != intPlayerIndexCurrent){
		intPlayerIndexCurrent=strImageNumber.toInt();
		if(window.webkit && bolInitialLoad){
			swapBackground.delay(300, false, [intPlayerIndexCurrent, false, 1]);
		}else{
			swapBackground(intPlayerIndexCurrent, false, 1);
		}
	}
	
	//handle open and closed state of the player
	if(strPlayerState=="closed" && bolPlayerActive) playerClose();
	if(strPlayerState=="open" && bolPlayerActive==false) playerOpen();
	
	//handle the zoom state
	if(bolPlayerActive){
		if(strZoomState=="false") strZoomState=false;
		else strZoomState=true;
		
		if(strZoomState != bolPlayerZoom) playerZoomSwap();
	}
	
}

function toggleZoomButton(){
	
	var objBtnZoom = $('but_player_zoom_img');
	
	if(objBtnZoom.getProperty('src') == '/images/system/zoom_out.gif'){
		objBtnZoom.setProperty('src', '/images/system/zoom_in.gif');
	}
	else{
		objBtnZoom.setProperty('src', '/images/system/zoom_out.gif');
	}
	
}
