﻿/***************************/
//@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 loadPopupLogin(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#popupContactLogin").fadeIn("slow");
		popupStatus = 1;
	}
}

function loadPopupEdit(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#popupContactEdit").fadeIn("slow");
		popupStatus = 1;
	}
}

function loadPopupCorp(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#popupContactCorp").fadeIn("slow");
		popupStatus = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopupLogin(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#backgroundPopup").fadeOut("slow");
		$("#popupContactLogin").fadeOut("slow");
		popupStatus = 0;
	}
}

//disabling popup with jQuery magic!
function disablePopupEdit(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#backgroundPopup").fadeOut("slow");
		$("#popupContactEdit").fadeOut("slow");
		popupStatus = 0;
	}
}

//disabling popup with jQuery magic!
function disablePopupCorp(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#backgroundPopup").fadeOut("slow");
		$("#popupContactCorp").fadeOut("slow");
		popupStatus = 0;
	}
}

//disabling popup with jQuery magic!
function disablePopup(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#backgroundPopup").fadeOut("slow");
		$("#popupContactLogin").fadeOut("slow");
		$("#popupContactEdit").fadeOut("slow");
		$("#popupContactCorp").fadeOut("slow");
		popupStatus = 0;
	}
}



//centering popup
function centerPopupLogin(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeightLogin = $("#popupContactLogin").height();
	var popupWidthLogin = $("#popupContactLogin").width();
	
	//centering
	$("#popupContactLogin").css({
		"position": "absolute",
		"top": windowHeight/2-popupHeightLogin/2,
		"left": windowWidth/2-popupWidthLogin/2
	});
	//only need force for IE6
		
	$("#backgroundPopup").css({
		"height": windowHeight
	});
	
}

function centerPopupEdit(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeightEdit = $("#popupContactEdit").height();
	var popupWidthEdit = $("#popupContactEdit").width();
	
	//centering
	$("#popupContactEdit").css({
		"position": "absolute",
		"top": windowHeight/2-popupHeightEdit/2,
		"left": windowWidth/2-popupWidthEdit/2
	});
	//only need force for IE6
	
	$("#backgroundPopup").css({
		"height": windowHeight
	});
	
}


//centering popup
function centerPopupCorp(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeightLogin = $("#popupContactCorp").height();
	var popupWidthLogin = $("#popupContactCorp").width();
	
	//centering
	$("#popupContactCorp").css({
		"position": "absolute",
		"top": windowHeight/2-popupHeightLogin/2,
		"left": windowWidth/2-popupWidthLogin/2
	});
	//only need force for IE6
		
	$("#backgroundPopup").css({
		"height": windowHeight
	});
	
}

//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
	
	//LOADING POPUP
	//Click the button event!
	//$("#button").click(function(){
		//centering with css
		//centerPopup();
		//load popup
		//loadPopup();
	//});
	
	$('A[rel="externalLogin"]').click( function() {
        //centering with css
		centerPopupLogin();
		//load popup
		loadPopupLogin();
		//$("#flower_popup").attr('innerHTML') = 'http://localhost/member_login/index.php?action='+action;
    });
	
	$('A[rel="externalEdit"]').click( function() {
        //centering with css
		centerPopupEdit();
		//load popup
		loadPopupEdit();
		//$("#flower_popup").attr('innerHTML') = 'http://localhost/member_login/index.php?action='+action;
    });
	
	$('A[rel="externalCorp"]').click( function() {
        //centering with css
		centerPopupCorp();
		//load popup
		loadPopupCorp();
		//$("#flower_popup").attr('innerHTML') = 'http://localhost/member_login/index.php?action='+action;
    });
				
	//CLOSING POPUP
	//Click the x event!
	$("#popupContactCloseLogin").click(function(){
		disablePopupLogin();
	});
	
	//Click the x event!
	$("#popupContactCloseEdit").click(function(){
		disablePopupEdit();
	});	
	
	//Click the x event!
	$("#popupContactCloseCorp").click(function(){
		disablePopupCorp();
	});
	
	//Click out event!
	$("#backgroundPopup").click(function(){
		disablePopup();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
	});

});
