// JavaScript Document
var isiPad = navigator.userAgent.match(/iPad/i) != null;

var bgFull = 0


if(location.href=='http://www.arena.es/' || location.href=='http://arena.es/'){
	location.href='http://www.arena.es/Default.aspx?prd=1&lng=1';
}

if(location.href=='http://www.arenaitalia.it/' || location.href=='http://arenaitalia.it/'){
	location.href='http://www.arenaitalia.it/Default.aspx?prd=1&lng=2';
}


//Menu hover
function hoverMenu(){
	//$('.contSubmenu').hide();
	//on over
	function viewSubmenu(){
		var menuLiW = $(this).width();
		$('.pointer').width(menuLiW);
		
		if($('.contSubmenu', this).lenght != 0){
			if(navigator.appName == "Microsoft Internet Explorer"){ 
				$('.contSubmenu', this).show();	
			}else{
				$('.contSubmenu', this).fadeIn('slow');
				
			}	
		}
		
	}
	//on out
	function hideSubmenu(){
		if(navigator.appName == "Microsoft Internet Explorer"){ 
			$('.contSubmenu', this).hide();	
		}else{
			$('.contSubmenu', this).fadeOut('slow');
		}	
	}
			
	var menuconfig = {    
		over: viewSubmenu, // function = onMouseOver callback (REQUIRED)    
		timeout: 300, // number = milliseconds delay before onMouseOut    
		out: hideSubmenu // function = onMouseOut callback (REQUIRED)    
	};
	
	
	
	if(isiPad){
		$('.menu li.sub').click(function(){
			var menuLiW = $(this).width();
			$('.pointer').width(menuLiW);	
			$('.contSubmenu', this).toggle('slow');
		});
		
		
		
	}else{
		$('.menu li.sub').hoverIntent(menuconfig)	
	}
}

function hoveSubMenu(){
	
	function viewSubSubmenu(){
		
		if($('.contSubSubmenu', this).lenght != 0){
			
			if(navigator.appName == "Microsoft Internet Explorer"){ 
				$('.contSubSubmenu', this).show();	
			}else{
				$('.contSubSubmenu', this).fadeIn('slow');
				
			}	
			
			if ($(document).width() > $(window).width()) {
				var subsubL = $('.contSubSubmenu', this).css('left')
				
				if(subsubL >= '230px'){
					$('.contSubSubmenu', this).css({'left':'-288px'})
					$('.arrow', this).addClass('dx')
				}
			}
		}
		
	}
	//on out
	function hideSubSubmenu(){
		if(navigator.appName == "Microsoft Internet Explorer"){ 
			$('.contSubSubmenu', this).hide();	
		}else{
			$('.contSubSubmenu', this).fadeOut('slow');
		}	
	}
	
	var submenuconfig = {    
		over: viewSubSubmenu, // function = onMouseOver callback (REQUIRED)    
		timeout: 300, // number = milliseconds delay before onMouseOut    
		out: hideSubSubmenu // function = onMouseOut callback (REQUIRED)    
	};
	
	
	if(isiPad){
		$('.submenu li.subsub').click(function(){
			$('.contSubSubmenu', this).toggle('slow');
		});
		
	}else{
		$('.submenu li.subsub').hoverIntent(submenuconfig)	
	}
	
}


// Slideshow Home
function SlideshowHome(){
	if($('.slideshowHome .slide').size() == 1){
		$('.contSlideshowHome .footer').hide();
		
		$('.slideshowHome .slide:first').fadeIn(800, function(){
			$('.contSlideshowHome .footer').fadeIn(800)														  
		});
		var titoloSlide = $('.slideshowHome .slide').attr('titolo');
		var testoSlide = $('.slideshowHome .slide').attr('testo');
		var linkSlide = $('.slideshowHome .slide').find('a').attr('href');
		$('.contSlideshowHome .footer h1').html(titoloSlide);
		$('.contSlideshowHome .footer h2').html(testoSlide);
		////Cufon.refresh()
		
	}else{
		
		function onAfterSlideHome(curr,next,opts) {
		
			var currBtn = opts.currSlide + 1
			$('.contSlideshowHome ul.nav li').removeClass('off');
			$('.contSlideshowHome ul.nav li:nth-child('+currBtn+')').addClass('off');
			
			var titoloSlide = $(this).attr('titolo');
			var testoSlide = $(this).attr('testo');
			var linkSlide = $(this).find('a').attr('href');
			$('.contSlideshowHome .footer h1').html(titoloSlide);
			$('.contSlideshowHome .footer h2').html(testoSlide);
			$('.contSlideshowHome .footer a').attr('href', linkSlide)
			////Cufon.refresh()
		}
		
		
		$('.contSlideshowHome .footer').hide();
		//$('.slideshowHome .slide').hide();
		
		var btnSlideW = 0;
		var indiceFoto=0; 
		
		var bc = $('.contSlideshowHome ul.nav'); 
		
		$('.slideshowHome .slide:first').fadeIn(800, function(){
			$('.contSlideshowHome .footer').fadeIn(800)														  
		});
		
		var $container = $('.slideshowHome').cycle({ 
			fx:     'fade', 
			speed:   300, 
			timeout: 8000,
			after: onAfterSlideHome,
			cleartype:  true,
			pause: true
			
		});
	}
	
	$container.children().each(function(i) { 
		// create LI 
		$('<li><a href="'+(i+1)+'"></a></li>') 
			// append it to button container 
			.appendTo(bc) 
			// bind click handler 
			.click(function() { 
				// cycle to the corresponding slide 
				$('.contSlideshowHome ul.nav li').removeClass('off');
				$(this).addClass('off');
				$container.cycle(i); 
				return false; 
			}).hide();
			
		$('.contSlideshowHome ul.nav li:first').addClass('off');
	});
	
	$('.contSlideshowHome ul.nav li').each(function(){
		
		indiceFoto=indiceFoto+1;						   
								   
		$(this).delay(indiceFoto*200).fadeIn();
		
		btnSlideW = btnSlideW + $(this).outerWidth();
		$('.contSlideshowHome ul.nav').width(btnSlideW);
		$('.contSlideshowHome ul.nav').css('margin-left', -(btnSlideW/2))
		
	});
	

}

