$(document).ready(function() {
	$('.bnwRollOver').imgflip();
	$('#header li.not_current').topnav();

	$('.swf').swfalt(7);

	$('#input_ship_same_as_billing').bind('click', function() {
		var $this = $(this);
		if ( $this.attr('checked') ) {
			$('#input_ship_address1_wrapper, #input_ship_address2_wrapper, #input_ship_city_wrapper, #input_ship_state_id_wrapper, #input_ship_zip_wrapper').hide();
		} else {
			$('#input_ship_address1_wrapper, #input_ship_address2_wrapper, #input_ship_city_wrapper, #input_ship_state_id_wrapper, #input_ship_zip_wrapper').show();
		}
	});


	$('.video_image_1').hover(
		function(){//over
			if ( $(this).hasClass('current_video') ) {
			
			} else {

				$('.current_video_text').hide();	
				$('.video_text_area_1').removeClass("hide");	
				$('.video_text_area_1').addClass("show");	
			}	
		},
		function(){//out 
			if ( $(this).hasClass('current_video') ) {
			
			} else {

				$('.video_text_area_1').removeClass("show");	
				$('.video_text_area_1').addClass("hide");	
				$('.current_video_text').show();	
			}
	});
	$('.video_image_2').hover(
		function(){//over
			if ( $(this).hasClass('current_video') ) {
			
			} else {
				$('.current_video_text').hide();	
				$('.video_text_area_2').removeClass("hide");	
				$('.video_text_area_2').addClass("show");	
			}	
		},
		function(){//out 
			if ( $(this).hasClass('current_video') ) {
			
			} else {
				$('.video_text_area_2').removeClass("show");	
				$('.video_text_area_2').addClass("hide");	
				$('.current_video_text').show();	
			}
	});
	$('.video_image_3').hover(
		function(){//over
			if ( $(this).hasClass('current_video') ) {
			
			} else {
				$('.current_video_text').hide();	
				$('.video_text_area_3').removeClass("hide");	
				$('.video_text_area_3').addClass("show");	
			}	
		},
		function(){//out 
			if ( $(this).hasClass('current_video') ) {
			
			} else {
				$('.video_text_area_3').removeClass("show");	
				$('.video_text_area_3').addClass("hide");	
				$('.current_video_text').show();	
			}
	});
	$('.video_image_4').hover(
		function(){//over
			if ( $(this).hasClass('current_video') ) {
			
			} else {
				$('.current_video_text').hide();	
				$('.video_text_area_4').removeClass("hide");	
				$('.video_text_area_4').addClass("show");	
			}	
		},
		function(){//out 
			if ( $(this).hasClass('current_video') ) {
			
			} else {
				$('.video_text_area_4').removeClass("show");	
				$('.video_text_area_4').addClass("hide");	
				$('.current_video_text').show();	
			}
	});
	$('.video_image_5').hover(
		function(){//over
			if ( $(this).hasClass('current_video') ) {
			
			} else {
				$('.current_video_text').hide();	
				$('.video_text_area_5').removeClass("hide");	
				$('.video_text_area_5').addClass("show");	
			}	
		},
		function(){//out 
			if ( $(this).hasClass('current_video') ) {
			
			} else {
				$('.video_text_area_5').removeClass("show");	
				$('.video_text_area_5').addClass("hide");	
				$('.current_video_text').show();	
			}
	});




	if ( $('body').is('#purchase_select') ) $.purchase_select.init();
	
});

$.purchase_select = {
	init: function() {
		$('#total_sale_message, #you_saved').show();

		$('#product_form select').bind('change', function() {
			$.purchase_select.update();
		});

		$('#product_form #recurring').bind('click', function() {
			$.purchase_select.update();
		});

		$.purchase_select.update(1);
	},

	update: function(initializing) {
		var $content = $('<div/>');
		var nodes = '#recurring_discount, #shipping_discount, #tax_free_discount, #total_amount, #discount_amount, #status, #no_recurring_discount, #no_shipping_discount, #no_tax_free_discount';
		$content.load($('#product_form').attr('action') + '?ajax=1' + ' ' + nodes, $('#product_form').serializeArray(), function() {
			if ( $('#shipping_discount', $content).length ) {
				$('#free_shipping').css({display: 'inline'});
				$('#no_free_shipping').css({display: 'none'});
			} else if ( $('#no_shipping_discount', $content).length ) {
				$('#free_shipping').css({display: 'none'});
				$('#no_free_shipping').css({display: 'inline'});
			} else {
				$('#free_shipping').css({display: 'none'});
				$('#no_free_shipping').css({display: 'none'});
			}

			if ( $('#tax_free_discount', $content).length ) {
				$('#tax_free').css({display: 'inline'});
				$('#no_tax_free').css({display: 'none'});
			} else if ( $('#no_tax_free_discount', $content).length ) {
				$('#tax_free').css({display: 'none'});
				$('#no_tax_free').css({display: 'inline'});
			} else {
				$('#tax_free').css({display: 'none'});
				$('#no_tax_free').css({display: 'none'});
			}

			$('#total_amount').html($('#total_amount', $content).html());
			$('#discount_amount').html($('#discount_amount', $content).html());
			if ( $('#recurring').is(':checked') && $('#no_recurring_discount', $content).length ) {
				alert("We're sorry, but you must order 2 or more boxes to qualify for the monthly recurring option.");
				$('#recurring').attr({checked: false});
			}			
			$content.html('');
		});
	}
}

jQuery.fn.topnav = function() {

	var img_src = $("#header .current img").attr("src");

	$(this).hover(
		function(){//over
			$(this).addClass("on_top");	
			var img_src_to_off = img_src.replace(/_on.gif/, "_off.gif");			
			$("#header .current img").attr("src",img_src_to_off);				
		},
		function(){//out 
			$(this).removeClass("on_top");	
			var img_src_to_on = img_src.replace(/_off.gif/, "_on.gif")			
			$("#header .current img").attr("src",img_src_to_on);
	});
}