
var carouselRotatorInterval = 5000;
var liBanners = 0, visibleBanner = 0, carouselTimeout;

jQuery.noConflict();

jQuery(function () {	
	
	if (jQuery("#login-box #username").html() == null || jQuery("#login-box #username").html() == "")
		jQuery("#login-box").html('\
			<ul>\
				<li><a href="/login">Login</a></li>\
				<li><a href="/login#signup">Sign Up</a></li>\
			</ul>');
	

	jQuery('#home-banners').append('<div id="home-banners-nav"></div>'); 
	jQuery('#home-banners li').each(function(index) {
		jQuery(document.createElement('a'))
		.attr("href", "#").html(index+1)
		.appendTo('#home-banners-nav')
		.click(function() {
				showBanner(index);
				return false;
			});
		liBanners++;
	});
	jQuery("#home-banners-nav a").eq(0).addClass("selected");

	carouselTimeout = setTimeout("rotateBanner()", carouselRotatorInterval);

	
	jQuery('#home-photogallery img').each(function(index) {
		if (index < 3)
			jQuery(this).addClass("photoImg").appendTo('#home-photogallery');
	});
	jQuery('#home-photogallery img.photoImg').wrap('<a class="photoLink" href="/photo-gallery"></a>');
	
	jQuery("tr:odd").addClass("odd"); 

	jQuery('.catProdAttributeItem input').change(function() {
		calcTotalPrice();
	});
	calcTotalPrice();
	
	jQuery('.quantity input.productTextInput').val(1);
	
	jQuery('#EmailAddress').blur(function() {
		jQuery('#Username, #Password, #PasswordConfirm').val(jQuery('#EmailAddress').val());
	});
	jQuery('#EmailAddress').val('');
	
});

function calcTotalPrice()
{
	var numChecked = 0;
	jQuery('.catProdAttributeItem input').each(function() {
		if (jQuery(this).attr('checked')) numChecked++;
	});
	if (numChecked < 2)
	{
		jQuery('span.elementprice').css('display','inline');
		jQuery('span.totalprice').css('display','none');
	} else {
		jQuery('span.elementprice').css('display','none');
		jQuery('span.totalprice').css('display','inline').html('$' + numChecked *(parseFloat(removedollar(jQuery('span.elementprice').html())) - 10)); 
	}
	jQuery('input.productTextInput').val(numChecked);
}

function removedollar(str)
{
	re = /^\$|,/g;
	return str.replace(re, "");
}

function checkCheckBox(inputId)
{
	jQuery('#catProdAttributes2_884770 .catProdAttributeItem input').attr('checked', false);
	jQuery('#'+inputId).attr('checked', true);
}

function showBanner(index)
{
	if ((index < 0) || (index > (liBanners - 1))) return false;

	visibleBanner = index;
	var newUlTop = visibleBanner*400;
	
	clearTimeout(carouselTimeout);
	jQuery('#home-banners ul').animate({top: "-" + newUlTop + "px"}, 500, function() {
		carouselTimeout = setTimeout("rotateBanner()", carouselRotatorInterval);
	});
	
	jQuery("#home-banners-nav a").removeClass("selected");
	jQuery("#home-banners-nav a").eq(index).addClass("selected");
	
}

function rotateBanner() {
	var showBannerIndex = visibleBanner + 1;
	if ((showBannerIndex < 0) || (showBannerIndex > (liBanners - 1))) showBannerIndex = 0;
	showBanner(showBannerIndex);
}









