
//SETTING UP 
//0 means disabled; 1 means enabled;
var tourStatus = 0;

//loading tour with jQuery magic!
function loadTour(){
	//loads tour only if it is disabled
	if(tourStatus==0){
		$("#backgroundTour").css({
			"opacity": "0.7"
		});
		$("#backgroundTour").fadeIn("fast");
		$("#tourContact").css({
			"display": "none"
		});
		$("#tourContact").css({
			"display": "block"
		});
		$("#tourContact").fadeIn("fast");
		$("#tourContact").css({
			"visibility": "visible"
		});
		tourStatus = 1;
	}
}

//disabling tour with jQuery magic!
function disableTour(){
	//disables tour only if it is enabled
	if(tourStatus==1){
		$("#backgroundTour").fadeOut("fast");
		$("#tourContact").fadeOut("fast");
		tourStatus = 0;
	}
}

//centering tour
function centerTour(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var tourHeight = $("#tourContact").height();
	var tourWidth = $("#tourContact").width();
	//centering
	$("#tourContact").css({
		"position": "absolute",
		"top": windowHeight/2-tourHeight/2,
		"left": windowWidth/2-tourWidth/2
	});
	//only need force for IE6
	
	$("#backgroundTour").css({
		"height": windowHeight
	});
	
}
function hideFrame(){
	var el = document.getElementById( "tour-video" );
	el.style.display  = 'none';	
}

//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
	
	
	//LOADING 
	//Click the button event!
	$("#button").click(function(){
		//centering with css
		centerTour();
		//load tour
		loadTour();
		
		var el = document.getElementById( "tour-video" );
		el.style.display  = 'block';
	});
				
	//CLOSING 
	//Click the x event!
	$("#tourContactClose").click(function(){
		disableTour();
		hideFrame();
		
	});
	//Click out event!
	$("#backgroundTour").click(function(){
		disableTour();
		hideFrame();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && tourStatus==1){
			disableTour();
			hideFrame();
		}
	});

});
