﻿/***************************/
//@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 FB Connect popup with jQuery magic!
function loadPopup4(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.9"
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#popupVideo").delay("900").slideDown("slow");
		popupStatus = 1;
	}
}

//loading register popup with jQuery magic!
function loadPopup(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.9"
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#popupRegister").slideDown("slow");
		popupStatus = 1;
	}
}

//loading login popup with jQuery magic!
function loadPopup2(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.9"
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#popupLogin").delay("900").slideDown("slow");
		popupStatus = 1;
	}
}

//loading forgot password popup with jQuery magic!
function loadPopup3(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.9"
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#popupForgot").delay("900").slideDown("slow");
		popupStatus = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopup(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#popupVideo").slideUp("slow");
		$("#popupRegister").slideUp("slow");
		$("#popupLogin").slideUp("slow");
		$("#popupForgot").slideUp("slow");
		$("#backgroundPopup").fadeOut("slow");
		$("#resetPwd").hide();
		$("#registerformlog").show();
		$("#RegMessage").hide();
		$("#registerform").show();
		document.getElementById("loginHeader").innerHTML="Login to your IQuest account";
		popupStatus = 0;
	}
}

//centering login popup
function centerPopup4(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupVideo").height();
	var popupWidth = $("#popupVideo").width();
	//centering
	$("#popupVideo").css({
		"position": "absolute",
		"top": Math.abs(windowHeight/2-popupHeight/2)+getScrollXY(),
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	$("#backgroundPopup").css({
		"height": windowHeight
	});
	
}

//centering register popup
function centerPopup(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupRegister").height();
	var popupWidth = $("#popupRegister").width();
	//centering
	$("#popupRegister").css({
		"position": "absolute",
		"top":Math.abs(windowHeight/2-popupHeight/2)+getScrollXY(),
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	$("#backgroundPopup").css({
		"height": windowHeight
	});
	
}

//centering login popup
function centerPopup2(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupLogin").height();
	var popupWidth = $("#popupLogin").width();
	//centering
	$("#popupLogin").css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	$("#backgroundPopup").css({
		"height": windowHeight
	});
	
}

//centering login popup
function centerPopup3(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupForgot").height();
	var popupWidth = $("#popupForgot").width();
	//centering
	$("#popupForgot").css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	$("#backgroundPopup").css({
		"height": windowHeight
	});
	
}

//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
	//LOADING REGISTER POPUP
		//Click the button event!
	$("#videoBtn").click(function(){
		//centering with css
		$("#RegMessagefb").hide();
		//document.registerform.reset();
		$("#registerformfb").show();
		centerPopup4();
		//load popup
		loadPopup4();
	});
	//Click the button event!
	$("#registerButton").click(function(){
		//centering with css
		$("#RegMessage").hide();
		document.registerform.reset();
		$("#registerform").show();
		$("#popHeader").show();
		centerPopup();
		//load popup
		loadPopup();
	});
	
	//LOADING LOGIN POPUP
	//Click the button event!
	$("#loginButton").click(function(){
		//centering with css
		centerPopup2();
		//load popup
		loadPopup2();
	});	
	
		//Click the button event!
	$("#forgotLink").click(function(){
		//centering with css
		centerPopup3();
		//load popup
		loadPopup3();
	});	
		
	//CLOSING POPUP
	//Click the x event!
	$(".popupClose").click(function(){
		disablePopup();
	});
	//Click out event!
//	$("#backgroundPopup").click(function(){
//		disablePopup();
//	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
	});

});
//calculate scrolling offset
function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return scrOfY;
}
