function setFocus(text,ele){
	if(ele.value==text)	 ele.value='';
}

function removeFocus(text,ele){
	if(ele.value=='') ele.value=text;
}
var caseStudyIdPressed=0;
var closingPlayer=false;
var loadingPlayer=false;

function displayMovieLayer(caseId){
	caseStudyIdPressed=caseId;
	loadingPlayer=true;
	open_form('movieContainer');
	Effect.ScrollTo('movieContainer');
	new Ajax.Request('/case_studies/play/'+caseId,{
		method: 'get',
		onSuccess: function(response){

			$('movieLoadMessageDiv').innerHTML='Initializing...';
			var theResponse=response.responseText;
			//			$('moviePlayerContainer').innerHTML=theResponse;

			var parameters=theResponse.split('|delimiter|');
			eval("var s"+caseId+" = new SWFObject('/movie/player.swf','ply','365','230','9','#FFFFFF');")

			eval("s"+caseId+".addParam('allowfullscreen','true');");
			eval("s"+caseId+".addParam('allowscriptaccess','always');");
			eval("s"+caseId+".addParam('flashvars','file=/files/videos/flv/'+parameters[0]+'&image=/files/videos/images/preview/'+parameters[1]);");

			/*animateBg=function(){new Effect.Morph('moviePlayerContainer', {
			style: 'background-color:#48A0AE; width:350px;height:300px;',
			duration: 0.8 // Core Effect properties
			});}

			setTimeout("animateBg()",1000);*/
			myFunction=function(){eval("s"+caseId+".write('moviePlayerContainer');");};
			window.focus();
			setTimeout("myFunction()",2000);
			setTimeout("loadingPlayer=false;",2000);

		},
		onFailure: function(){
			alert('An error occured while loading the player. Please refresh the page and try again.');
			closePlayer('movieContainer');
			loadingPlayer=false;
		}
	});
}


function closePlayer(divName){
	if(!closingPlayer && !loadingPlayer){
		closingPlayer=true;
		$('ply').sendEvent('STOP');
		$(divName).fade();
		fadeLayer=function(){$('layerDiv').switchOff();}
		setTimeout('fadeLayer()',1000);
		setTimeout('closingPlayer=false;',3000);
		scrollbackFunction=function(){
			Effect.ScrollTo('caseStudyEntry_'+caseStudyIdPressed);
		};
		setTimeout('scrollbackFunction()',1500);

		setTimeout('caseStudyIdPressed=0;',3000);
		rewriteLoader=function(){
			$('moviePlayerContainer').innerHTML="<div>&nbsp;&nbsp;&nbsp;<div id='movieLoadMessageDiv'>Loading Player - Please Wait...</div><br /><img src='/img/ajax-loader.gif' alt='Loading Player - Please Wait...' title='Loading Player - Please Wait...' /></div>";
		}
		setTimeout("rewriteLoader()",3000);
	}
}


function open_form(divName){

	var arrayPageSize = getPageSize();
	var moveFromLeft=0;
	moveFromLeft=parseInt(arrayPageSize[0])/2;

	Math.round(moveFromLeft);
	moveFromLeft=moveFromLeft-250;
	$('moviePlayerContainer').style.left=moveFromLeft+"px";
	$('layerDiv').style.height=arrayPageSize[1]+"px";
	Effect.Grow('layerDiv');

	//	$('layerDiv').style.display='block';
	displayPlayer=function(){$(divName).style.display='block';}
	setTimeout("displayPlayer()",1000);

}

function getPageSize(){

	var xScroll, yScroll;

	if (window.innerHeight  && window.scrollMaxY) {
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;

	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	var windowWidth, windowHeight;

	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth;
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}

	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else {
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){
		pageWidth = xScroll;
	} else {
		pageWidth = windowWidth;
	}

	return [pageWidth,pageHeight];
}