/* -- gestione menu -- */
jQuery(document).ready(function () {		
	jQuery("ul.menutophome a.$page.namepage:first ").addClass("select");
	jQuery("ul.menucentrale a.$page.namepage").addClass("select");
	jQuery("a.$page.namepage").parents("li").addClass("select");
	jQuery("ul.liv1").slideUp(0);
	jQuery("ul.select").slideDown(0).attr("visibility", "visibled");
	jQuery("li.select>ul").slideDown(0).addClass("select");
	jQuery("ul.menucentrale li.liv0 a[href='/#'],ul.menucentrale li.liv0_ultimo a[href='/#']").removeAttr("href");
	jQuery("ul.menucentrale li.liv0 a,ul.menucentrale li.liv0_ultimo a").click(function () {	
		 if (jQuery(this).hasClass("select")) {
		    jQuery(this).parents("li").removeClass("select");
		    var ulopen = jQuery(this).next("ul");
		    jQuery(ulopen).hide();
		 }
		 else {
		    jQuery(this).addClass("select");
		    jQuery(this).parents("li").addClass("select");
		    var ulopen = jQuery(this).next("ul");
		    jQuery(ulopen).show();
		 }
	});
});
/* ----- */


/* slideshow */
function slideShow(elemento){
	if(jQuery(elemento+" > img").length>1){
		jQuery(elemento).slideShow();
	} else {
		jQuery(elemento+" > img").css("opacity","1");
	}
};
function slideShowTxt(elemento){
		jQuery(elemento).slideShowTxt();
};

/* rollover vari */
function rolloverHome(){
	jQuery("#banner a").hover(function() {
		jQuery(this).animate({ opacity: 0.70 }, 200, function() {
		    // Animation complete.
		  });
	},function() {
		jQuery(this).animate({ opacity: 1 }, 200, function() {
		    // Animation complete.
		  });
	}); 
}; 

/* popup stile ikea */
function popup(){
	$(".more").hover(function(){
		var h = $(this).find("div").height()+40;
		$(this).stop().animate({ width: '500px', height: h }, 200);
	}, function () {
		$(this).stop().delay(500).animate({ width: '40px', height: '40px' }, 200);
	});  
};


jQuery(document).ready(function () {
    //select all the a tag with name equal to modal
    $('a[rel=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(500);	
    	$('#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(500); 
    
    });
    
    //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();
    });	
});

