/***************************/
//@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 loadPopup1(){
    //loads popup only if it is disabled
    if(popupStatus==0){
        $("#backgroundPopup").css({
            "opacity": "0.7"
        });
        $("#backgroundPopup").fadeIn("slow");
        $("#channeldb2").css({
            "display": "none"
        });
        $("#login").fadeIn("slow");
        $("#signup").fadeOut("slow");
        popupStatus = 1;
    }
}
function loadPopup2(){
    //loads popup only if it is disabled
    if(popupStatus==0){
        $("#backgroundPopup").css({
            "opacity": "0.7"
        });
        $("#backgroundPopup").fadeIn("slow");
        $("#login").fadeOut("slow");
        $("#signup").fadeIn("slow");
        popupStatus = 1;
    }
}
function loadPopupCer(){
    //loads popup only if it is disabled
    if(popupStatus==0){
        $("#backgroundPopup").css({
            "opacity": "0.7"
        });
        $("#backgroundPopup").fadeIn("slow");
        $("#certificate").fadeIn("slow");
        popupStatus = 1;
    }
}
function loadPopupDet(){
    //loads popup only if it is disabled
    if(popupStatus==0){
        $("#backgroundPopup").css({
            "opacity": "0.7"
        });
        $("#backgroundPopup").fadeIn("slow");
        $("#det").fadeIn("slow");
        popupStatus = 1;
    }
}

function loadChanneldb2Popup(){
    //loads popup only if it is disabled
    if(popupStatus==1){
		
        $("#channeldb2").fadeIn("slow");
		
    }
}

//disabling popup with jQuery magic!
function disablePopup(){
    //disables popup only if it is enabled
    if(popupStatus==1){
        $("#backgroundPopup").fadeOut("slow");
        $("#login").fadeOut("slow");
        $("#signup").fadeOut("slow");
        $("#certificate").fadeOut("slow");
        $("#det").fadeOut("slow");
        popupStatus = 0;
    }
}

//centering popup
function centerPopup1(){
    //request data for centering
    var windowWidth = document.documentElement.clientWidth;
    var windowHeight = document.documentElement.clientHeight;
    var popupHeight = $("#login").height();
    var popupWidth = $("#login").width();
    //centering
    $("#login").css({
        "position": "absolute",
        "top": windowHeight/2-popupHeight/2,
        "left": windowWidth/2-popupWidth/2
    });
    //only need force for IE6
	
    $("#backgroundPopup").css({
        "height": windowHeight
    });
	
}
function centerPopup2(){
    //request data for centering
    var windowWidth = document.documentElement.clientWidth;
    var windowHeight = document.documentElement.clientHeight;
    var popupHeight = $("#signup").height();
    var popupWidth = $("#signup").width();
    //centering
    $("#signup").css({
        "position": "absolute",
        "top": windowHeight/2-popupHeight/2,
        "left": windowWidth/2-popupWidth/2
    });
	
    //only need force for IE6
	
    $("#backgroundPopup").css({
        "height": windowHeight
    });
	
}
function centerPopupCer(){
    //request data for centering
    var windowWidth = document.documentElement.clientWidth;
    var windowHeight = document.documentElement.clientHeight;
    var popupHeight = $("#certificate").height();
    var popupWidth = $("#certificate").width();
    //centering
    $("#certificate").css({
        "position": "absolute",
        "top": windowHeight/2-popupHeight/2,
        "left": windowWidth/2-popupWidth/2
    });
	
    //only need force for IE6
	
    $("#backgroundPopup").css({
        "height": windowHeight
    });
	
}
function centerPopupDet(){
    //request data for centering
    var windowWidth = document.documentElement.clientWidth;
    var windowHeight = document.documentElement.clientHeight;
    var popupHeight = $("#det").height();
    var popupWidth = $("#det").width();
    //centering
    $("#det").css({
        "position": "absolute",
        "top": windowHeight/2-popupHeight/2,
        "left": windowWidth/2-popupWidth/2
    });
	
    //only need force for IE6
	
    $("#backgroundPopup").css({
        "height": windowHeight
    });
	
}

function placeChannelDB2(){
    //request data for centering
    var windowWidth = $("#login").width();     
    var windowHeight = $("#login").height();
    var popupHeight = $("#channeldb2").height();
    var popupWidth = $("#channeldb2").width();
    //centering
    $("#channeldb2").css({
        "position": "absolute",
        "top": windowHeight-popupHeight ,
        "left": windowWidth-popupWidth - 30
    });  
}

function submitNing()
{
    $('#channeldb2').append('<input type="hidden" name="method" value="ning" />');
    $('#channeldb2').append('<input type="hidden" id="openid_identifier" name="openid_identifier" value="www.channeldb2.com"/>');
    $('#channeldb2').submit();
}


//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
    openid.init('openid_identifier');
     
    $("#db2").click(function(){
        placeChannelDB2();
        loadChanneldb2Popup();
    });
    //LOADING POPUP
    //Click the button event!
/*
    $("#loginbutton").click(function(){
        //centering with css
        centerPopup1();
        //load popup
        loadPopup1();
    });
    $("#signbutton").click(function(){
        //centering with css
        centerPopup1();
        //load popup
        loadPopup1();
    });

    $("#sgn").click(function(){
        //centering with css
        centerPopup1();
        //load popup
        loadPopup1();
    });


    $("#signbutton2").click(function(){
        //centering with css
        centerPopup1();
        //load popup
        loadPopup1();
    });
*/
			
	$("#cer").click(function(){
		disablePopup();
		centerPopupCer();
		loadPopupCer();
	});	


	$("#boy").click(function(){
		disablePopup();
		centerPopupDet();
		loadPopupDet();
	});

/*
	$("#detlog").click(function(){
        disablePopup();
        //centering with css
        centerPopup1();
        //load popup
        loadPopup1();
    });
*/
		
    //Click out event!
    $("#backgroundPopup").click(function(){
        disablePopup();
    });
    $("#close").click(function(){
        disablePopup();
    });
	
    $("#close2").click(function(){
        disablePopup();
    });
	
    $("#close3").click(function(){
        disablePopup();
    });
	$("#close4").click(function(){
        disablePopup();
    });
    //Press Escape event!
    $(document).keypress(function(e){
        if(e.keyCode==27 && popupStatus==1){
            disablePopup();
        }
    });

});

