﻿/***************************/
//@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;

//loading popup with jQuery magic!
function loadPopup(numPopup){
    var indexPopup = numPopup; 
    //loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("slow");
		switch (indexPopup) {
		    case 1:
		        $("#popupContact1").fadeIn("slow");
		        break;
		    case 2:
		        $("#popupContact2").fadeIn("slow");
		        break;
		    case 3:
		        $("#popupContact3").fadeIn("slow");
		        break;
		    case 4:
		        $("#popupContact4").fadeIn("slow");
		        break;
		    case 5:
		        $("#popupContact5").fadeIn("slow");
		        break;
		    case 6:
		        $("#popupContact6").fadeIn("slow");
		        break;
		    case 7:
		        $("#popupContact7").fadeIn("slow");
		        break;
		    case 8:
		        $("#popupContact8").fadeIn("slow");
		        break;
		    case 9:
		        $("#popupContact9").fadeIn("slow");
		        break;
		    case 10:
		        $("#popupContact10").fadeIn("slow");
		        break;
		}
		popupStatus = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopup(numPopup){
    var indexPopup = numPopup;
    //alert(indexPopup);
	//disables popup only if it is enabled
	if (popupStatus==1){
	    $("#backgroundPopup").fadeOut("slow");
	    switch (indexPopup) {
	        case 1:
	            $("#popupContact1").fadeOut("slow");
	            break;
	        case 2:
	            $("#popupContact2").fadeOut("slow");
	            break;
	        case 3:
	            $("#popupContact3").fadeOut("slow");
	            break;
	        case 4:
	            $("#popupContact4").fadeOut("slow");
	            break;
	        case 5:
	            $("#popupContact5").fadeOut("slow");
	            break;
	        case 6:
	            $("#popupContact6").fadeOut("slow");
	            break;
	        case 7:
	            $("#popupContact7").fadeOut("slow");
	            break;
	        case 8:
	            $("#popupContact8").fadeOut("slow");
	            break;
	        case 9:
	            $("#popupContact9").fadeOut("slow");
	            break;
	        case 10:
	            $("#popupContact10").fadeOut("slow");
	            break;
	    }
		popupStatus = 0;
	}
}

//centering popup
function centerPopup(numPopup) {
    var indexPopup = numPopup;
    //request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
    switch (indexPopup){
        case 1:
            var popupHeight = $("#popupContact1").height();
            var popupWidth = $("#popupContact1").width();
            //centering
//            $("#popupContact1").css({
//                "position": "absolute",
//                "top": windowHeight / 2 - popupHeight / 2,
//                "left": windowWidth / 2 - popupWidth / 2
//            });
            $("#popupContact1").css({
                "position": "fixed",
                "top": 15,
                "left": 100
            });

            break;
        case 2:
            var popupHeight = $("#popupContact2").height();
            var popupWidth = $("#popupContact2").width();
            //centering
//            $("#popupContact2").css({
//                "position": "absolute",
//                "top": windowHeight / 2 - popupHeight / 2,
//                "left": windowWidth / 2 - popupWidth / 2
//            });
            $("#popupContact2").css({
                "position": "fixed",
                "top": 15,
                "left": 100
            });

            break;
        case 3:
            var popupHeight = $("#popupContact3").height();
            var popupWidth = $("#popupContact3").width();
            //centering
//            $("#popupContact3").css({
//                "position": "absolute",
//                "top": windowHeight / 2 - popupHeight / 2,
//                "left": windowWidth / 2 - popupWidth / 2
//            });
            $("#popupContact3").css({
                "position": "fixed",
                "top": 15,
                "left": 100
            });
            break;
        case 4:
            var popupHeight = $("#popupContact4").height();
            var popupWidth = $("#popupContact4").width();
            //centering
//            $("#popupContact4").css({
//                "position": "absolute",
//                "top": windowHeight / 2 - popupHeight / 2,
//                "left": windowWidth / 2 - popupWidth / 2
//            });

            $("#popupContact4").css({
                "position": "fixed",
                "top": 15,
                "left": 100
            });

            break;
        case 5:
            var popupHeight = $("#popupContact5").height();
            var popupWidth = $("#popupContact5").width();
            //centering
//            $("#popupContact5").css({
//                "position": "absolute",
//                "top": windowHeight / 2 - popupHeight / 2,
//                "left": windowWidth / 2 - popupWidth / 2
//            });
            $("#popupContact5").css({
                "position": "fixed",
                "top": 15,
                "left": 100
            });
            break;
        case 6:
            var popupHeight = $("#popupContact6").height();
            var popupWidth = $("#popupContact6").width();
            //centering
//            $("#popupContact6").css({
//                "position": "absolute",
//                "top": windowHeight / 2 - popupHeight / 2,
//                "left": windowWidth / 2 - popupWidth / 2
//            });
            $("#popupContact6").css({
                "position": "fixed",
                "top": 15,
                "left": 100
            });
            break;
        case 7:
            var popupHeight = $("#popupContact7").height();
            var popupWidth = $("#popupContact7").width();
            //centering
//            $("#popupContact7").css({
//                "position": "absolute",
//                "top": windowHeight / 2 - popupHeight / 2,
//                "left": windowWidth / 2 - popupWidth / 2
//            });
            $("#popupContact7").css({
                "position": "fixed",
                "top": 15,
                "left": 100
            }); 
            break;
        case 8:
            var popupHeight = $("#popupContact8").height();
            var popupWidth = $("#popupContact8").width();
            //centering
//            $("#popupContact8").css({
//                "position": "absolute",
//                "top": windowHeight / 2 - popupHeight / 2,
//                "left": windowWidth / 2 - popupWidth / 2
//            });
            $("#popupContact8").css({
                "position": "fixed",
                "top": 15,
                "left": 100
            });
            break;
        case 9:
            var popupHeight = $("#popupContact9").height();
            var popupWidth = $("#popupContact9").width();
            //centering
//            $("#popupContact9").css({
//                "position": "absolute",
//                "top": windowHeight / 2 - popupHeight / 2,
//                "left": windowWidth / 2 - popupWidth / 2
//            });
            $("#popupContact9").css({
                "position": "fixed",
                "top": 15,
                "left": 100
            });
            break;
        case 10:
            var popupHeight = $("#popupContact10").height();
            var popupWidth = $("#popupContact10").width();
            //centering
//            $("#popupContact10").css({
//                "position": "absolute",
//                "top": windowHeight / 2 - popupHeight / 2,
//                "left": windowWidth / 2 - popupWidth / 2
//            });
            $("#popupContact10").css({
                "position": "fixed",
                "top": 15,
                "left": 100
            });
            break;
    }
	//only need force for IE6
	
	$("#backgroundPopup").css({
		"height": windowHeight
	});
	
}


//CONTROLLING EVENTS IN jQuery
$(document).ready(function () {
    //LOADING POPUP
    //Click the offerta event!
    if ($("#offerta1")) {
        $("#offerta1").click(function () {
            //centering with css
            centerPopup(1);
            //load popup
            loadPopup(1);
        });
    };
    if ($("#offerta2")) {
        $("#offerta2").click(function () {
            //centering with css
            centerPopup(2);
            //load popup
            loadPopup(2);
        });
    };
    if ($("#offerta3")) {
        $("#offerta3").click(function () {
            //centering with css
            centerPopup(3);
            //load popup
            loadPopup(3);
        });
    };
    if ($("#offerta4")) {
        $("#offerta4").click(function () {
            //centering with css
            centerPopup(4);
            //load popup
            loadPopup(4);
        });
    };
    if (document.getElementById("offerta5")) {
        $("#offerta5").click(function () {
            //centering with css
            centerPopup(5);
            //load popup
            loadPopup(5);
        });
    };
    if (document.getElementById("offerta6")) {
        $("#offerta6").click(function () {
            //centering with css
            centerPopup(6);
            //load popup
            loadPopup(6);
        });
    };
    if (document.getElementById("offerta7")) {
        $("#offerta7").click(function () {
            //centering with css
            centerPopup(7);
            //load popup
            loadPopup(7);
        });
    };
    if (document.getElementById("offerta8")) {
        $("#offerta8").click(function () {
            //centering with css
            centerPopup(8);
            //load popup
            loadPopup(8);
        });
    };
    if (document.getElementById("offerta9")) {
        $("#offerta9").click(function () {
            //centering with css
            centerPopup(9);
            //load popup
            loadPopup(9);
        });
    };
    if (document.getElementById("offerta10")) {
        $("#offerta10").click(function () {
            //centering with css
            centerPopup(10);
            //load popup
            loadPopup(10);
        });
    };
    //CLOSING POPUP
    //Click the x event!    
    if ($("#popupContactClose1")) {
        $("#popupContactClose1").click(function () {
            disablePopup(1);
        });
    };
    if ($("#popupContactClose2")) {
        $("#popupContactClose2").click(function () {
            disablePopup(2);
        });
    };
    if ($("#popupContactClose3")) {
        $("#popupContactClose3").click(function () {
            disablePopup(3);
        });
    };
    if ($("#popupContactClose4")) {
        $("#popupContactClose4").click(function () {
            disablePopup(4);
        });
    };
    if (document.getElementById("popupContactClose5")) {
        $("#popupContactClose5").click(function () {
            disablePopup(5);
        });
    };
    if (document.getElementById("popupContactClose6")) {
        $("#popupContactClose6").click(function () {
            disablePopup(6);
        });
    };
    if (document.getElementById("popupContactClose7")) {
        $("#popupContactClose7").click(function () {
            disablePopup(7);
        });
    };
    if (document.getElementById("popupContactClose8")) {
        $("#popupContactClose8").click(function () {
            disablePopup(8);
        });
    };
    if (document.getElementById("popupContactClose9")) {
        $("#popupContactClose9").click(function () {
            disablePopup(9);
        });
    };
    if (document.getElementById("popupContactClose10")) {
        $("#popupContactClose10").click(function () {
            disablePopup(10);
        });
    };

    //Click out event!
    if ($("#backgroundPopup")) {
        $("#backgroundPopup").click(function () {
            disablePopup(1);
            disablePopup(2);
            disablePopup(3);
            disablePopup(4);
            disablePopup(5);
            disablePopup(6);
            disablePopup(7);
            disablePopup(8);
            disablePopup(9);
            disablePopup(10);
        });
    };
    
//    //Press Escape event!
//    $(document).keypress(function (e) {
//        if (e.keyCode == 27 && popupStatus == 1) {
//            disablePopup(1);
//            disablePopup(2);
//            disablePopup(3);
//            disablePopup(4);
//            disablePopup(5);
//            disablePopup(6);
//            disablePopup(7);
//            disablePopup(8);
//            disablePopup(9);
//            disablePopup(10);
//        }
//    });

    if ($("#popupPrint1")) {
        $("#popupPrint1").click(function () {
            var o = $("#popupContact1");
            o.jqprint();
        });
    };
    if ($("#popupPrint2")) {
        $("#popupPrint2").click(function () {
            var o = $("#popupContact2");
            o.jqprint();
        });
    };
    if ($("#popupPrint3")) {
        $("#popupPrint3").click(function () {
            var o = $("#popupContact3");
            o.jqprint();
        });
    };
    if ($("#popupPrint4")) {
        $("#popupPrint4").click(function () {
            var o = $("#popupContact4");
            o.jqprint();
        });
    };
    if (document.getElementById("popupPrint5")) {
        $("#popupPrint5").click(function () {
            var o = $("#popupContact5");
            o.jqprint();
        });
    };
    if (document.getElementById("popupPrint6")) {
        $("#popupPrint6").click(function () {
            var o = $("#popupContact6");
            o.jqprint();
        });
    };
    if (document.getElementById("popupPrint7")) {
        $("#popupPrint7").click(function () {
            var o = $("#popupContact7");
            o.jqprint();
        });
    };
    if (document.getElementById("popupPrint8")) {
        $("#popupPrint8").click(function () {
            var o = $("#popupContact8");
            o.jqprint();
        });
    };
    if (document.getElementById("popupPrint9")) {
        $("#popupPrint9").click(function () {
            var o = $("#popupContact9");
            o.jqprint();
        });
    };
    if (document.getElementById("popupPrint10")) {
        $("#popupPrint10").click(function () {
            var o = $("#popupContact10");
            o.jqprint();
        });
    };
});
