//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.5"
		});
		$("#backgroundPopup").toggle();
		$("#popupContact").toggle();
		popupStatus = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopup(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#backgroundPopup").toggle();
		$("#popupContact").toggle();
		popupStatus = 0;
	}
}

//centering popup
function centerPopup(){
	//request data for centering
	var documentHeight;
	if(navigator.appVersion.indexOf('MSIE 6.0') != -1)
	{
		documentHeight = document.body.clientHeight;
	}
	else
	{
		documentHeight = document.documentElement.clientHeight;
	}

	var windowHeight = document.documentElement.clientHeight;
	var windowWidth = document.documentElement.clientWidth;
	var popupHeight = $("#popupContact").height();
	var popupWidth = $("#popupContact").width();
	//calculating percentage of visible screen to place the position top of the pop up
    var per_top = ((windowHeight * 10) /100);
	//centering
	$("#popupContact").css({
		//"position": "absolute",
		"top": per_top,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6


	$("#backgroundPopup").css({
		"height": documentHeight
	});

}


//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();
	});
	//Click out event!
	$("#backgroundPopup").click(function(){
		disablePopup();
	});

});



function show_popup(name){
        close_popup();
	centerPopup();
	loadPopup();
        document.getElementById(name).className = 'popupContactShow';
        
        if (document.getElementById('ad-box-1')){
           
           document.getElementById('ad-box-1').style.display = 'none';
           
        }
       
}

function close_popup(){
	if(document.getElementById('popupContent')){
		var div = document.getElementById('popupContent');
		var oKid = div.firstChild;
		while (oKid){
			oKid.className = 'popupContactHide';
			oKid = oKid.nextSibling;
	    }
	}

        if (document.getElementById('ad-box-1')){
            document.getElementById('ad-box-1').style.display = 'block';           
        }
	return true;
}
