		jQuery(document).ready(function($){
			
				// external links
			$('a[rel^="external"]')
			.attr({
			target: '_blank',
			title: 'This link directs you to an external website and will open in a new window.'
			});

			$('.featuredseq, .horz').cycle();

			$('#subscriberbutton').click(function(){
				$('#sfrm1313').submit();
			});

			// writing a save customer info form to every page for ajax updating.
			$.get('{path=cart/x_save_customer_info_form}', function(data) {
 				$('body').append(data); 
				$("#hidden_save_customer_info_form").attr("style", "display:none"); 
			}); 

			// when billing and shipping data is changed, this is fired. 
			$("#state, #shipping_state, #country_code, #shipping_country_code, #zip, #shipping_zip, #region, #shipping_region").live('change',function(){
				// display a message indicating that we're updating fields cost
				update_fields(); 

				$('#hidden_save_customer_info_form form').ajaxSubmit({
					success: function(data) {
 						
						load_fields(); 
					}
				});
			});
			
			function update_fields()
			{
				// update the value of the hidden form field
				$('#hidden_country_code')	.val( $("#country_code").val() );
				$('#hidden_state')			.val( $("#state").val() );
				$('#hidden_zip')			.val( $("#zip").val() );
				$('#hidden_region')			.val( $("#region").val() );

				$('#hidden_shipping_country_code')	.val( $("#shipping_country_code").val() );
				$('#hidden_shipping_state')			.val( $("#shipping_state").val() );
				$('#hidden_shipping_zip')			.val( $("#shipping_zip").val() );
				$('#hidden_shipping_region')		.val( $("#shipping_region").val() );
			}
			function load_fields()
			{
				$('.cart_tax')			.html( 'updating...' );
				$('.cart_total')		.html( 'updating...' );
				$('.cart_shipping')		.html( 'updating...' );
				$('.cart_subtotal')		.html( 'updating...' );
				$('.cart_discount')		.html( 'updating...' );
				
				$('.cart_tax').	load('{path=cart/x_tax}');
				$('.cart_total').load('{path=cart/x_total}');
				$('.cart_shipping').load('{path=cart/x_shipping}');
				$('.cart_discount').load('{path=cart/x_discount}');
				$('.cart_subtotal').load('{path=cart/x_subtotal}');
			}
			function set_config(act, param)
			{
				$.get('{path=cart/x_set_config/}'+act+"/"+param, function(data) {
					load_fields(); 
				});
			}
			$("#checkout_button").click(function(){
				$("#return_url").val("cart/checkout"); 
				$("#update_cart_form").submit(); 
				return false; 
			}); 
			$("#update_button").click(function(){
				$("#return_url").val("cart/view_cart"); 
				$("#update_cart_form").submit(); 
				return false;
			});

    // copy billing to shipping
	var f1 = $('#billing input');
    $('#billCopy').click(function() {
    		f1.each(function(index){
 				$('#shipping_first_name').val($('#first_name').val());
 				$('#shipping_last_name').val($('#last_name').val());
 				$('#shipping_address').val($('#address').val());
 				$('#shipping_address2').val($('#address2').val());
 				$('#shipping_city').val($('#city').val());
 				$('#shipping_state').val($('#state').val());
 				$('#shipping_zip').val($('#zip').val());
 				$('#shipping_country_code').val($('#country_code').val());
    		});
     	return false;
    }); // end copy bill to ship function

    $('.poselect').change(function(){
    		var this_product = $(this).parents('div.productchoice').attr('id');
    		var chosen_side = ($(this).val()== 'Vertical')? 'p.hs':'p.vs';
    		var other_side = ($(this).val()== 'Horizontal')? 'p.hs':'p.vs';
    			$("#"+this_product+" "+chosen_side).hide();
    			$("#"+this_product+" "+other_side).show();
    })
	$('.ffselect').change(function(){
			var this_product = $(this).parents('div.productchoice').attr('id');
			$("#"+this_product+" .ff").html($(this).val());
	})
 	});
