/******************************************************************************************************************/
//	SEARCH
/******************************************************************************************************************/

function searchHandle(){
	$('#s').focus(function(){
		$(this).attr('value', '');
	});
}

/******************************************************************************************************************/
//	BRANDS NAV FX
/******************************************************************************************************************/

function brandsHandle(){
	$('#brands').append('<div class="cursor"><div class="arrow">+</div></div>');
	$('#brands .arrow').css('opacity','0');
	$('#brands .cloud').css('opacity','0.8');
	$('#brands .cloud').hide();
	
	// selected
	if ($('#brands .sel').size()) {
		var seloffset = $('#brands .sel A').offset();
		var selpos = seloffset.left + ($('#brands .sel A').width() / 2) - 10;
		$('#brands .arrow').stop().animate({ opacity: '1', left: selpos }, 300);
	}
	
	$('#brands .images A').hover(function(){
		var offset = $(this).offset();
		var pos = offset.left + ($(this).width() / 2) - 10;
		$('#brands .arrow').stop().animate({ opacity: '1', left: pos }, 300);
	}, function(){
		if ($('#brands .sel').size()) $('#brands .arrow').stop().animate({ left: selpos }, 500);
		else $('#brands .arrow').stop().animate({ opacity: '0' }, 500);
	});
	
	$('#brands .more').hover(function(){
		$('#brands .cloud').show(200);
	}, function(){
		$('#brands .cloud').hide(200);
	});
}

/******************************************************************************************************************/
//	LAST CARS FX
/******************************************************************************************************************/

function lastcarsHandle(){
	$('#lastcars .more').css('top','300px');
	$('#lastcars .more').css('opacity','0');
	$('#lastcars .more').hide();
	
	$('#lastcars LI').hover(function(){
		offset = $(this).offset();
		pos = offset.top - 28;
		$(this).find('.info A').css('background-position','0px -20px');
		$(this).find('.more').show();
		$(this).find('.more').animate({top: pos, opacity: '0.95'}, 300);
	}, function(){
		$(this).find('.info A').css('background-position','0px 0px');
		$(this).find('.more').animate({top: '300px', opacity: '0'}, 200);
		$(this).find('.more').hide();
	});
}

/******************************************************************************************************************/
//	SINGLE PHOTO
/******************************************************************************************************************/

function photoHandle(){
	$('#single .small A').hover(function(){
		$(this).fadeTo(300, 0.5);
	}, function(){
		$(this).fadeTo(300, 1);
	});
	
	$('#single .small A').click(function(){
		link = $(this).attr('href');
		$('#single .big IMG').attr('src', link);
		$('#single .big A').attr('href', link);
		
		return false;
	});
}

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

$(function(){
	searchHandle()
	brandsHandle();
	lastcarsHandle();
	photoHandle();
	
	$('.cloud A').removeAttr('style');
});