//Carousel Home
function CarouselHome(){
	/*
	$('.carousel li').hover(function(){
		$(this).stop().fadeTo('slow', 0.6)
	}, function(){
		$(this).stop().fadeTo('slow', 1)	
	});*/
	
	/*
	function CarouselHomeonBeforeSlide(){
		if($('.carousel li').size()>5){
			$('.carousel').bxSlider().startShow();
		}else{
			$('.carousel').stopShow();	
		}
	}
	
	
	
	$('.carousel').bxSlider({
		controls: false,
		pager: false,
		pause: 8000,
		autoHover: true,
		easing: 'swing',
		displaySlideQty: 5,
		moveSlideQty: 1,
		auto: true,
		onBeforeSlide:function(currentSlideNumber, totalSlideQty, currentSlideHtmlObject){
			if(totalSlideQty>5){
			}else{
				$('.carousel').stopShow();	
			}		
		}
	});*/
	
	//scroll Thumb
	function scrollThumbCarousel(){
		//alert('eccoci')
		//Get our elements for faster access and set overlay width
		var div = $('div.contThumbCarousel'),
					 ul = $('ul.carousel'),
					 // unordered list's left margin
					 ulPadding = 0;
	
		//Get menu width
		var divWidth = div.width();
	
		//Remove scrollbars
		div.css({overflow: 'hidden'});
	
		//Find last image container
		var lastLi = ul.find('li:last-child');
	
		//When user move mouse over menu
		div.mousemove(function(e){
	
		  //As images are loaded ul width increases,
		  //so we recalculate it each time
		  var ulWidth = lastLi[0].offsetLeft + lastLi.outerWidth() + ulPadding;
	
		  var left = (e.pageX - div.offset().left) * (ulWidth-divWidth) / divWidth;
		  div.scrollLeft(left);
		});
	}
	
	$('.carousel').waitForImages(function() {
		$('.carousel li').fadeIn('fast');	
		scrollThumbCarousel();
	});
	
	var totWidthThumb=0;
	//var positionsThumb = new Array();
	
	$('ul.carousel li').each(function(i){
		/* Traverse through all the slides and store their accumulative widths in totWidth */
		//positionsThumb[i] = totWidthThumb;
		totWidthThumb = totWidthThumb + $(this).width();
		/* The positions array contains each slide's commulutative offset from the left part of the container */
		if(!$(this).width())
		{
			alert("Please, fill in width & height for all your images!");
			return false;
		}
	});
	$('ul.carousel').width(totWidthThumb);
	
	
}


//Carousel Prodotti
function CarouselProducts(){
	var sliderProduct = $('.carouselP').bxSlider({
		easing: 'swing',
		displaySlideQty: 3,
		moveSlideQty: 1,
		auto: false,
		controls: false
	});
	
	$('.carouselP').waitForImages(function() {
		$('.carouselP li').fadeIn('fast', function(){
			
			$('.carouselP li .contTitle h1').each(function(){
				$(this).css('margin-top', -($(this).height()/2))						 
			});
			
		});
	});
	
	$('.carouselP li img').each(function(){
		$(this).css({'margin-top': -($(this).height()/2), 'margin-left': -($(this).width()/2)})						 
	});
	
	
	
	$('.productsCarousel .bx-prev').click(function() {
		sliderProduct.goToPreviousSlide();
		return false;
	});
	
	$('.productsCarousel .bx-next').click(function() {
		sliderProduct.goToNextSlide();
		return false;
	}); 
	
	$('.carouselP li').hover(function(){
		$('.carouselP li').not(this).stop().fadeTo('slow', 0.2)
	}, function(){
		$('.carouselP li').not(this).stop().fadeTo('slow', 1)	
	});
	
}


//Input focus
function InputFocus() {
    //$('input[type="text"]').addClass("idleField");
	/*if($('input[type="text"]').lenght != 0){
		$('input[type="text"]').focus(function() {
			//$(this).removeClass("idleField").addClass("focusField");
			if (this.value == this.defaultValue){
				this.value = '';
			}
			if(this.value != this.defaultValue){
				this.select();
			}
		});
		$('input[type="text"]').blur(function() {
			//$(this).removeClass("focusField").addClass("idleField");
			if ($.trim(this.value == '')){
				this.value = (this.defaultValue ? this.defaultValue : '');
			}
		});
	}*/
	//$('input[type="text"]').addClass("idleField");
       		$('input[type="text"]').focus(function() {
       			//$(this).removeClass("idleField").addClass("focusField");
    		    if (this.value == this.defaultValue){ 
    		    	this.value = '';
				}
				if(this.value != this.defaultValue){
	    			this.select();
	    		}
    		});
    		$('input[type="text"]').blur(function() {
    			//$(this).removeClass("focusField").addClass("idleField");
    		    if ($.trim(this.value) == ''){
			    	this.value = (this.defaultValue ? this.defaultValue : '');
				}
    		});  
}

//Allineamento centrato div
function centerDiv(div){
  	var DIVwidth = $(div).width();	
	var DIVheight = $(div).height();
	var SCREENwidth = $(document).width();
	var SCREENheight = $(window).height();	
	var SCREENscrolltop = $(window).scrollTop();
    $(div).hide();
	$(div).css({"position":"absolute","left":(SCREENwidth-DIVwidth)/2+"px","top":(SCREENheight-DIVheight)/2+SCREENscrolltop+"px"});
	$(div).show();
}


