var shoppingCartContents;
var carouselSelection = 0;
$(document).ready( function() {

	var currentCarouselId = $.cookie('carouselView');
	
	// initialize carousels
	var cRecentlyViewed = $('#recentlyViewed');
	var cShoppingCart = $('#shoppingCart');
	var l = cRecentlyViewed.css('left');
	
	cRecentlyViewed.css('left', '-300px');
	$('#recentlyViewedCarousel').jcarousel();
	cRecentlyViewed.hide();
	cRecentlyViewed.css('left',l);
	
	cShoppingCart.css('left', '-300px');
	$('#shoppingCartCarousel').jcarousel();
	cShoppingCart.hide();
	cShoppingCart.css('left',l);
	
	
	if(currentCarouselId == '1') {
		cShoppingCart.show();
		$('#lnkCarouselSelector').html('Shopping Cart');
		carouselSelection = 1;
	} else {
		cRecentlyViewed.show();
		$('#lnkCarouselSelector').html('Recently Viewed');
		carouselSelection = 0;
	}

	$('#lblCarouselSelector').click( function() { 
		return false; 
	});
	$('#lblCarouselSelector').mouseover( function() {
		$('#lstCarouselSelector').show();
		$('#lblCarouselSelector img').attr('src', 'images/site/arrow-down.gif');
	});
	$('#lblCarouselSelector').mouseout( function() {
		$('#lstCarouselSelector').hide();
		$('#lblCarouselSelector img').attr('src', 'images/site/arrow.gif');
	});
	$('#lblRecentlyViewed').click( function() {
		showRecentlyViewed();
	});
	$('#lblShoppingCart').click( function() {
		showShoppingCart();
	});
	
});

function showRecentlyViewed() {
	if( $('#shoppingCart') == null) return;
	
	$('#shoppingCart').hide(); 
	$('#recentlyViewed').fadeIn('slow'); 
	$('#lnkCarouselSelector').html('Recently Viewed');
	$('#lstCarouselSelector').hide();
	$.cookie('carouselView', '0');
}
function showShoppingCart() {
 	if( $('#shoppingCart') == null) return;
	
	$('#recentlyViewed').hide(); 
	$('#shoppingCart').fadeIn('slow'); 
	$('#lnkCarouselSelector').html('Shopping Cart');
	$('#lstCarouselSelector').hide();
	$.cookie('carouselView', '1');
}
