$(document).ready( function(){

$('#desk').css({display: 'none', right: '-890px'});
$('#drawer').css({display: 'none', top: '200px'});
$('.menu').css({top : '-30px'});
$('.lang').css({display: 'none'});

$('#loader').fadeIn(800);

$(window).load(function(){

    $("#loader").fadeOut(2500, function(){        
        $("#desk").css({display: 'block'});
        $('#desk').animate({right: '+0px'},1500,'easeOutSine', function() {

            $("#desk").prepend('<div id="deskTop"></div>');
            $("#desk").append('<div id="drawer"></div>');
            $('#drawer').fadeIn(10000);
            $("#drawer").delay(200).animate({top: '+200px'},400)
                        
            load_object();                
  });

    });

});

});

function initializeHint (objectID, title, hRight, hTop)
{
	$('#'+objectID).hoverIntent({
				sensitivity: 3,
				interval: 200,
				over: function() { showHint ("h"+objectID, title, hRight, hTop); },
				timeout: 500,
				out: function() { hideHint ("h"+objectID); }
	});
}

function showHint (id, title, hRight, hTop)
{
	var hint = '<div class="hint" id="'+id+'">';
	hint += title;
	hint += '<div class="left"></div>';
	hint += '<div class="right"></div>';
	hint += '<div class="arrow"></div>';
	hint += '</div>';

	$('#'+id).remove();
	$('#room').append(hint);
	$('#'+id).css("opacity", 0);
	$('#'+id).css("top", hTop);
	$('#'+id).css("right", hRight);
	$('#'+id).show();
	$('#'+id).animate({opacity: 0.7}, "slow");
}

function hideHint (id)
{
	$('#'+id).animate({opacity: 0}, 300);
}


function load_object()
{	
        

        $("#desk").append('<a id="note" href="portfolio.html" ></a><a id="phone" href="contatti.html"></a>');

        if (lang == "en") initializeHint ('note', 'Portfolio', 530, 160);
	if (lang == "it") initializeHint ('note', 'Portfolio', 530, 160);

        if (lang == "en") initializeHint ('phone', 'Contact us', 380, 230);
	if (lang == "it") initializeHint ('phone', 'Contatti', 380, 230);
        
        if(check== 1){
        if (lang == "en") initializeHint ('captchainfo', 'Enter the correct result', 520, 946);
	if (lang == "it") initializeHint ('captchainfo', 'Inserisci il risultato corretto ', 500, 946);
        }
        else{
        if (lang == "en") initializeHint ('captchainfo', 'Enter the correct result', 520, 966);
	if (lang == "it") initializeHint ('captchainfo', 'Inserisci il risultato corretto ', 490, 976);
        }
        $("#desk").append('<div id="paper"></div><div id="keyboard"></div><div id="mouse"></div>');
        $("#desk").append('<div id="display"></div><div id="harddisk"></div><div id="magazines"></div>');
        $("#desk").append('<a id="camera" href="servizi.html"></a><a id="flash" href="staff.html"></a><div id="coffee"></a>');
        $("#room").append('<div id="plant"></div><div id="'+portfolio+'"></div><div id="palm"></div>');
        
	if (lang == "en") initializeHint ('camera', 'Services', 415, 75);
	if (lang == "it") initializeHint ('camera', 'Servizi', 430, 75);

        if (lang == "en") initializeHint ('flash', 'About Us', 782, 115);
	if (lang == "it") initializeHint ('flash', 'Staff ', 815, 115);

        $("#note, #paper, #phone, #keyboard, #mouse, #display, #harddisk, #magazines, #camera, #flash, #coffee, #palm, #chair").css({display: 'none'});
        $('#note, #paper').fadeIn(1000)
        $('#phone').delay(200).fadeIn(1300)
        $('#keyboard').delay(500).fadeIn(1700)
        $('#mouse').delay(800).fadeIn(2000)
        $('#display').delay(1100).fadeIn(2300)
        $('#harddisk').delay(1400).fadeIn(2600)
        $('#camera').delay(1700).fadeIn(2900)
        $('#flash').delay(2000).fadeIn(3200)
        $('#magazines').delay(2300).fadeIn(3500)
        $('#coffee').delay(2600).fadeIn(3800)
        $('#plant').delay(2900).fadeIn(4100)
        $('#chair').delay(3200).fadeIn(4400)
        $('#palm').delay(3500).fadeIn(4700,function(){

            $('.menu').animate({top: '+20px'},1000,'easeOutBounce');
            $('.lang').fadeIn(2500);

        });

        initializeDrawer();
        
        if($.browser.msie){$.scrollTo( '30%', 1600);}
        else{$.scrollTo( '10%', 1600);}

        boxlogin();
}

function initializeDrawer()
{       
	$('#drawer').html('<div id="drawerPic"><img width="159" height="150" src="'+$('#drawerPicParams img').attr('src')+'" /></div>');
	$('#room').append('<a id="drawerToggle" href="'+$('#drawerPicParams').attr('href')+'" title="'+$('#drawerPicParams').attr('title')+'" onfocus="this.blur()"></a>');
        $("#drawerPic").fadeIn(3000);

        $('#drawerToggle').hoverIntent({
		sensitivity: 3,
		interval: 200,
		over: function() { $('#drawer').animate({top: 295}, 600); },
		timeout: 500,
		out: function() { $('#drawer').animate({top: 200}, 600); }
	});
	
}

function slideAccordion (id)
{
	$('#'+id).animate({height: 'toggle'}, 700);

}

function boxlogin()
{
    //select all the a tag with name equal to modal
	$('a[name=modal]').click(function(e) {
		//Cancel the link behavior
		e.preventDefault();

		//Get the A tag
		var id = $(this).attr('href');

		//Get the screen height and width
		var maskHeight = $(document).height();
		var maskWidth = $(window).width();

		//Set heigth and width to mask to fill up the whole screen
		$('#mask').css({'width':maskWidth,'height':maskHeight});

		//transition effect
		$('#mask').fadeIn(1000);
		$('#mask').fadeTo("slow",0.8);

		//Get the window height and width
		var winH = $(window).height();
		var winW = $(window).width();

		//Set the popup window to center
		$(id).css('top',  winH/2-$(id).height()/2);
		$(id).css('left', winW/2-$(id).width()/2);

		//transition effect
		$(id).fadeIn(2000);

	});

	//if close button is clicked
	$('.window .close').click(function (e) {
		//Cancel the link behavior
		e.preventDefault();

		$('#mask').hide();
		$('.window').hide();
	});

	//if mask is clicked
	$('#mask').click(function () {
		$(this).hide();
		$('.window').hide();
	});
}
