/******************************************************************************************************************/
//  CATEGORY HANDLE
/******************************************************************************************************************/

function categoryHandle(){
	// adjust titles
	max = 0;
	
	$('#category .items H1').each(function(){
		h = $(this).height();
		if (h > max) max = h;
	});
	
	$('#category .items H1').height(max);
	
	// over categories handle
	$('#categories .current-cat A:eq(0)').css('font-weight','bold');
	
	$('#categories LI UL').hide();
	
	$('#categories .current-cat').parents('UL').show();
	//$('#categories .current-cat').parents('UL').find('LI:eq(0)').addClass('open');
	$('#categories .current-cat').addClass('open');
	$('#categories .current-cat').find('UL').show();
	
	$('#categories LI').hover(function(){
		num = $(this).children().size();
		if (num > 1) {
			$(this).addClass('open');
			$(this).find('UL:eq(0)').stop().fadeIn(500);
		}
	}, function(){
		num = $(this).children().size();
		if (num > 1) {
			$(this).find('UL').hide();
			$(this).removeClass('open');
		}
		$('#categories .current-cat').parents('UL').show();
		//$('#categories .current-cat').parents('UL').find('LI:eq(0)').addClass('open');
		$('#categories .current-cat').addClass('open');
		$('#categories .current-cat').find('UL').show();
	});
}

/******************************************************************************************************************/
//  PRIMOPIANO TICKER FUNCTIONS
/******************************************************************************************************************/

function showItem(i){
	$('#primopiano LI').hide();
	$('#primopiano LI:eq('+ i +')').fadeIn(500);
	
	i++;
	if (i >= num) i = 0;
	
	timerId = window.setTimeout('showItem('+ i +')', 3500);
}

function tickerHandle(){
	$('#primopiano LI A').append('<div class="frame"></div>');
	
	num = $('#primopiano LI').size();
	
	if (num > 1) {
		showItem(0);
		
		$('#primopiano LI').hover(function(){
			clearTimeout(timerId);
			index = $('#primopiano LI').index(this);
		}, function(){
			timerId = window.setTimeout('showItem('+ index +')', 0);
		});
	}
}

/******************************************************************************************************************/
// On document load...
/******************************************************************************************************************/

$(function(){
	// search focus
	$('.search .txt-input').focus(function(){ $(this).attr('value',''); });
	
	// primopiano ticker
	tickerHandle();
	
	// category handle
	categoryHandle();
	
	// over items photos handle
	$('.photo, .gal A').hover(function(){
		$(this).find('IMG').fadeTo(500, 0.7);
	}, function(){
		$(this).find('IMG').fadeTo(500, 1);
	});
});
