//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");
		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");
   //HidePanel("backgroundPopup");
   //HidePanel("popupContact");

document.getElementById("contactArea").innerHTML = '';
		popupStatus = 0;
//document.getElementById("PopDiv").innerHTML = '';
Popup.hideAll();

//if(document.getElementById('div_userPhotoUploader'))
//document.getElementById('div_userPhotoUploader').style.display="none";
if(document.getElementById('div_backgroundSettings'))
document.getElementById('div_backgroundSettings').style.display="none";

if(!document.getElementById('bgColor'))
document.getElementById('bgColor').color.hidePicker();
	}
}

//centering popup
function centerPopup(w, h){
	//request data for centering
	
	var windowWidth;
	var windowHeight;
	
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
	windowWidth = window.innerWidth;
    windowHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    windowWidth = document.documentElement.clientWidth;
	windowHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
	windowWidth = document.body.clientWidth;
    windowHeight = document.body.clientHeight;
  }

	//var windowWidth = document.documentElement.clientWidth;
	//var windowHeight = document.documentElement.clientHeight;

	var popupHeight;
	var popupWidth;
	
        if(h!="")
        popupHeight = h;
        else
	popupHeight = $("#popupContact").height();	
   
        if(w!="")
        popupWidth = w;
        else      
	popupWidth = $("#popupContact").width();

        var yPos;
        if(popupHeight>650)
        {
yPos=20;
        }
        else
        {
yPos=windowHeight/2-popupHeight/2;
        }

//alert("Width: " + $("#popupContact").width());
	//centering
	$("#popupContact").css({
		"position": "absolute",
		"top": yPos,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6   
	
	$("#backgroundPopup").css({
		"height": windowHeight
	});
	
}

function popupfunNormal(w, h)
{
  centerPopup(w, h);
  loadPopup();
 // $("#backgroundPopup").style.display="none";
  document.getElementById("popupContactClose").style.display="block";
  document.getElementById("contactHeader").style.display="block";
  document.getElementById("contactHeaderUl").style.display="block";
}


function popupfun(w, h)
{
		centerPopup(w, h);
		loadPopup();
document.getElementById("backgroundPopup").style.display="block";

document.getElementById("popupContactClose").style.display="block";
document.getElementById("contactHeader").style.display="block";
document.getElementById("contactHeaderUl").style.display="block";
}
function popupstatusfun(w, h)
{
		centerPopup(w, h);
		loadPopup();
document.getElementById("backgroundPopup").style.display="block";
document.getElementById("popupContactClose").style.display="none";
document.getElementById("contactHeader").style.display="none";
document.getElementById("contactHeaderUl").style.display="none";

}

//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
				
	//CLOSING POPUP
	//Click the x event!
	$("#popupContactClose").click(function(){
		disablePopup();
	});
	//Click out event!
	$("#backgroundPopup").click(function(){
		disablePopup();
	});
	$(document).keydown(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
	});
});
