$(document).ready(function() {
	
	//DN: accordion menu
	//add .acc_header class to only the top level "li a" - not "li li a". 
	//I'm doing it here because it's not easy in the template/php.
	$('#accordion li a').addClass('acc_header'); 	//add the class to the top level UL
	$('#accordion li li a').removeClass('acc_header'); //remove from the lower-level ULs
	$('#accordion').accordion({navigation: true, autoheight: false, event: 'mouseover', header: '.acc_header' });

	//DN: carousel
	$('#FeaturedProductsCarousel').jCarouselLite({
        btnNext: "#FeaturedProductsNext",
        btnPrev: "#FeaturedProductsPrev",
		visible: 1,
		auto: 3500
    });

	$('#XmasGiftsCarousel').jCarouselLite({
        btnNext: "#XmasGiftsNext",
        btnPrev: "#XmasGiftsPrev",
		visible: 1,
		auto: 3500
    });


	
	function PositionFooter() {
		$('#FooterImg').show();
		if($(window).height() - ($('#Container').height() + $('#FooterImg').height()) >= 0) {
			$('#FooterImg').css({position: 'relative', top: ($(window).height() - ($('#Container').height() + $('#FooterImg').height())-20)});
		}
		else {
			$('#FooterImg').css({position: 'static'});
		}
		
	}
	$(window).resize(function() {
		PositionFooter();
	});
	
	PositionFooter();

	var maxHeight = 0;
	$('.Content .ProductList li').each(function() {
			if($(this).height() > maxHeight) {
				maxHeight = $(this).height();
			}
	});
	$('.Content .ProductList li').css('height', maxHeight);
	
	if(document.all) {
		$('.CategoryList ul > li').hover(function(event) {
			$(this).addClass('Over');
			event.preventDefault();
			event.stopPropagation();
		}, function(event) {
			if(event.target == this) {
				$(this).removeClass('Over');
			}
			event.preventDefault();
			event.stopPropagation();
		});
	}
	
	$('body').append('<div id="TopSellerHover" style="display: none"></div>');
	var hoverOut = null;
	$('.TopSellers li .TinyThumb').hover(function(event) {
		if($('body').data('activeTopSeller') == this) {
			return false;
		}
		window.clearTimeout(hoverOut);
		$('#TopSellerHover').html($(this).parent().find('.HoverDetails').html());
		$('body').data('activeTopSeller', this);
		var position = $(this).position();
		if($.browser.msie && $.browser.version == '6.0') {
			$('#TopSellerHover').css({position: 'absolute', left: (position.left-180)+'px', top: (position.top+40)+'px'});
		}
		else {
			$('#TopSellerHover').css({position: 'absolute', left: (position.left-130)+'px', top: (position.top+70)+'px'});
		}
		$('#TopSellerHover').fadeIn();
		
		$('#TopSellerHover').hover(function(event) {
			$('body').data('activeSellerOver', 1);
		}, function() {
			$('body').data('activeSellerOver', 0);
		});
	}, function(event) {
		hoverOut = window.setTimeout(function() {
			$('body').data('activeSellerOver', 0);
			$('body').data('activeTopSeller', null);
			$('#TopSellerHover').fadeOut();
			window.clearTimeout(hoverOut);
		}, 800);
	});	
	
	
});
