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

//SETTING UP OUR POPUP
//0 means disabled; 1 means enabled;


//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
	var popupStatus = 0;
	//loading popup with jQuery magic!
	$.loadPopup = function(selector, bg){
		//loads popup only if it is disabled
		//alert(selector+":"+ bg);
		if(popupStatus==0){
			popupStatus = 1;
			$(bg).css({
				"opacity": "0.7"
			});
			$(bg).fadeIn("slow");
			$(selector).fadeIn("slow");
			
		}
		centerPopup(selector, bg);
	}

	//disabling popup with jQuery magic!
	$.disablePopup = function(selector, bg){
		//disables popup only if it is enabled
		//alert(selector+":"+ bg);
		//if(popupStatus==1){
			popupStatus = 0;
			$(bg).fadeOut(10);
			$(selector).fadeOut(10);
			
		//}
	}

	//centering popup
	function centerPopup(selector, bg){
		//request data for centering
		var windowWidth = document.documentElement.clientWidth;
		//alert(windowWidth);
		var windowHeight = document.documentElement.clientHeight;
		var popupHeight = $(selector).height();
		var popupWidth = $(selector).width();
		//centering
		$(selector).css({
			"position": "fixed",
			"top": windowHeight/2-popupHeight/2,
			"left": windowWidth/2-popupWidth/2
		});
		//only need force for IE6
		
		$(bg).css({
			"height": windowHeight
		});
		
	}

	$("#popupClose").click(function(){
		
		$.disablePopup("#popup", "#backgroundPopup");
		//var href = $('.tabs li.active a').attr('href');
		/*$.ajax({
			url: referer,
			cache:false,
			success: function(data){
				//alert(data);
				$.disablePopup(".ajax-loader", ".ajax-loader-bg");
				$('div.content3').html(data);
			},
			error: function(){
				//alert("error");
				$.disablePopup(".ajax-loader", ".ajax-loader-bg");
			}
		})*/
	});
	//Click out event!
	$("#backgroundPopup").click(function(){
		$.disablePopup("#popup", "#backgroundPopup");
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			$.disablePopup("#popup", "#backgroundPopup");
		}
	});

});
