$(document).ready(function(){
	
	$.load = function() {
		$("ul#browseTab li:first").addClass("active");
		$.loadShoppingPageBrowsed();
	}
	
	/**
	 * Used to changed the last Shopping page Browsed in the profile.
	 */
	$.loadShoppingPageBrowsed = function(){
		$.ajax({ url: "/browse/contents/submitShoppingPageBrowsed.jsp", data: ({shoppingPageBrowsed: document.URL.split('#')[0] + parent.location.hash})});
	}
	
	/**
	 * "ul#browseTab li - event Click
	 */
	$("ul#browseTab li").click(function() {
		$("ul#browseTab li").removeClass("active");
		$(this).addClass("active");
	});

	/**
	 * QuickSearch
	 */
	$('input#brandSearchInput').quicksearch('ul#brandList li',{
		attached: 'div.brandSearch',
		position: 'after',
		noResults: 'li.noResult',
		labelText: '',
		inputText: $('div#brandAZ').attr("startText"),
		loaderText: '',
		onAfter:function() {
			// Set scroll Top to 0px;
			$("div#brandCont").scrollTop("0px");
		}
	});
	
	$("div#brandCont, #topSlider, #bottomSlider").mouseenter(function(){
		$("#topSlider").addClass("over");
		$("#bottomSlider").addClass("over");
	});
	
	$("div#brandCont, #topSlider, #bottomSlider").mouseleave(function(){
		$("#topSlider").removeClass("over");
		$("#bottomSlider").removeClass("over");
	});
	
	/**
	 * Handle the brand search, when the result is found, and hitting enter
	 */
	$('#brandSearchInput').keyup(function(e){
		var keyCode = e.keyCode ? e.keyCode : e.which ? e.which : e.charCode;
		if (keyCode == 13) {			
			var elem = $('#brandList li:visible > a');
			if ((elem.length == 1) && elem.attr('href')){
				document.location = elem.attr('href');
			}
		}
	});
	
	/**
	 * Handle the brand search, when the result is found, and clicking the arrow
	 */
	$('#brandAZ .buttonBlue').click(function(){
		var elem = $('#brandList li:visible > a');
		if ((elem.length == 1) && elem.attr('href')){
			document.location = elem.attr('href');
		}
	});
	
	$.load();
	
});