//Video Gallery
function openVideoGallery(){
	//stoppo lo slideshow se c'è
	/*if($('.categoryCarousel').lenght != 0){
		$('.carousel').bxSlider.stopShow;
	}*/
	//stoppo il carosello se c'è
	if($('.slideshowHome').lenght != 0){
		$('.slideshowHome .slide').cycle('pause');
	}
	
	
	//scroll Thumb
	function scrollThumb(){
		//Get our elements for faster access and set overlay width
		var div = $('div.contThumb'),
					 ul = $('ul.videoList'),
					 // unordered list's left margin
					 ulPadding = 0;
	
		//Get menu width
		var divWidth = div.width();
	
		//Remove scrollbars
		div.css({overflow: 'hidden'});
	
		//Find last image container
		var lastLi = ul.find('li:last-child');
	
		//When user move mouse over menu
		div.mousemove(function(e){
	
		  //As images are loaded ul width increases,
		  //so we recalculate it each time
		  var ulWidth = lastLi[0].offsetLeft + lastLi.outerWidth() + ulPadding;
	
		  var left = (e.pageX - div.offset().left) * (ulWidth-divWidth) / divWidth;
		  div.scrollLeft(left);
		});
	}
	
	//mostra video
	function mostraVideo(){
		$('ul.videoList li').click(function(){
			
			/*var videoFlv = $(this).attr('linkflv');
			var videoMp4 = $(this).attr('linkmp4');
			var videoOgv = $(this).attr('linkogv');*/
			$('ul.videoList li').fadeTo('slow', 1);
			$(this).fadeTo('slow', 0.3);
			
			var titleZoom = $(this).attr('titolo');
			
			/*$('.fsVideo').find('source:nth-child(1)').attr('src', videoMp4)
			$('.fsVideo').find('source:nth-child(2)').attr('src', videoOgv)
			
			var so = new SWFObject("video/videoPlayer.swf", "mymovie", "605", "340", "8", "#000");
			so.useExpressInstall('video/expressinstall.swf');
		  	so.addParam("movie", "video/videoPlayer.swf");
		   	so.addParam("flashvars", "controlbar=over&amp;flvname="+videoFlv);
		  	so.write("flashcontent");*/
			var videoToView = $(this).attr('link');
			$('.fsVideo #ytvideo').fadeOut('slow', function(){
				$('.fsVideo #ytvideo').html('');
				$('<iframe width="640" height="390" src="http://www.youtube.com/embed/'+videoToView+'" frameborder="0" allowfullscreen></iframe>').appendTo('#ytvideo');
			});
			
			
			$('.fsVideo #ytvideo').fadeIn('slow')
			
			$('#videogallery .header h1').html(titleZoom)
			
		});	
	}
	
	function VideoOpen(){
		$("html").css("overflow", "hidden");
		var liVideo = $('.videoListOff').html();
				
		$('<div id="overWin" style="background:url(../img/bg_overWin.png) repeat;"><div id="videogallery"><div class="header"><h1>Video title</h1><a href="javascript:void(0)" class="close"></a></div><div class="fsVideo"><div id="ytvideo"></div><div class="contThumb"><ul class="videoList"></ul></div></div></div></div>').appendTo('body');
		
		$('#overWin .videoList').html(liVideo);
		
		var div = "#overWin";
		centerDiv(div);
		
		$('.fsVideo video').hide();
		
		$('a.close').click(function(){
			$('#overWin').fadeOut('slow').remove();
			$("html").css("overflow", "auto");
		});
		
		//Faccio muovere le thumb con il mouse e centro il contenitore
		scrollThumb();
	
		var totWidthThumb=0;
		var positionsThumb = new Array();
		
		$('ul.videoList li').each(function(i){
			/* Traverse through all the slides and store their accumulative widths in totWidth */
			positionsThumb[i]= totWidthThumb;
			totWidthThumb = totWidthThumb + $(this).width() + 2;
			/* The positions array contains each slide's commulutative offset from the left part of the container */
			if(!$(this).width())
			{
				alert("Please, fill in width & height for all your images!");
				return false;
			}
			
			var videoThumb = $(this).attr('link');
			$('<img src="http://img.youtube.com/vi/'+videoThumb+'/1.jpg"/>').appendTo(this);

			
		});
		$('ul.videoList').width(totWidthThumb);
		
		if($('ul.videoList').width()<640){
			$('ul.videoList').css({'float':'none', 'margin-left':'auto', 'margin-right':'auto'});
		}
		
		var videoToView = $('ul.videoList li:first-child').attr('link');
		$('ul.videoList li:first-child').fadeTo('slow', 0.3);
		
		/*var videoFlv = $('ul.videoList li:first-child').attr('linkflv');
		var videoMp4 = $('ul.videoList li:first-child').attr('linkmp4');
		var videoOgv = $('ul.videoList li:first-child').attr('linkogv');*/
		
		var titleZoom = $('ul.videoList li:first-child').attr('titolo');
		
		$('.fsVideo #ytvideo').html('')
		$('<iframe width="640" height="390" src="http://www.youtube.com/embed/'+videoToView+'" frameborder="0" allowfullscreen></iframe>').appendTo('#ytvideo');
		
		/*$('.fsVideo').find('source:nth-child(1)').attr('src', videoMp4)
		$('.fsVideo').find('source:nth-child(2)').attr('src', videoOgv)*/
		/*
		var so = new SWFObject("video/videoPlayer.swf", "mymovie", "605", "340", "8", "#000");
		so.useExpressInstall('video/expressinstall.swf');
		so.addParam("movie", "video/videoPlayer.swf");
		so.addParam("flashvars", "controlbar=over&amp;flvname="+videoFlv);
		so.write("flashcontent");
		*/
		$('#videogallery .header h1').html(titleZoom)
		
		$('.fsVideo video').fadeIn('slow')
		
		mostraVideo();
	};
	
	//faccio apparire la copertura nera
	$('.videoThumb').click(function(){VideoOpen()})
	$('a.videoBtn').click(function(){VideoOpen()})
}

// Slideshow Prodotti
function SlideshowProduct(){
	
	//$('.slideshowProduct .slide').hide();
	
	$('.slideshowProduct .slide:first').fadeIn(800, function(){
		$('.slideshowProduct').cycle({ 
			fx:     'fade',
			timeout: 5000,
			prev:   '.slideshowControl #prev', 
			next:   '.slideshowControl #next',
			pause: true
		});
	});
}


// Slide top banner
function slideTopBanner(){
	$('.slideTopBanner img').hide();
	$('.slideTopBanner img:first').fadeIn(800, function(){
		$('.slideTopBanner').cycle({ 
			fx:     'fade',
			timeout: 6000,
			pause: true
		});
	});
}

//Choose Category
function ChooseCategory(){
	$('.categoryChoose').waitForImages(function() {
		$('.categoryChoose ul li:last-child').css('margin-right', 0);
	});
}



// Tabs Product Information BODYLIFT
function productInfoSlide(){
	
	function onAfterproductInfoSlide(curr,next,opts) {
		var currBtn = opts.currSlide + 1
		
		var contPH = $('.contProductInfo .slide:nth-child('+currBtn+')').height() + $('.contProductInfo ul.nav').height();
		$('.contProductInfo').animate({height: contPH})	
		$('#container').animate({height: contPH +40})
		
		$('.contProductInfo ul.nav li').removeClass('off');
		$('.contProductInfo ul.nav li:nth-child('+currBtn+')').addClass('off');
		
		//Cufon.refresh();
		
	}
	
	
	//$('.productInfo .slide').hide();
	
	var btnSlideW = 0;
	var indiceFoto=0; 
	
	var bc = $('.contProductInfo ul.nav'); 
	
	$('.productInfo').waitForImages(function() {
		$('.productInfo .slide:first').fadeIn(800);
	});	
		var $container = $('.productInfo').cycle({ 
			fx:     'scrollLeft', 
			speed:   300, 
			timeout: 0,
			after: onAfterproductInfoSlide,
			cleartype:  true,
			pause: true
		});
	
	
	$container.children().each(function(i) { 
		// create LI 
		var titleSlide = $('h1',this).html()
		$('<li><a href="'+(i+1)+'" class="pn">'+titleSlide+'</a></li>') 
			// append it to button container 
			.appendTo(bc) 
			// bind click handler 
			.click(function() { 
				// cycle to the corresponding slide 
				$('.contSlideshowHome ul.nav li').removeClass('off');
				$(this).addClass('off');
				$container.cycle(i); 
				return false; 
			}).hide();
			
		$('.contProductInfo ul.nav li:first').addClass('off');
		
	});
	
	$('.contProductInfo ul.nav li').each(function(){
		
		indiceFoto=indiceFoto+1;						   
								   
		$(this).delay(indiceFoto*200).fadeIn();
	});
	$('.contProductInfo ul.nav li:last-child').css('border-right', 0);

}

