﻿/***************************/
//@Author: Adrian "yEnS" Mato Gondelle
//@website: www.yensdesign.com
//@email: yensamg@gmail.com
//@license: Feel free to use it, but keep this credits please!					
/***************************/

/***************************/
//@Modified: Mike Marrache
//@Date: September, 2010
//@email: sunkube@gmail.com
/***************************/

var popupStatus = 0;

function disablePopup(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#backgroundPopup").fadeOut("slow");
		$(".fullsize_photo").fadeOut("slow");
		popupStatus = 0;
		scrollPics();
	}
}

//CONTROLLING EVENTS IN jQuery
popupImage = function(photoID){
	//LOADING POPUP
	//Click the button event!
	$("#button_"+photoID).click(function(){
		//centering with css
		//centerPopup();
			var windowWidth = document.documentElement.clientWidth;
			var windowHeight = document.documentElement.clientHeight;
			var popupHeight = $("#photo_"+photoID).height();
			var popupWidth = $("#photo_"+photoID).width();
			//centering
			$("#photo_"+photoID).css({
				"position": "absolute",
				"top": windowHeight/2-popupHeight/2,
				"left": windowWidth/2-popupWidth/2
			});
			//only need force for IE6
			
			$("#backgroundPopup").css({
				"height": windowHeight
			});
		
		//load popup
		//loadPopup();
			//loads popup only if it is disabled
			if(popupStatus==0){
				$("#backgroundPopup").css({
					"opacity": "0.8"
				});
				$("#backgroundPopup").fadeIn("slow");
				$("#photo_"+photoID).fadeIn("slow");
				popupStatus = 1;
				stopScrollPics();
			}
	});
				
	//CLOSING POPUP
	//Click the x event!
	$(".fullsize_photo").click(function(){
		disablePopup();
	});
	//Click out event!
	$("#backgroundPopup").click(function(){
		disablePopup();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
	});
};

