//SETTING UP OUR POPUP
//0 means disabled; 1 means enabled;
var loginPopupStatus = 0;
var registerPopupStatus = 0;

//loading popup with jQuery magic!



function loadLoginPopup(){
	//loads popup only if it is disabled
	if(loginPopupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#loginPopup").fadeIn("slow");
		loginPopupStatus = 1;
	}
}


function loadRegisterPopup(){
	//loads popup only if it is disabled
	if(registerPopupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#registerPopup").fadeIn("slow");
		registerPopupStatus = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopup(){
	//disables popup only if it is enabled
	if(loginPopupStatus==1){
		$("#backgroundPopup").fadeOut("slow");
		$("#loginPopup").fadeOut("slow");
		loginPopupStatus = 0;
	}
	if(registerPopupStatus==1){
		$("#backgroundPopup").fadeOut("slow");
		$("#registerPopup").fadeOut("slow");
		registerPopupStatus = 0;
	}
}



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

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




//DISJOINTED ROLLOVERS USING BUTTON NAVIGATION AND IMAGES FADING IN AND OUT

$(document).ready(function(){					
				
		var divid;			
		
		$("div#tour li").mouseout(function(){
		//make a variable and assign the hovered id to it
		var elid = $(this).attr('id');
		divid = elid;
		//hide the image currently there
		//$("div#images div").hide();		
		//fade in the image with the same id as the selected buttom
		$("li #t_" + elid + "").hide();
		});	
		
		//disjointed rollover function starting point
		$("div#tour li").mouseover(function(){
		//make a variable and assign the hovered id to it
		var elid = $(this).attr('id');
		divid = elid;
		//hide the image currently there
		//$("div#images div").hide();
		//fade in the image with the same id as the selected buttom		
		$("li #t_" + elid + "").show();
		
		});
				
		$("div#tour li a.closewindow").mousedown(function(){	
		//make a variable and assign the hovered id to it
		var elid = 	divid ;
		//hide the image currently there
		//fade in the image with the same id as the selected buttom
		$("li #t_" + elid + "").hide();	
		});	
		
				//LOADING POPUP
		//Click the button event!
		$(".login_popup").click(function(){
			//centering with css
			centerLoginPopup();
			//load popup
			loadLoginPopup();
		});

		$(".register_popup").click(function(){
			//centering with css

			centerRegisterPopup();
			//load popup
			loadRegisterPopup();
		});
					
		//CLOSING POPUP
		//Click the x event!
		$("#popupContactClose").click(function(){
			disablePopup();
		});
		//Click out event!
		$("#backgroundPopup").click(function(){
			disablePopup();
		});
		//Press Escape event!
		$(document).keypress(function(e){
			if(e.keyCode==27 && loginPopupStatus==1){
				disablePopup();
			}
		});

		
			


});