function changeSizeById( id, size, size1, size2){
	if( size!= 0){
		document.getElementById( id).style.width= size1;
		document.getElementById( id).style.height= size2;
		document.getElementById( id).style.paddingLeft= 0;
		document.getElementById( id).style.paddingTop= 0;
		document.getElementById( id+ "b").style.background= "transparent";
		document.getElementById( id+ "b").style.height= "auto";
	} else{
		document.getElementById( id).style.width= size1;
		document.getElementById( id).style.height= size2;
		document.getElementById( id).style.paddingLeft= '10em';
		document.getElementById( id).style.paddingTop= '12em';
		document.getElementById( id+ "b").style.background= "#f49b01";
		document.getElementById( id+ "b").style.height= ( ( parseInt( size2)/ 12.8)+ 20)+ "em";
		//window. location . hash= id;
}	}

function openCloseComment( id){
	if( $( "#comment"+ id). css( "display")== "block"){
		$( "#comment"+ id). hide( "slow");
	} else{
		$( "#comment"+ id). show( "slow");
}	}

String.prototype.get = function(p){
	return (match = this.match(new RegExp("[?|&]?" + p + "=([^&]*)"))) ? match[1] : false;
}

function openMenu( el){
	if( $( el). parent(). children( ":nth-child(2)"). css( "display")== "none"){
		$( el). parent(). children( ":nth-child(2)"). show( "slow");
	} else{
		$( el). parent(). children( ":nth-child(2)"). hide( "slow");
	}
}

function loader(){
	$( "#loader"). css( "top", $( window). scrollTop()+ "px");
	$( "#loader"). css( "left", $( window). scrollLeft()+ "px");
	$( "#loader"). fadeTo( 0, 0.75);
}


$( function(){
	$( ".avanzate"). click( function(){
		if( $( ".browse"). css( "display")== "block"){
			$( ".browse"). slideUp( "slow");
		} else{
			$( ".browse"). slideDown( "slow");
		}
	});

	$( "#comment"+ window. location . hash. replace( '#a', '')). slideDown( "slow");

	$( ".comments span"). click( function(){
		if( $( this). parent(). parent(). children( ":nth-child(2)"). css( "display")== "block"){
			$( this). parent(). parent(). children( ":nth-child(2)"). slideUp( "slow");
		} else{
			$( this). parent(). parent(). children( ":nth-child(2)"). slideDown( "slow");
		}
	});

	$( ".catMenu"). click( function(){
		openMenu( this);
		return false;
	});
	$( ".catMenu"). parent(). children( ":nth-child(2)"). css( "display", "none");

	$( ".cat"). click( function(){
		temp= $( this). parent(). attr( "id");
		if( temp== "") temp= $( this). parent(). parent(). attr( "id");
		if( $( "#sub"+ temp). css( "display")== "none"){
			$( "#sub"+ temp). show( "slow");
			$( this). text( "[-]");
			return false;
		} else if( $( "#sub"+ temp). css( "display")== "block"){
			$( "#sub"+ temp). hide( "slow");
			$( this). text( "[+]");
			return false;
		} else{
			return true;
		}
	});

	var open= window. location. search. get( "c");
	if( open!= ""){
		while( open!= ""){
			$( "#cat"+ open+ "> .cat"). click();
			if( $( "#cat"+ open+ " .cat"). text()== "") $( "#cat"+ open). children( ":nth-child(1)"). wrap( "<b></b>");
			else $( "#cat"+ open). children( ":nth-child(2)"). wrap( "<b></b>");
			open= $( "#cat"+ open). parent(). attr( "id"). replace( "subcat", "");
		}
	}
	open= window. location. search. get( "Produttore");
	if( open!= ""){
		$( ".leftmenu a[href~=\"?Produttore="+ open+ "\"]"). wrap( "<b></b>");
		$( ".leftmenu a[href~=\"?Produttore="+ open+ "\"]"). parent(). parent(). parent(). parent(). children( "a"). click();
		$( ".leftmenu a[href~=\"?Produttore="+ open+ "\"]"). parent(). parent(). parent(). parent(). parent(). parent(). children( "a"). click();
	}
	open= window. location. search. get( "Promozioni");
	if( open!= ""){
		$( ".leftmenu a[href~=\"?Promozioni="+ open+ "\"]"). wrap( "<b></b>");
		$( ".leftmenu a[href~=\"?Promozioni="+ open+ "\"]"). parent(). parent(). parent(). parent(). children( "a"). click();
		$( ".leftmenu a[href~=\"?Promozioni="+ open+ "\"]"). parent(). parent(). parent(). parent(). parent(). parent(). children( "a"). click();
	}

	window. onbeforeunload= function(){
		loader();
	};
	$( window). unload( function(){
		loader();
	});
	$( ".pagesel a"). click( function(){
		loader();
	});
	$( ".minibrowse a"). click( function(){
		loader();
	});
	$( ".topbutton1"). click( function(){
		loader();
	});
	i= 0;
	countImg= $( '.cycle img').length;
	$( '.cycle img').load( function(){
		++ i;
		$( this).removeAttr("width").removeAttr("height").css({ width: "", height: "" });
		if( $( this).css( 'width')< $( this).css( 'height')) $( this).css( 'height', '200px');
		else $( this).css( 'width', '200px');
		$( this).css( 'left', ( 100- $( this).width()/ 2)+ 'px');
		$( this).css( 'top', ( 100- $( this).height()/ 2)+ 'px');
		if( i== countImg){
			setTimeout( "$( '.centerminiel1 .cycle').cycle( { fx: 'scrollLeft'})", 1000);
			setTimeout( "$( '.centerminiel2 .cycle').cycle( { fx: 'fade'})", 1000);
			setTimeout( "$( '.centerminiel3 .cycle').cycle( { fx: 'scrollUp'})", 1000);
			setTimeout( "$( '.centerminiel4 .cycle').cycle( { fx: 'zoom'})", 1000);
		}
	});
});
