//SETTING UP OUR POPUP
//0 means disabled; 1 means enabled;

var popupStatus = 0;

//loading popup with jQuery magic!
function loadPopup(bgContainer, popUpContainer){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#"+bgContainer).css({
			"opacity": "0.7"
		});
		$("#"+bgContainer).fadeIn("fast");
		//$("#"+popUpContainer).fadeIn("fast");
		$("#"+popUpContainer).fadeIn("fast",function(){
			try{
			$(".express-itr").dropShadow();
		}catch(e){}	        });

		popupStatus = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopup(bgContainer, popUpContainer){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#"+bgContainer).fadeOut("fast");
		$("#"+popUpContainer).fadeOut("fast");
		popupStatus = 0;
	}
}

//centering popup
function centerPopup(bgContainer, popUpContainer){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#"+popUpContainer).height();
	var popupWidth = $("#"+popUpContainer).width();
	//centering
	$("#"+popUpContainer).css({
		"position": "fixed",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	$("#"+bgContainer).css({
		"height": windowHeight,
		"z-index":1000
	});
	
}
(function() {
try{
	window.addEventListener("resize", function(event) {
		if(popupStatus == 1){
			centerPopup("backgroundPopup", "popup");
			loadPopup("backgroundPopup", "popup");
			centerPopup("backgroundPopup", "thank_you_error");
			loadPopup("backgroundPopup", "thank_you_error");
loadPopup("backgroundPopup", "map_popup");
			centerPopup("backgroundPopup", "map_popup");
		}
	}, false);
}catch(e){
	window.attachEvent("onresize", function(event) {
		if(popupStatus == 1){
			centerPopup("backgroundPopup", "popup");
			loadPopup("backgroundPopup", "popup");
			centerPopup("backgroundPopup", "thank_you_error");
			loadPopup("backgroundPopup", "thank_you_error");
loadPopup("backgroundPopup", "map_popup");
			centerPopup("backgroundPopup", "map_popup");
		}
	}, false);
}
})();




//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
	try{
		$(".prompt").blur(function () {
		   var inputValue = $.trim($(this).val());
		   $(this).val(inputValue);
		});
	}catch(e){alert(e);}



	//LOADING POPUP
	//Click the button event!
	$("#express_interest").click(function(){
		//centering with css
		centerPopup("backgroundPopup", "popup");
		//load popup
		loadPopup("backgroundPopup", "popup");
		$('#popup form').get(0).reset();
		
		$("#item_type").selectbox().bind('change', function(){
			$("<div>Value of #item_type changed to: "+$(this).val()+"<\/div>").appendTo('#item_type .demoTarget').fadeOut(5000, function(){
				$(this).remove();
			});
		});
		$('.jquery-selectbox-currentItem').text("Please select");
		//$(".express-itr").dropShadow();
	});
				
	//CLOSING POPUP
	//Click the x event!
	$("#popupClose").click(function(){
		disablePopup("backgroundPopup", "popup");
		$(".express-itr").removeShadow();
	});
	$("#victoria_street, #edgware_road, #old_brompton_road, #fleet_street").live('click', function(){
	loadPopup("backgroundPopup", "map_popup");
	centerPopup("backgroundPopup", "map_popup");
	
	
	
});
$("#close_butngmap").live('click', function(){
	disablePopup("backgroundPopup", "map_popup");
});
});


