$( function(){
    /* MENU DROPDOWN SENZA HOVERINTENT */
	$( "#Category> ul> li"). mouseenter( function(){
		$( "ul", this).show(300);
		$( "ul> li> ul", this).hide(0);
	});
	$( "#Category> ul> li> ul"). mouseenter( function( event){
		event.stopPropagation();
		$( "#Category> ul> li> ul").stop(true,true).hide(0);
		$( this).show( 0);
	});
	$( "#Category> ul> li> ul> li"). mouseenter( function(){
		$( "ul", this).show(300);
		$( "ul> li> ul", this).hide(0);
	});
	$( "#Category> ul> li> ul> li> ul"). mouseenter( function( event){
		event.stopPropagation();
		$( "#Category> ul> li> ul> li> ul").stop(true,true).hide(0);
		$( this).show( 0);
	});
	$( "#Category> ul"). mouseleave( function(){
		$( "#Category> ul> li> ul").hide(300);
	});
	$( "#Category> ul> li"). mouseleave( function(){
		$( "#Category> ul> li> ul").hide(300);
	});
	$( "#Category> ul> li> ul"). mouseleave( function(){
		$( "#Category> ul> li> ul> li> ul").hide(300);
	});
	$( "#Category> ul> li> ul> li"). mouseleave( function(){
		$( "#Category> ul> li> ul> li> ul").hide(300);
	});
    /**/
    
    /* MENU DROPDOWN CON HOVERINTENT *\/
        var config = {    
             sensitivity: 3, // number = sensitivity threshold (must be 1 or higher)    
             interval: 200,  // number = milliseconds for onMouseOver polling interval    
             over: doOpen,   // function = onMouseOver callback (REQUIRED)    
             timeout: 300,   // number = milliseconds delay before onMouseOut    
             out: doClose    // function = onMouseOut callback (REQUIRED)    
        };
        
        function doOpen() {
            $(this).addClass("hover");
            $('ul:first',this).stop().slideDown('slow');
        }
     
        function doClose() {
            $(this).removeClass("hover");
            $('ul:first',this).stop().slideUp('fast');
        }

        $("#Category li").hoverIntent(config);
        $("#Category li ul li:has(ul)").find("a:first").append(" &raquo; ");
        $("#Category ul li:has(ul)").find("b:first").append(" &raquo;");
    /**/
    
    /* CAROUSEL e LIGHTBOX */
        $('#fileCarousel').jcarousel({
            visible: 4
        });
        $('#fileCarousel').yoxview({
            playDelay: 5000,
            infoBackOpacity: 0.8,
            infoBackColor: '#000000',
            titleAttribute: 'alt'
        });
    /**/
    
    
    /* TABS PER LE SCHEDE PRODOTTO, IMMAGINI E CORRELATI */
        if ($("#tabs-list").length > 0) {
            if ($("#schedaProdotto").html().length == 0) {
                $('.schedaProdotti').remove();
            }
            if ($("#immaginiProdotto").html().length == 0) {
                $('.immaginiProdotto').remove();
            }
            if ($("#articoliCorrelati").html().length == 0) {
                $('.articoliCorrelati').remove();
            }
            if ($("#tabs-list").children().length > 1) {
                $("#tabs").tabs();
            } else {
                $("#tabs-list").remove();
            }
        }
    /**/
    

	$( '#cartExp'). prev(). mouseenter( function(){ $( '#cartExp'). slideToggle();});
	$( '#cartExp'). prev(). click( function(){ $( '#cartExp'). slideToggle();});
	$( '#cartExp'). mouseleave( function(){ $( '#cartExp'). slideUp();});

	$( '#Marchio'). jScrollPane( { showArrows:true});


	$( '#SideBar> .center'). jScrollPane( { showArrows:true});
	$( '#SideBar2> .center'). jScrollPane( { showArrows:true});
	$( '#SideBarCenter> .center'). jScrollPane( { showArrows:true});


	$( '#alert'). slideDown( 'slow'). delay( 4000). slideUp( 'slow');
	
	$( '.no2'). click( function(){
		if( $( this). parent(). parent(). next(). nextUntil( '.odd'). length<  $( this). parent(). parent(). next(). nextUntil( '.even'). length){
			$( this). parent(). parent(). next(). nextUntil( '.odd'). slideToggle( 0);
		} else{
			$( this). parent(). parent(). next(). nextUntil( '.even'). slideToggle( 0);
		}
	});
	$( '.no0'). click( function(){
		if( close== true){
			if( $( this). nextUntil( '.odd'). length<  $( this). nextUntil( '.even'). length){
				$( this). nextUntil( '.odd'). slideUp( 0);
			} else{
				$( this). nextUntil( '.even'). slideUp( 0);
			}
		} else{
			if( $( this). nextUntil( '.odd'). length<  $( this). nextUntil( '.even'). length){
				$( this). nextUntil( '.odd'). slideToggle( 0);
			} else{
				$( this). nextUntil( '.even'). slideToggle( 0);
			}
		}
	});
/*	var close= false;
	$( '.white h3').each( function(){//chiude gli equivalenti se già mostrati
		close= true;//atomic force close
		$( this).parent().parent().parent().nextAll('.no0:contains('+ $( this).text()+ ')').click();
		temp= $( this).text();
		$( this).parent().parent().parent().nextAll('.white:contains('+ temp+ ')').each( function(){
			$( this).prevUntil( '.no0').prev().click();
		});
		close= false;
	});
*/
	$( '.no2').click();
	$( '.espandi'). click( function(){
		$( '.white'). slideDown( 0);
		$( '.white'). next(). slideDown( 0);
	});
	$( '.Comprimi'). click( function(){
		$( '.white'). slideUp( 0);
		$( '.white'). next(). slideUp( 0);
	});
	$( '#SelectPayment').change( function(){
		window.location.search= '?buy&modPag='+ $( '#SelectPayment option:selected').attr('value');
	});
});


/* DOPPI LINK */
function count(arrayObj){return arrayObj.length;}
function openPage(url) {
  var w = 800;
  var h = 500;
  var l = Math.floor((screen.width-w)/2);
  var t = Math.floor((screen.height-h)/2);
  var url_array = url.split(";");

  if (count(url_array) > 1) {
  	window.open(url_array[1],"","width=" + w + ",height=" + h + ",top=" + t + ",left=" + l);
  	window.location.href = url_array[0];
  } else {
  	window.location.href = url_array[0];
  }
}
/**/
