﻿/***************************/
//@Author: Adrian "yEnS" Mato Gondelle
//@website: www.yensdesign.com
//@email: yensamg@gmail.com
//@license: Feel free to use it, but keep this credits please!					
/***************************/
var simplePopup = jQuery.noConflict();
//SETTING UP OUR POPUP
//0 means disabled; 1 means enabled;
var popupStatus = 0;
var linkStatus = 0;

//loading popup with jQuery magic!
function loadPopup1(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		simplePopup("#backgroundPopup").css({
			"opacity": "0.7"
		});
		simplePopup("#backgroundPopup").fadeIn("slow");
		simplePopup("#popupContact").fadeIn("slow");
		popupStatus = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopup1(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		simplePopup("#backgroundPopup").fadeOut("slow");
		simplePopup("#popupContact").fadeOut("slow");
		popupStatus = 0;
	}
}

//centering popup
function centerPopup1(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = simplePopup("#popupContact").height();
	var popupWidth = simplePopup("#popupContact").width();
	//centering
	simplePopup("#popupContact").css({
		"position": "absolute",
		//"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	simplePopup("#backgroundPopup").css({
		"height": windowHeight
	});
	
}






//CONTROLLING EVENTS IN jQuery
simplePopup(document).ready(function () {

    var a_href = simplePopup('.first-caption .moreLink').attr('href');

    simplePopup(".moreLink:contains('ASK THE GURU')").each(function () {


        simplePopup(this).removeClass().addClass('buttonPopup moreLink');
        simplePopup(this).removeAttr("href");
        simplePopup(this).attr("href", "#")


    });

    

    simplePopup(".moreLink:contains('Ask The Guru')").each(function () {


        simplePopup(this).removeClass().addClass('buttonPopup moreLink');
        simplePopup(this).removeAttr("href");
        simplePopup(this).attr("href", "#")


    });

    function click_handler() {
        // do something


        window.location = a_href;
    }

    simplePopup('.first-caption').parent("div").click(function () {

        centerPopup1();

        loadPopup1();

        // simplePopup('.first-caption').parent("div").bind('click', click_handler);

    });

    //LOADING POPUP
    //Click the button event!
    simplePopup(".buttonPopup").click(function () {

        //simplePopup('.first-caption').parent("div").unbind('click');
        //centering with css
        centerPopup1();
        //load popup
        loadPopup1();


    });

    simplePopup('.first-caption').parent("div").click(function () {
        //simplePopup(this).bind('click', click_handler);

        // click_handler();
    });

    //CLOSING POPUP
    //Click the x event!
    simplePopup("#popupContactClose").click(function () {
        disablePopup1();
        // simplePopup('.first-caption').parent("div").bind('click');
        //simplePopup('.first-caption').parent("div").bind('click', click_handler);
    });
    //Click out event!
    simplePopup("#backgroundPopup").click(function () {
        disablePopup1();
        //simplePopup('.first-caption').parent("div").bind('click', click_handler);
    });
    //Press Escape event!
    simplePopup(document).keypress(function (e) {
        if (e.keyCode == 27 && popupStatus == 1) {
            disablePopup();
        }
    });

});


//loading popup with jQuery magic!
function loadPopup() {
    //loads popup only if it is disabled
    if (popupStatus == 0) {
        simplePopup("#backgroundPopupT8").css({
            "opacity": "0.7"
        });
        simplePopup("#backgroundPopupT8").fadeIn("slow");
        simplePopup("#popupContactT8").fadeIn("slow");
        popupStatus = 1;
    }
}

//disabling popup with jQuery magic!
function disablePopup() {
    //disables popup only if it is enabled
    if (popupStatus == 1) {
        simplePopup("#backgroundPopupT8").fadeOut("slow");
        simplePopup(".popupContactT8").fadeOut("slow");
        popupStatus = 0;
    }
}

//centering popup
function centerPopup() {
    //request data for centering
    var windowWidth = document.documentElement.clientWidth;
    var windowHeight = document.documentElement.clientHeight;
    var popupHeight = simplePopup(".popupContactT8").height();
    var popupWidth = simplePopup(".popupContactT8").width();
    //centering
    simplePopup(".popupContactT8").css({
        //"position": "absolute",
        //"top": windowHeight/2-popupHeight/2,
        "left": windowWidth / 2 - popupWidth / 2
    });
    //only need force for IE6

    simplePopup("#backgroundPopupT8").css({
        "height": windowHeight
    });

}


//CONTROLLING EVENTS IN jQuery
simplePopup(document).ready(function () {

    //LOADING POPUP
    //Click the button event!
    simplePopup(".buttonPopupT8").click(function () {
        //centering with css
        centerPopup();
        //load popup
        //loads popup only if it is disabled
        if (popupStatus == 0) {
            simplePopup("#backgroundPopupT8").css({
                "opacity": "0.7"
            });
            simplePopup(this).parent().next('.popupContactT8').fadeIn('slow');
            simplePopup("#backgroundPopupT8").fadeIn("slow");
            //simplePopup("#popupContactT8").fadeIn("slow");
            popupStatus = 1;
        }
    });

    simplePopup(".buttonPopupT8").hover(function () {

        var rImgSrc = simplePopup(this).next('.rolloverImgHidden').html();
        
        if (rImgSrc != null) {
            var rPathImg = "background:url(" + rImgSrc + ") no-repeat 0 0;";
            simplePopup(this).attr('style', rPathImg);
        }

    },

    function () {

        var sImgSrc = simplePopup(this).parent().children('.standardImgHidden').html();

        if (sImgSrc != null) {
            var sPathImg = "background:url(" + sImgSrc + ") no-repeat 0 0;";
            simplePopup(this).attr('style', sPathImg);
        }
    });

    //CLOSING POPUP
    //Click the x event!
    simplePopup(".popupContactCloseT8").click(function () {
        disablePopup();
    });
    //Click out event!
    simplePopup("#backgroundPopupT8").click(function () {
        disablePopup();
    });
    //Press Escape event!
    simplePopup(document).keypress(function (e) {
        if (e.keyCode == 27 && popupStatus == 1) {
            disablePopup();
        }
    });

});
