var panes = new Array();
var homeLogoRightPanes = 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;
			}
		}
	} 
	
	document.getElementById('heightSpacerImg').setAttribute('height',screenHeight+1-40);
} 


function highlightClip(cuepoint) {
	$(".pli img").css("borderColor","#000");
	$(".pli#cue" + cuepoint + " img").css("borderColor","#fff");
	$('#hiddenLink').focus();
}


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
	
//	alert('lastpane=' + lastPane + ', activepane = ' + activePane);
	
	$("#homeBanner" + panes[lastPane]).fadeOut(1000);
	$("#homeBanner" + panes[activePane]).fadeIn(1000);
	$("#homeLogoRight" + homeLogoRightPanes[lastPane]).fadeOut(1000);
	$("#homeLogoRight" + homeLogoRightPanes[activePane]).fadeIn(1000);
	paneTimer = setTimeout("loadImg();",4000);
} 


function startPanes() {
	if (panes.length > 1) {
		paneTimer = setTimeout("loadImg();",4000);
	}
} 


function loadHomePanes() {

	if ($("#homeBanner")) {
		for (i=1;i<=5;i++) {
			if ($("#homeBanner" + i).html() != '') {
				panes[panes.length] = i;
			}			
			if ($("#homeLogoRight" + i).html() != '') {
				homeLogoRightPanes[homeLogoRightPanes.length] = i;
			}			
		}

		if (panes.length > 0) {
			startPanes();
		} 
	}
	
}


function loadHtmlFromUrl(url, target) {
  if (window.XMLHttpRequest) {
    req = new XMLHttpRequest();
  } else if (window.ActiveXObject) {
    req = new ActiveXObject("Microsoft.XMLHTTP");
  }
  if (req != undefined) {
    req.onreadystatechange = function() {updateInnerHtml(url, target);};
    req.open("GET", url, true);
    req.send("");
  }
}  

function updateInnerHtml(url, target) {
  if (req.readyState == 4) {
	  targetElement =  document.getElementById(target);
    if (req.status == 200) {
      targetElement.innerHTML = req.responseText;
    } else {
      targetElement.innerHTML=" loadHtmlFromUrl Error:  url = " + url + ", target = " + target  + " ,status = "+ req.status + "\n" +req.statusText;
    }
  }
}


$(function() {

	
//	loadHtmlFromUrl('/navbar.php', 'navbar');

	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();
			}
		}
		
		);
	}
});


