Shadowbox.init();

$(document).ready(function() {
	$('#div_float').masonry({columnWidth: 175});
	
	$('#txt_full').expander({
		slicePoint:       80,  // default is 100
		userCollapseText: 'chiudi tutto...'  // default is '[collapse expanded text]'
	});

	$('#scroll_rassegna').jScrollPane({
		scrollbarWidth: 2,
		scrollbarOnLeft: true
	});

	$('#scroll_negozi').jScrollPane({
		scrollbarWidth: 2,
		scrollbarOnLeft: true
	});
	
	$('#pannel').jScrollPane({
		scrollbarWidth: 2
	});
	
	$('#pannel2').jScrollPane({
		scrollbarWidth: 2
	});
	
	$('#pannel3').jScrollPane({
		scrollbarWidth: 2
	});
	
	$('#pannel4').jScrollPane({
		scrollbarWidth: 2
	});
	
	$('#pannel5').jScrollPane({
		scrollbarWidth: 2
	});
	
	$('#brochure-1').jScrollPane({
		scrollbarWidth: 2
	});
	
	$('#brochure-2').jScrollPane({
		scrollbarWidth: 2
	});
	
	$('#brochure-3').jScrollPane({
		scrollbarWidth: 2
	});
	
	$("#image-home").cycle({
		timeout: 4000
	});
		
	$("#cycles").cycle({
		timeout: 6000,
		prev:"#prev",
		next:"#next",
		after: onAfter
	});
	
	function onAfter(curr, next, opts) {
		var index = opts.currSlide;
		$('#prev')[index == 0 ? 'hide' : 'show']();
		$('#next')[index == opts.slideCount - 1 ? 'hide' : 'show']();
	}
	
	$('#descr').cycle({ 
    	timeout: 0, 
    	speed:   300 
	});
	
	$('#main_brochure').cycle({ 
		fx:     'fade', 
		speed:  'fast', 
		timeout: 0, 
		next:   '#next-2', 
		prev:   '#prev-2',
		after: onAfter_brochure
	});
	
	function onAfter_brochure(curr, next, opts) {
		var index = opts.currSlide;
		$('#prev-2')[index == 0 ? 'hide' : 'show']();
		$('#next-2')[index == opts.slideCount - 1 ? 'hide' : 'show']();
	}
	
	$('#btn01').addClass('sele');
	
	$('#btn01').click(function() { 
    	$('#menu_sx a').removeClass('sele');
		$(this).addClass('sele');
		$('#descr').cycle(0); 
    	return false; 
	}); 
	
	$('#btn02').click(function() { 
		$('#menu_sx a').removeClass('sele');
		$(this).addClass('sele');
    	$('#descr').cycle(1); 
    	return false; 
	});
	
	$('#btn03').click(function() { 
    	$('#menu_sx a').removeClass('sele');
		$(this).addClass('sele');
		$('#descr').cycle(2); 
    	return false; 
	});
	
	$('#btn04').click(function() { 
    	$('#menu_sx a').removeClass('sele');
		$(this).addClass('sele');
		$('#descr').cycle(3); 
		return false; 
	});
	
	$('#pagine_brand').cycle({ 
		fx:     'fade',
		timeout: 0, 
    	speed:   300 
	});
	
	$('#image-brand1').cycle({ 
		fx:     'fade',
		timeout: 4000, 
    	speed:   300,
		prev:".prev1",
		next:".next1",
		after: onAfter1 
	});
	$('#image-brand2').cycle({ 
		fx:     'fade',
		timeout: 4000, 
    	speed:   300,
		prev:".prev2",
		next:".next2",
		after: onAfter2 
	});
	$('#image-brand3').cycle({ 
		fx:     'fade',
		timeout: 4000, 
    	speed:   300,
		prev:".prev3",
		next:".next3",
		after: onAfter3 
	});
	
	function onAfter1(curr, next, opts) {
		var index = opts.currSlide;
		$('.prev1')[index == 0 ? 'hide' : 'show']();
		$('.next1')[index == opts.slideCount - 1 ? 'hide' : 'show']();
	}
	function onAfter2(curr, next, opts) {
		var index = opts.currSlide;
		$('.prev2')[index == 0 ? 'hide' : 'show']();
		$('.next2')[index == opts.slideCount - 1 ? 'hide' : 'show']();
	}
	function onAfter3(curr, next, opts) {
		var index = opts.currSlide;
		$('.prev3')[index == 0 ? 'hide' : 'show']();
		$('.next3')[index == opts.slideCount - 1 ? 'hide' : 'show']();
	}
	
	
	$("#puls_brand a")
		.css({opacity: 0.5})
		.mouseover(function(){				
			$("#txt_roll").html($(this).attr('rel'));
			$(this).stop().animate({opacity: 1}, {duration:150})
			
		})
		.mouseout(function(){		   
			$("#txt_roll").html("");
			$(this).stop().animate({opacity: 0.5}, {duration:150, complete:function(){
					$(this).css({opacity: 0.5})
					}})
			
		});	
		
	$("#puls_brand a").each(function(i) {
		var el = $(this);
		el.click(function(e) {
			$('#pagine_brand').cycle(i+1);
			return false;
		});
	});
	
	var stat_a=0;
	
	$("#b1").hover(
		function(){		
				$("#b1").css('z-index','12');
				$("#b2").css('z-index','8');
				$("#b3").css('z-index','8');
				$("#b4").css('z-index','8');
				$("#img_1").show('fast');
				$("#t1").show('fast');
				},
		function(){		
				$("#b1").css('z-index','11');
				$("#b2").css('z-index','11');
				$("#b3").css('z-index','11');
				$("#b4").css('z-index','11');
				$("#img_1").hide('fast');
				$("#t1").hide('fast');
				}
	);
	
	$("#b2").hover(
		function(){		
				$("#b1").css('z-index','8');
				$("#b2").css('z-index','12');
				$("#b3").css('z-index','8');
				$("#b4").css('z-index','8');
				$("#img_2").show('fast');
				$("#t2").show('fast');
				},
    	function(){		
				$("#b1").css('z-index','11');
				$("#b2").css('z-index','11');
				$("#b3").css('z-index','11');
				$("#b4").css('z-index','11');
				$("#img_2").hide('fast');
				$("#t2").hide('fast');
				}
	);
	
	$("#b3").hover(
		function(){		
				$("#b1").css('z-index','8');
				$("#b2").css('z-index','8');
				$("#b3").css('z-index','12');
				$("#b4").css('z-index','8');
				$("#img_3").show('fast');
				$("#t3").show('fast');
			    },
		function(){		
				$("#b1").css('z-index','11');
				$("#b2").css('z-index','11');
				$("#b3").css('z-index','11');
				$("#b4").css('z-index','11');
				$("#img_3").hide('fast');
				$("#t3").hide('fast');
				}
	);
	
	$("#b4").hover(
		function(){		
				$("#b1").css('z-index','8');
				$("#b2").css('z-index','8');
				$("#b3").css('z-index','8');
				$("#b4").css('z-index','12');
				$("#img_4").show('fast');
				$("#t4").show('fast');
				},
		function(){		
				$("#b1").css('z-index','11');
				$("#b2").css('z-index','11');
				$("#b3").css('z-index','11');
				$("#b4").css('z-index','11');
				$("#img_4").hide('fast');
				$("#t4").hide('fast');
				}
	);
	
/*	var stat_a=0;
	
	$("#b1").click(
		function(){		
			if(stat_a==0) {	
				$("#b1").css('z-index','12');
				$("#b2").css('z-index','8');
				$("#b3").css('z-index','8');
				$("#b4").css('z-index','8');
				$("#img_1").show('fast');
				$("#t1").show('fast');
				stat_a=1;
			} else {
				$("#b1").css('z-index','11');
				$("#b2").css('z-index','11');
				$("#b3").css('z-index','11');
				$("#b4").css('z-index','11');
				$("#img_1").hide('fast');
				$("#t1").hide('fast');
				stat_a=0;
			}
		}
	);
	
	$("#b2").click(
		function(){		
			if(stat_a==0) {	
				$("#b1").css('z-index','8');
				$("#b2").css('z-index','12');
				$("#b3").css('z-index','8');
				$("#b4").css('z-index','8');
				$("#img_2").show('fast');
				$("#t2").show('fast');
				stat_a=1;
			} else {
				$("#b1").css('z-index','11');
				$("#b2").css('z-index','11');
				$("#b3").css('z-index','11');
				$("#b4").css('z-index','11');
				$("#img_2").hide('fast');
				$("#t2").hide('fast');
				stat_a=0;
			}
		}
	);
	
	$("#b3").click(
		function(){		
			if(stat_a==0) {	
				$("#b1").css('z-index','8');
				$("#b2").css('z-index','8');
				$("#b3").css('z-index','12');
				$("#b4").css('z-index','8');
				$("#img_3").show('fast');
				$("#t3").show('fast');
				stat_a=1;
			} else {
				$("#b1").css('z-index','11');
				$("#b2").css('z-index','11');
				$("#b3").css('z-index','11');
				$("#b4").css('z-index','11');
				$("#img_3").hide('fast');
				$("#t3").hide('fast');
				stat_a=0;
			}
		}
	);
	
	$("#b4").click(
		function(){		
			if(stat_a==0) {	
				$("#b1").css('z-index','8');
				$("#b2").css('z-index','8');
				$("#b3").css('z-index','8');
				$("#b4").css('z-index','12');
				$("#img_4").show('fast');
				$("#t4").show('fast');
				stat_a=1;
			} else {
				$("#b1").css('z-index','11');
				$("#b2").css('z-index','11');
				$("#b3").css('z-index','11');
				$("#b4").css('z-index','11');
				$("#img_4").hide('fast');
				$("#t4").hide('fast');
				stat_a=0;
			}
		}
	);*/
	
	
	$("#news-evidenza a").hover(
		function(){		
			$(this).find('div.news_roll').slideDown(350);
			//$(this).find('div.news_roll').css('display','table');
		},
		function(){			   
			//$(this).find('div.news_roll').css('display','none');
			$(this).find('div.news_roll').slideUp(150);
		}
	);
	
	$(".round_news").corner("cc:#fff 4px").parent().corner("round 6px");
	$("div.news_roll").corner("round 4px").parent().corner("round 6px");
		
	/*$("#news-evidenza a").hover(
		function(){		
			$this=$(this);
			$("#news-evidenza a").fadeTo('fast',0.4,function() {
				$this.fadeTo('fast',1);
    		});	
		},
		function(){			   
			$("#news-evidenza a").fadeTo('fast',1);
		}
	);*/
	
	/*$('#news-evidenza').find("a[title]").qtip({
			show: { delay: 500, effect: { type:'fade', length: 300 } },
			hide: { delay: 300, effect: { type:'fade', length: 300 } },
			content: {
				title: "NEWS",
				text: false
			},
			position: {
				corner: {
					target: 'topMiddle',
            		tooltip: 'bottomLeft'
				}
			},
			style: {
				width: { max: 350 },
				padding: '0px 20px 5px 20px',
				background: '#e1fbc7',
				color: '#666666',
				textAlign: 'center',
				border: {
					width: 1,
					radius: 4,
					color: '#b7da93'
				},		
				tip: {
					size: { x: 15, y: 15 },
					corner: 'bottomLeft'
				},
				title: { 'color': '#95968b', 'background': '#e1fbc7', 'text-align': 'center', 'padding': '5px 20px 0px 20px' }
			}		
		});*/
	
	
	$('#categorie').infiniteCarousel();
	
	$('#livelli ul li a')
		.css( {paddingTop:"15px"} )
		.mouseover(function(){
			$(this).stop().animate({paddingTop:"0px"}, {duration:250}).animate({paddingTop:"15px"}, {duration:250})
		})
		.mouseout(function(){
			$(this).stop().animate({paddingTop:"15px"}, {duration:250, complete:function(){
					$(this).css({paddingTop:"15px"})
					}})
		});
	
	$('#categorie').find("img[alt]").qtip({
			show: { delay: 500, effect: { type:'fade', length: 300 } },
			hide: { delay: 300, effect: { type:'fade', length: 300 } },
			content: {
				text: false
			},
			position: {
				corner: {
					target: 'topMiddle',
            		tooltip: 'bottomLeft'
				}
			},
			style: {
				width: { max: 350 },
				padding: '2px 10px 2px 10px',
				background: '#FFFFFF',
				color: '#858585',
				textAlign: 'center',
				border: {
					width: 1,
					radius: 1,
					color: '#858585'
				},		
				tip: {
					size: { x: 10, y: 10 },
					corner: 'bottomLeft'
				}
			}		
		});
	
	$('#mapsItalia').find("area[title]").qtip({
			show: { delay: 150, effect: { type:'fade', length: 150 } },
			hide: { delay: 150, effect: { type:'fade', length: 150 } },
			content: {
				text: false
			},
			position: {
				target: 'mouse',
				corner: {
					target: 'topMiddle', tooltip: 'bottomLeft'
				}
			},
			style: {
				width: { max: 350 },
				padding: '2px 10px 2px 10px',
				background: '#FFFFFF',
				color: '#858585',
				textAlign: 'center',
				border: {
					width: 1,
					radius: 1,
					color: '#858585'
				},		
				tip: {
					size: { x: 10, y: 10 },
					corner: 'bottomLeft'
				}
			}		
		});
});
