$(window).load(function () {
	
	$(".scrollable").scrollable({ speed:500 }).navigator({
		// select #flowtabs to be used as navigator
		navi: "#scrollTab",
		// select A tags inside the navigator to work as items (not direct children)
		naviItem: 'a',
		// assign "current" class name for the active A tag inside navigator
		activeClass: 'active',
		// make browser's back button work
		history: false
	});

	$("#scrollTab a").bind("click", function(event) {
		$("#homevideo").attr({src: ''});
	});

	$('.faqStyleList li > a').click(function() {
		var actualID = $(this).attr('id');
		$(this).toggleClass('active').next('div').slideToggle();
		$('.faqStyleList li > a').each(function(i) {
			i++;
			if( actualID != "faq"+i ) $(this).removeClass('active').next('div').slideUp();
		});
	});

	$('.addTxt').toggle(function() {
		$(this).html('&raquo; chiudi').prev('div').slideToggle(); },
		function() {
		$(this).html('&raquo; mostra le caratteristiche').prev('div').slideToggle();
	});
	
	$('.addTxtTitle').toggle(function() {
		$(this).parent().parent().children('a.addTxt').html('&raquo; chiudi').prev('div').slideToggle(); },
		function() {
		$(this).parent().parent().children('a.addTxt').html('&raquo; mostra le caratteristiche').prev('div').slideToggle();
	});
	
	$('#menuProdotti.outer a').click(function(event) {
		$(this).parent().parent().children('ul').slideToggle();	  
		var thisUl = $(this).html();
		var thisUlClass = $(this).parent().parent().attr('class');
		$('#menuProdotti.outer a').each(function()  {
			if( $(this).html() != thisUl && $(this).parent().parent().attr('class') == thisUlClass) $(this).parent().parent().children('ul').slideUp();	
		});
	});
	
	$('#menuProdotti ul.inner a').click(function(event) {
		$(this).next('ul').slideToggle();	
		var thisUl = $(this).html();
		var thisUlClass = $(this).parent().attr('class');
		$('#menuProdotti ul.inner a').each(function()  {
			if( $(this).html() != thisUl && $(this).parent().attr('class') == thisUlClass) $(this).next('ul').slideUp();	
		});
		// foglia, carica ajax
		if($(this).parent().parent().children("ul.inner").size() == 0) {
			$('#grigliaprodotti').showLoading();
			$('#menuProdotti li').removeClass("active");
			$(this).parent().parent().addClass("active");
			$('#grigliaprodotti').load('index.php?id=1585&prodid=' + $(this).attr('id').substring(2), function() {
				$('.addTxt').toggle(function() {
					$(this).html('&raquo; chiudi').prev('div').slideToggle(); },
					function() {
					$(this).html('&raquo; mostra le caratteristiche').prev('div').slideToggle();
				});
				$('#grigliaprodotti').hideLoading();
			});
		}
	});

	$('#menuProdotti li.active').each(function() {
		$(this).parents('ul').addClass('active');
	});

	$("a[rel^='prettyPhoto']").prettyPhoto({social_tools:'', slideshow:3000, overlay_gallery:false});

	$('#loaderon').click(function(event) {
		event.preventDefault();
		$('#grigliaprodotti').showLoading();
	});

	$('#loaderoff').click(function(event) {
		event.preventDefault();
		$('#grigliaprodotti').hideLoading();
	});
});