// Tabs Elite Team
function eliteTeamInfoAtleta(){
	
	function onAftereliteTeamInfoAtleta(curr,next,opts) {
		var currBtn = opts.currSlide + 1
		
		/*var contPH = $('.atletaInfo .slide:nth-child('+currBtn+')').height() + $('.atletaInfo ul.nav').height();
		$('#contentElite').animate({height: contPH +40})
		*/
		$('.contAtletaInfo ul.nav li').removeClass('off');
		$('.contAtletaInfo ul.nav li:nth-child('+currBtn+')').addClass('off');
		setTimeout("$('.atletaInfo .slide').jScrollPane(), $('.jspDrag').css({'background':'#999'}), $('.jspTrack').css({'background':'#333'})", 800)
		////Cufon.refresh();
		if ( jQuery.browser.mozilla) {
			
		}else{
			//Cufon.refresh();
		}
		
	}
	
	
	$('.atletaInfo .slide').hide();
	
	var btnSlideW = 0;
	var indiceFoto=0; 
	
	var bc = $('.contAtletaInfo ul.nav'); 
	
	$('.atletaInfo .slide:first').fadeIn(800);
	
	var $container = $('.atletaInfo').cycle({ 
		fx:     'scrollLeft', 
		speed:   300, 
		timeout: 0,
		after: onAftereliteTeamInfoAtleta,
		cleartype:  true,
		pause: true
	});
	
	$container.children().each(function(i) { 
		// create LI 
		var titleSlide = $(this).attr('titolo')
		$('<li><a href="'+(i+1)+'" class="pn">'+titleSlide+'</a></li>') 
			// append it to button container 
			.appendTo(bc) 
			// bind click handler 
			.click(function() { 
				// cycle to the corresponding slide 
				$('.contAtletaInfo ul.nav li').removeClass('off');
				$(this).addClass('off');
				$container.cycle(i); 
				return false; 
			}).hide();
			
		$('.contAtletaInfo ul.nav li:first').addClass('off');
		
	});
	
	$('.contAtletaInfo ul.nav li').each(function(){
		
		indiceFoto=indiceFoto+1;						   
								   
		$(this).delay(indiceFoto*200).fadeIn();
	});
	
	//$('<li><a href="javascript:void(0)" class="pn videoBtn">videos</a></li><li><a href="" class="pn">face to face</a></li>').appendTo('.contAtletaInfo ul.nav') 
	
	$('.bottonBtnAtleta li:last-child').css('border-right', 0);
}

function slideshowAtleta(){
	
	function onAfterSlideAtleta(curr,next,opts) {
		//alert('cazzo')
		currBtn = opts.currSlide + 2;
		//alert(currBtn)
		//alert($('.thumbAtleta li:nth-child(currBtn)'))
		$('ul.thumbAtleta li').fadeTo('slow', 0.3)
		$('ul.thumbAtleta li:nth-child('+currBtn+')').fadeTo('slow', 1)
		
	}
	
	$('.atletaSlideshow img:first').fadeIn(800, function(){
		$('.atletaSlideshow').cycle({
			fx:'fade',
			speed:  1000,
			timeout: 5000,
			pager:  'ul.thumbAtleta',
			after: onAfterSlideAtleta,
			pagerAnchorBuilder: function(idx, slide) {
									return '<li><a href="#"><img src="' + slide.src + '"/></a></li>';
									
								 }
			
		  });
	});
	
	
	var slideThumbAtleta = $('.thumbAtleta').bxSlider({
		easing: 'swing',
		infiniteLoop:false,
		displaySlideQty: 4,
		moveSlideQty: 1,
		auto: false,
		hideControlOnEnd: true,
		controls: false
	});	
	
	

	$('.contThumbAtleta .bx-prev').click(function() {
		slideThumbAtleta.goToPreviousSlide();
		return false;
	});
	
	$('.contThumbAtleta .bx-next').click(function() {
		slideThumbAtleta.goToNextSlide();
		return false;
	}); 	
	
	$('ul.thumbAtleta li').fadeTo('slow', 0.3);
	$('ul.thumbAtleta li.activeSlide').fadeTo('slow', 1);
		
	
		
}

function productList(){
	
	$('.paginazione:last-child').css({'border-bottom':0, 'border-top': '1px solid #e1e1e1', 'margin-top': '-1px'})
	$('.pag a:last-child').css('border-right', 0)
	$('.pag span:last-child').css('border-right', 0)
	
	
	
	//$('.productList li').hide();
	var indiceFoto=0;
	var thisimgW  = 0;
	var thisimgH = 0;
	
	
	$('.productList li img').each(function(){
		
		if (this.complete) {
			
			thisimgW = -($(this).width()/2)
			thisimgH = -($(this).height()/2)
			
			$(this).css({'margin-left':thisimgW+'px', 'margin-top':thisimgH+'px'})
			
			
		} else {
			$(this).load(function() {
								  
				thisimgW = -($(this).attr('width'))/2
				thisimgH = -($(this).attr('height'))/2					 
				$(this).css({'margin-left':thisimgW, 'margin-top':thisimgH})
				
			});
		}
	});
	
	
	if($('.productList').hasClass('teamline')){
		
		$('.productList li').each(function(){
			
			$(this).hoverIntent(function(){
				$('.over',this).stop().fadeTo(600, .65)
			}, function(){
				$('.over',this).stop().fadeTo(600, 0)
			})
			
		});
			
	}else{
		
		$('.productList li').each(function(){
			
			$(this).hoverIntent(function(){
				$('.over',this).fadeIn('slow')
			}, function(){
				$('.over',this).fadeOut('slow')	
			})
			
		});
	}
	
	$('.productList li').each(function(){
			
		indiceFoto=indiceFoto+1;						   
								   
		$(this).delay(indiceFoto*200).fadeIn();
		$('.productList li:nth-child(5n)').css('border-right', 0)
		
	});
	
	
	
	
	
}

function submenuFilter(){
	//$('.contSubmenuFilter').hide();
	$('.filter li:last-child').css('border-bottom', 0)
	//on over
	function viewSubmenuFilter(){
		if($('.contSubmenuFilter', this).height()>420){
			$('.contSubmenuFilter', this).css('margin-top', -210)	
		}else{
			var submenuFilterH = -($('.contSubmenuFilter', this).height()/2);
			$('.contSubmenuFilter', this).css('margin-top', submenuFilterH)	
		}
		
		
		if($('.contSubmenuFilter', this).lenght != 0){
			if(navigator.appName == "Microsoft Internet Explorer"){ 
				$('.contSubmenuFilter', this).show();	
			}else{
				$('.contSubmenuFilter', this).slideToggle('slow');
				
			}	
		}
		
	}
	//on out
	function hideSubmenuFilter(){
		if(navigator.appName == "Microsoft Internet Explorer"){ 
			$('.contSubmenuFilter', this).hide();	
		}else{
			$('.contSubmenuFilter', this).slideToggle('slow');
		}	
	}
			
	var submenufilterconfig = {    
		over: viewSubmenuFilter, // function = onMouseOver callback (REQUIRED)    
		timeout: 500, // number = milliseconds delay before onMouseOut    
		out: hideSubmenuFilter // function = onMouseOut callback (REQUIRED)    
	};
	
	if(isiPad){
		$('.filter li.subfilter').click(function(){
			var submenuFilterH = -($('.contSubmenuFilter', this).height()/2);
			$('.contSubmenuFilter', this).css('margin-top', submenuFilterH)
			$('.contSubmenuFilter', this).slideToggle('slow');
		})
	}else{
		$('.filter li.subfilter').hoverIntent(submenufilterconfig)		
	}
	
	
}

