$(document).ready(function(){

	//Nascondo loading...
	$("#loading").hide();
	
	//Pulisco chace
	$.ajaxSetup({cache: false});
	
	//stampa pagina
    stampa_pagina();
	
	//Angolo
	applica_angoli();
	

	//Istruzioni del menu
	$("ul.sf-menu").superfish(); 

});


/// USATE PER MENU ATOMICO CATEGORIE//////////////////

ddaccordion.init({ //top level headers initialization
	headerclass: "expandable", //Shared CSS class name of headers group that are expandable
	contentclass: "categoryitems", //Shared CSS class name of contents group
	revealtype: "click", //Reveal content when user clicks or onmouseover the header? Valid value: "click", "clickgo", or "mouseover"
	mouseoverdelay: 200, //if revealtype="mouseover", set delay in milliseconds before header expands onMouseover
	collapseprev: true, //Collapse previous content (so only one open at any time)? true/false 
	defaultexpanded: [0], //index of content(s) open by default [index1, index2, etc]. [] denotes no content
	onemustopen: false, //Specify whether at least one header should be open always (so never all headers closed)
	animatedefault: false, //Should contents open by default be animated into view?
	persiststate: true, //persist state of opened contents within browser session?
	toggleclass: ["", "openheader"], //Two CSS classes to be applied to the header when it's collapsed and expanded, respectively ["class1", "class2"]
	togglehtml: ["prefix", "", ""], //Additional HTML added to the header when it's collapsed and expanded, respectively  ["position", "html1", "html2"] (see docs)
	animatespeed: "fast", //speed of animation: integer in milliseconds (ie: 200), or keywords "fast", "normal", or "slow"
	oninit:function(headers, expandedindices){ //custom code to run when headers have initalized
		//do nothing
	},
	onopenclose:function(header, index, state, isuseractivated){ //custom code to run whenever a header is opened or closed
		//do nothing
	}
})

ddaccordion.init({ //2nd level headers initialization
	headerclass: "subexpandable", //Shared CSS class name of sub headers group that are expandable
	contentclass: "subcategoryitems", //Shared CSS class name of sub contents group
	revealtype: "click", //Reveal content when user clicks or onmouseover the header? Valid value: "click" or "mouseover
	mouseoverdelay: 200, //if revealtype="mouseover", set delay in milliseconds before header expands onMouseover
	collapseprev: true, //Collapse previous content (so only one open at any time)? true/false 
	defaultexpanded: [], //index of content(s) open by default [index1, index2, etc]. [] denotes no content
	onemustopen: false, //Specify whether at least one header should be open always (so never all headers closed)
	animatedefault: false, //Should contents open by default be animated into view?
	persiststate: true, //persist state of opened contents within browser session?
	toggleclass: ["opensubheader", "closedsubheader"], //Two CSS classes to be applied to the header when it's collapsed and expanded, respectively ["class1", "class2"]
	togglehtml: ["none", "", ""], //Additional HTML added to the header when it's collapsed and expanded, respectively  ["position", "html1", "html2"] (see docs)
	animatespeed: "fast", //speed of animation: integer in milliseconds (ie: 200), or keywords "fast", "normal", or "slow"
	oninit:function(headers, expandedindices){ //custom code to run when headers have initalized
		//do nothing
	},
	onopenclose:function(header, index, state, isuseractivated){ //custom code to run whenever a header is opened or closed
		//do nothing
	}
})




/// USATE PER SHOWREEL IN HOME PAGE//////////////////

function slideSwitch() {
    var $active = $('.slideshow IMG.active');

    if ( $active.length == 0 ) $active = $('.slideshow IMG:last');

    // use this to pull the images in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : $('.slideshow IMG:first');

    // uncomment the 3 lines below to pull the images in random order
    
    // var $sibs  = $active.siblings();
    // var rndNum = Math.floor(Math.random() * $sibs.length );
    // var $next  = $( $sibs[ rndNum ] );


    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}
//////////////////////////////////////////////////////////















///QUICK/////////////////////////////////////////////////
// Seleziono le categoria del BRAND
function selbrand(brand_cercato) {

  $.get("/include/ajax_request/quick.php", { nome_brand: brand_cercato, requestItems: 'tipologia'}, 

	  function(datatipologia){

		$("select[id='tipologia']").empty();
		var options = '<option value="">-- Seleziona --</option>';
		var arraytipologia = datatipologia.split( '||');
		for (var i = 1; i < arraytipologia.length; i++) {
		  var tipologia = arraytipologia[i].split( /,/);
		  //gli passo sia id_cat che il nome del marchio come value
		  options += '<option value="' + tipologia[0] + "||" +tipologia[2]+ '">' + tipologia[1] + '</option>';
		}
		$("select[id='tipologia']").html(options);
	  });
}
//Seleziono i prodotti della categoria selezionata
function seltipologia(tipologia) {
	//devo ricordare di splittare il valore dato da id_cat e modulo

  $.get("/include/ajax_request/quick.php", { cat_mod: tipologia, requestItems: 'prodotto'}, 

	  function(dataprodotto){

		var options = '<option value="">-- Seleziona --</option>';
		var arrayprodotto = dataprodotto.split( '||');
		for (var i = 1; i < arrayprodotto.length; i++) {
		  var prodotto = arrayprodotto[i].split( /,/);
		  options += '<option value="' + prodotto[0] + '||'+ prodotto[2] + '">' + prodotto[1] + '</option>';
		}
		$("select[id='prodotto']").html(options);
	  });
}









/////////////////////////////////////////////////////////
function applica_angoli(){
	$(".angolo").corners("5px");
}


function stampa_pagina(){
    $(".stampa").click( function() {
    	$('#box_stampa').jqprint();
        return false;
    });
}
