var $j = jQuery.noConflict();
var intervalCount = 9000;
var myInterval = '';
var scrollNum = 1;

$j(document).ready(function () {
	myInterval = window.setInterval(autoScroll,intervalCount);
	$j("#submit_email_list").click(function () {
		if($j("#email_list_email").val() != "") {
			$j.ajax({
				type: "POST",
				url: "/send_email_list.php",
				data: "email="+$j("#email_list_email").val(),
				success: function(msg){
					//alert(msg);
					$j("#email_list_email").val("");
					alert("Your email has been added to our list. Thank you.");
				}
			});
		} else {
			alert("Please enter in your email address.");
		}
		return false;
	});
	$j('.inner_menu_container ul li').mouseenter(function () {
		$j(this).find('ul').fadeIn("fast");
	});
	$j('.inner_menu_container ul li').mouseleave(function () {
		$j(this).find('ul').fadeOut("fast");
	});
	$j('#shipping_same').click(function () {
		if($j(this).attr("checked") == true) {
			$j('#shipping_street_addr').val($j('#street_addr').val());
			$j('#shipping_street_addr2').val($j('#street_addr2').val());
			$j("#shipping_state_province option[value='"+$j('#state_province option:selected').val()+"']").attr("selected", "selected");
			$j('#shipping_zip_postal').val($j('#zip_postal').val());
			$j("#shipping_country option[value='"+$j('#country option:selected').val()+"']").attr("selected", "selected");
		} else {
			$j('#shipping_street_addr').val("");
			$j('#shipping_street_addr2').val("");
			$j("#shipping_state_province option").attr("selected", "");
			$j('#shipping_zip_postal').val("");
			$j("#shipping_country option").attr("selected", "");
		}
	});
	$j('.scroll_right').click(function () {
		clearInterval(myInterval);
		if($j('.image_scroller_true:animated ').size() < 1) {
			var oldMargin = parseInt($j('.image_scroller_true').css("margin-left"));
			var newMargin = oldMargin - 960;
			
			if(newMargin > -4800) {
				scrollNum++;
				$j('.scroll_num div').css("background", "none");
				$j('#scroll_num_'+scrollNum+" div").css("background", "#CCCCCC");
				
				$j('.image_scroller_true').animate({ 
					marginLeft: newMargin+"px"
				}, "normal");
			 } else {
				scrollNum = 1;
				$j('.scroll_num div').css("background", "none");
				$j('#scroll_num_'+scrollNum+" div").css("background", "#CCCCCC");
				
				$j('.image_scroller_true').animate({ 
					marginLeft: newMargin+"px"
				}, "normal", resetScroller);
			 }
	    }
	    
		return false;
	});
	$j('.scroll_left').click(function () {
		clearInterval(myInterval);
		if($j('.image_scroller_true:animated ').size() < 1) {
			var oldMargin = parseInt($j('.image_scroller_true').css("margin-left"));
			var newMargin = oldMargin + 960;
			
			if(newMargin <= 0) {
				scrollNum--;
				$j('.scroll_num div').css("background", "none");
				$j('#scroll_num_'+scrollNum+" div").css("background", "#CCCCCC");
				
				$j('.image_scroller_true').animate({ 
					marginLeft: newMargin+"px"
				}, "normal");
			 } else {
			 	$j('.image_scroller_true').css("margin-left", "-4800px");
			 	scrollNum = 5;
				$j('.scroll_num div').css("background", "none");
				$j('#scroll_num_'+scrollNum+" div").css("background", "#CCCCCC");
			 	newMargin = -3840;
			 	
			 	$j('.image_scroller_true').animate({ 
					marginLeft: newMargin+"px"
				}, "normal");
			 }
	    }
		
		return false;
	});
	$j('.scroll_num').click(function  () {
		var num = parseInt($j(this).attr("id").replace("scroll_num_", ""));
		var newMargin = ((num * 960)-960)*-1;
		scrollNum = num;
		
		$j('.scroll_num div').css("background", "none");
		$j('#scroll_num_'+scrollNum+" div").css("background", "#CCCCCC");
		
		$j('.image_scroller_true').animate({ 
			marginLeft: newMargin+"px"
		}, "normal");
		
		return false;
	});
	$j('#autoship_qty_0').keyup(function () {
		var total = formatAsMoney(((parseInt($j(this).val()) * parseInt($j('#autoship_price_0').val())) * 1.03));
		if(total < 0) {
			total = "";
		}
		$j('#autoship_total_0').val(total);
		
		var atotal = 0;
		var btotal = 0;
		var ctotal = 0;
		
		if(parseFloat($j('#autoship_total_0').val()) > 0) {
			atotal = parseFloat($j('#autoship_total_0').val());
		}
		if(parseFloat($j('#autoship_total_1').val()) > 0) {
			btotal = parseFloat($j('#autoship_total_1').val());
		}
		if(parseFloat($j('#autoship_total_2').val()) > 0) {
			ctotal = parseFloat($j('#autoship_total_2').val());
		}
		
		var grandTotal = atotal+btotal+ctotal;
		
		$j('#grandtotal').val(formatAsMoney(grandTotal));
	});
	$j('#autoship_qty_1').keyup(function () {
		var total = formatAsMoney(((parseInt($j(this).val()) * parseInt($j('#autoship_price_1').val())) * 1.03));
		if(total < 0) {
			total = "";
		}
		$j('#autoship_total_1').val(total);
		
		var atotal = 0;
		var btotal = 0;
		var ctotal = 0;
		
		if(parseFloat($j('#autoship_total_0').val()) > 0) {
			atotal = parseFloat($j('#autoship_total_0').val());
		}
		if(parseFloat($j('#autoship_total_1').val()) > 0) {
			btotal = parseFloat($j('#autoship_total_1').val());
		}
		if(parseFloat($j('#autoship_total_2').val()) > 0) {
			ctotal = parseFloat($j('#autoship_total_2').val());
		}
		
		var grandTotal = atotal+btotal+ctotal;
		
		$j('#grandtotal').val(formatAsMoney(grandTotal));
	});
	$j('#autoship_qty_2').keyup(function () {
		var total = formatAsMoney(((parseInt($j(this).val()) * parseInt($j('#autoship_price_2').val())) * 1.03));
		if(total < 0) {
			total = "";
		}
		$j('#autoship_total_2').val(total);
		
		var atotal = 0;
		var btotal = 0;
		var ctotal = 0;
		
		if(parseFloat($j('#autoship_total_0').val()) > 0) {
			atotal = parseFloat($j('#autoship_total_0').val());
		}
		if(parseFloat($j('#autoship_total_1').val()) > 0) {
			btotal = parseFloat($j('#autoship_total_1').val());
		}
		if(parseFloat($j('#autoship_total_2').val()) > 0) {
			ctotal = parseFloat($j('#autoship_total_2').val());
		}
		
		var grandTotal = atotal+btotal+ctotal;
		
		$j('#grandtotal').val(formatAsMoney(grandTotal));
	});
});
function autoScroll() {
	if($j('.image_scroller_true:animated ').size() < 1) {
		var oldMargin = parseInt($j('.image_scroller_true').css("margin-left"));
		var newMargin = oldMargin - 960;
		
		if(newMargin > -4800) {
			scrollNum++;
			$j('.scroll_num div').css("background", "none");
			$j('#scroll_num_'+scrollNum+" div").css("background", "#CCCCCC");
			
			$j('.image_scroller_true').animate({ 
				marginLeft: newMargin+"px"
			}, "normal");
		 } else {
			scrollNum = 1;
			$j('.scroll_num div').css("background", "none");
			$j('#scroll_num_'+scrollNum+" div").css("background", "#CCCCCC");
			
			$j('.image_scroller_true').animate({ 
				marginLeft: newMargin+"px"
			}, "normal", resetScroller);
		 }
    }
}
function resetScroller() {
	scrollNum = 1;
	$j('.scroll_num div').css("background", "none");
	$j('#scroll_num_'+scrollNum+" div").css("background", "#CCCCCC");
	
	$j('.image_scroller_true').css("margin-left", "0px");
}

function formatAsMoney(mnt) {
    mnt -= 0;
    mnt = (Math.round(mnt*100))/100;
    return (mnt == Math.floor(mnt)) ? mnt + '.00' 
              : ( (mnt*10 == Math.floor(mnt*10)) ? 
                       mnt + '0' : mnt);
}