// Slideshow Prodotti
var linkZoom = 0;
var titleView = 0;
var linkZoomGallery = 1;
var titleZoomGallery = 1;
var productImageSlideH = 0;
var imagemaxheight = 0;
var currBtn = 0;
function productImageSlide(){
	
	$('.navProdDett').prepend('<li class="btnzoom"><a href="javascript:void(0)" class="zoom">zoom</a></li>')
	
	function onAfterProductImageSlide(curr,next,opts) {
		//alert('cazzo')
		currBtn = opts.currSlide + 1;
		linkZoom = $('.productImageSlide a:nth-child('+currBtn+')').attr('zoomimg');
		titleView = $('.productImageSlide a:nth-child('+currBtn+')').attr('titleView');
		//alert(linkZoom)
		$('.navProdDett li:nth-child(2) p').html(titleView)
		$('.navProdDett li:first-child a').attr('imgZoom', linkZoom)
	}
	
		
	$('.productImageSlide a').hide();
	
	
	$('.productImageSlide a').each(function(){
		linkZoom = $(this).attr('zoomimg');
		titleView = $(this).attr('titleView');
		
		$('.navProdDett li:nth-child(2) p').html(titleView)
		$('.navProdDett li:first-child a').attr('imgZoom', linkZoom)
		
	});
	
	
	var btnSlideW = 0;
	var indiceFoto = 0; 
	
	var bc = $('ul.productImageSlideNav'); 
	
	
	$('.productImageSlide a:first').fadeIn(800);
	
	var $container = $('.productImageSlide').cycle({ 
		fx:     'fade', 
		speed:   300, 
		timeout: 0,
		after: onAfterProductImageSlide,
		cleartype:  true,
		pause: true
		
	});
	
	$container.children().each(function(i) {
		linkZoomGallery = $(this).attr('zoomimg')
		titleZoomGallery = $(this).attr('titleView')
		// create LI 
		$('<li><a href="'+(i+1)+'" zoomGallery="'+linkZoomGallery+'" titleNavGallery="'+titleZoomGallery+'"></a></li>') 
			// append it to button container 
			.appendTo(bc) 
			// bind click handler 
			.click(function() { 
				// cycle to the corresponding slide 
				$('.productImageSlideNav li').removeClass('off');
				$(this).addClass('off');
				$container.cycle(i); 
				return false; 
			}).hide();
			
		$('.productImageSlideNav li:first').addClass('off');
	});
	
	
	$('.productImageSlideNav li').each(function(){
		
		indiceFoto=indiceFoto+1;						   
								   
		$(this).delay(indiceFoto*200).fadeIn();
		
		btnSlideW = btnSlideW + $(this).outerWidth();
		$('.productImageSlideNav').width(btnSlideW);
		$('.productImageSlideNav').css('margin-left', -(btnSlideW/2))
		
	});
	
	if($('.zoom').size() != 0){
		$('.zoom').click(function(){
			openGallery();
		})
	}
}

//Color change
function changeProductColor(){
	$('p.changeColor a').click(function(){
		$('p.changeColor a').removeClass('off');
		$(this).addClass('off');
		var classToOpen = $(this).html().replace(/[/ ]/g,"").toLowerCase();
		
		$('.productImageSlide').fadeOut('slow', function(){
			$('.productImageSlideNav').html('')
			$('.productImageSlide').html('');
			$('.productImageSlide').html($('.'+classToOpen ,'.color').html())
			$('.productImageSlide').cycle('destroy');
			$('.navProdDett li.btnzoom').remove()
			productImageSlide();
			//openGallery()
			//return false;
		});
		$('.productImageSlide').fadeIn()
			
	})
}

// PHOTO GALLERY
/*function openGallery(){
	
		
		var footerTitle = 	$('.contDettProdotto .colDx h1 cufontext').html()			   
		$("html").css("overflow", "hidden");
		
		//faccio apparire la copertura nera
		$('<div id="overWin"><div class="preloader"></div><div class="contenuto"><div class="closeGallery"></div><div class="navImg"><p>title</p><ul></ul></div><div class="contImg"><img id="fsImage" src="" /></div></div><div class="footer"><h1>nome</h1></div></div>').appendTo('body');
		$('#overWin .contenuto').height($(window).height()-$('#overWin .footer').height())
		$('#overWin .contImg').height($('#overWin .contenuto').height())
		
		
		
		var div = "#overWin";
		centerDiv(div);
		
		$('#overWin .footer h1').html(footerTitle)
		$('#overWin .navImg p').html(titleView)
		
		$('.productImageSlideNav li').each(function(){
			linkZoomGallery = $('a',this).attr('zoomgallery')
			titleView = $('a',this).attr('titleNavGallery')
			$('<li><a href="javascript:void(0)" zoomGallery="'+linkZoomGallery+'" titleNavGallery="'+titleView+'"></a></li>').appendTo('#overWin .navImg ul');
		});
		
		mostraPhoto();
		
		
		
		//chiudo la gallery
		$('.closeGallery').click(function(){
			$('#overWin').fadeOut('slow', function(){
				$('#overWin').remove();									   
			});
			$("html").css("overflow", "auto");
		});
		
		
		$('#overWin .navImg ul li').click(function(){
			$('#overWin .navImg ul li').removeClass('off')
			$(this).addClass('off')
			titleView = $('a', this).attr('titleNavGallery')
			$('#overWin .navImg p').html(titleView)
			linkZoomGallery = $('a', this).attr('zoomgallery')
			$('img#fsImage').hide();
			$('#overWin .preloader').show();
			$('img#fsImage').attr('src', linkZoomGallery);	
			
			$('#overWin .contenuto').waitForImages(function() {
				resizeImg();
				$('#overWin .preloader').fadeOut('slow', function(){
					$('img#fsImage').fadeIn('slow');
				});	
			});	
		});
		
	
	$(window).resize(function(){
		$('#overWin .contenuto').height($(window).height()-$('#overWin .footer').height())
		$('#overWin .contImg').height($('#overWin .contenuto').height())
		resizeImg();
	});
}*/



// mostro immagine grande gallery
/*function mostraPhoto(){
	$('img#fsImage').hide();
	$('#overWin .preloader').show();
	$('img#fsImage').attr('src', linkZoom);
	
	$('#overWin .contenuto h1').fadeOut('slow');		
	
	$('#overWin .contenuto').waitForImages(function() {
		resizeImg();
		//setTimeout("resizeImg()", 200)
		
		var w = 0;
		var h = 0;
		
		function scrollFsImage(){
			//alert('eccoci')
			//Get our elements for faster access and set overlay width
			var div = $('#overWin .contImg'),
			ul = $('#fsImage'),
			// unordered list's left margin
			ulPadding = 0;
		
			//Get menu width
			var divHeight = div.height();
			//Remove scrollbars
			div.css({overflow: 'hidden'});
		
			//Find last image container
			
			//When user move mouse over menu
			div.mousemove(function(e){
				var top = (e.pageY - div.offset().top) * (divHeight-100) / divHeight;
			  div.scrollTop(top);
			});
		}
		
	
		$('#overWin .preloader').fadeOut('slow', function(){
			$('img#fsImage').fadeIn('slow');
			
			var fsImgW = $('img#fsImage').width()
			var fsImgH = $('img#fsImage').height()
			
			
			$('<div id="mycursor"></div>').appendTo('#overWin .contenuto')
			
			$('#fsImage').mouseout(function(){
				   $('#mycursor').hide();
				   return false;
			  });
			  $('#fsImage').mouseenter(function(){
				   $('#mycursor').show();
				   return false;
			  });
			  $('#fsImage').mousemove(function(e){
				   $('#mycursor').css('left', e.clientX - 20).css('top', e.clientY + 7);
			  });
			
			var zoomClick= 0
			
			$('img#fsImage').click(function(){
				if(zoomClick==0){
				var max_size = $(this).height() + 2000;
				if ($(this).height() > $(this).width()) {
					h = max_size;
					w = Math.ceil($(this).width() / $(this).height() * max_size);
				  } else {
					w = max_size;
					h = Math.ceil($(this).height() / $(this).width() * max_size);
				  }
				  
				  $(this).stop().animate({
						width : w, 
						height :  h,
						marginLeft:-(w/2)+"px",
						marginTop:-(h/2)+"px"
					},400, 'swing')
					
					zoomClick=1 
					scrollFsImage()
					$('#mycursor').css({'background-position':'0 -50px'})
					
				}else if(zoomClick==1){
					 $(this).stop().animate({
						width : fsImgW, 
						height :  fsImgH,
						marginLeft:-(fsImgW/2)+"px",
						marginTop:-(fsImgH/2)+"px"
					},400, 'swing')		
					zoomClick=0	
					$('#mycursor').css({'background-position':'0 0'})
				}
				
			})
		});		
			

	});
	
	$('#overWin .navImg ul li a').each(function(){
		if($(this).attr('zoomgallery') == linkZoom){
			$(this).parent().addClass('off')	
		}
	});
			
}*/

