jQuery(document).ready(function($){
	
	// apertura menu categorie/sottocategorie a destra
	
	var mnProds = $('#elencoProdotti li').not('.sub li')
	mnProds.each(function(){
		if($(this).children('a').hasClass('active')){
			$(this).children('ul').removeClass('alt')
		}
		/*
		$(this).children('a').click(function(){
			mnProds.not(this).children('a').removeClass('active')			
			mnProds.not(this).children('ul.sub').hide()
			var parent = $(this).parent('li')
			if(!$(this).hasClass('active')){
				$(this).addClass('active')
				parent.children('ul').show()
			}else{
			}
		})
		*/
	})
	
	// categoria dettaglio
	var cat = $('#galleria').not('.dettaglio')
	cat.children('a').each(function(){
		$(this).hover(function(){
			cat.children('a').not(this).stop().animate({'opacity':0.5})
		},function(){
			cat.children('a').not(this).stop().animate({'opacity':1})
		})
	})
	
	// click elenco prodotti
	var prods = $('.location .box .pad')
	prods.each(function(){
		var a = $(this).find('a')
		var href = a.attr('href')
		if(!href)
			$(this).css('cursor','default')
		else
			$(this).css('cursor','pointer')

		//alert(href)
		$(this).hover(function(){
			a.css('color','#ccc')
		},function(){
			a.css('color','#3D3E3C')
		})
		$(this).click(function(){
			if(href)
				window.location=href
			else
				return false
		})
	})
	
	var prods = $('.marche .box, .elencoNews .box, #news .item')
	prods.each(function(){
		var a = $(this).find('a')
		var href = a.attr('href')
		if(!href)
			$(this).css('cursor','default')
		else
			$(this).css('cursor','pointer')

		//alert(href)
		$(this).hover(function(){
			a.css('color','#ccc')
			a.css('background-position','right -23px')
		},function(){
			a.css('color','#3D3E3C')
			a.css('background-position','right 1px')
		})
		$(this).click(function(){
			if(href)
				window.location=href
			else
				return false
		})
	})

	var offerte = $('.elencoOfferte .box')
	offerte.each(function(){
		var a = $(this).find('a')
		if(a!='undefined') {
			var href = a.attr('href')
			if(!href)
				$(this).css('cursor','default')
			else
				$(this).css('cursor','pointer')
	
			//alert(href)
			$(this).hover(function(){
				a.css('color','#ccc')
			},function(){
				a.css('color','#3D3E3C')
			})
			$(this).click(function(){
				if(href)
					window.location=href
				else
					return false
			})
		}
	})

	// image source
	$('#galleria .dettaglio').hide()
	var src = $('#galleria .dettaglio').attr('src')
	var img = new Image();
	$(img).load(function () {
		$(this).hide();
		$('#loader').removeClass('loading').append(this)
		$(this).fadeIn(1000)
		$('#galleria .prevImg, #galleria .nextImg').css({'top':($('#galleria #loader img').height())/2-34})
		$('#galleria .prevImg').css({'left':'11px'})
		$('#galleria .nextImg').css({'left':($('#galleria #loader img').width())-40})
	}).error(function () {
		// notify the user that the image could not be loaded
	}).attr('src', src)
	
	$('#galleria .prevImg, #galleria .nextImg').css({'opacity':0.5}).hover(function(){
		$(this).stop().animate({'opacity':0.8})
	},function(){
		$(this).stop().animate({'opacity':0.5})
	})

	function openBrochure(){
	}
	
	$('.evidenzaItem,.boxScuolaTeatroEvento').each(function(){
		var href = $(this).find('a').attr('href')
		$(this).hover(function(){
			$(this).css('cursor','pointer')
		})
		$(this).click(function(){
			location.href = href
		})
	})
})
