﻿/***************************/
//@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 popupStatus = 0;
var popupStatusHor = 0;

function loadPopup(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#popupForm").fadeIn("slow");
		popupStatus = 1;
	}
}
function loadPopupHor(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#popupFormHor").fadeIn("slow");
		popupStatusHor = 1;
	}
}

function disablePopup(){

	if(popupStatus==1){
		$("#backgroundPopup").fadeOut("slow");
		$("#popupForm").fadeOut("slow");
		popupStatus = 0;
	}
}

function disablePopupHor(){

	if(popupStatusHor==1){
		$("#backgroundPopup").fadeOut("slow");
		$("#popupFormHor").fadeOut("slow");
		popupStatusHor = 0;
	}
}

function centerPopup(){
	
	 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;
 	 }

	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupForm").height();
	var popupWidth = $("#popupForm").width();
	//centering
	$("#popupForm").css({
		"position": "absolute",
		"top": (windowHeight/2-popupHeight/2)+scrOfY,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	$("#backgroundPopup").css({
		"height": windowHeight
	});
	
}

function centerPopupHor(){
	
	 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;
 	 }

	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupFormHor").height();
	var popupWidth = $("#popupFormHor").width();
	//centering
	$("#popupFormHor").css({
		"position": "absolute",
		"top": (windowHeight/2-popupHeight/2)+scrOfY,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	$("#backgroundPopup").css({
		"height": windowHeight
	});
	
}


$(document).ready(function(){
	
	$(".adcadePopup").hover(
		function()
		{$(this).addClass("adcadePopupOver").css({
			"opacity": "0.5"});
		},
		function()
		{$(this).removeClass("adcadePopupOver").css({
			"opacity": "1.0"});
		}
	);
	
	$(".adcadePopup").click(function(){
		var filepath='adcade_includes/'+this.id;
		$.ajax({
        url: filepath,
        cache: false,
        success: function(html) { 
			$('#popupForm').empty();
			$("#popupForm").append(html);
			$("#popupFormClose").click(function(){
			disablePopup();
			});
			centerPopup();
			loadPopup();
			}
    	});
	});
	
	$(".adcadePopupHor").hover(
		function()
		{$(this).addClass("adcadePopupHorOver").css({
			"opacity": "0.5"});
		},
		function()
		{$(this).removeClass("adcadePopupHorOver").css({
			"opacity": "1.0"});
		}
	);
	
	$(".adcadePopupHor").click(function(){
		var filepath='adcade_includes/'+this.id;
		$.ajax({
        url: filepath,
        cache: false,
        success: function(html) { 
			$('#popupFormHor').empty();
			$("#popupFormHor").append(html);
			$("#popupFormCloseHor").click(function(){
			disablePopupHor();
			});
			centerPopupHor();
			loadPopupHor();
			}
    	});
	});
	
				
	$("#popupFormClose").click(function(){
		disablePopup();
	});
	
	$("#popupFormCloseHor").click(function(){
										   alert("HORIZONTAL");
		disablePopupHor();
	});
	

	$("#backgroundPopup").click(function(){
		disablePopup();
		disablePopupHor();
	});

	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
			disablePopupHor();
		}
	});

});

