$(document).ready(function() {
	// Tabs Setup Code \\
	if ($("div#body_tabs").size()) {
		var tabContainers = $('div#body_tabs > div');
		tabContainers.hide().filter(':first').show();
		$('div#body_tabs ul.tab_nav a').click(function () {
			tabContainers.hide();
			tabContainers.filter(this.hash).show();
			$('div#body_tabs ul.tab_nav a').removeClass('selected');
			$(this).addClass('selected');
			return false;
		}).filter(':first').click();
	};
	
	// Overlay Elements \\
	if ($("#flash_overlay a[rel]").size()) { var player = $f("player", "includes/flowplayer-3.1.5.swf"); $("#flash_overlay a[rel]").overlay({ effect: 'apple',	expose: '#000000', onLoad: function() { player.load(); }, onClose: function() { player.unload(); } }); };
	if ($("a.triggers").size()) { $("a.triggers").overlay({ target: '#gallery', expose: '#000000' }).gallery({ speed: 800 }); };
	
	// Script for handling the search and join text boxes \\
	$("input#search_box").bind("focus", function(e){ if ($("input#search_box").val() == "search") { $("input#search_box").val(""); } });
	$("input#search_box").bind("blur", function(e){ if ($("input#search_box").val() == "") { $("input#search_box").val("search"); } });
	$("input#join_box").bind("focus", function(e){ if ($("input#join_box").val() == "Join our e-mail list") { $("input#join_box").val(""); } });
	$("input#join_box").bind("blur", function(e){ if ($("input#join_box").val() == "") { $("input#join_box").val("Join our e-mail list"); } });
	
	// Mouseovers \\
	$("div#cart_menu").bind("mouseenter", function(e){ $(this).css("background","url(images/icon_cart_on.jpg) no-repeat right"); });
	$("div#cart_menu").bind("mouseleave", function(e){ $(this).css("background","url(images/icon_cart_off.jpg) no-repeat right"); });
	$("img#enlarge_img").bind("mouseenter", function(e){ var on = $(this).attr("src").replace(/_off.png$/gi,"_on.png"); $(this).attr("src",on); });
	$("img#enlarge_img").bind("mouseleave", function(e){ var off = $(this).attr("src").replace(/_on.png$/gi,"_off.png"); $(this).attr("src",off); });
	$("input#add_to_cart").bind("mouseenter", function(e){ var on = $(this).attr("src").replace(/_off.jpg$/gi,"_on.jpg"); $(this).attr("src",on); });
	$("input#add_to_cart").bind("mouseleave", function(e){ var off = $(this).attr("src").replace(/_on.jpg$/gi,"_off.jpg"); $(this).attr("src",off); });
	
	// onClick Event listeners \\
	$("#shipping_info").bind("click", function(e){ var w=window.open('popup_ship_info.htm','ShipInfo','width=550,height=400,titlebar=no,menubar=no,toolbar=no,scrollbars=yes,resizable=yes'); w.focus(); e.preventDefault(); });
	$("#sizing_info").bind("click", function(e){ var w=window.open('popup_sizing.htm','SizeInfo','width=550,height=300,titlebar=no,menubar=no,toolbar=no,scrollbars=yes,resizable=yes'); w.focus(); e.preventDefault(); });
	$("#sizing_info_spikes").bind("click", function(e){ var w=window.open('popup_sizing_microspikes.htm','SizeInfo','width=550,height=550,titlebar=no,menubar=no,toolbar=no,scrollbars=yes,resizable=yes'); w.focus(); e.preventDefault(); });
	$("#comparison").bind("click", function(e){ var w=window.open('popup_comparison.htm','Comparison','width=550,height=570,titlebar=no,menubar=no,toolbar=no,scrollbars=yes,resizable=yes'); w.focus(); e.preventDefault(); });
	$("#flash_overlay a").bind("click", function(e){ e.preventDefault(); });
	
	// Alternating lines on tables with the class lined_table \\
	if ($("table.lined_table").size()) { $("table.lined_table tr:odd").css("background-color", "#ffffff"); };
	if ($("table.lined_table").size()) { $("table.lined_table tr:even").css("background-color", "#e3e3e3"); };
	
	// IE Hacks \\
	jQuery.each(jQuery.browser, function(i) { if ($.browser.msie){ $("#size_id").css("width","auto"); } else { $("#size_id").css("width","150px"); } });

	// Form Validation \\
	if ($("#order_catalog[name='order_catalog']").size()) {	
		$("#order_catalog[name='order_catalog']").validate({
			invalidHandler: function(e, validator) {
				var errors = validator.numberOfInvalids();
				if (errors) {
					var message = errors == 1
						? '<p><b>You missed 1 field. It has been highlighted below.</b></p>'
						: '<p><b>You missed ' + errors + ' fields.  They have been highlighted below.</b></p>';
					$("div.body_error span").html(message);
					$("div.body_error").show();
				} else {
					$("div.body_error").hide();
				}
			},
			rules: {
				zip: { required: true, minlength: 5, maxlength: 7 },
				email: { required: true, email: true }
			},
			submitHandler: function(form) { form.submit(); },
			debug:true
		});
	};
	 
	if ($("#contact_form[name='contact_form']").size()) {
		$("#contact_form[name='contact_form']").validate({
			invalidHandler: function(e, validator) {
				var errors = validator.numberOfInvalids();
				if (errors) {
					var message = errors == 1
						? '<p><b>You missed 1 field. It has been highlighted below.</b></p>'
						: '<p><b>You missed ' + errors + ' fields.  They have been highlighted below.</b></p>';
					$("div.body_error span").html(message);
					$("div.body_error").show();
				} else {
					$("div.body_error").hide();
				}
			},
			rules: {
				email: { required: true, email: true }
			},
			submitHandler: function(form) { form.submit(); },
			debug:true
		});
	};
	
	// next script \\
	
});