//RESIZE IMG
/*function resizeImg() {
	var iWidth = 0;
	var iHeight = 0;
	iWidth = $('#fsImage').width();
	iHeight = $('#fsImage').height();
	
	$('#fsImage').height($('#overWin .contenuto').height());
	$('#fsImage').css("width", 'auto');
	
	if($('#fsImage').width()>=$(window).width()-100){
		$('#fsImage').width($('#overWin .contenuto').width());	
		$('#fsImage').css("height", 'auto');
	}
	
	
	var newWidth = $('#fsImage').width();
	var newHeight = $('#fsImage').height();
	
	$('#fsImage').css("margin-left",-(newWidth/2)+"px");
	$('#fsImage').css("margin-top",-(newHeight/2)+"px");
	
}*/


//OPEN PRIVACY
function OverTotView(){
	$('a.overbox').click(function(){
		
		var htmltoopen = $(this).attr('link');
		$("html").css("overflow", "hidden");
		
		$('<div id="overWin" style="display:none;background:url(../img/bg_overWin.png) repeat;"><div id="contwinCopertura"><div class="header"><h1>titolo</h1><a class="close" href="javascript:void(0)"></a></div><div class="content"><p class="pn"></p></div></div></div>').appendTo('body')	
		var div = "#overWin";
		centerDiv(div)
		
		$('#contwinCopertura .header h1').html($(this).html());
		
		$('#contwinCopertura .content').height($('#contwinCopertura').height() - $('#contwinCopertura .header').outerHeight() - 40);
		
		$('#contwinCopertura .content p').load(htmltoopen, function(){
			setTimeout("$('#contwinCopertura .content').jScrollPane()", 100)
			$('#overWin').fadeIn('slow');
			
		});
		
		$('#contwinCopertura .header a.close').click(function(){
			$('#overWin').fadeOut('slow', function(){
				$(this).remove();		
				$("html").css("overflow", "auto");
			});											 
		});
		
	});
}

//NEWS
function newsHover(){
	$('.news li').hover(function(){
		$('.news li').not(this).stop().animate({
			opacity:	0.2									   
		})							 
	}, function(){
		$('.news li').not(this).stop().animate({
			opacity:	1
		})	
	});
}

//Facebook Like
function addFacebookLike(){
	
	var urlfacebook = escape(location.href)
	
	$('<br /><br /><iframe src="http://www.facebook.com/plugins/like.php?href='+urlfacebook+'&amp;layout=standard&amp;show_faces=true&amp;width=450&amp;action=like&amp;font=arial&amp;colorscheme=light&amp;height=80" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:100%; height:80px;" allowTransparency="true"></iframe>').appendTo('#facebooklike');
	
}

//Facebook Like 1
function addFacebookLike1(){
	
	var urlfacebook = escape(location.href)
	
	$('<iframe src="http://www.facebook.com/plugins/like.php?href='+urlfacebook+'&amp;layout=button_count&amp;show_faces=false&amp;width=100&amp;action=like&amp;font=arial&amp;colorscheme=light&amp;height=36" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:100px; height:60px;" allowTransparency="true"></iframe>').appendTo('#facebooklike1');
	
}

//Federations List
function federationsList(){
	$('.federations li').fadeTo('slow', 0.7)
		$('.federations li').hover(function(){
			$(this).stop().fadeTo('slow', 1)								
		}, function(){
			$(this).stop().fadeTo('slow', 0.7)	
		})

}

//Apre spiegazione filtri
function ViewFilters(){
	$('a.viewFilters').click(function(){
		
		var htmltoopen = $(this).attr('link');
		$("html").css("overflow", "hidden");
		
		$('<div id="overWin" style="display:none;background:url(../img/bg_overWin.png) repeat;"><div id="contwinCopertura"><div class="header"><h1>titolo</h1><a class="close" href="javascript:void(0)"></a></div><div class="content"><p class="pn"></p></div></div></div>').appendTo('body')	
		var div = "#overWin";
		centerDiv(div)
		
		$('#contwinCopertura .header h1').html($(this).text());
		
		$('#contwinCopertura .content').height($('#contwinCopertura').height() - $('#contwinCopertura .header').outerHeight() - 40);
		
		$('#contwinCopertura .content p').load(htmltoopen, function(){
			setTimeout("$('#contwinCopertura .content').jScrollPane()", 100)
			$('#overWin').fadeIn('slow');
			
		});
		
		$('#contwinCopertura .header a.close').click(function(){
			$('#overWin').fadeOut('slow', function(){
				$(this).remove();		
				$("html").css("overflow", "auto");
			});											 
		});
		
	});
}

function VideoAdvHome(){
	$("html").css("overflow", "hidden");
			
	$('<div id="overAdvH" style="background:url(img/bg_overWin.png) repeat;"><div id="videogalleryAdvH"><div class="header"><h1>Video title</h1><a href="javascript:void(0)" class="close"></a></div><div class="fsVideo"><div id="ytvideo"></div></div></div></div>').appendTo('body');
	
	var div = "#overAdvH";
	centerDiv(div);
	
	$('#videogalleryAdvH .fsVideo video').hide();
	
	$('#videogalleryAdvH a.close').click(function(){
		$('#videogalleryAdvH').fadeOut('slow', function(){
			$('#overAdvH').fadeOut('slow').remove();
		})
		$("html").css("overflow", "auto");
	});
	
	var videoToView = $('.videoListAdvH div').attr('link');
	var titleZoom = $('.videoListAdvH div').attr('titolo');
	//alert(videoToView)
	
	$('#videogalleryAdvH .fsVideo #ytvideo').html('')
	$('<iframe width="640" height="390" src="http://www.youtube.com/v/'+videoToView+'&autoplay=1?rel=0'+'" frameborder="0" allowfullscreen></iframe>').appendTo('#videogalleryAdvH #ytvideo');
	
	
	$('#videogalleryAdvH .header h1').html(titleZoom)
	
	$('#videogalleryAdvH .fsVideo video').fadeIn('slow')
	
};

