// JavaScript Document
function showmenu(elmnt){document.getElementById(elmnt).style.display="block";};
function hidemenu(elmnt){document.getElementById(elmnt).style.display="none";};
function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
    	window.onload = func;
	} else {
		window.onload = function() {
			func();
			if (oldonload) {
				oldonload();
			}
		}
	}
}
//navigation rollover
//no longer used
/*function navButtons(divName) {
	var imgPreload=new Array();
	var navButtonDiv = document.getElementById('navButtons');
	var navImages=navButtonDiv.childNodes;
	for (i=0;i<navImages.length-1; i++) {
		currentImg=navImages[i].firstChild;
		currentImg.setAttribute('osrc', currentImg.src);
		imgPreload[i]=new Image();
		imgPreload[i].src=currentImg.src.slice(0,currentImg.src.length-4)+'_o.gif'
		currentImg.onmouseover=function(){
			this.src=this.getAttribute('osrc').slice(0,this.getAttribute('osrc').length-4)+'_o.gif';
		}
		currentImg.onmouseout=function(){
			this.src=this.getAttribute('osrc');
		}
	}
}
window.onload=navButtons;*/
function fileDownloading(serverData) {
	var thisURL=window.location.href;
	var thisPath=thisURL.split('/');
	var postWWWpath=thisPath.splice(3,thisPath.length-4);
	//gets the files path.
	var filePath=serverData.href.split('/');
	filePath=filePath.splice(3,filePath.length-3);
	filePath=filePath.join('/');
	var add2DB = $.ajax({
		type: "POST",
		url: "http://"+location.host+"/scripts/AJAX.add2Database.php",
		data: 'filePath='+postWWWpath+'/'+filePath + "&upDown=" + "down",
		async: false
	}).responseText;	
}
function deleteFile(obj,fileName) {
	
	var deleteFile= confirm("Do you really want to delete this file?");
	if (deleteFile==true){//path minus www.gauger-associates.com
		var thisURL=window.location.href;
		var thisPath=thisURL.substring(thisURL.indexOf("\/",8),thisURL.lastIndexOf("\/"));
		var html = $.ajax({//deletes the file
			type: "POST",
			url: "http://"+location.host+"/scripts/AJAX.DeleteClient.php",
			data: "uploadName=" + fileName + "&baseDir=" + thisPath,
			async: false
		}).responseText;
		if(html==1) {//if file deleted
			obj.parentNode.parentNode.parentNode.removeChild(obj.parentNode.parentNode);
			//updates the file list for things uploaded in this session only.
			var uploadImg = document.getElementById("uploadImg");
			if(uploadImg) {
				var uploadImages=uploadImg.value.split(",");
				var newImages="";
				for (i in uploadImages) {
					justDeletedFileName=uploadImages[i].split("/");
					justDeletedFileName=justDeletedFileName[justDeletedFileName.length-1];
					justFileName=fileName.split("/");
					justFileName=justFileName[justFileName.length-1];
					if(justDeletedFileName==justFileName) {
						continue;	
					}
					newImages+=uploadImages[i];
				}
				uploadImg.value=newImages;
			}
		} else {//if there was an error deleting
			var newP = document.createElement('p');
			newP.appendChild(document.createTextNode('Error deleting: '+html));
			obj.parentNode.appendChild(newP);
		}
	}
}
//crappy img functions
function preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.p) d.p=new Array();
    var i,j=d.p.length,a=preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.p[j]=new Image; d.p[j++].src=a[i];}}
}

function findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function swapImg() { //v3.0
  var i,j=0,x,a=swapImg.arguments; document.sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=findObj(a[i]))!=null){document.sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function swapImgRestore() { //v3.0
  var i,x,a=document.sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

//blackbox
//determines the scoll position... used for placing popup images
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;
}

//shows the still popup images
function showFull(args,movie) {
	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;
	}
	//scales the blackBackground/container to fill the entire page.
	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")
	//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("container");
	var contY = container.offsetHeight;
	//resizes the two DIV's based on the container size + menu elements (134px)
	popContainer.style.height=contY+134+"px";
	blackBack.style.height=contY+134+"px";
	//if arguments are supplied by the function, add images, add loading gif
	if (args) {//finds just the name of the image thumbnail that was clicked
		if(args.nodeName!="IMG" && args.parentNode.id!='mapLinks') {//if the element isn't an image then we can't pull it's source... Find the image!
			var thisPath=args.firstChild.src.substring(0,args.firstChild.src.lastIndexOf("\/")-4);
			var thisImg=args.firstChild.src.substring(args.firstChild.src.lastIndexOf("\/")+1);
		} else if (args.src) {
			var thisPath=args.src.substring(0,args.src.lastIndexOf("\/")-4);
			var thisImg=args.src.substring(args.src.lastIndexOf("\/")+1);
		}
		//the element that is centered... Holds the popup image
		//var popCenter=document.getElementById("popCenter");
		//new image element
		var img = new Image();
		var imgX = new Image();
		var imgBlocker = new Image();
		//when image is loaded
		img.onload = function() {
			//writes the image once it's loaded
			popCenter.innerHTML='<img src="'+img.src+'" id="popImg" name="popImg" />';
			//adds a border if this is the graph pages... if not graph pages, leave border at 0.
			var xtraBorder=0;
			if(args.parentNode.id=='graphContainer') {
				var popImg=document.getElementById("popImg");
				popImg.style.border='15px solid #000000';
				var xtraBorder=30;
			}
			//finds the demensions
			popCenter.style.width=img.width+xtraBorder+"px";
			popCenter.style.height=img.height+xtraBorder+"px";
			//middle of the screen, unless image > screen height
			if(bodyH>img.height+20) {
				var centerPic=(bodyH-img.height)/2;
				popCenter.style.top=pageScroll[1]+centerPic+"px"; 
			} else {
				popCenter.style.top=pageScroll[1]+"px"; 
			}
			//adds the closeX
			imgX.onload = function() {
				popCenter.innerHTML+='<img src="'+imgX.src+'" id="closeX" name="closeX" />';
			}
			
			imgX.src = "http://gauger-associates.com/images/closebox.png";
			//puts up a transparant gif over the pop'd up image... hiding it.
			/*imgBlocker.onload = function() {
				popCenter.innerHTML+='<img src="'+imgBlocker.src+'" id="imgBlocker" name="imgBlocker" width="'+img.width+'" height="'+img.height+'" />';
			}
			imgBlocker.src = "http://"+location.host+"/img/spacer.gif";*/
		};
		//writes the loading gif
		popCenter.innerHTML='<img src="http://gauger-associates.com/images/loader.gif" id="loading" name="loading" />';
		var popLoading=document.getElementById("loading");
		//alert(popCenter.offsetHeight);
		var borderWidth=60;
		var imgHeight=32;
		popLoading.style.marginTop=((popCenter.offsetHeight-(borderWidth*2))/2)-(imgHeight/2)+"px";
		//alert(popLoading.style.marginTop);
		img.src = "lrg/"+thisImg+"";	
	}
}
function videoPop(videoName,size,basePath) {
	//size must be lowercase
	size=size.toLowerCase(); 
	//videoName=videoName.parentNode.parentNode.id;
	//scales the blackBackground/container to fill the entire page.
	var blackBack=document.getElementById("blackBack");
	var popContainer=document.getElementById("popContainer")
	blackBack.style.display="block";
	popContainer.style.display="block";
	//adds the video container... to be replaced by swf embedd
	var popCenter=document.getElementById("popCenter");
	popCenter.innerHTML+='<div id="videoContainer"></div>';
	//Finds the height of the content container
	var container = document.getElementById("container");
	var contY = container.offsetHeight;
	//resizes the two DIV's based on the container size + menu elements (134px)
	popContainer.style.height=contY+134+"px";
	blackBack.style.height=contY+134+"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=='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 (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0){//IE 6
       bodyH = document.documentElement.clientHeight
 	} else {
		bodyH=document.body.offsetHeight;
	}
	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 popFlash(videoName,size,basePath) {
	//size must be lowercase
	size=size.toLowerCase(); 
	//videoName=videoName.parentNode.parentNode.id;
	//scales the blackBackground/container to fill the entire page.
	var blackBack=document.getElementById("blackBack");
	var popContainer=document.getElementById("popContainer")
	blackBack.style.display="block";
	popContainer.style.display="block";
	//adds the video container... to be replaced by swf embedd
	var popCenter=document.getElementById("popCenter");
	popCenter.innerHTML='<div id="videoContainer"></div>';
	//Finds the height of the content container
	var container = document.getElementById("container");
	var contY = container.offsetHeight;
	//resizes the two DIV's based on the container size + menu elements (134px)
	popContainer.style.height=contY+134+"px";
	blackBack.style.height=contY+134+"px";
	
	//decides the size
	if(size=='728'){vWidth=728; vHeight=90;}
	if(size=='160'){vWidth=160; vHeight=600;}
	//scales center/white border based on size
	var popCenter=document.getElementById("popCenter");
	popCenter.style.width=vWidth+"px";
	popCenter.style.height=vHeight+"px";
	
	//middle of the screen, unless image > screen height
	var pageScroll =getPageScroll();
	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;
	}
	if(bodyH>vHeight+20) {
		var centerPic=(bodyH-vHeight)/2;
		popCenter.style.top=pageScroll[1]+centerPic+"px"; 
	} else {
		popCenter.style.top=pageScroll[1]+"px"; 
	}
	
	var imgX = new Image();
	imgX.onload = function() {
		popCenter.innerHTML+='<img src="'+imgX.src+'" id="closeX" name="closeX" />';

	//sets/inserts the video
	//inits
	var flashvars = {
	};
	//var flashvars = false;
	var params = {
		scale: "noscale",
		salign: "tl"
	};	
	var attributes = {
		id: "Vid",
		name: "Vid"
	};
	//flashvars.streamName = size+'/'+videoName;
	swfobject.embedSWF(videoName+".swf", "videoContainer", vWidth, vHeight, "9.0.0", false, flashvars, params, attributes);
	}
	imgX.src = "http://gauger-associates.com/images/closebox.png";
}
//hides popups
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>';}
}