this.tooltip = function(){	
	/* CONFIG */		
		xOffset = 10;
		yOffset = 20;		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result		
	/* END CONFIG */		
	$("a.tooltip").hover(function(e){											  
		this.t = this.title;
		this.title = "";									  
		$("body").append("<p id='tooltip'>"+ this.t +"</p>");
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");		
    },
	function(){
		this.title = this.t;		
		$("#tooltip").remove();
    });	
	$("a.tooltip").mousemove(function(e){
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
};


function center_home(){
	//request data for centering
	var windowWidth1 = document.documentElement.clientWidth;
	var windowHeight1 = document.documentElement.clientHeight;
	var center_homeHeight = $("#mac").height();
	var center_homeWidth = $("#mac").width();
	//centering
	$("#mac").css({
		"position": "absolute",
		"top": windowHeight1/2-center_homeHeight/2,
		"left": windowWidth1/2-center_homeWidth/2
	});

}

function center(){
	//request data for centering
	var windowWidth2 = document.documentElement.clientWidth;
	var windowHeight2 = document.documentElement.clientHeight;
	var centerHeight = $("#center").height();
	var centerWidth = $("#center").width();
	//centering
	$("#center").css({
		"position": "absolute",
		"top": windowHeight2/2-centerHeight/2,
		"left": windowWidth2/2-centerWidth/2
	});

}

$(document).ready(function(){
	//centra l'home page
	center_home();
	center();	
	tooltip();
	
	//$("#sfondo_mac").css({'background-color' : '#000'});
	//$("p#enter").click(function () {
	$("#sfondo_mac").css({'background-color' : '#1F1F1F'});
	$("#center_home").fadeIn(7000);
	//$("p#enter").css({'display' : 'none'});
	//});

	
	$(function() {
	$("#featured").tabs({ fx: { height: 'toggle', opacity: 'toggle' } }); }); 
	
		$("#submit").click(function () {
			$('.status').fadeIn(3000);	
			$('.status').fadeOut(3000);
	  });

						   
    $("a#lavori").click(function () {
      $("div#center").hide();
	  $("div#featured").fadeIn('slow');
	  return false;
	  });
	
	$("a#lavori_en").click(function () {
      $("div#center").hide();
	  $("div#featured").fadeIn('slow');
	  return false;
	  });
	
	$("div.close").click(function () {
	  $("div#featured").hide();
      $("div#center").fadeIn('slow');
	  return false;
	 });
	
	$("a#about").click(function () {
	  //$('body').append('<embed src="sound.wav" autostart="true" hidden="true" loop="false">');
      $("div#center").hide();
	  $("div#about_wrapper").fadeIn('slow');
	  return false;
	  });
	
	$("div.close_about").click(function () {
      $("div#center").fadeIn('slow');
	  $("div#about_wrapper").hide();
	  return false;
	  });
	
	
});

//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");
		popupStatus = 0;
	}
}

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


//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
	
	//LOADING POPUP
	//Click the button event!
	$("#button").click(function(){
		//centering with css
		centerPopup();
		//load popup
		loadPopup();
	});
				
	//CLOSING POPUP
	//Click the x event!
	$("#popupContactClose").click(function(){
		disablePopup();
	});
	
	//Click out event!
	//$("#backgroundPopup_no").click(function(){
		//disablePopup();
	//});
	
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
	});

});