function mappaStorelocator(){
	$('.mapS').gmap('clearMarkers');
	$('.mapS').gmap({zoom: 6});
	var latlngFirst = new google.maps.LatLng(41.992726,12.392578);;
	$('.mapS').gmap({ 'center': latlngFirst })
	
	if($('.storeResult .cont div').size()!=0){
		
		$('.mapS').gmap('clearMarkers');
		$('.mapS').gmap({zoom: 9});
		var latitudineFirst = 0;
		var longitudineFirst = 0;
		var firstPoint = true;
		latlngFirst = 0
		$('.storeResult .cont div').each(function(marker){
			if(firstPoint){
				latitudineFirst = $(this).attr('lat');
				longitudineFirst = $(this).attr('lng');
				latlngFirst= new google.maps.LatLng(latitudineFirst, longitudineFirst);
				firstPoint = false;
			}
			var latitudineFirst = $(this).attr('lat');
			var longitudineFirst = $(this).attr('lng');
			var latitudine = $(this).attr('lat');
			var longitudine = $(this).attr('lng');
			var contentTitle = $(this).find('h1').html()
			var contentText = $(this).find('p').html()
			latlng = new google.maps.LatLng(latitudine, longitudine);
			mapName = $('.mapS')
			
			if(latitudine==0 && longitudine==0){
				
			}else{
				$(this).css('cursor', 'pointer')
				var infoWindowContent = '<div style="font-size: 8pt;">'+ contentTitle +'<br>'+ contentText + '...</div>';
			
				mapName.gmap('addMarker', { 
										  'position': latlng,
										  'animation': google.maps.Animation.DROP, 
										  'icon': new google.maps.MarkerImage( 
														'img/marker.png', 
														new google.maps.Size(38, 33), 
														new google.maps.Point(0,0), 
														new google.maps.Point(0, 0) 
														) 
											}, function(map, marker){
											mapName.gmap('addInfoWindow', { 'position':marker.getPosition(), 'content': infoWindowContent }, function(iw) {
												$(marker).click(function() {
														iw.open(map, marker);
														//map.panTo(marker.getPosition());
												});
											});
				});
					
			}
			
			$(this).click(function(){
				var thislatitudine = $(this).attr('lat');
				var thislongitudine = $(this).attr('lng');
				var thislatlng = new google.maps.LatLng(thislatitudine, thislongitudine);
				$('.mapS').gmap({ 'center': thislatlng, zoom: 14 })		
			})
			
		}) 
	$('.mapS').gmap({ 'center': latlngFirst })
		
		$(".storeResult .filtra label:last-child").css({'margin-right':0,'padding-right':0,'border-right':0})
		$(".storeResult .cont").jScrollPane()
		$(".storeResult .cont .jspVerticalBar").css({'width':'14px', 'background':'none'})
		$(".storeResult .cont .jspTrack").css({'width':'14px', 'background':'none'})
		$(".storeResult .cont .jspDrag").css({'width':'14px', 'background-color':'#B0B0B0'})
		
	}
}

function selectStoreLocator(){
				$('.contIstituzionale').css({'padding-bottom':0})
		$('#colSx').height($('.contIstituzionale').height())
		$(".selectStore select").msDropDown({mainCSS:'cc'});
		var zIndexNumber = 500;
		$('.cc').each(function() {
			$(this).css('zIndex', zIndexNumber);
			zIndexNumber -= 5;
		});
}

var latlng =0
var primaVolta=true;
var mapName = 0


function createSiteMap() {
	$.ajax({
		type: "POST",
		url: "http://" + window.document.location.host + "/sitemap.aspx",
		success: function() {
		}
	});
}	


function showLanguage(){
	var display = $('.listaLingue').css('display');
	if (display == 'none'){
		if (navigator.appName == "Microsoft Internet Explorer") {
			$('.listaLingue').show();
		} else {
			$('.listaLingue').fadeIn('slow');
		}
		$('.listaLingue a').mouseout(function(e){
			hideLanguage(e);
		});
	}
	else{
		if (navigator.appName == "Microsoft Internet Explorer") {
			$('.listaLingue').hide();
		} else {
			$('.listaLingue').fadeOut('slow');
		}
	}
}

function hideLanguage(e){
	if(e.currentTarget.attributes['class'].value != 'listaLingue' && e.currentTarget.attributes['class'].value.indexOf('linkLingue')<0){
		var display = $('.listaLingue').css('display');
		if (display == 'block'){
			if (navigator.appName == "Microsoft Internet Explorer") {
				$('.listaLingue').hide();
			} else {
				$('.listaLingue').fadeOut('slow');
			}
		}
	}
}



