// JavaScript Document
// multiple onloads
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      func();
	  if (oldonload) {
        oldonload();
      }
    }
  }
}

/* checks the link just clicked to see if it's the current page... if so, change the ID=self */
function linkCurrentPage() { 
	if (!document.getElementsByTagName) return;  
		 //oDiv=document.getElementById('divName') //if I want to limit it to a specific div
		 //checks all the links
		 var topBar = document.getElementById('topBar');
		 var links = topBar.getElementsByTagName("a"); 
		 //gets the pages location
		 var thispage = document.location.href;
		 thispage=thispage.split('/');
			thispage=thispage.slice(-1);
			thispage=thispage.join("/");
			//removes any server generate pages... always links to the top page even if a sub page is displayed
			thispage=thispage.split('?');
			thispage=thispage.slice(0,1);
			
		 //alert(thispage);
		 //checks to see if the page has a .php/.htm extension, if so adjusted comparisson
		/* var postFix=thispage.slice(-4);
		 if(postFix!='.htm' && postFix!='.php') {//has to return something to compare, so compares directory
			 thispage=thispage.split('/');
			 thispage=thispage.slice(-2);
			 thispage=thispage.join("/");
		 }  else {//compares page name if exists
			thispage=thispage.split('/');
			thispage=thispage.slice(-1);
			thispage=thispage.join("/");
		 }*/
		 for (var i=0; i<links.length; i++) {//loops all the links
			 var link = links[i];
			 //breaks apart the links (don't show relative path info)
			 thisHREF = link.getAttribute("href");
			 
			 thisHREF=thisHREF.split('/');
			 thisHREF=thisHREF.slice(-1);
			 thisHREF=thisHREF.join("/");
			 //alert(thisHREF);
			 if (thisHREF == thispage) {//if the page and link are the same, add a self class
				link.className = "sel"; 
				//return; 
			 }
	 	}  
} 
addLoadEvent(linkCurrentPage);
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 videoPop(videoName,size,basePath) {
	if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0){//IE 6
       bodyH = document.documentElement.clientHeight
 	} else {
		bodyH=document.body.offsetHeight;
	}
	
	var blackBack=document.getElementById("blackBack");
	//creates/scales the blackBackground/container to fill the entire page.
	if(!blackBack) {
		document.body.innerHTML+='<div id="blackBack" class="fullScreen"></div><div id="popContainer" class="fullScreen" onclick="hideFull();"><div id="popCenter"></div></div>';
	}
	var blackBack=document.getElementById("blackBack");
	var popContainer=document.getElementById("popContainer")
	blackBack.style.display="block";
	popContainer.style.display="block";
	//middle of the screen, unless image > screen height
	var popCenter=document.getElementById("popCenter")
	//adds the video container... to be replaced by swf embedd
	popCenter.innerHTML+='<div id="videoContainer"></div>';
	//current screen position
	var pageScroll=getPageScroll();
	if(bodyH>popCenter.offsetHeight+20) {
		var centerNothing=(bodyH-popCenter.offsetHeight)/2;
		popCenter.style.top=pageScroll[1]+centerNothing+"px"; 
	} else {
		popCenter.style.top=pageScroll[1]+"px"; 
	}
	//Finds the height of the content container
	var container = document.getElementById('content');
	var contY = container.offsetHeight;
	//resizes the two DIV's based on the container size + menu elements (134px)
	if(bodyH<contY+160) {
		popContainer.style.height=contY+160+"px";
		blackBack.style.height=contY+160+"px";
	} else {
		popContainer.style.height=bodyH+"px";
		blackBack.style.height=bodyH+"px";
	}
	
	//decides the size
	if(size=='sm_wide'){vWidth=427; vHeight=240;}
	if(size=='sm'){vWidth=420; vHeight=236;}
	if(size=='med'){vWidth=656; vHeight=376;}
	if(size=='lrgW'){vWidth=720; vHeight=405;}
	if(size=='lrg'){vWidth=864; vHeight=486;}
	//scales center/white border based on size
	var popCenter=document.getElementById("popCenter");
	popCenter.style.width=vWidth+"px";
	popCenter.style.height=vHeight+"px";
	var imgX = new Image();
	imgX.onload = function() {
		popCenter.innerHTML+='<img src="'+imgX.src+'" id="closeX" name="closeX" />';
		//middle of the screen, unless image > screen height
		var pageScroll =getPageScroll();
		if(bodyH>vHeight+20) {
			var centerPic=(bodyH-vHeight)/2;
			popCenter.style.top=pageScroll[1]+centerPic+"px"; 
		} else {
			popCenter.style.top=pageScroll[1]+"px"; 
		}
		
		//sets/inserts the video
		//inits
		var flashvars = {
			MM_ComponentVersion: "1",
			skinName: basePath+"Clear_Skin_1",
			autoPlay: "true",
			autoRewind: "true",
			streamName: videoName
		};
		//var flashvars = false;
		var params = {
			scale: "noscale",
			salign: "tl"
		};	
		var attributes = {
			id: "Vid",
			name: "Vid"
		};
		//flashvars.streamName = size+'/'+videoName;
		swfobject.embedSWF(basePath+"FLVPlayer_Progressive.swf", "videoContainer", vWidth, vHeight, "9.0.0", false, flashvars, params, attributes);
	}
	imgX.src = "http://gauger-associates.com/images/closebox.png";
}
function hideFull() {
	var blackBack=document.getElementById("blackBack");
	var popContainer=document.getElementById("popContainer");
	var popCenter=document.getElementById("popCenter");
	blackBack.style.display="none";
	popContainer.style.display="none";
	var video=document.getElementById('Vid');
	if(video) {popCenter.innerHTML='<div id="videoContainer"></div>';}
}
