// Jeff LaPlante Photography Global Website Functions

// Global variables:
		var gBehaviorsArray = [];
		
		function initSlideshow(){
			resizeSlideshow();
			doSlideshowLayout();
		}
		
		
		// Set Opacity to Zero for named element and turn it on
		function setOpacityZero(element){
			gBehaviorsArray[element] = new Spry.Effect.AppearFade(element,{duration: 100,from: 100,to: 0, finish: 
	        			function(){
	        				gBehaviorsArray[element] = null;
	        				displayOn(element); 
	        			}
	        		});
		}
		
		function doSlideshowLayout(){
			displayOn("slideshowContent");
			displayOn("contactInfoOptions");
		}
		
		function resizePage(){
			var winW = 1000;
			var winH = 750;
			var mainW = 900;
			var mainH = 600;
			var gap = 5;
			var navW = 900;
			var navH = 20;
			var offsetW = 20;
			var offsetH = 20;
			
			if (window.innerWidth) {
			  winW = window.innerWidth;
			  winH = window.innerHeight;
			}else if (document.body.offsetWidth) {
			  winW = document.body.offsetWidth;
			  winH = document.body.offsetHeight;
		 	}
			
			// combined space used by the overall layout
			var usedSpace = parseInt(mainH + gap + navH);
			
			offsetW = (winW - mainW)/2;
			offsetH = (winH - mainH - gap - navH)/2;
			
			if(offsetW < 0) offsetW = 0;
			if(offsetH < 0) offsetH = 0;
			
			// If the viewport height is not large enough then scale down the main div height
			var overUnder = winH - usedSpace;
			if(overUnder > 0) overUnder = 0;
			
			var adjustedMainH = mainH + overUnder;
			
			
		}
		
		function resizeSlideshow(){
			displayOn("slideshowContent");
		
			var winW = 1000;
			var winH = 720;
			
			if (window.innerWidth) {
			  winW = window.innerWidth;
			  winH = window.innerHeight;
			}else if (document.body.offsetWidth) {
			  winW = document.body.offsetWidth;
			  winH = document.body.offsetHeight;
		 	}
		 	
		 	var h = .95 * winH;
		 	var w = .92 * winW;
			
			offsetW = (winW - w)/2;
			offsetH = (winH - h)/2;
			
			if(offsetW < 0) offsetW = 0;
			if(offsetH < 0) offsetH = 0;
			
			// move/resize slideshowContent and logo
			if(document.getElementById('slideshowContent')){
				document.getElementById('slideshowContent').style.top = offsetH + 10 + 'px';
				document.getElementById('slideshowContent').style.left = offsetW - 10 + 'px';
				document.getElementById('slideshowContent').style.height = h - 0 + 'px';
				document.getElementById('slideshowContent').style.width = w + 'px';
			}
			

		}
		
		function makeRed(item){
			document.getElementById(item).style.color = "red";
		}
		
		function makeWhite(item){
			document.getElementById(item).style.color = "#ffffff";
		}
		
		function setInfo(text){
			document.getElementById('info').innerHTML = text;
		}
		
		function getInfo(){
			return document.getElementById('info').innerHTML;
		}
		
		
		function getElement(aID){
         	var rv = (document.getElementById) ? document.getElementById(aID) : document.all[aID];
         	//alert("id:" + aID + " value:" +  rv);
         	rv = document.getElementById(aID);
         	return rv;
       	}
		
		function allOff(){
			displayOff('referralSplash');
			displayOff('affiliations');
			displayOff('affiliationLogos');
			displayOff('ipodImage');
			displayOff('ipodText');
			displayOff('ipodSlideshowDiv');			
			displayOff('slideshows');
			displayOff('slideshowAperture');
			displayOff('aboutJeff');
			displayOff("joinMailingList");
			displayOff('contact');
			displayOff('clients');
			displayOff('events');
			displayOff("frontPageNews");
			displayOff("galleryControls");
			displayOff("gear");
			displayOff("pop");
			displayOff("photoBySusieHamidi");
			displayOff("clusterMap");
		}
		
		// Toggle display of DIV
		function toggleDisplay(me){
			if (me.style.display=="inline" || me.style.display=="block"){
				me.style.display="none";
			}
			else {
				me.style.display="block";
			}
		}
		
		// Turn on a DIV
		function displayOn(me){
			var elem = getElement(me);
			if(elem){
				elem.style.display="block";
			}
		}
		
		// Turn off a DIV
		function displayOff(me){
			var elem = getElement(me);
			if(elem){
				elem.style.display="none";
			}
		}
		
		// Fade Off an element
		function displayFadeOff(me){
			var elem = getElement(me);
			if(elem){
				gBehaviorsArray["fadeOffElement"] = new Spry.Effect.AppearFade(me, {duration: 200,from: 100,to: 0, finish: 
		        			function(){
		        				gBehaviorsArray["fadeOffElement"] = null; 
							elem.style.display="none";
		        			}
				});
			}
		}
		
		function getCoordX(event)
		{
			x=event.clientX
			return x;
		}
		
		function getCoordsY(event){
			y=event.clientY
			return y;
		}
	
		
		// Sets the background image on the main DIV
		function set_photo(img_path){
			gImageLoaded = 0;
			
			img = new Image();
			img.src = img_path;
			
			img.onload = function(){
				if(img_path){
					getElement("main").style.background='url('+ img_path +')';			
				}else{
					getElement("main").style.background='none';
				}	
			}
			
			
		}
		
		// Sets the background image on the main DIV
		function set_slide_photo(img_path){
			img = new Image();
			img.src = img_path;
			
			img.onload = function(){
				//getElement("main").style.background='url(' + img.src + ')';
				
				getElement("mainImage").src = img_path;
				
				// Fade In behavior
				gBehaviorsArray["main"] = new Spry.Effect.AppearFade('main',{duration: 1000,from: 0,to: 100, finish: 
	        			function(){
	        				gBehaviorsArray["main"] = null; 
	        			}
	        		});
			}
			
		}
		
		// Sets the background color on the main DIV
		function setMainDivColor(hexColor){
			getElement("main").style.background=hexColor;
		}
		
		// Function to fix PNG transparency problems in IE
		var arVersion = navigator.appVersion.split("MSIE")
		var version = parseFloat(arVersion[1])
		
		function fixPNG(myImage) 
		{
		    if ((version >= 5.5) && (version < 7) && (document.body.filters)) 
		    {
		       var imgID = (myImage.id) ? "id='" + myImage.id + "' " : ""
			   var imgClass = (myImage.className) ? "class='" + myImage.className + "' " : ""
			   var imgTitle = (myImage.title) ? 
				             "title='" + myImage.title  + "' " : "title='" + myImage.alt + "' "
			   var imgStyle = "display:inline-block;" + myImage.style.cssText
			   var strNewHTML = "<span " + imgID + imgClass + imgTitle
		                  + " style=\"" + "width:" + myImage.width 
		                  + "px; height:" + myImage.height 
		                  + "px;" + imgStyle + ";"
		                  + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
		                  + "(src=\'" + myImage.src + "\', sizingMethod='scale');\"></span>"
			   myImage.outerHTML = strNewHTML	  
		    }
		}


