//SETTING UP OUR POPUP  
//0 means disabled; 1 means enabled;  
var popupStatus = 0;  




//loading popup with jQuery magic!  
function loadPopup(){  
//loads popup only if it is disabled  
if(popupStatus==0){  
$("#backgroundPopup").css({  
"opacity": "0.7"  
});  
$("#backgroundPopup").fadeIn("slow");  
$("#popupContact").fadeIn("slow");  
popupStatus = 1;  
}  
}  


//disabling popup with jQuery magic!  
function disablePopup(){  
//disables popup only if it is enabled  
if(popupStatus==1){  
$("#backgroundPopup").fadeOut("slow");  
$("#popupContact").fadeOut("slow");  
popupStatus = 0;

}  
}  

var ie7FixFlag="no";

//centering popup  
function centerPopup(){  
//request data for centering  
var windowWidth = document.documentElement.clientWidth;  
var windowHeight = document.documentElement.clientHeight;  
var popupHeight = $("#popupContact").height();  
var popupWidth = $("#popupContact").width();  

//centering  
if ((myversion.indexOf("MSIE 7")!=-1 || myversion2.indexOf("MSIE 7")!=-1) && ie7FixFlag=="no") {windowWidth=windowWidth/4; ie7FixFlag="yes";} else {windowWidth=windowWidth;}
$("#popupContact").css({  
"position": "absolute",  
"top": windowHeight/2-popupHeight/2,  
"left": windowWidth/2-popupWidth/2
});  
//only need force for IE6  
  
$("#backgroundPopup").css({  
"height": windowHeight  
});  

if (numPhotosPopUp==1) {$('#popupContact').css({margin:'0 auto 0 auto'});}
}  

function sizePics(myID) {
	var maxwid=800;
	var maxht=600;
	var ht=myID.attr("height");
	var wid=myID.attr("width");
	var finalHt=myID.attr("height");
	var finalWid=myID.attr("width");
	
		if (ht>maxht) {
			finalHt=maxht;
			finalWid=(maxht/ht)*wid;
		}
	
		if (wid>maxwid) {
			finalWid=maxwid;
			finalHt=(maxwid/wid)*ht;
		}
	
		leftMarg=(maxwid-finalWid)/2;
		rightMarg=leftMarg;
		topMarg=(maxht-finalHt)/2;
		
		$(myID).css({width:finalWid+'px',height:finalHt+'px',margin:topMarg+'px '+rightMarg+'px '+bottomMarg+' '+leftMarg+'px'});
	}


$(document).ready(function(){  
//LOADING POPUP  
//Click the button event!

	//for (z=0; z<numLgPhotos; z++) {
	//	var theName="#largePhoto_"+z;
		//sizePics($(theName));
	//}
	
	$("#next2").click(function(){picShowing++;}); 
	$("#prev2").click(function(){picShowing--;}); 
	 
	$("#mainPhoto").click(function(){  
		//$("#largeGalleryNav").css({display:'inline'});
		//centering with css  
		centerPopup();  
		//load popup  
		loadPopup();  
	});  
	//CLOSING POPUP  
	//Click the x event!  
	$("#popupContactClose").click(function(){  
		//$("#largeGalleryNav").css({display:'none'});
		disablePopup();  
	});  
	//Click out event!  
	$("#backgroundPopup").click(function(){  
		//$("#largeGalleryNav").css({display:'none'});
		disablePopup();  
	});  
});  



