 jQuery.fn.fadeSliderToggle = function(settings) {
  	 settings = jQuery.extend({
		speed:500,
		easing : "swing"
	}, settings)
	
	caller = this
 	if($(caller).css("display") == "none"){
 		$(caller).animate({
 			opacity: 1,
 			height: 'toggle'
 		}, settings.speed, settings.easing);
	}else{
		$(caller).animate({
 			opacity: 0,
 			height: 'toggle'
 		}, settings.speed, settings.easing);
	}
};


$(document).ready(function(){
	
	$('.news_home .block_news:gt(1)').addClass('smallimg');
	$('.news_home .block_news:gt(2) .over_image').hide();
	$('.no_link').click(function(e){e.preventDefault()});
	$('.no_link').mouseover(function(){
		$(this).parent().css('background','#fff');
	});
	$('.generic_item').each(function(){
			if($('.breakspace').length > 0){
			$('.generic_item').each(function(){
				$('.breakspace:first',this).hide();
			});
			}
			if($('img',this).length > 0){
				
				var images = $('img',this).innerWidth();
				var content= $(this).innerWidth();
				var neWidth = content - images -30;
				$('span',this).width(neWidth);
				$('h3',this).width(neWidth);
				$('h4',this).width(neWidth);
				$('h5',this).width(neWidth);
				$('.breakspace',this).width(neWidth);
			}
			if($('.sub_evento_si',this).length > 0){
				var images = $('.sub_evento_si',this).innerWidth();
				var content= $(this).innerWidth();
				var neWidth = content - images -30;
				$('span',this).width(neWidth);
				$('h3',this).width(neWidth);
				$('h4',this).width(neWidth);
				$('h5',this).width(neWidth);
				$('.breakspace',this).width(neWidth);
			}
		});
	
	if($('.loghi_action').length >0){
	
	$('.loghi_action input').change(function(){
	
		Download();
	});
	
	
	
	
	Download = function () {
	
	if($('#accetta').is(':checked')){
		
			$('.dow_zip').removeClass('no_down');
			
		}
		else{
			$('.dow_zip').addClass('no_down');
			
		}
	
	}
	Download();
	}
	 if(($('body').hasClass('contatti'))){
		  	$('.nav_bar ul li a').each(function(){
		  		if($(this).attr('name') == 'contatti'){
		  			$(this).attr('id','active');
		  		}
		  	});
		  }
	 if(($('body').hasClass('stampa'))){
		  	$('.nav_bar ul li a').each(function(){
		  		if($(this).attr('name') == 'stampa'){
		  			$(this).attr('id','active');
		  		}
		  	});
		  }
	
	if(($('body').hasClass('home'))){
		  	$('.nav_bar ul li a').each(function(){
		  		if($(this).attr('name') == 'home'){
		  			$(this).attr('id','active');
		  		}
		  	});
		  }
	 if(($('body').hasClass('espositori'))){
		  	$('.nav_bar ul li a').each(function(){
		  		if($(this).attr('name') == 'espositori'){
		  			$(this).attr('id','active');
		  		}
		  	});
		  }
	if(($('body').hasClass('visitatori'))){
		  	$('.nav_bar ul li a').each(function(){
		  		if($(this).attr('name') == 'visitatori'){
		  			$(this).attr('id','active');
		  		}
		  	});
		  }
	if(($('body').hasClass('eventi'))){
		  	$('.nav_bar ul li a').each(function(){
		  		if($(this).attr('name') == 'eventi'){
		  			$(this).attr('id','active');
		  		}
		  	});
		  }
	if(($('body').hasClass('new'))){
		  	$('.nav_bar ul li a').each(function(){
		  		if($(this).attr('name') == 'newsletter'){
		  			$(this).attr('id','active');
		  		}
		  	});
		  }
	liAccordion=function(){
	$('.accordion_menu ul').hide();
		$('.accordion_menu h4').click(function(){
			$(this).toggleClass('select');
			$(this).next().fadeSliderToggle()
		});
		var pathname = $(location).attr('href').split('search=');
		if($(pathname)[1] != null){
			
			var preUse=$(pathname)[1].split('&id_field=');
			var toUse =$(preUse)[0];
			var ulRef=$(preUse)[1];
			console.log(toUse);
			console.log(ulRef);
			
			$('.accordion_menu ul#'+ulRef+' li a').each(function(){
				if($(this).attr('id') == toUse){
					$('.accordion_menu ul').show();
					$(this).addClass('selected');
				}
			
			});
			
		}
		if($('.open').length >0){
			$('.accordion_menu ul').show();
		}
		
	};
	
	if($('a.fancy').length >0){$("a.fancy").fancybox();};
	if($('a.fancy_fancy').length >0){$("a.fancy_fancy").fancybox({
				'width'				: 260,
				'height'			: 240,
				'autoScale'			: false,
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'type'				: 'iframe',
				'scrolling'         : 'no'
				
			} );};
	if($('.generic_item a.no_zoom').length >0){
		$(".generic_item a.no_zoom").click(function(e){
			e.preventDefault();
		});
	};
	
	if($('.accordion_menu')){liAccordion();};
	
	if($('.generic_item').length >1){
		$('.generic_item:last').css('border-bottom', 'none');
	}
	
	$('.menu_inside ul li:first').hide();
	
	if(($('#where').length >0)){
		if(($('#where').text() > 1)){$('.menu_inside ul').attr('id', '');}

		$('.menu_inside ul li a').each(function(){
			
			
		
			if(($(this).attr('id')) == $('#where').text()){
			$(this).parent().attr('id','sel');
			}
			
			if(($(this).attr('id')) == $('#where').text()){
			$(this).parent().attr('id','sel');
			}
			
			if(($(this).text() == $('#where').text())){ // || ($(this).text() == 'contacts')
			$(this).parent().attr('id','sel');
			}
		
		});
		
			
		
	}
	
	
	
	
		
	
});
