$(function(){$('input[title!=""]').hint();});
			
	
	$(document).ready(function() {
            var order_price;
		
		$('.trigger').tooltip({ 
		    track: true, 
		    delay: 0, 
		    showURL: false, 
		    showBody: " - ", 
		    fade: 250 
		});	
		
		// Prevent multiple submissions of forms
		$('form').submit(function(){
		    $('.button').attr("disabled", "disabled");
		});	
		
		$('input[name=product]').each(function(){
			if ($(this).is(':checked')) {
				$('#price').val($("#" + 'price'+$(this).attr('id').replace('product','')).val());
			}
		});	

		// Set hidden field price on the fly
		$('input[name=product]').each(function(){
			$(this).change(function(){
				 $('#price').val($("#" + 'price'+$(this).attr('id').replace('product','')).val());
				 if ($('#quantity').val().replace(/[^0-9]/g, '')) {
                                     total = $('#price').val() * $('#quantity').val();
                                     if (!total) total = 0;
                                     total = total.toFixed(2);
				 	$('#order-price').html('$'+ total);
                                        $('#price_subtotal').val(total);
                                        $('#subtotal').html('$'+total);
                                        $('input[name=shipping_method]:checked').change();
				 }
			});
		});

                
		
		// Calculate order price on the fly
		$('#quantity').each(function(){
			$(this).keyup(function(){
				// update value
                                if ($(this).val()>0){
                                    total = $('#price').val() * $(this).val();
                                    if (!total) total = 0;
                                    total = total.toFixed(2);
                                    $('#order-price').html('$'+ total);
                                    $('#price_subtotal').val(total);
                                    $('#subtotal').html('$'+total);
                                    $('input[name=shipping_method]:checked').change();
                                }
			});
                        $('input[name=shipping_method]:checked').change();
		});
                $('input[name=product]:checked').change();
                $('#quantity').keyup();


                $('#shipping_zip').change(function(){
                    $('input[name=shipping_method]:checked').change();
                });
		
		/*$("#ground").click(function(){

			$('#total').html("$"+$('#price_subtotal').val());
                        
		});			
		
		$("#air").click(function(){
			$('#total').html("$"+String(parseFloat($('#price_subtotal').val()) + parseFloat($('#price_air').val())));					
		});	*/
                /*function update_air_price() {
                    shipping_price = parseFloat(data);
                  shipping_price = shipping_price.toFixed(2);
                  $('#shipping_price').html('for $'+shipping_price);
                }*/

		$('input[name=shipping_method]').each(function(){
			$(this).change(function(){
                            
                            if (($('#shipping_zip').val() != 'Zip Code' && $('#shipping_zip').val() != null) && $('#quantity').val() != null) {

                                $('#total').html("...Calculating...");

                                $.post("/product/ajax_shipping_calc", {quantity: $('#quantity').val(), shipping_method: $(this).val(), shipping_zip: $('#shipping_zip').val()},
                                  function(data){
                                      //alert(Number.toFixed(2))
                                      if (data>=0) {
                                          $('#total').html("Error");
                                      }

                                      total = (parseFloat($('#price_subtotal').val())+parseFloat(data));
                                      if (!total) total = 0;
                                    $('#total').html("$"+total.toFixed(2));
                                  });

				 /*$('#price').val($("#" + 'price'+$(this).attr('id').replace('product','')).val());
				 if ($('#quantity').val().replace(/[^0-9]/g, '')) {
				 	$('#order-price').html('$'+ $('#price').val() * $('#quantity').val());
                                        $('#price_subtotal').val($('#price').val() * $('#quantity').val());
                                        $('#subtotal').html('$'+$('#price').val() * $('#quantity').val());
				 }*/
                            } else {
                                $('#total').html("Please enter your zipcode and quantity.");
                            }
			});
		});
                $('input[name=shipping_method]:checked').change();
		
		// Automatically populate shipping fields based on billing info
		$('#shipping_address_line_1').each(function(){
			$(this).focus(function(){
				// update value
				if($('#shipping_address_line_1').val() == ''){
					$('#shipping_address_line_1').val($('#billing_address_line_1').val());
					$('#shipping_address_line_2').val($('#billing_address_line_2').val());
					$('#shipping_city').val($('#billing_city').val());
					$('#shipping_state').val($('#billing_state').val());
					$('#shipping_zip').val($('#billing_zip').val());
                                        $('input[name=shipping_method]:checked').change();
				}
			});
		});	
			
	    $(function() {
	        $('#gallery a').lightBox();
	    });

		
		// Accordion FAQs
		$('.accordion .head').click(function() {
			$(this).next().toggle('slow');
			return false;
		}).next().hide();
		
		$('#accordion').accordion({autoHeight: false});
		
	});

	Cufon.replace('h2');
	Cufon.replace('h4');	
	Cufon.replace('em');
	Cufon.replace('#landing');
	Cufon.replace('#comment_img h4');	
	Cufon.replace('.whos-talking');	
	Cufon.replace('.page-header h1');
	Cufon.replace('.page-header h2');
	Cufon.replace('#hydra h3');
	Cufon.replace('.hydra label');
	Cufon.replace('.hooker-content h3');
	Cufon.replace('.unwind h3');
	Cufon.replace('.blend');
	Cufon.replace('.footer-blog-title');
	Cufon.replace('.footer-blog-headlines');
	
