$(document).ready(function(){


	$('#area_magazine').serialScroll({
		target:'#magazine',
		items:'li', // Selector to the items ( relative to the matched elements, '#magazine' in this case )
		prev:'a.prev',// Selector to the 'prev' button (absolute!, meaning it's relative to the document)
		next:'a.next',// Selector to the 'next' button (absolute too)
		axis:'xy',// The default is 'y' scroll on both ways
		duration:700,// Length of the animation (if you scroll 2 axes and use queue, then each axis take half this time)
		force:true // Force a scroll to the element specified by 'start' (some browsers don't reset on refreshes)
	});


	$('li.headlink').hover(
		function() {
                    $(this).children("ul").css('display', 'block');
		    //$('ul', this).css('display', 'block');
		    //$('#loopedSlider').css('display', 'none');    /* mi servirà per il flash, per farlo andare sopra */
		    },
		function() {
                    $(this).children("ul").css('display', 'none');
		    //$('ul', this).css('display', 'none');
		    //$('#loopedSlider').css('display', 'block');
		}
	);
            
            $('ul.sublink li').hover(
		function() {
                    $(this).children("ul").css('display', 'block');
		 },
		function() {
                    $(this).children("ul").css('display', 'none');
		}
            );


       /*$("#trova_rivenditore").fancybox({
	    'titleShow'		: false,
	    'transitionIn'	: 'fade',
	    'transitionOut'	: 'fade'
	});*/

	$(".popup_iframe").fancybox({
		'width'				: 550,
		'height'			: 350,
		'autoScale'			: false,
		'transitionIn'			: 'none',
		'transitionOut'			: 'none',
		'type'				: 'iframe',
		onComplete	:	function() {
		    $("#container_video_player_micro").css('visibility', 'hidden');
		},
		onClosed	:	function() {
		    $("#container_video_player_micro").css('visibility', 'visible');
		}
	});



	$("ul.lista_prodotti_nascosta").hide();

	$(".link_prodotti_classificazioni").click(function(){

	    $(this).next('ul.lista_prodotti_nascosta').slideToggle();
	    $("ul.lista_prodotti_nascosta").not($(this).next('ul.lista_prodotti_nascosta')).slideUp("slow");

	});


	//$(".ultimo_video_dx").load("area-dx-ultimi-video-ajax.php");

	/*
	 * per compensare la mancanza di min-height in ie6
	 */
	var altezza_area_centrale = $("#area_centrale").height();
	if (altezza_area_centrale<700) {
	    $("#area_centrale").css("height",700);
	}


	$("a.single_image_fancybox").fancybox();


	//per evitare che l'area dx sia più grande della sinistra
	/*var altezza_area_centrale_prodotti  = $("#area_centrale_prodotti").height();
	var altezza_area_dx		    = $("#area_dx").height();
            alert(altezza_area_centrale_prodotti + " " + altezza_area_dx);
	if ( altezza_area_centrale_prodotti < altezza_area_dx) {
		$("#area_centrale_prodotti").css("height",altezza_area_dx-30);
	}*/
        
        
        
        /*
         * apri una classificazione se nell'hash è indicato
         */
        if(window.location.hash != "") {
            
            var current_hash = window.location.hash;
            apri_classificazione_da_hash(current_hash);
            
        }
        
        $(window).bind('hashchange', function(){
            
            var current_hash = window.location.hash;
            apri_classificazione_da_hash(current_hash);
            
        });



});

$(window).load(
    function() {
        
        var altezza_area_centrale_prodotti  = $("#area_centrale_prodotti").height();
	var altezza_area_dx		    = $("#area_dx").height();

	if ( altezza_area_centrale_prodotti < altezza_area_dx) {
		$("#area_centrale_prodotti").css("height",altezza_area_dx-30);
	}
        
    }
);

function apri_classificazione_da_hash(current_hash) {
            
    if (current_hash.toLowerCase().indexOf("classificazione_") >= 0) {

        var current_id_classificazione = current_hash.substring(17);

        $(".id_classificazione_"+current_id_classificazione).show();
        $("ul.lista_prodotti_nascosta").not($(".id_classificazione_"+current_id_classificazione)).slideUp("slow");

    }
    
}


function polaroid_gallery() {

    //$("#area_centrale_home").load("polaroid-gallery/brazil.html");

    $.ajax({
	    type: "GET",
	    url: "polaroid-gallery/brasil/brasil.php",
	    data: "",
	    cache: false,
	    success: function(html) {
		    
		    //$("#area_centrale_home").html(html).hide();
		    $("#area_centrale_home").html(html);
		    $("#area_centrale_home #pp_thumbContainer .content").hide();

		    $.ajax({
			url:"polaroid-gallery/css/polaroid-gallery.css",
			success:function(data){

				 //$("<style></style>").appendTo("head").html(data);
				 $("<style>" + data + "</style>").appendTo("head");

				 $.ajax({

					url: "polaroid-gallery/js/jquery.transform-0.8.0.min.js",
					dataType: "script",
					success: function() {

					    $.ajax({

						url: "polaroid-gallery/js/polaroid-gallery.js",
						dataType: "script",
						success: function() {

						   //$("#area_centrale_home").show();
						   $("#area_centrale_home #pp_thumbContainer .content").show();

						}

					    });

					}
				});
				 
			}
		    });

	    }
    });


}
