function toggleStepLadderOffer(jqParent, performClick) {
  var jqContent = jqParent.find('div.offer-container')
  var jqCheckbox = jqParent.find('.offer-selection-elements input[@type=checkbox]')
  var domCheckbox = jqCheckbox[0]
  var jqCheckboxImage = jqParent.find('.offer-selection-elements .image')
  var isChecked = domCheckbox.checked

  if (performClick) {
    domCheckbox.checked = !domCheckbox.checked
    isChecked = !isChecked
  }

  var newImageStatus = '_on'

  if (isChecked) {
    if (!jqContent.is(':visible')) {
      if (performClick) {
        jqContent.slideDown()
      } else {
        jqContent.show()
      }
    }
  } else {
    jqContent.slideUp()
    newImageStatus = '_off'
  }

  var newImageSource = jqCheckboxImage.attr('src').replace(/_on\.|_off\./, newImageStatus + '.')
  if (newImageSource != jqCheckboxImage.attr('src')) {
    jqCheckboxImage.attr('src', newImageSource)
  }
}



jQuery(document).ready(function(){
  /////////////////////////////////////////////////////////
  // OFFER SELECTION
  jQuery('.offer-selection .hot-area').click(function(){
    var jqCheckbox = jQuery(this).find('input[@type=checkbox]')
    var jqCheckboxImage = jQuery(this).find('.offer-selection-image')

    jqCheckbox.click()
    var isChecked = jqCheckbox.attr('checked')

    var newImageStatus = '_off'

    if (isChecked) {
      newImageStatus = '_on'
    }

    var newImageSource = jqCheckboxImage.attr('src').replace(/_on\.|_off\./, newImageStatus + '.')
    if (newImageSource != jqCheckboxImage.attr('src')) {
      jqCheckboxImage.attr('src', newImageSource)
    }
  }) 

  
  /////////////////////////////////////////////////////////
  // STEP-LADDER
  jQuery('ul.step-ladder div.offer-description').click(function(){
    var jqParent = jQuery(this).parent('li')
    toggleStepLadderOffer(jqParent, true)
  })

  // Show all offers that are selected (they will be hidden by default
  // even though the browser may have the checkbox selected)
  jQuery('ul.step-ladder div.offer-description').each(function(){
    var jqParent = jQuery(this).parent('li')
    toggleStepLadderOffer(jqParent, false)
  })

  /////////////////////////////////////////////////////////
  // PATH FORM
  jQuery('#path-form').submit(function(){ return Path.validateForm() })
  jQuery('#path-form .skip-button').click(function(){ return Path.skipOffer() })

  jQuery('.element-wrapper input:not(:hidden,:image),select').each(function() {
    jQuery(this).focus(function(){
      jQuery(this).addClass('field-being-fixed')
    })
  })

})