//Document ready
$(function() {
		$('.linguaCorrente').hover(function() {
				$('.listaLingue').fadeIn("slow");
			}, function() { });

			$('.listaLingue').mouseleave(function() {
				$(this).fadeOut("slow");
			}, function() { });




	createSiteMap();

	//set background image to fullscreen
	if($('.bgChange').size() != 0){
		bgFull = $('.bgChange img').attr('src')
		$.backstretch(bgFull); 
	}else{
		$.backstretch("img/bg.jpg");	
	}
		   
	//$('.page').hide();
	OverTotView();
	ViewFilters();
	hoverMenu();
	hoveSubMenu();
	
	//top menu
	if($(".topmenu").size() != 0){
		$("ul.topmenu li:last").css({'border-right':0, 'padding-right':0});
	}
	
	
	//SElect lang
	if($("#header select").size() != 0){
		$("#header select").msDropDown();
	}
	
	//map Store locator
	if($(".mapS").size() != 0){
		mappaStorelocator();
		selectStoreLocator();
	}
	
	if($('.carousel').size() != 0){
		$('.carousel').waitForImages(function() {
    		CarouselHome();
			//$('#preloader').fadeOut('slow');
			//$('.page').fadeIn('slow');
			
			if($('.slideshowHome').size() != 0){
				$('.slideshowHome').waitForImages(function() {
					SlideshowHome();
				});
			}
			if($('fieldset').lenght != 0){
				InputFocus();
			}
			
		});	
	}

	
	
	if($('.videoThumb').size() != 0 || $('.videoBtn').size() != 0){
		openVideoGallery();
	};
	
	if($('.slideshowProduct').size() != 0){
		$('.slideshowProduct').waitForImages(function() {
    		SlideshowProduct();
			//$('#preloader').fadeOut('slow');
			//$('.page').fadeIn('slow');
			
			//
			if($('.carouselP li').size() != 0){
				CarouselProducts();
			}
			
			//
			if($('#presentation_container').size() != 0){
				presentationCycle.init();
				$('.left .year').css('color', '#000')	
				
				$('.pc_bar_container div').click(function(){
					$('.year').css('color', '#b3b3b3')
					$('.year',this).css('color', '#000')										  
				})
				$('.pc_bar_container_overflow div').click(function(){
					$('.year').css('color', '#b3b3b3')
					$('.year',this).css('color', '#000')										  
				})
			};
			
			//
			if($('.productInfo').size() != 0){
				productInfoSlide();
			}
					
			
			//
			if($('.categoryChoose ul').size() != 0){
				ChooseCategory();
			}
			
			//
			if($('.slideTopBanner img').size() != 0){
				slideTopBanner();
			}
			
			//
			if($('.productInfo #Map').size() != 0){
				$("area.zoomBodyLook").fancybox();
			}
		});	
	}
	
	if($('.atletaSlideshow').size() != 0){
		$('.atletaSlideshow').waitForImages(function() {
    		//$('#preloader').fadeOut('slow');
			//$('.page').fadeIn('slow');
			slideshowAtleta();
			//
			if($('.atletaInfo').size() != 0){
				eliteTeamInfoAtleta()
			}
			
			//
			if($('.carouselP li').size() != 0){
				CarouselProducts();
			}
			
		});	
	}
	
	if($('.productList').size() != 0){
		$('.productList').waitForImages(function() {
    		//$('#preloader').fadeOut('slow');
			//$('.page').fadeIn('slow');
			productList();
			
			//
			if($('.filter').size() != 0){
				submenuFilter();
			};
		});	
		
	}
	
	if($('.productImageSlide').size() != 0){
		$('.color').waitForImages(function() {
			var firstToOpen = $('p.changeColor a.off').html().replace(/[/ ]/g,"").toLowerCase();
    		$('.productImageSlide').html($('.color div.'+firstToOpen).html())
			
			$('.colDx p:last-child').css({'margin-bottom':50})
			
			//$('#preloader').fadeOut('slow');
			//$('.page').fadeIn('slow');
			productImageSlide();
			changeProductColor();
			//
			if($('.carouselP li').size() != 0){
				CarouselProducts();
			}
			//
			/*if($('a.zoom').size() != 0){
				openGallery();
			}*/
		});
	}
	
	if($('.pagProdotti').size() != 0){
		$('.pagProdotti li:last-child').css('border-right', 0)
	};
	
	if($('.contIstituzionale').size() != 0){
		/*$('.contIstituzionale').waitForImages(function() {
			$('#preloader').fadeOut('slow');
			$('.page').fadeIn('slow');								   
		});*/
		
		if($('#map').size() != 0){
			var lat = $("#map").attr('lat');
			var lng = $("#map").attr('lng');
			var addressMap = $("#colSx span.address").html()
			
			$("#map").gmap({zoom: 9});
			var latlngContactMap = new google.maps.LatLng(lat, lng);;
			$("#map").gmap({ 'center': latlngContactMap })
			
			var mapName = $("#map")
			
			var infoWindowContent = '<div style="font-size: 8pt;">'+ addressMap + '...</div>';
			
			mapName.gmap('addMarker', { 
									  'position': latlngContactMap,
									  'animation': google.maps.Animation.DROP, 
									  'icon': new google.maps.MarkerImage( 
													'img/marker.png', 
													new google.maps.Size(35, 40), 
													new google.maps.Point(0,0), 
													new google.maps.Point(0, 0) 
													) 
										}, function(map, marker){
										mapName.gmap('addInfoWindow', { 'position':marker.getPosition(), 'content': 		infoWindowContent }, function(iw) {
											$(marker).click(function() {
													iw.open(map, marker);
													//map.panTo(marker.getPosition());
											});
										});
			});
			
			
			
		};
		
		
		if($('.paginazione').size() != 0){
			$('.paginazione:last-child').css({'border-bottom':0, 'border-top': '1px solid #e1e1e1', 'margin-top': '-1px'})
			$('.pag a:last-child').css('border-right', 0);
			$('.pag span:last-child').css('border-right', 0);
		};
		
		if($('.news li').size() != 0){
			newsHover();
		};
		
		if($('.menuNewsDett li').size() != 0){
			$('.menuNewsDett li:last-child').css({'border-right': 0})
		};
		
		if($('#newsgallery img').size() != 0){
			var firstImg = $('#newsgallery img:first-child').attr('src')
			$('.previewImg').attr('src', firstImg)
			if($('#newsgallery img').size() <= 1){
				$("#openNewsGallery").hide();
			}
			
			$("#openNewsGallery").click(function() {
			
				var newsGalleryArray = [];
				$('#newsgallery img').each(function(){
					var items = $(this).attr('src');
					newsGalleryArray.push(items);
				});
			
				function formatTitle(title, currentArray, currentIndex, currentOpts) {
					return '<div id="tip7-title"><span><a href="javascript:;" onclick="$.fancybox.close();"><img src="img/fancybox/closelabel.gif" /></a></span>' + (title && title.length ? '<b>' + title + '</b>' : '' ) + '<p>Image ' + (currentIndex + 1) + ' of ' + currentArray.length + '<p></div>';
				}
				
				$.fancybox(newsGalleryArray,{
					'padding' 	: 0,
					'type'              : 'image',
					'showCloseButton'	: false,
					'titlePosition' 	: 'inside',
					'titleFormat'		: formatTitle
					
				});
			});
			
		}else{
			$("#openNewsGallery").hide();
			$(".previewImg").hide();
		};
	
	
	if($('.slideCompany').size() != 0){
		$('.slideCompany img').hide();
		$('.slideCompany img:first').fadeIn(800, function(){
				$('.slideCompany').cycle({ 
					fx:     'fade', 
					speed:   800, 
					timeout: 3000,
					cleartype:  true,
					pause: true
					
				});	
			});
		}	
	
	};
	
	if($('#facebooklike').size() != 0){
		addFacebookLike();
	}
	
	if($('#facebooklike1').size() != 0){
		addFacebookLike1();
	}
	
	if($('.federations').size() != 0){
		federationsList();
	}
	
	if($('.videoListAdvH').size() != 0){
		if($('.videoListAdvH div').attr('link') != 0){
			VideoAdvHome()
		}
	}
	
	if($('.anchorLink').size() != 0){
		$("a.anchorLink").anchorAnimate()
	}
	
	
	if($('.backshapes').size() != 0){
		$(".backshapes:last-child").css({'border-bottom': 0, 'padding-bottom': 0})
	}
	
	if($('.floatArrow').size() != 0){
		$(".floatArrow").makeFloat({x:300,y:"current"});
	}
	
	if($('.homeBottom .box').size() != 0){
		$(".homeBottom .box:first").css({'background-color':'#202020'})
		$(".homeBottom .box:first h1 span").css({'color':'#fff'})
	}
	
	if($('input[type=file]').size() != 0){
		SI.Files.stylizeAll();
	}
	
	if($('.jobContForm').size() != 0){
		$('.sendCV').click(function(){
			$('.jobContForm').slideToggle(600)		
		})
	}
});

$(window).scroll(function() {
	if($('.floatArrow').size() != 0){
		if ($(this).scrollTop() <= 390) {
			$(".floatArrow").fadeOut();
		}
		if ($(this).scrollTop() >= 400) {
			$(".floatArrow").fadeIn();
		}
	}
});

//RESIZE
$(window).resize(function(){
	try
  	{
	
	if($('#overWin').lenght != 0){
		var div = "#overWin";
		centerDiv(div)
	};	
	
	
	}catch(err){
	}
});
