/*
$(window).unload( function () { } );

(function ($) {
	$.event.special.load = {
		add: function (hollaback) {
			if ( this.nodeType === 1 && this.tagName.toLowerCase() === 'img' && this.src !== '' ) {
				// Image is already complete, fire the hollaback (fixes browser issues were cached
				// images isn't triggering the load event)
				if ( this.complete || this.readyState === 4 ) {
					hollaback.handler.apply(this);
				}

				// Check if data URI images is supported, fire 'error' event if not
				else if ( this.readyState === 'uninitialized' && this.src.indexOf('data:') === 0 ) {
					$(this).trigger('error');
				}

				else {
					$(this).bind('load', hollaback.handler);
				}
			}
		}
	};
}(jQuery));



$("#menu li.interno").click(function(){
    var project= $(this).attr("id");
    $('#body-background').fadeOut('fast',function(){
	    //$("#footer").animate({ scrollLeft:0, easing: "swing" }, 1000);
	    $("#inner_container").animate({ right: -840, easing: "swing" }, 1000, function(){
		    if ($("body").attr("class")=="miiiiiiii")
			    $("#ticker").animate({ right: 280, easing: "swing" }, 1000, function(){
			    window.location = project  + ".php"
			    });
		    else
			    window.location = project  + ".php"
	    });
    });
});

	$(window).resize(function(){
		$("#body-background").ezBgResize();
	});
*/
$(document).ready(function() {     
     
    jQuery('#mycarousel').jcarousel({
        // Configuration goes here
	scroll: 1,
	vertical: false,
        itemVisibleInCallback: {
            onBeforeAnimation: mycarousel_itemVisibleInCallbackBeforeAnimation,
            onAfterAnimation:  mycarousel_itemVisibleInCallbackAfterAnimation
        }
    });
    $('#main_content').height(calculate_container_height());


    setTimeout("massimizza_offerte()"   ,500);
    setTimeout("massimizza_contenuto()" ,500);
    setTimeout("massimizza_prenota()"   ,2000);


    setTimeout(function(){
	$('div#cortina').fadeOut(750);
//	$('#supersized').fadeIn(750);
    },1500)

});
// setupCallback

$(window).resize(function(){
    $('#main_content').height(calculate_container_height());
});

function calculate_container_height()
{
    var newHeight = $(window).height() - 250;
    if (newHeight <= 250)
	newHeight = 250;
    return newHeight;
}

function mycarousel_itemVisibleInCallbackBeforeAnimation(carousel, item, idx, state) {
    // No animation on first load of the carousel
    if (state == 'init')
        return;
    abbassaDesc(item);
};

function mycarousel_itemVisibleInCallbackAfterAnimation(carousel, item, idx, state) {
    $(item).find('p').animate({'bottom': 0}, 500);
};

function abbassaDesc(item)
{
    var pos = -1 * $(item).find('p').height();
    $(item).find('p').css('bottom', pos+'px');
}
