//SETTING UP OUR POPUP
//0 means disabled; 1 means enabled;
var popupStatusUpdateAccount = 0;
var popupStatusChangePicture = 0;
var popupStatusVideo=0;

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 {X:scrOfX, Y:scrOfY};
}

function getWindowSize() {
	var myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
	//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
	//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
	//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}
	return{X:myWidth, Y:myHeight}
} 

//loading popup with jQuery magic!
function loadUpdateAccountPopup(){
		//loads popup only if it is disabled
	if(popupStatusUpdateAccount==0){
			$("#backgroundPopup").css({
			"opacity": "0.7"
			});
			$("#backgroundPopup").fadeIn("slow");
			$("#div_popupUpdateAccount").fadeIn("slow");
			popupStatusUpdateAccount = 1;
	}
}

function loadChangePicturePopup(){
		//loads popup only if it is disabled
	if(popupStatusChangePicture==0){
			$("#backgroundPopup").css({
			"opacity": "0.7"
			});
			$("#backgroundPopup").fadeIn("slow");
			$("#div_popupChangePicture").fadeIn("slow");
			popupStatusChangePicture = 1;
	}
}

function loadVideoPopup(){
    if(popupStatusVideo==0){
		$("#backgroundPopup").css({
		"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#div_popupVideo").fadeIn("slow");
		popupStatusVideo = 1;
	}
    
}

//disabling popup with jQuery magic!
function disableUpdateAccountPopup(){
	//disables popup only if it is enabled
	if(popupStatusUpdateAccount==1){
		$("#backgroundPopup").fadeOut("slow");
		$("#div_popupUpdateAccount").fadeOut("slow");
		popupStatusUpdateAccount = 0;
	}
}

//disabling popup with jQuery magic!
function disableChangePicturePopup(){
	//disables popup only if it is enabled
	if(popupStatusChangePicture==1){
		$("#backgroundPopup").fadeOut("slow");
		$("#div_popupChangePicture").fadeOut("slow");
		popupStatusChangePicture = 0;
	}
}

function disableVideoPopup(){
    //disables popup only if it is enabled
	if(popupStatusVideo==1){
		$("#backgroundPopup").fadeOut("slow");
		$("#div_popupVideo").fadeOut("slow");
		popupStatusVideo = 0;
	}
}

//centering popup
function centerUpdateAccountPopup(){
	
	var windowDim = getWindowSize();
	var popupHeight = $("#div_popupUpdateAccount").height();
	var popupWidth = $("#div_popupUpdateAccount").width();
	var scroll = getScrollXY(); 
	

	//centering
	$("#div_popupUpdateAccount").css({
	"position": "absolute",
	"top": windowDim.Y/2-popupHeight/2 + scroll.Y-5,
	"left": windowDim.X/2-popupWidth/2 + scroll.X-15 
	});
	//only need force for IE6
	
	$("#backgroundPopup").css({
		"height": windowDim.Y 
	});

}

function centerChangePicturePopup(){
	
	var windowDim = getWindowSize();
	var popupHeight = $("#div_popupChangePicture").height();
	var popupWidth = $("#div_popupChangePicture").width();
	var scroll = getScrollXY(); 
	

	//centering
	$("#div_popupChangePicture").css({
	"position": "absolute",
	"top": windowDim.Y/2-popupHeight/2 + scroll.Y-5,
	"left": windowDim.X/2-popupWidth/2 + scroll.X-15 
	});
	//only need force for IE6
	
	$("#backgroundPopup").css({
		"height": windowDim.Y 
	});

}


function centerVideoPopup(){
	
	var windowDim = getWindowSize();
	var popupHeight = $("#div_popupVideo").height();
	var popupWidth = $("#div_popupVideo").width();
	var scroll = getScrollXY(); 
	

	//centering
	$("#div_popupVideo").css({
	"position": "absolute",
	"top": windowDim.Y/2-popupHeight/2 + scroll.Y-5,
	"left": windowDim.X/2-popupWidth/2 + scroll.X-15 
	});
	//only need force for IE6
	
	$("#backgroundPopup").css({
		"height": windowDim.Y 
	});

}

$(document).ready(function(){
	
	//LOADING POPUP
	//Click the button event!
	$("#div_updateAccount").click(function(){
	//centering with css
		centerUpdateAccountPopup();
	//load popup
		loadUpdateAccountPopup();
	});
    
    //LOADING POPUP
	//Click the button event!
    $("#div_changePicture").click(function(){
	//centering with css
		centerChangePicturePopup();
	//load popup
		loadChangePicturePopup();
	});
    $("#img_changePicture").click(function(){
    	//centering with css
    		centerChangePicturePopup();
    	//load popup
    		loadChangePicturePopup();
    	});    
    
    //LOADING POPUP
	//Click the button event!
    $("#a_Video").click(function(){
	//centering with css
		centerVideoPopup();
	//load popup
		loadVideoPopup();
	});
   
	
	//CLOSING POPUP
	//Click the x event!
	$("#popupUpdateAccountClose").click(function(){
		disableUpdateAccountPopup();
	});
    
    $("#popupChangePictureClose").click(function(){
		disableChangePicturePopup();
	});
    
    $("#popupVideoClose").click(function(){
		disableVideoPopup();
	});
    
    
	//Click out event!
	$("#backgroundPopup").click(function(){
		disableUpdateAccountPopup();
	});
    $("#backgroundPopup").click(function(){
        disableChangePicturePopup();
	});
    
    $("#backgroundPopup").click(function(){
        disableVideoPopup();
	});
	//Press Escape event!
	$(document).keypress(function(e){
	if(e.keyCode==27 && (popupStatusUpdateAccount==1 || popupStatusChangePicture==1 || popupStatusVideo==1)){
		disableUpdateAccountPopup();
        disableChangePicturePopup();
        disableVideoPopup();
	}
	});

});




