﻿/***************************/
//@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 loadPopup(){

	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#popupContact").fadeIn("slow");
		$("#popupContactAgentList").fadeIn("slow");
		$("#popupContactWall").fadeIn("slow");
		$("#popupContact1").fadeIn("slow");
		$("#popupContactBuyer").fadeIn("slow");
		
		
		if ( document.getElementById("content_search")!=null) {
			document.getElementById("content_search").style.display = 'none'
		}
		
		
		popupStatus = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopup(){
	
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#backgroundPopup").fadeOut("slow");
		$("#popupContact").fadeOut("slow");
		$("#popupContactAgentList").fadeOut("slow");
		$("#popupContactWall").fadeOut("slow");
		$("#popupContact1").fadeOut("slow");
		$("#popupContactBuyer").fadeOut("slow");
		
		if ( document.getElementById("content_search")!=null) {
			document.getElementById("content_search").style.display = 'inline'
		}
		
		
		popupStatus = 0;
		
		if ( document.getElementById("popupContactWall")!=null) {
		$.unblockUI();
		}
	}
}

//centering popup
function centerPopup(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var windowHeight123 = document.body.clientHeight;
	
	var popupHeight = $("#popupContact").height() - 100;
	var popupWidth = $("#popupContact").width();
	
	var popupWidth1 = $("#popupContact1").width();
	
	var popupHeight = $("#popupContactWall").height() - 500;
	var popupWidth = $("#popupContactWall").width()+100;
	
	var popupWidth3 = $("#popupContactBuyer").width();
	var popupHeight3 = $("#popupContactBuyer").height() ;
	
	
	var popupHeightAgent = $("#popupContactAgentList").height() - 100;
	var popupWidthAgent = $("#popupContactAgentList").width();

	
	
	

	//centering
	
	$("#popupContactWall").css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});

	
	$("#popupContact").css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2 -560,
		"left": windowWidth/2-popupWidth/2 -180
	});
	
	$("#popupContactAgentList").css({	
		"position": "absolute",
		"top": 160,
		"left": 500
	});
	$("#popupContact1").css({
		"position": "absolute",
		top: 650,
		"left": windowWidth/2-popupWidth/2
	});
		$("#popupContactBuyer").css({
		"position": "absolute",
		"top": windowHeight123 - popupHeight3*2,
		"left": 300
	});
	
	//only need force for IE6
	
	$("#backgroundPopup").css({
		"height":  document.body.offsetHeight
		
	});
	
}


//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
	
	//LOADING POPUP
	//Click the button event!
	$("#button").click(function(){
		//centering with css
		centerPopup();
		//load popup
		loadPopup();
	});
	
				
	//CLOSING POPUP
	//Click the x event!
	
	
	
	
	$("#popupContactClose").click(function(){
		disablePopup();
	});
	$("#popupContactAgentListClose").click(function(){
		disablePopup();
	});
	$("#popupContactClose1").click(function(){
		disablePopup();
	});
	$("#popupContactBuyerClose").click(function(){
		disablePopup();
	});
	
	//Click out event!
	$("#backgroundPopup").click(function(){
		disablePopup();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
	});

});