jQuery(function($){
	
	 $("#mycarousel").jcarousel({
        scroll: 1,
        auto: 6,
        wrap:"both",
        buttonNextHTML: null,
        buttonPrevHTML: null
    });	
	
	$('.dd').slideDown('slow',function(){
		$('.dd-content').fadeIn();
	});
	
	$('.dd-content a').address(function() {  
	    return $(this).attr('href').replace($.address.baseURL(), '');
	});  
	
	$('.dd > .dd-content > ul > li > a').live('click', function(){
		//Animation in progress?
		if ($('.dd ul li').find('ul:animated').length > 0) {
			return false;
		}
		
		//Clicking on current opened item?
		if ($(this).parents('li').find('ul:eq(0)').is(':visible')) {
			$('.dd ul li').find('ul').slideUp();
			return false;
		}
		
		if (!$(this).hasClass('more-brands')) {		
			var id = $(this).parent().attr('class').replace(/[a-z\s-]+/g, '');
			$('#brands-content .subcategory').stop().fadeTo(product_anim_speed, 0, function() {
				$(this).css('display', 'none');
			});
			$('#cat-item-' + id).css({'display': 'block', 'opacity': 0}).stop().fadeTo(product_anim_speed, 1);
		}
		
		$('.dd ul li').find('ul').slideUp();
		var sub_list = $(this).parents('li').find('ul:eq(0)');
		if(sub_list){
			sub_list.slideDown();
		}
		return false;
	});
	
	var product_anim_speed = 700;
	
	$('.dd ul li li a').live('click', function(){
		if (!$(this).hasClass('next-brands') && !$(this).hasClass('previous-brands')) {		
			var id = $(this).parent().attr('class').replace(/[a-z\s-]+/g, '');
			/*
			if ($('#brands-content img:visible').attr('src') == $('#cat-item-' + id).find('.brands-img img').attr('src')) {
				return false;
			}
			*/
			$('#brands-content .subcategory').stop().fadeTo(product_anim_speed, 0, function() {
				$(this).css('display', 'none');
			});
			$('#cat-item-' + id).css({'display': 'block', 'opacity': 0}).stop().fadeTo(product_anim_speed, 1);
			return false;
		}
	});
	
	$('input.blink').focus(function(){
		if($(this).val() == $(this).attr('title')){
			$(this).val('');
		}
	});
	
	$('input.blink').blur(function(){
		if($(this).val() == ''){
			$(this).val($(this).attr('title'));
		}
	});
	
	if($.browser.msie && $.browser.version==6) {
		$('.dd').css('background', 'transparent');
	}
	
	$('#navigation > ul > li:last').addClass('last');
	
	function equalize_height(collection) {
		var h = 0;
		$(collection).each(function() {
			if($(this).height() > h)  {
				h = $(this).height();
			}
		});
		$(collection).each(function() {
			$(this).height(h);
		});
	}
	
	equalize_height('.main-image-container, .default-content');
	
	$('.previous-brands').live('click', function() {
		var ul = $(this).closest('ul.children');
		ul.hide();
		ul.prev().show();
		return false;
	});
	
	$('.next-brands').live('click', function() {
		var ul = $(this).closest('ul.children');
		ul.hide();
		ul.next().show();
		return false;
	});

	if (window.location.hash) {
		var href = $.address.baseURL() + window.location.hash.replace('#', '');
		var link = $('a[href=' + href + ']');
		link.click();
		
		if (link.parents('.children').length) {
			link.parents('.children:eq(0)').show();
		}

	}

	
});
