
function initCategories(){
	$('#categories LI').prepend('<img class="subcat-toggle" src="images/cat-arrow-plus.gif"/>');	// qui dovrebbe prima controllare se c'è un sottomenu
	$('#categories LI UL LI IMG').remove();
	
	$('#categories LI UL').hide();
}

function adjustList() {
	max = 0;
	$('#prodotti .cat-list LI').each(function(){
		n = $(this).find('UL').size();
		if (n != 0) {
			h = $(this).height();
			if (h > max) max = h;
		}
	});
	
	$('#prodotti .cat-list LI').each(function(){
		n = $(this).find('UL').size();
		if (n != 0) $(this).height(max);
	});
}

function striped(sel) {
	i = 0;
	
	$(sel).each(function(){
		if (i) { 
			$(this).addClass('stripe'); 
			i = 0; 
		}
		else i = 1;
	});
}

$(document).ready(function(){
	
	initCategories();
	
	hidden = false;
	
	$('.btn-toggle').click(function(){
		if (!hidden) {
			$(this).find('IMG').attr('src','images/toggle-right.gif');
			$('#content').css('background','url(\'images/side-bg-small.gif\') repeat-y');
			$('#sidebar').css('margin-left','-260px');
			$('#main').css('margin-left','10px');
			hidden = true;
		}
		else {
			$(this).find('IMG').attr('src','images/toggle-left.gif');
			$('#content').css('background','url(\'images/side-bg.gif\') repeat-y');
			$('#sidebar').css('margin-left','0px');
			$('#main').css('margin-left','270px');
			hidden = false;
		}
	}); 
	
	$('.subcat-toggle').click(function(){
		if ($(this).parent().find('UL:hidden').size() != 0) {
			$(this).parent().find('UL:hidden').show();
			$(this).attr('src','images/cat-arrow-minus.gif');
		}
		else {
			$(this).parent().find('UL:visible').hide();
			$(this).attr('src','images/cat-arrow-plus.gif');
		}
	});
	
	adjustList();
		
	striped('TR');
	striped('#clienti LI');
	
});