﻿/***************************/
//@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;
var popupStatusC = 0;
var popupStatusS = 0;

//loading popup with jQuery magic!
function loadPopupC(){
	//loads popup only if it is disabled
	if(popupStatusC==0){
		$("#backgroundPopupC").css({
			"opacity": "0.7"
		});
		$("#backgroundPopupC").fadeIn("slow");
		$("#popupContactC").fadeIn("slow");
		popupStatusC = 1;
	}
}

//loading popup with jQuery magic!
function loadPopupS(){
	//loads popup only if it is disabled
	if(popupStatusS==0){
		$("#backgroundPopupS").css({
			"opacity": "0.7"
		});
		$("#backgroundPopupS").fadeIn("slow");
		$("#popupContactS").fadeIn("slow");
		popupStatusS = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopupC(){
	//disables popup only if it is enabled
	if(popupStatusC==1){
		$("#backgroundPopupC").fadeOut("slow");
		$("#popupContactC").fadeOut("slow");
		popupStatusC = 0;
	}
}

//disabling popup with jQuery magic!
function disablePopupS(){
	//disables popup only if it is enabled
	if(popupStatusS==1){
		$("#backgroundPopupS").fadeOut("slow");
		$("#popupContactS").fadeOut("slow");
		popupStatusS = 0;
	}
}

//centering popup
function centerPopupC(){
	//request data for centering
	var windowWidthC = screen.width;
	var windowHeightC = screen.height - 200;
	var popupHeightC = $("#popupContactC").height();
	var popupWidthC = $("#popupContactC").width();
	//centering
	$("#popupContactC").css({
		"position": "absolute",
		"top": windowHeightC/2-popupHeightC/2,
		"left": windowWidthC/2-popupWidthC/2
	});
	//only need force for IE6
	
	
}

//centering popup
function centerPopupS(){
	//request data for centering
	var windowWidthS = screen.width;
	var windowHeightS = screen.height - 200;
	var popupHeightS = $("#popupContactS").height();
	var popupWidthS = $("#popupContactS").width();
	//centering
	$("#popupContactS").css({
		"position": "absolute",
		"top": windowHeightS/2-popupHeightS/2,
		"left": windowWidthS/2-popupWidthS/2
	});
	//only need force for IE6
	
	
}

function ShowComments(){
		//centering with css
		centerPopupC();
		//load popup
		loadPopupC();
}

function ShowShare(){
		//centering with css
		centerPopupS();
		//load popup
		loadPopupS();
}

//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
	
				
	//CLOSING POPUP
	//Click the x event!
	$("#popupContactCloseC").click(function(){
		disablePopupC();
	});
	//Click out event!
	$("#backgroundPopupC").click(function(){
		disablePopupC();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatusC==1){
			disablePopupC();
		}
	});
	
	//CLOSING POPUP S
	//Click the x event!
	$("#popupContactCloseS").click(function(){
		disablePopupS();
	});
	//Click out event!
	$("#backgroundPopupS").click(function(){
		disablePopupS();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatusS==1){
			disablePopupS();
		}
	});

});
