var videoFilename = "";

// Initialisation
$(document).ready(function(){	
	
	// If JavaScript is enabled and Flash meets minimum version of 7, show the video links
	if (jimAuld.utils.flashsniffer.meetsMinVersion(7)) {
		$(".jstFlashShow").show();
	}

	// Assign event handlers
	$("a.jstVideoLinkAlternativeEnergy").click(showVideoAlternativeEnergy);
	$("a.jstVideoLinkBioFuel").click(showVideoBioFuel);
	$("a.jstVideoLinkSolar").click(showVideoSolar);
	$("a.jstVideoLinkWater").click(showVideoWater);
	$("a.jstVideoLinkFull").click(showVideoFull);
	$("a.jstVideoLinkGeothermal").click(showVideoGeothermal);
	$("a.jstVideoLinkFuelCells").click(showVideoFuelCells);
	$("a.jstVideoLinkWind").click(showVideoWind);
	$("a.jstVideoLinkKlimaat").click(showVideoKlimaat);
	$("a.jstVideoLinkKlimaatverandering").click(showVideoKlimaatverandering);
	$("a.jstVideoLinkHermanWijffels").click(showVideoHermanWijffels);
	$("a.jstVideoLinkAbnSwf").click(showVideoAbnSwf);
	$("a.jstVideoLinkGoud").click(showVideoGoud);

	$(window).resize(positionLightbox);
	
});

function showVideoKlimaatverandering()
{
	 videoFilename = "kansen.xml";
	 
	 // add click to Omniture
	 //var s=s_gi(s_account);
	 //s.tl(this,'o','CleanRenewable');

	 showLightbox();
	 return false;
}

function showVideoKlimaat()
{
	 videoFilename = "climatehot.xml";
	 
	 // add click to Omniture
	 //var s=s_gi(s_account);
	 //s.tl(this,'o','CleanRenewable');

	 showLightbox();
	 return false;
}

function showVideoAlternativeEnergy()
{
	 videoFilename = "alternativeenergy.xml";
	 
	 // add click to Omniture
	 //var s=s_gi(s_account);
	 //s.tl(this,'o','CleanRenewable');

	 showLightbox();
	 return false;
}

function showVideoBioFuel()
{
	 videoFilename = "biofuel.xml";	 	 
	 
	 // add click to Omniture
	 //var s=s_gi(s_account);
	 //s.tl(this,'o','BioFuel');
	 
	 showLightbox();
	 return false;
}

function showVideoSolar()
{
	 videoFilename = "solar.xml";
	 
	 // add click to Omniture
	 //var s=s_gi(s_account);
	 //s.tl(this,'o','Solar');
	 	 
	 showLightbox();
	 return false;
}

function showVideoWater()
{
	 videoFilename = "water.xml";
	 
	 // add click to Omniture
	 //var s=s_gi(s_account);
	 //s.tl(this,'o','Water');
	 	 
	 showLightbox();
	 return false;
}

function showVideoFull()
{
	 videoFilename = "full.xml";
	 
	 // add click to Omniture
	 //var s=s_gi(s_account);
	 //s.tl(this,'o','Full');
	 	 
	 showLightbox();
	 return false;
}

function showVideoGeothermal()
{
	 videoFilename = "geothermal.xml";
	 
	 // add click to Omniture
	 //var s=s_gi(s_account);
	 //s.tl(this,'o','Full');
	 	 
	 showLightbox();
	 return false;
}

function showVideoFuelCells()
{
	 videoFilename = "fuelcells.xml";
	 
	 // add click to Omniture
	 //var s=s_gi(s_account);
	 //s.tl(this,'o','Full');
	 	 
	 showLightbox();
	 return false;
}

function showVideoWind()
{
	 videoFilename = "wind.xml";
	 
	 // add click to Omniture
	 //var s=s_gi(s_account);
	 //s.tl(this,'o','Full');
	 	 
	 showLightbox();
	 return false;
}

