// JavaScript Document
$(document).ready(function () {

        $('input,textarea').emuPlaceholder();

		// Servizio
		$.localToGlobal = function( context, localX, localY ){
			var position = context.offset();
			return({
				x: Math.floor( localX + position.left ),
				y: Math.floor( localY + position.top )
			});
		};

		// Main menu
		var spazio = 0;
		var somma_voci = 0;

		var count_voci = $("#main-menu>ul>li").size();
		
		$('#main-menu>ul>li').each(function(i,e){
			
			var rientro_menu = 0;
			somma_voci += $(this).width() + 2;
						
		});
		
		spazio = (960 - somma_voci) / (count_voci-1);
		spazio /= 2;	
		
		$('#main-menu>ul>li').css({
			"padding-left" : spazio,
			"padding-right" : spazio,
			"border-right" : "1px solid #d0d0d0",
			"border-left" : "1px solid white"
		})
		
		$('#main-menu>ul>li').each(function(i,e){
		
			if (i == 0)  {
				$(this).children("ul").css({	"left":  "0px"})
				$(this).children("ul").css({	"left": "0px" , "background" : "transparent url(/wp-content/themes/mastertag/extera.images/over-menu-left.png) top center no-repeat" , "width": "230px;"})
			} else if (i == (count_voci-1)) {
				
				rientro_menu =  ($(this).width() - 230) + spazio;
				$(this).children("ul").css({	"left": rientro_menu + "px" , "background" : "transparent url(/wp-content/themes/mastertag/extera.images/over-menu-right.png) top center no-repeat" , "width":  "230px;"})
			
			} else {
				
				rientro_menu =  (($(this).width() - 230) / 2) + spazio;
				$(this).children("ul").css({	"left":  rientro_menu +"px"})
				
			}
			
		});
		
		$('#main-menu>ul>li:first-child').css({ "border-left" : "none", "padding-left": "0px" });
		$('#main-menu>ul>li:last-child').css({ "border-right" : "none", "padding-right": "0px" });
		
		// Zoom immagini content
		$(".page-content .gallery-icon a[href$=.jpg],.page-content .gallery-icon a[href$=.jpeg],.page-content .gallery-icon a[href$=.png],.page-content .gallery-icon a[href$=.gif],.page-content .gallery-icon a[href$=.JPG],.page-content .gallery-icon a[href$=.JPEG],.page-content .gallery-icon a[href$=.PNG],.page-content .gallery-icon a[href$=.GIF],")
		.each(function()
		   {
			var $a = $(this);
			$a.attr('rel','gallery');
		})
		
		$(".page-content a[href$=.jpg],.page-content a[href$=.jpeg],.page-content a[href$=.png],.page-content a[href$=.gif],.page-content a[href$=.JPG],.page-content a[href$=.JPEG],.page-content a[href$=.PNG],.page-content a[href$=.GIF],")
		   .each(function()
		   {
		       var $a = $(this);
		       var title  = $a.find('img').attr('title');
		       if ($a.attr('title')=='' && title) $a.attr('title',title);
		   })
		   .fancybox({
		 'titlePosition'   : 'over',
		 'padding'         : 1,
		 'cyclic'          : true,
		 'overlayOpacity'  : .5,
		 'overlayColor'    : '#000'
		});
		
		//Aggiustamenti pagine
		
	// non in homepage
	if (!home) {
	
		var heightContent = $('.menu-contestuale-page').height() +230;
		if (($('.content-banda.page').height()+50) > heightContent) {
			heightContent = $('.content-banda.page').height();
		}
	
		$('.page #banda').height((heightContent + 80) + "px" )
	}


});
