$(window).load(function() {
	$('#nav > ol li').hover(
		function () {
			$(this).toggleClass('over');
			if ($(this).next().hasClass('press')) {
				$(this).next().toggleClass('ie6fix');
			}
		},
		function () {
			$(this).toggleClass('over');
			if ($(this).next().hasClass('press')) {
				$(this).next().toggleClass('ie6fix');
			}
		}
	);

	$('#scroll_me').jScrollPane({showArrows:true, scrollbarWidth: 11, arrowSize: 11});
    $("#infield label").inFieldLabels();
    
   
    $('#slide_01 img:first').fadeIn(1000, function() {
       
      $('#slide_01').cycle({
                speed: 1000
                
       
      });
    });
   
    $('#slide_03 img:first').fadeIn(1000, function() {
       $('#slide_03').cycle({
                speed: 4000
                
                
        });
    });
    
    $('#aside_slide_01 img:first').fadeIn(1000, function() {
        $('#aside_slide_01').cycle({
               speed: 2500 
               
                
        });
    });
    
    $('#aside_slide_02 img:first').fadeIn(1000, function() {
       $('#aside_slide_02').cycle({
                speed:6000
                
        });
        
        $('#aside_slide_02 img').click(function() { 
            
            window.location = 'business-partners.php';
        
        });
        
    });
    
    $('#pages_russell img:first').fadeIn(1000, function() {
        $('#pages_russell').cycle();
    });
    
    $('#pages_story img:first').fadeIn(1000, function() {
        $('#pages_story').cycle({
                speed:4000
                
        });
    });
    
    $('#pages_foundation img:first').fadeIn(1000, function() {
        $('#pages_foundation').cycle();
    });
    
     $('#rotates img:first').fadeIn(1000, function() {
        $('#rotates').cycle();
    });
    
    
    
});





function checkQuantity(quantity) {
    
    if (!quantity || isNaN(quantity) || parseInt(quantity) <= 0) {
        alert("Quantity must be a number greater than 0");
        $('qty').focus();
        return false;
        
    }
    
}

function popUp(URL) {

var centerWidth = (window.screen.width - 400) / 2;
var centerHeight = (window.screen.height - 350) / 2;

day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=400,height=350,left = " + centerWidth + ",top = " + centerHeight + "');");
}  

function setCardDiv() {
   
   if ($('#payment_method').val() == 'invoice') 
        $('#card_information').hide();
   
    else 
        $('#card_information').show();
        
    
}

function setBADiv() {
   
   if ($('#application_type').val() == 2)
        $('#ba_instructions').show();
    else
        $('#ba_instructions').hide();
}


function setInvoiceOnly() {
    
    if ($("#ship_date_pulldown").attr("selectedIndex") == 0) {
        //$('#card_information').show();
       $("#payment_method").prepend("<option value='credit'>Credit Card</option>");
    }
    else {
        $('#card_information').hide();
        $("#payment_method option[value='credit']").remove();
    }
    
    
}

function initalizePaymentForms() {
    
    if ($("#ship_date_pulldown").attr("selectedIndex") != 0) {
       $('#card_information').hide();
       $("#payment_method option[value='credit']").remove();
       
    }
    
    if ($('#payment_method').val() == 'invoice') {
        $('#card_information').hide();
        
        
    }
    
       
}

function togglePaymentButton(direction) {
    if (direction == 'on') {
        $("#payment_button").removeAttr("disabled");
        $("#payment_button").css({ opacity: 1 });
        $("#payment_button").css({ cursor: 'pointer' });
        
    } else {
        $("#payment_button").css({ opacity: 0.35 });
        $("#payment_button").attr("disabled", "disabled");
        $("#payment_button").css({ cursor: 'default' });
    }
}

function toggleDiv(name, direction) {
    
    if (direction == 'on') 
        $(name).show();
    else
        $(name).hide();
}

function routeForm() {
    
    var payment_method = $('#payment_method').val();
    
    if (payment_method && payment_method == 'invoice')
        $('#payment_form').attr('action', 'payment.php');
        
    //$('#payment_form').submit();
    return true;
    
}

function getControlValues() {
   
    var shipping = $("#shipping_pulldown").val();
    var donation = $("#donation").is(':checked');
    var terms_agree = $("#terms_agree").is(':checked');
    
    return new Array(shipping, donation, terms_agree);
    
}

function updateCart() {

    var shipping = $("#shipping_pulldown").val();
    var donation = $("#donation").is(':checked');
    var shipping_cost;
    var total;
    var tr_data;
    var shipping_message;
           
    var ajaxData = "x_shipping=" + shipping + "&x_donation=" + donation; 
        
    $.ajax({
     url: '/admin/update_shipping_cost.php',
     data: ajaxData,
     dataType: 'xml',
     beforeSend: function() {
        $.blockUI({ css: { 
            border: 'none', 
            padding: '15px', 
            backgroundColor: '#000', 
            '-webkit-border-radius': '10px', 
            '-moz-border-radius': '10px', 
            opacity: .5, 
            color: '#fff' 
        } }); 
     },
     success: function updateValues(data) {
        
         $(data).find("CartInfo").each(function() {
             
             shipping_cost = parseFloat($(this).find('shipping_cost').text());
             total = parseFloat($(this).find('total').text());
             tr_data = $(this).find('trdata').text();
             
         }); //close each
         
         shipping_message = (isNaN(shipping_cost)) ? 'Please select a shipping method' : '$' + shipping_cost.toFixed(2);
         
         $("#shipping_display").html(shipping_message);
         $("#total_display").html('$' + total.toFixed(2));
         $("#tr_data").val(tr_data);
         $("#button_status").html('Clicking "process order" will charge your card <strong>$' + total.toFixed(2) + '</strong>');
              
         $.unblockUI();
         
         initializePage();
     }
     
          
   });
   
   

}

function initializePage() {
    
    var control_values = getControlValues();
    var shipping = control_values[0];
    var donation = control_values[1];
    var terms_agree = control_values[2];
    
    if (donation) 
        toggleDiv('.donation', 'on');
    else 
        toggleDiv('.donation', 'off');
        
    if (shipping == '' || shipping == null) {
        togglePaymentButton('off');
        toggleDiv('#button_status', 'off');
        toggleDiv('#terms', 'off');
    } else if (shipping == 'usps_0') {
        toggleDiv('#terms', 'on');
        if (terms_agree) {
            togglePaymentButton('on');
            $("#button_status").html('Clicking "process order" will charge your card <strong>' + $("#total_display").html() + '</strong>');
        } else {
            togglePaymentButton('off');
            $("#button_status").html('Please agree to the shipping terms before completing your order.');
        }
        toggleDiv('#button_status', 'on');
    } else {
        togglePaymentButton('on');
        toggleDiv('#button_status', 'on');
        toggleDiv('#terms', 'off');
    }
    
       
}

