﻿/***************************/
//@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 popupStatus = 0;
var popupDiv = "";

//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");
		$(popupDiv).fadeIn("slow");
		popupStatus = 1; 
	}
}

//disabling popup with jQuery magic!
function disablePopup(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#backgroundPopup").fadeOut("slow");
		$(popupDiv).fadeOut("slow");
		popupStatus = 0;
	}
}

//centering popup
function centerPopup(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $(popupDiv).height();
	var popupWidth = $(popupDiv).width();
	
	
	
	
	//centering
	$(popupDiv).css({
		"position": "absolute",		
		"left": windowWidth/2-popupWidth/2 - 10
	});
	//"top": windowHeight/2-popupHeight/2,
	
	//only need force for IE6
	
	
	
	$("#backgroundPopup").css({
		"height": windowHeight
	});

	
	
}


//CONTROLLING EVENTS IN jQuery
$(document).ready(function() {

	//LOADING POPUP
	//Click the button event!
	$("#buttonContact").click(function() {
		popupDiv = "#popupContact";
		//centering with css
		centerPopup();
		//load popup
		loadPopup();
	});


	//Click the button event!
	$("#buttonCarriers").click(function() {
		popupDiv = "#popupCarriers";
		//centering with css
		centerPopup();
		//load popup
		loadPopup();
	});


	//Click the button event!
	$("#buttonWriteUs").click(function() {
	popupDiv = "#popupWriteUs";
		//centering with css
		centerPopup();
		//load popup
		loadPopup();
	});

	
	


	//CLOSING POPUP
	//Click the x event!
	$(".popUpCloseBtn").click(function() {
		disablePopup();
	});


	//Click out event!
	$("#backgroundPopup").click(function() {
		disablePopup();
	});
	//Press Escape event!
	$(document).keypress(function(e) {
		if (e.keyCode == 27 && popupStatus == 1) {
			disablePopup();
		}
	});

});




function open_popup(dokument, sirka, vyska, centrovat, pozice_l, pozice_h) {
	if (centrovat == 1) {
		so = screen.width;
		vo = screen.height;
		zleva = ((so - sirka) / 2) - 13;
		shora = (vo - vyska) / 2;
		//shora = 100;
	} else {
		zleva = pozice_l;
		shora = pozice_h;
	}
	popup_win = window.open(dokument, "popup_okno", "width=" + sirka + ",height=" + vyska + ",left=" + zleva + ",top=" + shora + ",location=0,menubar=0,resizable=0,scrollbars=1,status=0,titlebar=0,toolbar=0");
	popup_win.focus();
}

