var panes = new Array();
var activePane = 0;
var paneTimer = null;
var preview = false;

function getScreenSize() {
	var screenWidth = 0;
	var screenHeight = 0;
	
	if (typeof( window.innerWidth ) == 'number') {
		//Non-IE
		screenWidth = window.innerWidth;
		screenHeight = window.innerHeight;
	} else {
		if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
			//IE 6+ in 'standards compliant mode'
			screenWidth = document.documentElement.clientWidth;
			screenHeight = document.documentElement.clientHeight;
		} else {
			if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
				//IE 4 compatible
				screenWidth = document.body.clientWidth;
				screenHeight = document.body.clientHeight;
			} //end if
		} // end if-else
	} //end if-else
	
	document.getElementById('heightSpacerImg').setAttribute('height',screenHeight+1-40);
} //end function



function highlightClip(cuepoint) {
	$(".pli img").css("borderColor","#000");
	$(".pli#cue" + cuepoint + " img").css("borderColor","#fff");
	$('#hiddenLink').focus();
	//.css('height','500px');
}


function loadImg(imgId) {
	clearTimeout(paneTimer);
	var lastPane = activePane;

	if (!imgId) {
		activePane++;
		if (activePane >= panes.length) { activePane = 0; }		
	} else {
		for (i=0;i<panes.length;i++) {
			if (panes[i] == imgId) {
				activePane = i;
			} //end if
		} //end for
	}//end if
	
	$("#ht" + panes[lastPane]).fadeOut();
	$("#ht" + panes[activePane]).fadeIn();
	$('#hb' + panes[lastPane]).removeClass('on');
	$('#hb' + panes[activePane]).addClass('on');	
	paneTimer = setTimeout("loadImg();",8000);
} //end loadImg

function startPanes() {
	if (panes.length > 1) {
		paneTimer = setTimeout("loadImg();",8000);
	} //end id
} //end loadImg


function loadHomePanes() {

	if ($("#ht1")) {
		for (i=1;i<=5;i++) {
			if ($("#ht" + i).html() != '') {
				$('#hb' + i).css('display','block');
				panes[panes.length] = i;
			}			
		} //end for loop

		if (panes.length > 0) {
			$('#ht' + panes[0]).css('display','block');
			$('#hb' + panes[0]).addClass('on');	
			startPanes();
		} // end if panes exist
	} //end if home page
	
} //end func


$(function() {

	if (preview == false) {
		loadHomePanes();
	}
	//fix home page menus
	
	$("#menu81").css('top',-(parseInt($("#menu81 > ul").height())+53) + 'px');
	$("#menu4").css('top',-(parseInt($("#menu4 > ul").height())+53) + 'px');
	$("#menu1").css('top',-(parseInt($("#menu1 > ul").height())+53) + 'px');
		   
	if ($("#videoLink")) {
		$("#videoLink").overlay({
			expose: { 
				color: '#000', 
				loadSpeed: 200, 
				opacity: 1.0 
			}, 
			closeOnClick: false,
			onLoad: function() {
				vid = $f("player", { src:"/flash/flowplayer-3.1.5.swf"}, {
						wmode: 'opaque',
						key: '#@a13e4d6d933d62deccc',
						clip: { 
						autoPlay: false, 
						autoBuffering: true
					},
					plugins: { 
						controls: { 
							play:true, 
							volume:true, 
							mute:false, 
							time:true, 
							stop:false, 
							playlist:false, 
							fullscreen:true,
							height: 20
						}
					}, 
					// player config 
					clip: { 
						// common clip properties 
						scaling: "none",
						onCuepoint: [[0,5400,81500,161000], function(clip, cuepoint) { highlightClip(cuepoint); }] 
					}, onLoad: function() {
						setTimeout("vid.pause().seek(2)",1000);
					}
					
				});
			},
			onClose: function() {
				vid.unload();
			}
		}
		
		);
	}
});