function showVideoHermanWijffels()
{
	 videoFilename = "HermanWijffels.xml";
	 showLightbox();
	 return false;
}
			
function showVideoGoud()
{
	 videoFilename = "Goud.xml";
	 showLightbox();
	 return false;
}
			
			
function showVideoAbnSwf()
{
	videoFilename = "abn.swf";
	showLightbox();
	return false;
}

function hideVideo()
{	
	$(".jstFlashContent").html("<div id=\"jstFlashContentContainer\"></div>");
	$("#jstFlashContentContainer").remove();
	$(".jstFlashContent").hide();
	$("#overlay").hide();
}

function showLightbox()
{

	$(".jstFlashContent").html("<div id=\"jstFlashContentContainer\"></div>");
	
	var swfObject;
	
	if (videoFilename.indexOf(".xml") > -1)	{
		if (jimAuld.utils.flashsniffer.meetsMinVersion(8)) {
			swfObject = new SWFObject("flash/video_player.swf?path=flash/movies/flash8/xml/" + videoFilename + "&nocache=" + new Date().getTime(), "jstFlashContentContainer", "565", "450", "8","#000000");
		} else {
			swfObject = new SWFObject("flash/video_player.swf?path=flash/movies/flash7/xml/" + videoFilename + "&nocache=" + new Date().getTime(), "jstFlashContentContainer", "565", "450", "7","#000000");
		}
		swfObject.addParam("wmode", "transparent");
	} else {
		swfObject = new SWFObject("flash/movies/swf/" + videoFilename, "jstFlashContentContainer", "790", "445", "8","#000000");
	}
	
	swfObject.addParam("salign", "tl");
	swfObject.addParam("menu", "false");
    swfObject.write("jstFlashContentContainer");
	 
	// Show elements so that measurements can be taken and new values set
	$("#overlay").show();
	$(".jstFlashContent").show();
    
	positionLightbox();
	
}

function positionLightbox()
{
	
	// Get viewport and page dimensions (pageWidth, pageHeight, windowWidth, windowHeight) 
	var dimensions = getPageSize();
	
	// Get current scroll position (x, y)
	var scrollPositions = getPageScroll();
	
	// Calculate values
	var videoTop = (getVisibleHeight() / 2) - ($(".jstFlashContent").height() / 2) + scrollPositions[1];
	var videoLeft = (getVisibleWidth() / 2) - ($(".jstFlashContent").width() / 2);
	var overlayHeight = dimensions[1];
	var overlayWidth = dimensions[0];
	
	// Set values
	$(".jstFlashContent").css("top", videoTop + "px");
	$(".jstFlashContent").css("left", videoLeft + "px");
	$("#overlay").css("height", overlayHeight + "px");
	$("#overlay").css("width", overlayWidth + "px");
	
}

// Get width of visible browser area
function getVisibleWidth()
{
	
	var clientWidth;

	if (window.innerWidth)
	{
		clientWidth = (window.__safari ? window.innerWidth : Math.min(window.innerWidth, document.documentElement.clientWidth));
	}
	else
	{
		if (document.documentElement.clientWidth == 0)
		{
			clientWidth = document.body.clientWidth;
		}
		else
		{
			clientWidth = document.documentElement.clientWidth;
		}
	}
	
	return clientWidth;
	
}

// Get height of visible browser area
function getVisibleHeight()
{
	
	var clientHeight;


	if (window.innerHeight)
	{
		clientHeight = (window.__safari ? window.innerHeight : Math.min(window.innerHeight, document.documentElement.clientHeight));
	}
	else
	{
		if (document.documentElement.clientHeight == 0)
		{
			clientHeight = document.body.clientHeight;
		}
		else
		{
			clientHeight = document.documentElement.clientHeight;
		}
	}
	
	return clientHeight;
	
}

// Returns array with x,y page scroll values.
function getPageScroll(){

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}

// Returns array with page width, height and window width, height
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		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
		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 = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}
