///*
//-----------------------------------------------
//Horizon Shutters Pricing
//Author: Chad Spencer & Jeremy Boles
//----------------------------------------------- */

window.addEvent('domready', function() {
  
  var pricing = $('pricing');
  if ($defined(pricing)) { }
  
  var pricing_swf = $('pricing-swf');
  if ($defined(pricing_swf)) {
    var swf_opts = { 'container' : pricing_swf, 'height' : 280, 'width' : 500 };
    var swf = new Swiff('/media/img/pricing/preview.gif', swf_opts);
    
    // Grab the calulating elements
    var total = $('total');
    var total_price = $('total-price');
    var calculate = $('calculate');
    
    // Grab the form elements
    var width = $('width');
    var width_plus = $('width-plus');
    var height = $('height');
    var height_plus = $('height-plus');
    var shutter_style = $('shutter-style');
    var unit_configuration = $('unit-configuration');
    var fields = $$([width, width_plus, height, height_plus, shutter_style]);
    var fields_with_unit = $$(fields).extend([unit_configuration]);
    
    // Functions to calulate the full width and height
    var width_full = function() {
      return width.get('value').toFloat() + width_plus.get('value').toFloat();
    };
    var height_full = function() {
      return height.get('value').toFloat() + height_plus.get('value').toFloat();
    };
    
    // Simple function to see if all of the fields are filled
    var fields_ready = function(include_unit_config) {
      var ready = (width_full() > 0  && height_full() > 0  && shutter_style.get('value') != '');
      if (include_unit_config) ready = (ready && unit_configuration.get('value') != '');
      return ready;
    };
    
    fields_with_unit.addEvent('change', function() {
      // Hide the total since it is no longer valid after the change
      total.setStyle('display', 'none');
      var swf = new Swiff('/media/img/pricing/preview.gif', swf_opts);
    });
    
    // When the fields change
    fields.addEvent('change', function() {
      
      // If all of the fields are ready, populate the select menu
      if (fields_ready()) {
        // Enable the field
        unit_configuration.set('disabled', false);
        
        // Short cut variables
        var w = width_full();
        var h = height_full();
        
        calculate.set('disabled', false);
        
        // Initialize the optiosn variable
        var options = '';
        // If it's a Traditional
        if (shutter_style.get('value').charAt(0) == 'T') {
          // Wrap the logic in a function so I can collapse it in TextMate
          options = (function(w, h) {
            // Big mess of if statements
            if (w >=  7 && w < 15 && h < 40) {
              return '<option value="1 Panel - Single Tier Full Height">1 Panel - Single Tier Full Height</option>' + 
                     '<option value="1 Panel - Single Tier Full Height With Divider Rail">1 Panel - Single Tier Full Height With Divider Rail</option>' +
                     '<option value="1 Panel - Double Tier">1 Panel - Double Tier</option>' +
                     '<option value="1 Panel - Single Tier Cafe">1 Panel - Single Tier Cafe</option>';
            } else if (w >=  7 && w < 15 && h >= 40 && h < 100) {
              return '<option value="1 Panel - Single Tier Full Height With Divider Rail">1 Panel - Single Tier Full Height With Divider Rail</option>' +
                     '<option value="1 Panel - Double Tier">1 Panel - Double Tier</option>';
            } else if (w >= 15 && w < 17 && h < 40) {
              return '<option value="1 Panel - Single Tier Full Height">1 Panel - Single Tier Full Height</option>' + 
                     '<option value="1 Panel - Single Tier Full Height With Divider Rail">1 Panel - Single Tier Full Height With Divider Rail</option>' +
                     '<option value="1 Panel - Double Tier">1 Panel - Double Tier</option>' +
                     '<option value="1 Panel - Single Tier Cafe">1 Panel - Single Tier Cafe</option>' +
                     '<option value="2 Panel - Single Tier Full Height">2 Panel - Single Tier Full Height</option>' + 
                     '<option value="2 Panel - Single Tier Full Height With Divider Rail">2 Panel - Single Tier Full Height With Divider Rail</option>' +
                     '<option value="2 Panel - Double Tier">2 Panel - Double Tier</option>' +
                     '<option value="2 Panel - Single Tier Cafe">2 Panel - Single Tier Cafe</option>';
            } else if (w >= 15 && w < 17 && h >= 40 && h < 100) {
              return '<option value="1 Panel - Single Tier Full Height With Divider Rail">1 Panel - Single Tier Full Height With Divider Rail</option>' +
                     '<option value="1 Panel - Double Tier">1 Panel - Double Tier</option>' +
                     '<option value="2 Panel - Single Tier Full Height With Divider Rail">2 Panel - Single Tier Full Height With Divider Rail</option>' +
                     '<option value="2 Panel - Double Tier">2 Panel - Double Tier</option>';
            } else if (w >= 17 && w < 23 && h < 40) {
              return '<option value="2 Panel - Single Tier Full Height">2 Panel - Single Tier Full Height</option>' + 
                     '<option value="2 Panel - Single Tier Full Height With Divider Rail">2 Panel - Single Tier Full Height With Divider Rail</option>' +
                     '<option value="2 Panel - Double Tier">2 Panel - Double Tier</option>' +
                     '<option value="2 Panel - Single Tier Cafe">2 Panel - Single Tier Cafe</option>';
            } else if (w >= 17 && w < 22 && h >= 40 && h < 100) {
              return '<option value="2 Panel - Single Tier Full Height With Divider Rail">2 Panel - Single Tier Full Height With Divider Rail</option>' +
                     '<option value="2 Panel - Double Tier">2 Panel - Double Tier</option>';
            } else if (w >= 22 && w < 29 && h < 40) {
              return '<option value="2 Panel - Single Tier Full Height">2 Panel - Single Tier Full Height</option>' + 
                     '<option value="2 Panel - Single Tier Full Height With Divider Rail">2 Panel - Single Tier Full Height With Divider Rail</option>' +
                     '<option value="2 Panel - Double Tier">2 Panel - Double Tier</option>' +
                     '<option value="2 Panel - Single Tier Cafe">2 Panel - Single Tier Cafe</option>' +
                     '<option value="3 Panel - Single Tier Full Height">3 Panel - Single Tier Full Height</option>' + 
                     '<option value="3 Panel - Single Tier Full Height With Divider Rail">3 Panel - Single Tier Full Height With Divider Rail</option>' +
                     '<option value="3 Panel - Double Tier">3 Panel - Double Tier</option>' +
                     '<option value="3 Panel - Single Tier Cafe">3 Panel - Single Tier Cafe</option>';
            } else if (w >= 22 && w < 29 && h >= 40 && h < 100) {
              return '<option value="2 Panel - Single Tier Full Height With Divider Rail">2 Panel - Single Tier Full Height With Divider Rail</option>' +
                     '<option value="2 Panel - Double Tier">2 Panel - Double Tier</option>' +
                     '<option value="3 Panel - Single Tier Full Height With Divider Rail">3 Panel - Single Tier Full Height With Divider Rail</option>' +
                     '<option value="3 Panel - Double Tier">3 Panel - Double Tier</option>';
            } else if (w >= 29 && w < 33 && h < 40) {
              return '<option value="2 Panel - Single Tier Full Height">2 Panel - Single Tier Full Height</option>' + 
                     '<option value="2 Panel - Single Tier Full Height With Divider Rail">2 Panel - Single Tier Full Height With Divider Rail</option>' +
                     '<option value="2 Panel - Double Tier">2 Panel - Double Tier</option>' +
                     '<option value="2 Panel - Single Tier Cafe">2 Panel - Single Tier Cafe</option>' +
                     '<option value="3 Panel - Single Tier Full Height">3 Panel - Single Tier Full Height</option>' + 
                     '<option value="3 Panel - Single Tier Full Height With Divider Rail">3 Panel - Single Tier Full Height With Divider Rail</option>' +
                     '<option value="3 Panel - Double Tier">3 Panel - Double Tier</option>' +
                     '<option value="3 Panel - Single Tier Cafe">3 Panel - Single Tier Cafe</option>' + 
                     '<option value="4 Panel - Single Tier Full Height">4 Panel - Single Tier Full Height</option>' + 
                     '<option value="4 Panel - Single Tier Full Height With Divider Rail">4 Panel - Single Tier Full Height With Divider Rail</option>' +
                     '<option value="4 Panel - Double Tier">4 Panel - Double Tier</option>' +
                     '<option value="4 Panel - Single Tier Cafe">4 Panel - Single Tier Cafe</option>';
            } else if (w >= 29 && w < 33 && h >= 40 && h < 100) {
              return '<option value="2 Panel - Single Tier Full Height With Divider Rail">2 Panel - Single Tier Full Height With Divider Rail</option>' +
                     '<option value="2 Panel - Double Tier">2 Panel - Double Tier</option>' +
                     '<option value="3 Panel - Single Tier Full Height With Divider Rail">3 Panel - Single Tier Full Height With Divider Rail</option>' +
                     '<option value="3 Panel - Double Tier">3 Panel - Double Tier</option>' +
                     '<option value="4 Panel - Single Tier Full Height With Divider Rail">4 Panel - Single Tier Full Height With Divider Rail</option>' +
                     '<option value="4 Panel - Double Tier">4 Panel - Double Tier</option>';
            } else if (w >= 33 && w < 43 && h < 40) {
              return '<option value="3 Panel - Single Tier Full Height">3 Panel - Single Tier Full Height</option>' + 
                     '<option value="3 Panel - Single Tier Full Height With Divider Rail">3 Panel - Single Tier Full Height With Divider Rail</option>' +
                     '<option value="3 Panel - Double Tier">3 Panel - Double Tier</option>' +
                     '<option value="3 Panel - Single Tier Cafe">3 Panel - Single Tier Cafe</option>' +
                     '<option value="4 Panel - Single Tier Full Height">4 Panel - Single Tier Full Height</option>' + 
                     '<option value="4 Panel - Single Tier Full Height With Divider Rail">4 Panel - Single Tier Full Height With Divider Rail</option>' +
                     '<option value="4 Panel - Double Tier">4 Panel - Double Tier</option>' +
                     '<option value="4 Panel - Single Tier Cafe">4 Panel - Single Tier Cafe</option>';
            } else if (w >= 33 && w < 43 && h >= 40 && h < 100) {
              return '<option value="3 Panel - Single Tier Full Height With Divider Rail">3 Panel - Single Tier Full Height With Divider Rail</option>' +
                     '<option value="3 Panel - Double Tier">3 Panel - Double Tier</option>' +
                     '<option value="4 Panel - Single Tier Full Height With Divider Rail">4 Panel - Single Tier Full Height With Divider Rail</option>' +
                     '<option value="4 Panel - Double Tier">4 Panel - Double Tier</option>';
            } else if (w >= 43 && w < 49 && h < 40) {
              return '<option value="3 Panel - Single Tier Full Height">3 Panel - Single Tier Full Height</option>' + 
                     '<option value="3 Panel - Single Tier Full Height With Divider Rail">3 Panel - Single Tier Full Height With Divider Rail</option>' +
                     '<option value="3 Panel - Double Tier">3 Panel - Double Tier</option>' +
                     '<option value="3 Panel - Single Tier Cafe">3 Panel - Single Tier Cafe</option>' + 
                     '<option value="4 Panel - Single Tier Full Height">4 Panel - Single Tier Full Height</option>' + 
                     '<option value="4 Panel - Single Tier Full Height With Divider Rail">4 Panel - Single Tier Full Height With Divider Rail</option>' +
                     '<option value="4 Panel - Double Tier">4 Panel - Double Tier</option>' +
                     '<option value="4 Panel - Single Tier Cafe">4 Panel - Single Tier Cafe</option>' + 
                     '<option value="6 Panel - Single Tier Full Height">6 Panel - Single Tier Full Height</option>' + 
                     '<option value="6 Panel - Single Tier Full Height With Divider Rail">6 Panel - Single Tier Full Height With Divider Rail</option>' +
                     '<option value="6 Panel - Double Tier">6 Panel - Double Tier</option>' +
                     '<option value="6 Panel - Single Tier Cafe">6 Panel - Single Tier Cafe</option>';
            } else if (w >= 43 && w < 49 && h >= 40 && h < 100) {
              return '<option value="3 Panel - Single Tier Full Height With Divider Rail">3 Panel - Single Tier Full Height With Divider Rail</option>' +
                     '<option value="3 Panel - Double Tier">3 Panel - Double Tier</option>' +
                     '<option value="4 Panel - Single Tier Full Height With Divider Rail">4 Panel - Single Tier Full Height With Divider Rail</option>' +
                     '<option value="4 Panel - Double Tier">4 Panel - Double Tier</option>' +
                     '<option value="6 Panel - Single Tier Full Height With Divider Rail">6 Panel - Single Tier Full Height With Divider Rail</option>' +
                     '<option value="6 Panel - Double Tier">6 Panel - Double Tier</option>';
            } else if (w >= 49 && w < 65 && h < 40) {
              return '<option value="4 Panel - Single Tier Full Height">4 Panel - Single Tier Full Height</option>' + 
                     '<option value="4 Panel - Single Tier Full Height With Divider Rail">4 Panel - Single Tier Full Height With Divider Rail</option>' +
                     '<option value="4 Panel - Double Tier">4 Panel - Double Tier</option>' +
                     '<option value="4 Panel - Single Tier Cafe">4 Panel - Single Tier Cafe</option>' + 
                     '<option value="6 Panel - Single Tier Full Height">6 Panel - Single Tier Full Height</option>' + 
                     '<option value="6 Panel - Single Tier Full Height With Divider Rail">6 Panel - Single Tier Full Height With Divider Rail</option>' +
                     '<option value="6 Panel - Double Tier">6 Panel - Double Tier</option>' +
                     '<option value="6 Panel - Single Tier Cafe">6 Panel - Single Tier Cafe</option>';
            } else if (w >= 49 && w < 65 && h >= 40 && h < 100) {
              return '<option value="4 Panel - Single Tier Full Height With Divider Rail">4 Panel - Single Tier Full Height With Divider Rail</option>' +
                     '<option value="4 Panel - Double Tier">4 Panel - Double Tier</option>' +
                     '<option value="6 Panel - Single Tier Full Height With Divider Rail">6 Panel - Single Tier Full Height With Divider Rail</option>' +
                     '<option value="6 Panel - Double Tier">6 Panel - Double Tier</option>';
            } else if (w >= 65 && w < 96 && h < 40) {
              return '<option value="6 Panel - Single Tier Full Height">6 Panel - Single Tier Full Height</option>' + 
                     '<option value="6 Panel - Single Tier Full Height With Divider Rail">6 Panel - Single Tier Full Height With Divider Rail</option>' +
                     '<option value="6 Panel - Double Tier">6 Panel - Double Tier</option>' +
                     '<option value="6 Panel - Single Tier Cafe">6 Panel - Single Tier Cafe</option>';
            } else if (w >= 65 && w < 96 && h >= 40 && h < 100) {
              return '<option value="6 Panel - Single Tier Full Height With Divider Rail">6 Panel - Single Tier Full Height With Divider Rail</option>' +
                     '<option value="6 Panel - Double Tier">6 Panel - Double Tier</option>';
            } else {
              total.setStyle('display', 'block');
              total.getElements('strong').setStyle('display', 'none');
              total_price.set('html', '<a href="/contact">Call for Pricing</a>');
              calculate.set('disabled', true);
              var swf = new Swiff('/media/img/pricing/traditional-error.png', swf_opts);
              return '<option disabled="true">Desired Configuration Not Shown</option>';
            }
          }).run([width_full(), height_full()]);
        } else { // Plantation
          // Wrap the logic in a function so I can collapse it in TextMate
          options = (function(w, h) {
            // Big mess of if statements
            if (w >=  7 && w < 17 && h < 76) {
              return '<option value="1 Panel - Single Tier Full Height">1 Panel - Single Tier Full Height</option>' + 
                     '<option value="1 Panel - Single Tier Full Height With Divider Rail">1 Panel - Single Tier Full Height With Divider Rail</option>' +
                     '<option value="1 Panel - Double Tier">1 Panel - Double Tier</option>' +
                     '<option value="1 Panel - Single Tier Cafe">1 Panel - Single Tier Cafe</option>';
            } else if (w >=  7 && w < 17 && h >= 76 && h < 100) {
              return '<option value="1 Panel - Single Tier Full Height With Divider Rail">1 Panel - Single Tier Full Height With Divider Rail</option>' +
                     '<option value="1 Panel - Double Tier">1 Panel - Double Tier</option>';
            } else if (w >= 17 && w < 25 && h < 76) {
              return '<option value="1 Panel - Single Tier Full Height">1 Panel - Single Tier Full Height</option>' + 
                     '<option value="1 Panel - Single Tier Full Height With Divider Rail">1 Panel - Single Tier Full Height With Divider Rail</option>' +
                     '<option value="1 Panel - Double Tier">1 Panel - Double Tier</option>' +
                     '<option value="1 Panel - Single Tier Cafe">1 Panel - Single Tier Cafe</option>' + 
                     '<option value="2 Panel - Single Tier Full Height">2 Panel - Single Tier Full Height</option>' + 
                     '<option value="2 Panel - Single Tier Full Height With Divider Rail">2 Panel - Single Tier Full Height With Divider Rail</option>' +
                     '<option value="2 Panel - Double Tier">2 Panel - Double Tier</option>' +
                     '<option value="2 Panel - Single Tier Cafe">2 Panel - Single Tier Cafe</option>';
            } else if (w >= 17 && w < 25 && h >= 76 && h < 100) {
              return '<option value="1 Panel - Single Tier Full Height With Divider Rail">1 Panel - Single Tier Full Height With Divider Rail</option>' +
                     '<option value="1 Panel - Double Tier">1 Panel - Double Tier</option>' +
                     '<option value="2 Panel - Single Tier Full Height With Divider Rail">2 Panel - Single Tier Full Height With Divider Rail</option>' +
                     '<option value="2 Panel - Double Tier">2 Panel - Double Tier</option>';
            } else if (w >= 25 && w < 33 && h < 76) {
              return '<option value="1 Panel - Single Tier Full Height">1 Panel - Single Tier Full Height</option>' + 
                     '<option value="1 Panel - Single Tier Full Height With Divider Rail">1 Panel - Single Tier Full Height With Divider Rail</option>' +
                     '<option value="1 Panel - Double Tier">1 Panel - Double Tier</option>' +
                     '<option value="1 Panel - Single Tier Cafe">1 Panel - Single Tier Cafe</option>' + 
                     '<option value="2 Panel - Single Tier Full Height">2 Panel - Single Tier Full Height</option>' + 
                     '<option value="2 Panel - Single Tier Full Height With Divider Rail">2 Panel - Single Tier Full Height With Divider Rail</option>' +
                     '<option value="2 Panel - Double Tier">2 Panel - Double Tier</option>' +
                     '<option value="2 Panel - Single Tier Cafe">2 Panel - Single Tier Cafe</option>' + 
                     '<option value="3 Panel - Single Tier Full Height">3 Panel - Single Tier Full Height</option>' + 
                     '<option value="3 Panel - Single Tier Full Height With Divider Rail">3 Panel - Single Tier Full Height With Divider Rail</option>' +
                     '<option value="3 Panel - Double Tier">3 Panel - Double Tier</option>' +
                     '<option value="3 Panel - Single Tier Cafe">3 Panel - Single Tier Cafe</option>';
            } else if (w >= 25 && w < 33 && h >= 76 && h < 100) {
              return '<option value="1 Panel - Single Tier Full Height With Divider Rail">1 Panel - Single Tier Full Height With Divider Rail</option>' +
                     '<option value="1 Panel - Double Tier">1 Panel - Double Tier</option>' +
                     '<option value="2 Panel - Single Tier Full Height With Divider Rail">2 Panel - Single Tier Full Height With Divider Rail</option>' +
                     '<option value="2 Panel - Double Tier">2 Panel - Double Tier</option>' +
                     '<option value="3 Panel - Single Tier Full Height With Divider Rail">3 Panel - Single Tier Full Height With Divider Rail</option>' +
                     '<option value="3 Panel - Double Tier">3 Panel - Double Tier</option>';
            } else if (w >= 33 && w < 37 && h < 76) {
              return '<option value="1 Panel - Single Tier Full Height">1 Panel - Single Tier Full Height</option>' + 
                     '<option value="1 Panel - Single Tier Full Height With Divider Rail">1 Panel - Single Tier Full Height With Divider Rail</option>' +
                     '<option value="1 Panel - Double Tier">1 Panel - Double Tier</option>' +
                     '<option value="1 Panel - Single Tier Cafe">1 Panel - Single Tier Cafe</option>' + 
                     '<option value="2 Panel - Single Tier Full Height">2 Panel - Single Tier Full Height</option>' + 
                     '<option value="2 Panel - Single Tier Full Height With Divider Rail">2 Panel - Single Tier Full Height With Divider Rail</option>' +
                     '<option value="2 Panel - Double Tier">2 Panel - Double Tier</option>' +
                     '<option value="2 Panel - Single Tier Cafe">2 Panel - Single Tier Cafe</option>' + 
                     '<option value="3 Panel - Single Tier Full Height">3 Panel - Single Tier Full Height</option>' + 
                     '<option value="3 Panel - Single Tier Full Height With Divider Rail">3 Panel - Single Tier Full Height With Divider Rail</option>' +
                     '<option value="3 Panel - Double Tier">3 Panel - Double Tier</option>' +
                     '<option value="3 Panel - Single Tier Cafe">3 Panel - Single Tier Cafe</option>' + 
                     '<option value="4 Panel - Single Tier Full Height">4 Panel - Single Tier Full Height</option>' + 
                     '<option value="4 Panel - Single Tier Full Height With Divider Rail">4 Panel - Single Tier Full Height With Divider Rail</option>' +
                     '<option value="4 Panel - Double Tier">4 Panel - Double Tier</option>' +
                     '<option value="4 Panel - Single Tier Cafe">4 Panel - Single Tier Cafe</option>';
            } else if (w >= 33 && w < 37 && h >= 76 && h < 100) {
              return '<option value="1 Panel - Single Tier Full Height With Divider Rail">1 Panel - Single Tier Full Height With Divider Rail</option>' +
                     '<option value="1 Panel - Double Tier">1 Panel - Double Tier</option>' +
                     '<option value="2 Panel - Single Tier Full Height With Divider Rail">2 Panel - Single Tier Full Height With Divider Rail</option>' +
                     '<option value="2 Panel - Double Tier">2 Panel - Double Tier</option>' +
                     '<option value="3 Panel - Single Tier Full Height With Divider Rail">3 Panel - Single Tier Full Height With Divider Rail</option>' +
                     '<option value="3 Panel - Double Tier">3 Panel - Double Tier</option>' +
                     '<option value="4 Panel - Single Tier Full Height With Divider Rail">4 Panel - Single Tier Full Height With Divider Rail</option>' +
                     '<option value="4 Panel - Double Tier">4 Panel - Double Tier</option>';
            } else if (w >= 37 && w < 49 && h < 76) {
              return '<option value="2 Panel - Single Tier Full Height">2 Panel - Single Tier Full Height</option>' + 
                     '<option value="2 Panel - Single Tier Full Height With Divider Rail">2 Panel - Single Tier Full Height With Divider Rail</option>' +
                     '<option value="2 Panel - Double Tier">2 Panel - Double Tier</option>' +
                     '<option value="2 Panel - Single Tier Cafe">2 Panel - Single Tier Cafe</option>' + 
                     '<option value="3 Panel - Single Tier Full Height">3 Panel - Single Tier Full Height</option>' + 
                     '<option value="3 Panel - Single Tier Full Height With Divider Rail">3 Panel - Single Tier Full Height With Divider Rail</option>' +
                     '<option value="3 Panel - Double Tier">3 Panel - Double Tier</option>' +
                     '<option value="3 Panel - Single Tier Cafe">3 Panel - Single Tier Cafe</option>' + 
                     '<option value="4 Panel - Single Tier Full Height">4 Panel - Single Tier Full Height</option>' + 
                     '<option value="4 Panel - Single Tier Full Height With Divider Rail">4 Panel - Single Tier Full Height With Divider Rail</option>' +
                     '<option value="4 Panel - Double Tier">4 Panel - Double Tier</option>' +
                     '<option value="4 Panel - Single Tier Cafe">4 Panel - Single Tier Cafe</option>';
            } else if (w >= 37 && w < 49 && h >= 76 && h < 100) {
              return '<option value="2 Panel - Single Tier Full Height With Divider Rail">2 Panel - Single Tier Full Height With Divider Rail</option>' +
                     '<option value="2 Panel - Double Tier">2 Panel - Double Tier</option>' +
                     '<option value="2 Panel - Single Tier Cafe With Divider Rail">2 Panel - Single Tier Cafe With Divider Rail</option>' +
                     '<option value="3 Panel - Single Tier Full Height With Divider Rail">3 Panel - Single Tier Full Height With Divider Rail</option>' +
                     '<option value="3 Panel - Double Tier">3 Panel - Double Tier</option>' +
                     '<option value="3 Panel - Single Tier Cafe With Divider Rail">3 Panel - Single Tier Cafe With Divider Rail</option>' +
                     '<option value="4 Panel - Single Tier Full Height With Divider Rail">4 Panel - Single Tier Full Height With Divider Rail</option>' +
                     '<option value="4 Panel - Double Tier">4 Panel - Double Tier</option>' +
                     '<option value="4 Panel - Single Tier Cafe With Divider Rail">4 Panel - Single Tier Cafe With Divider Rail</option>';
            } else if (w >= 49 && w < 73 && h < 76) {
              return '<option value="2 Panel - Single Tier Full Height">2 Panel - Single Tier Full Height</option>' + 
                     '<option value="2 Panel - Single Tier Full Height With Divider Rail">2 Panel - Single Tier Full Height With Divider Rail</option>' +
                     '<option value="2 Panel - Double Tier">2 Panel - Double Tier</option>' +
                     '<option value="2 Panel - Single Tier Cafe">2 Panel - Single Tier Cafe</option>' + 
                     '<option value="3 Panel - Single Tier Full Height">3 Panel - Single Tier Full Height</option>' + 
                     '<option value="3 Panel - Single Tier Full Height With Divider Rail">3 Panel - Single Tier Full Height With Divider Rail</option>' +
                     '<option value="3 Panel - Double Tier">3 Panel - Double Tier</option>' +
                     '<option value="3 Panel - Single Tier Cafe">3 Panel - Single Tier Cafe</option>' + 
                     '<option value="4 Panel - Single Tier Full Height">4 Panel - Single Tier Full Height</option>' + 
                     '<option value="4 Panel - Single Tier Full Height With Divider Rail">4 Panel - Single Tier Full Height With Divider Rail</option>' +
                     '<option value="4 Panel - Double Tier">4 Panel - Double Tier</option>' +
                     '<option value="4 Panel - Single Tier Cafe">4 Panel - Single Tier Cafe</option>' + 
                     '<option value="4 Panel - Single Tier Cafe With Divider Rail">4 Panel - Single Tier Cafe With Divider Rail</option>' +
                     '<option value="6 Panel - Single Tier Full Height">6 Panel - Single Tier Full Height</option>' + 
                     '<option value="6 Panel - Single Tier Full Height With Divider Rail">6 Panel - Single Tier Full Height With Divider Rail</option>' +
                     '<option value="6 Panel - Double Tier">6 Panel - Double Tier</option>' +
                     '<option value="6 Panel - Single Tier Cafe">6 Panel - Single Tier Cafe</option>';
            } else if (w >= 49 && w < 73 && h >= 76 && h < 100) {
              return '<option value="2 Panel - Single Tier Full Height With Divider Rail">2 Panel - Single Tier Full Height With Divider Rail</option>' +
                     '<option value="2 Panel - Double Tier">2 Panel - Double Tier</option>' +
                     '<option value="3 Panel - Single Tier Full Height With Divider Rail">3 Panel - Single Tier Full Height With Divider Rail</option>' +
                     '<option value="3 Panel - Double Tier">3 Panel - Double Tier</option>' +
                     '<option value="4 Panel - Single Tier Full Height With Divider Rail">4 Panel - Single Tier Full Height With Divider Rail</option>' +
                     '<option value="4 Panel - Double Tier">4 Panel - Double Tier</option>' +
                     '<option value="6 Panel - Single Tier Full Height With Divider Rail">6 Panel - Single Tier Full Height With Divider Rail</option>' +
                     '<option value="6 Panel - Double Tier">6 Panel - Double Tier</option>';
            } else if (w >= 73 && w < 109 && h < 76) {
              return '<option value="3 Panel - Single Tier Full Height">3 Panel - Single Tier Full Height</option>' + 
                     '<option value="3 Panel - Single Tier Full Height With Divider Rail">3 Panel - Single Tier Full Height With Divider Rail</option>' +
                     '<option value="3 Panel - Double Tier">3 Panel - Double Tier</option>' +
                     '<option value="3 Panel - Single Tier Cafe">3 Panel - Single Tier Cafe</option>' + 
                     '<option value="4 Panel - Single Tier Full Height">4 Panel - Single Tier Full Height</option>' + 
                     '<option value="4 Panel - Single Tier Full Height With Divider Rail">4 Panel - Single Tier Full Height With Divider Rail</option>' +
                     '<option value="4 Panel - Double Tier">4 Panel - Double Tier</option>' +
                     '<option value="4 Panel - Single Tier Cafe">4 Panel - Single Tier Cafe</option>' + 
                     '<option value="6 Panel - Single Tier Full Height">6 Panel - Single Tier Full Height</option>' + 
                     '<option value="6 Panel - Single Tier Full Height With Divider Rail">6 Panel - Single Tier Full Height With Divider Rail</option>' +
                     '<option value="6 Panel - Double Tier">6 Panel - Double Tier</option>' +
                     '<option value="6 Panel - Single Tier Cafe">6 Panel - Single Tier Cafe</option>';
            } else if (w >= 73 && w < 109 && h >= 76 && h < 100) {
              return '<option value="3 Panel - Single Tier Full Height With Divider Rail">3 Panel - Single Tier Full Height With Divider Rail</option>' +
                     '<option value="3 Panel - Double Tier">3 Panel - Double Tier</option>' +
                     '<option value="4 Panel - Single Tier Full Height With Divider Rail">4 Panel - Single Tier Full Height With Divider Rail</option>' +
                     '<option value="4 Panel - Double Tier">4 Panel - Double Tier</option>' +
                     '<option value="6 Panel - Single Tier Full Height With Divider Rail">6 Panel - Single Tier Full Height With Divider Rail</option>' +
                     '<option value="6 Panel - Double Tier">6 Panel - Double Tier</option>';
            } else if (w >= 109 && w < 144 && h < 76) {
              return '<option value="4 Panel - Single Tier Full Height">4 Panel - Single Tier Full Height</option>' + 
                     '<option value="4 Panel - Single Tier Full Height With Divider Rail">4 Panel - Single Tier Full Height With Divider Rail</option>' +
                     '<option value="4 Panel - Double Tier">4 Panel - Double Tier</option>' +
                     '<option value="4 Panel - Single Tier Cafe">4 Panel - Single Tier Cafe</option>' + 
                     '<option value="6 Panel - Single Tier Full Height">6 Panel - Single Tier Full Height</option>' + 
                     '<option value="6 Panel - Single Tier Full Height With Divider Rail">6 Panel - Single Tier Full Height With Divider Rail</option>' +
                     '<option value="6 Panel - Double Tier">6 Panel - Double Tier</option>' +
                     '<option value="6 Panel - Single Tier Cafe">6 Panel - Single Tier Cafe</option>';
            } else if (w >= 109 && w < 144 && h >= 76 && h < 100) {
              return '<option value="4 Panel - Single Tier Full Height With Divider Rail">4 Panel - Single Tier Full Height With Divider Rail</option>' +
                     '<option value="4 Panel - Double Tier">4 Panel - Double Tier</option>' +
                     '<option value="6 Panel - Single Tier Full Height With Divider Rail">6 Panel - Single Tier Full Height With Divider Rail</option>' +
                     '<option value="6 Panel - Double Tier">6 Panel - Double Tier</option>';
            } else {
              total.setStyle('display', 'block');
              total.getElements('strong').setStyle('display', 'none');
              total_price.set('html', '<a href="/contact">Call for Pricing</a>');
              calculate.set('disabled', true);
              var swf = new Swiff('/media/img/pricing/plantation-error.png', swf_opts);
              return '<option disabled="true">Desired Configuration Not Shown</option>';
            }
          }).run([width_full(), height_full()]);
        }
        
        if (!options.match(/disabled="true"/))
        {
          options = '<option></option>' + options;
          options = options + '<option>Desired Configuration Not Shown</option>';
          unit_configuration.set('disabled', false);
        }
        else
        {
          unit_configuration.set('disabled', true);
        }
        // Insert the options we just made into the select
        unit_configuration.set('html', options);
        
      } else {
        // Get the field back to a dislabled state
        unit_configuration.set('disabled', true);
        unit_configuration.set('html', '<option>Make Selections in All Areas Above First...</option>');
      }
    });
    
    calculate.addEvent('click', function(event) {
      event.stop();
      
      // Only calculate if all of the fields are set
      if (fields_ready(true)) {
        total.setStyle('display', 'block');
        total.getElements('strong').setStyle('display', 'inline');
        // Price calculator
        (function() {
          var unit = unit_configuration.get('value').charAt(0).toInt();
          if (unit_configuration.get('value').test('Double Tier')) { unit *= 2; }
          
          var style = shutter_style.get('value').substr(2).toFloat();
          var price = ( width_full().toFloat()
                      * height_full().toFloat()
                      * style.toFloat() )
                    + ( unit.toFloat() * (14).toFloat() );
                      
          total_price.set('text', '$' +  price.toFixed(2).toString());
        }).run();
        
        // The Flash stuff, in a function so I can collapse in TextMate
        (function() {
          var url = '/media/{long}_animations/{short}-{length}pan-{type}.swf';
          var unit = unit_configuration.get('value');
          var opts = $H();

          // See if it traditiona or plantation
          if (shutter_style.get('value').charAt(0) == 'T') {
            opts.combine({ 'long' : 'traditional', 'short' : 'trad' });
          } else {
            opts.combine({ 'long' : 'plantation', 'short' : 'plan' });
          }

          // Set the shutter length
          opts.set('length', unit.charAt(0));

          // Set the Type of shutter
          if (unit.test('Cafe')) {
            opts.set('type', 'cafe');
          } else if (unit.test('Divider')) {
            opts.set('type', 'div');
          } else if (unit.test('Full Height')) {
            opts.set('type', '1t');
          } else if (unit.test('Double Tier')) {
            opts.set('type', '2t');
          }

          url = url.substitute(opts);
          var swf = new Swiff(url, swf_opts);
          
        }).run()
      }else{alert('Please be sure all fields are selected.');}
      
      // We had to hack a "new" option for desired configuration not show at the last minute. Eff
      if (total_price.get('text') == '$NaN')
      {
        total.setStyle('display', 'block');
        total.getElements('strong').setStyle('display', 'none');
        total_price.set('html', '<a href="/contact">Call for Pricing</a>');
        if (shutter_style.get('value').charAt(0) == 'T') {
          var swf = new Swiff('/media/img/pricing/traditional-error.png', swf_opts);
        } else {
          var swf = new Swiff('/media/img/pricing/plantation-error.png', swf_opts);
        }
      }
    });
    
  }
  
});
