// JavaScript Document
function hideAllPops(){
	if(document.getElementById("2008atw")){
			document.getElementById("2008atw").style.display = "none";
	}
	if(document.getElementById("2009atw")){
			document.getElementById("2009atw").style.display = "none";
	}
	if(document.getElementById("naha2010")){
			document.getElementById("naha2010").style.display = "none";
	}
	if(document.getElementById("sterling_vid")){
			document.getElementById("sterling_vid").style.display = "none";
	}
}

function showVideoATW2008(){
	hideAllPops();
	var pop_width = 520;
	var pop_height = 580;
	var close_btn_x = pop_width - 16;

	document.getElementById("2008atw").style.display = "inline";
	document.getElementById('closeButton').style.left = close_btn_x + 'px';
	show_info(null, pop_width, pop_height);
    var so = new SWFObject("./assets/media/2008AroundTheWorld.swf", "embed_atw2008video", "480", "425", "8", "#000000");
	so.addVariable('autoPlay',true);	
	so.addParam("allowFullScreen", "true");
//	FULLSCREEN ME!  //
	
 	so.write("FLASH_2008ATWVideo");
	
}

function showVideoATW2009(){
	hideAllPops();
	var pop_width = 835;
	var close_btn_x = pop_width - 16;

	document.getElementById("2009atw").style.display = "inline";
	document.getElementById('closeButton').style.left = close_btn_x + 'px';
	show_info(null, pop_width, 411);
    var so = new SWFObject("./assets/media/vid_player.swf", "embed_atw2009video", "512", "288", "9.0.115", "#000000");
    so.addVariable("video", "../video/atw_2009.mp4");
	so.addParam("allowFullScreen", "true");
//	FULLSCREEN ME!  //
	
 	so.write("FLASH_2009ATWVideo");
	
}

function showVideoSterling(){
	hideAllPops();
	var pop_width = 825;
	var close_btn_x = pop_width - 16;

	document.getElementById("sterling_vid").style.display = "inline";
	document.getElementById('closeButton').style.left = close_btn_x + 'px';
	show_info(null, pop_width, 411);
    var so = new SWFObject("./assets/media/sterling_vid.swf", "embed_sterling_video", "640", "360", "9.0.115", "#000000");
	so.addParam("allowFullScreen", "true");
//	FULLSCREEN ME!  //
	
 	so.write("FLASH_SterlingVideo");
	
}


function showNAHA(){
	hideAllPops();
	var pop_width = 576;
	var close_btn_x = pop_width - 16;
	document.getElementById("naha2010").style.display = "inline";
	document.getElementById('closeButton').style.left = close_btn_x + 'px';
	show_info(null, pop_width, 411);

}


function close_info(){
	var content = document.getElementById("frameContent");
	//remove content from popup before hiding it...
	var embed_elements = content.getElementsByTagName('embed');
	for(var i=0;i<embed_elements.length;i++){
		var embed_ele = document.getElementById(embed_elements[i].id);
		embed_ele.parentNode.removeChild(embed_ele);
	}							
	var embed_elements = content.getElementsByTagName('object');
	for(var i=0;i<embed_elements.length;i++){
		var embed_ele = document.getElementById(embed_elements[i].id);
		embed_ele.parentNode.removeChild(embed_ele);
	}							

	document.getElementById('cover').style.visibility = "hidden";
	document.getElementById('cover').style.width = "0px";
	document.getElementById('cover').style.height = "0px";
	var objBody = document.getElementsByTagName("body").item(0);
	document.getElementById("frame").style.visibility = "hidden";
	showFlash();
	
}

function show_info(elemID, frameWidth, frameHeight){
	//define height and width of popup frame
	hideFlash();
			
	if(frameWidth==null){
		var frameWidth = 450;
	}
	if(frameHeight==null){
		var frameHeight = 468;
	}

	// stretch overlay to fill page and fade in
	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();
	var cover = document.getElementById('cover');
	cover.style.width = arrayPageSize[0]+arrayPageScroll[0]+'px';
	cover.style.height = arrayPageSize[1]+arrayPageScroll[1]+'px';
	cover.style.visibility = "visible";
	
	var frame = document.getElementById("frame");
	var boxTop = arrayPageScroll[1] + 30;
	//top and left corners are based size of viewable area
	var boxLeft = arrayPageScroll[0] + Math.round(arrayPageSize[0] / 2);

	if(boxLeft > frameWidth/2){ boxLeft -= Math.round(frameWidth/2);}
//	if(boxTop > frameHeight/2){ boxTop -= Math.round(frameHeight/2);}
	frame.style.top = boxTop + 'px';
	frame.style.left = boxLeft + 'px';
//	frame.style.height = frameHeight + 'px';
	frame.style.width = frameWidth + 'px';

	frame.style.visibility = 'visible';
}


// -----------------------------------------------------------------------------------
//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.com
// Edit for Firefox by pHaez
//
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;
	
//	console.log(self.innerWidth);
//	console.log(document.documentElement.clientWidth);

	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;
	}

//	console.log("xScroll " + xScroll)
//	console.log("windowWidth " + windowWidth)

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}
//	console.log("pageWidth " + pageWidth)

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}


// -----------------------------------------------------------------------------------

//
// getPageScroll()
// Returns array with x,y page scroll values.
// Core code from - quirksmode.com
//
function getPageScroll(){

	var xScroll, yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
		xScroll = self.pageXOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
		xScroll = document.documentElement.scrollLeft;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
		xScroll = document.body.scrollLeft;	
	}

	arrayPageScroll = new Array(xScroll,yScroll) 
	return arrayPageScroll;
}

// ---------------------------------------------------

function showFlash(){
	var flashObjects = document.getElementsByTagName("object");
	for (i = 0; i < flashObjects.length; i++) {
		flashObjects[i].style.visibility = "visible";
	}

	var flashEmbeds = document.getElementsByTagName("embed");
	for (i = 0; i < flashEmbeds.length; i++) {
		flashEmbeds[i].style.visibility = "visible";
	}
}

// ---------------------------------------------------

function hideFlash(){
	var flashObjects = document.getElementsByTagName("object");
	for (i = 0; i < flashObjects.length; i++) {
		flashObjects[i].style.visibility = "hidden";
	}

	var flashEmbeds = document.getElementsByTagName("embed");
	for (i = 0; i < flashEmbeds.length; i++) {
		flashEmbeds[i].style.visibility = "hidden";
	}

}

