$(document).ready(function(){
	$('div.media_video').hide();
	
	$('table.zebra tr').mouseover(function(){
		$(this).children('td').addClass('hl');
	});
	$('table.zebra tr').mouseout(function(){
		$(this).children('td').removeClass('hl');
	});
	
	$('table.zebra tr:even').addClass('tr1');
	
	
	
	$('#header #upper #b2bnav li').mouseover(function(){
		$(this).addClass('hl');
	});
	$('#header #upper #b2bnav li').mouseout(function(){
		$(this).removeClass('hl');
	});
	
	$('#concierge_nav li').mouseover(function(){
		$(this).addClass('hl');
	});
	$('#concierge_nav li').mouseout(function(){
		$(this).removeClass('hl');
	});
	
	
	$('a[@rel=external]').attr('target','_blank');
	
	$('#media_tab_images').click(function(){
		$(this).addClass('current');
		$('#media_tab_video').removeClass('current');
		$('div.media_video').hide();
		$('div.media_image').fadeIn();
		$('#product_thumbs').fadeIn();
		$('#photoflow').show();
		//$('h3.subtitle').show();
	});
	
	$('#media_tab_video').click(function(){
		$(this).addClass('current');
		$('#media_tab_images').removeClass('current');
		$('div.media_video').fadeIn();
		$('div.media_image').hide();
		$('#photoflow').hide();
		$('#product_thumbs').fadeOut();
		//$('h3.subtitle').hide();
	});
	
	$('#product_thumbs img').click(function(){
		$('#main_product_image').attr('src',$(this).attr('rel'));
	});
	
	$('p.contact_link').html('<strong>Email:</strong> <a href="mailto:sales@ritani.com">sales@ritani.com</a>');
	
	
	$('#dealer_pricing a').click(function(){
		$('#pricing_msrp').hide();
		$('#pricing_cost').hide();
		
		$('#tab_msrp').removeClass('ui-tabs-selected');
		$('#tab_cost').removeClass('ui-tabs-selected');
		var rel = $(this).attr('rel');
		$('#pricing_'+rel).slideDown();
		$('#tab_'+rel).addClass('ui-tabs-selected');
		return false;
	});
	
	//$('#pricing_cost').hide();
	//$('#tab_msrp').addClass('ui-tabs-selected');
	
	$(".request_date").each(function(){
		$(this).mask($(this).attr('title'));
	});
	
	$(".mask_date").each(function(){
		$(this).mask($(this).attr('title'));
	});
	
	
	$('#variation_order_submit').click(function(){
		var dt = $('.request_date').val();
		if(dt == ""){
			alert('Please enter a requested date.');
			return false;			
		}
		if( confirm('Clicking OK will send this order to be processed. Click cancel if you do not want to commit to this purchase.')){
			$('#singleorder').submit();
		}	
	});
	
	$('#customproduct_order_submit').click(function(){
		var dt = $('.request_date').val();
		if(dt == ""){
			alert('Please enter a requested date.');
			return false;			
		}
		if( confirm('Clicking OK will send this order to be processed. Click cancel if you do not want to commit to this purchase.')){
			$('#singleorder').submit();
		}	
	});
	
	$('#diamond_order_submit').click(function(){
		
		if( confirm('Clicking OK will send this order to be processed. Click cancel if you do not want to commit to this purchase.')){
			$('#singleorder').submit();
		}	
	});
	
	
	
	
	$('#quotecart_order_submit').click(function(){
		var dt = $('.request_date:first').val();
		if(dt == ""){
			alert('Please enter a requested date.');
			return false;			
		}
		
		/*
		// check custom item 
		var cp = $('#custom_price').val();
		if(cp != ""){			
			$('#update_total').click();
			var cd = $('#custom_description').val();
			if(cd == ""){			
				alert('Please enter a description for your custom item.');
				return false;
			}
		}
		*/
		
		return confirm('Clicking OK will send this order to be processed. Click cancel if you do not want to commit to this purchase.');
	});
	
	
	
	if($('.request_date').length > 1){
		$('.request_date:first').blur(function(){
			var val = $(this).val();
			$('.request_date:not(:first)').val(val);
		});
	}
	
	
	if($('.po_number').length > 1){
		$('.po_number:first').change(function(){
			var val = $(this).val();
			$('.po_number:not(:first)').val(val);
		});
	}
	
	
	$('#email_cart').hide();
	
	$('#email_cart_toggle').toggle(
		function(){
			$('#email_cart_toggle').text('Cancel Email');
			$('#email_cart').fadeIn('fast');
			return false;
		},
		function(){
			$('#email_cart_toggle').text('Email');
			$('#email_cart').fadeOut();
			return false;
		}
	);
	
	
	$('#selectcart').hide();
	
	$('a.noqc').click(function(){
		$('#selectcart').slideDown('slow');
		alert('Please select a QuoteCart before you proceed.');
		return false;
	});	
	
	
	
	
	/**
	 * 
	 * /pages/mm_billboard
	 *
	 **/
	
	$("#option_bleed").hide();
	$('#printing_info').hide();
	$('#billboard_samples').hide();
	$('#billboard_samples_content').hide();
	
	$('#billboard_samples a').toggle(
		function(){
			$(this).text('Hide Samples');
			$('#billboard_samples_content').slideDown();
			return false;
		},
		function(){
			$(this).text('Show Samples');
			$('#billboard_samples_content').slideUp();
			return false;
		}
	);
	
	
	$(":radio[name='data[Page][advertisement_or_billboard]']").click(function(){
		var val = $(this).val();
		if(val == "Advertisement"){
			$('#billboard_samples').hide();
			$('#billboard_samples_content').hide();
			$('#billboard_samples a').text('Show Samples');
			$(":input[name='data[Page][publication_info]']").parent().show();
			$('#printing_info').hide();
			$(":radio[name*='data[Page][bleed]']").parent().show();
			var bv = $(":radio[name='data[Page][bleed]']:checked").val();
			if(bv == "Yes"){
				$("#option_bleed").show();
				alert('show options');
			}else{
				$("#option_bleed").hide();
			}
		}else{
			$('#billboard_samples').show();
			$(":input[name='data[Page][publication_info]']").parent().hide();
			$('#printing_info').show();
			$(":radio[name='data[Page][bleed]']").parent().hide();
			$("#option_bleed").hide();
		}
	});
	
	$(":radio[name='data[Page][bleed]']").click(function(){
		var val = $(this).val();
		if(val == "Yes"){
			$("#option_bleed").show();
		}else{
			$("#option_bleed").hide();
		}
	});
	
	$(":radio[name='data[Page][bleed_all_sides]']").click(function(){
		var val = $(this).val();
		if(val == "Yes"){
			$(":input[name='data[Page][bleed_sides]']").parent().hide();
		}else{
			$(":input[name='data[Page][bleed_sides]']").parent().show();
		}
	});
	
	$(":input[name='data[Page][shipping_info]']").parent().hide();
	
	$(":radio[name='data[Page][ritani_doing_priting]']").click(function(){
		var val = $(this).val();
		if(val == "Yes"){
			$(":input[name='data[Page][printer_info]']").parent().hide();
			$(":input[name='data[Page][shipping_info]']").parent().show();
		}else{
			$(":input[name='data[Page][printer_info]']").parent().show();
			$(":input[name='data[Page][shipping_info]']").parent().hide();
		}
	});
	
	/**
	 * 
	 * /pages/mm_imagerequest
	 *
	 **/
	
	$('#send_via_cd').hide();
	$('#send_via_ftp').hide();
	
	
	$(":radio[name='data[Page][how_to_send]']").click(function(){
		var val = $(this).val();
		
		$('#send_via_cd').hide();
		$('#send_via_ftp').hide();
		$('#send_via_email').hide();
		
		if(val == "CD"){
			$('#send_via_cd').show();
		}else if(val == "Email"){
			$('#send_via_email').show();
		}else{
			$('#send_via_ftp').show();
		}
	});
	
	$("#form_mm_imagerequest").submit(function(){
		var c = $(":checkbox[name='data[Page][confirm]']").attr('checked');
		if(c == true){
			return true;
		}else{
			alert('Please confirm that you have read this form');
			return false;
		}
	});
	
	
	
	
	
	/**
	 * 
	 * /pages/mm_duratran
	 *
	 **/
	/*
	$('#poster_samples_content').hide();
	
	$('#poster_samples_toggle').toggle(
		function(){
			$(this).text('Hide Samples');
			$('#poster_samples_content').slideDown();
			return false;
		},
		function(){
			$(this).text('Show Samples');
			$('#poster_samples_content').slideUp();
			return false;
		}
	);
	*/
	
	
	$(":input[name='data[Page][poster_material]']").parent().hide();
	$(":checkbox[name='data[Page][grummet]']").parent().hide();
	
	$(":checkbox[name='data[Page][type_poster]']").click(function(){
		var checked = $(this).attr('checked');
		if(checked == true){
			$(":input[name='data[Page][poster_material]']").parent().show();
			var material = $(":input[name='data[Page][poster_material]']:checked").val();
			if(material == "neither"){
				$(":checkbox[name='data[Page][grummet]']").parent().hide();
			}else{
				$(":checkbox[name='data[Page][grummet]']").parent().show();
			}
		}else{
			$(":input[name='data[Page][poster_material]']").parent().hide();
			$(":checkbox[name='data[Page][grummet]']").parent().hide();
		}
	});
	
	$(":input[name='data[Page][poster_material]']").click(function(){
		var val = $(this).val();
		if(val == "neither"){
			$(":checkbox[name='data[Page][grummet]']").parent().hide();
		}else{
			$(":checkbox[name='data[Page][grummet]']").parent().show();
		}
	});
	
	$("#option_int_ext").hide();
	
	$(":checkbox[name='data[Page][type_duratran]']").click(function(){
		var checked = $(this).attr('checked');
		if(checked == true){
			$("#option_int_ext").show();
		}else{
			$("#option_int_ext").hide();
		}
	});
	
	$(":input[name='data[Page][shipping_info_multi]']").parent().hide();
	$(":checkbox[name='data[Page][multi_address]']").click(function(){
		var checked = $(this).attr('checked');
		if(checked == true){
			$(":input[name='data[Page][shipping_info_multi]']").parent().show();
		}else{
			$(":input[name='data[Page][shipping_info_multi]']").parent().hide();
		}
	});
	
	$("#form_mm_duratran").submit(function(){
		var poster = $(":checkbox[name='data[Page][type_poster]']").attr('checked');
		var duratran = $(":checkbox[name='data[Page][type_duratran]']").attr('checked');
		if(!poster && !duratran){
			alert('you must select Poster, Durotran or both');
			return false;
		}
		
	});
	
	
	$("#order_number_content").hide();
	
	$("#order_number_toggle").click(function(){
		var checked = $(this).attr('checked');
		if(checked == true){
			$("#order_number_content").show();
		}else{
			$("#order_number_content").hide();
		}
	});
	
	
	
	
	
	
	$('img.activeimage').click(function(){
		var sn = $(this).attr('alt');
		var v = $('#style_number_box').val();
		if(v == ""){
			var nv = sn;
		}else{
			var nv = v + ", " + sn;
		}
		
		$('#style_number_box').val(nv);
		document.location.href = "#styles";
		
	});
	
	
	
	var showrecent = $.cookie('showrecent');
	//alert(showrecent);
	if(showrecent != "true"){
		$('#recently_viewed div').hide();
		$('#recently_viewed h3 span').text('Show');
	}
	
	$('#recently_viewed h3 span').click(function(){
		var s = $('#recently_viewed div').css('display');
		
		if(s == "none"){
			$.cookie('showrecent','true');
			$('#recently_viewed div').fadeIn();
			$('#recently_viewed h3 span').text('Hide');
		}else{
			$.cookie('showrecent', 'false');
			$('#recently_viewed div').fadeOut();
			$('#recently_viewed h3 span').text('Show');
		}
	});
	
	
	
	
	
	/**
	 * 
	 * Poll Voting
	 *
	 **/
	$('#poll_submit').hide();
	$('a.vote_1').bind('click',function(){
		$('a.vote_1').removeClass('vote_1_s');
		$('a.vote_1').not($(this)).addClass('dead');
		$(this).addClass('vote_1_s');
		var pid = $(this).attr('rel');
		$('#poll_item_1').val(pid);
		
		var v1 = $('#poll_item_1').val();
		var v2 = $('#poll_item_2').val();
		var v3 = $('#poll_item_3').val();
		if(v1 != "" && v2 != "" && v3 != ""){
			$('#poll_submit').fadeIn();
		}
		
		return false;
	});
	
	$('a.vote_2').bind('click',function(){
		$('a.vote_2').removeClass('vote_2_s');
		$('a.vote_2').not($(this)).addClass('dead');
		$(this).addClass('vote_2_s');
		var pid = $(this).attr('rel');
		$('#poll_item_2').val(pid);
		
		var v1 = $('#poll_item_1').val();
		var v2 = $('#poll_item_2').val();
		var v3 = $('#poll_item_3').val();
		if(v1 != "" && v2 != "" && v3 != ""){
			$('#poll_submit').fadeIn();
		}
		
		return false;
	});
	
	$('a.vote_3').bind('click',function(){
		$('a.vote_3').removeClass('vote_3_s');
		$('a.vote_3').not($(this)).addClass('dead');
		$(this).addClass('vote_3_s');
		var pid = $(this).attr('rel');
		$('#poll_item_3').val(pid);
		
		var v1 = $('#poll_item_1').val();
		var v2 = $('#poll_item_2').val();
		var v3 = $('#poll_item_3').val();
		if(v1 != "" && v2 != "" && v3 != ""){
			$('#poll_submit').fadeIn();
		}
		
		return false;
	});
	
	
	
	
	$('a.sales_link').attr('href','mailto:sales@ritani.com');
	
	
	
	$('#quotecartemails').hide();
	$('#display_quotecartemails').toggle(
	function(){
		$('#quotecartemails').slideDown();
		$('#display_quotecartemails').text('Hide previous recipients');
		return false;
	},
	function(){
		$('#quotecartemails').slideUp();
		$('#display_quotecartemails').text('Display previous recipients');
		return false;
	}
	
	);
	
	
	$('.quotecart_update_submit').click(function(){
		$('#quotecart_order_form').attr('action','/quotecarts/order/');
		$('#quotecart_order_form').submit();
	});
	
	
	
	
});


function swapImage(img){
	$('#main_product_image').attr('src',img);
}


function CurrencyFormatted(amount){
	var i = parseFloat(amount);
	if(isNaN(i)) { i = 0.00; }
	var minus = '';
	if(i < 0) { minus = '-'; }
	i = Math.abs(i);
	i = parseInt((i + .005) * 100);
	i = i / 100;
	s = new String(i);
	if(s.indexOf('.') < 0) { s += '.00'; }
	if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
	s = minus + s;
	return s;
}






