function collapseThisList(listObject){

  var itemsToCollapse;

  itemsToCollapse = listObject.find('label').not('.is-checked').parents('li');
  itemsToCollapse.slideUp('slow');
  //only show the "li SHOW FULL LIST" if there 1 or more items in the list not counting the selected item and the "SHOW" item
  if(itemsToCollapse.length > 0){listObject.find('.showList').slideDown('slow');}
}

function expandThisList(listObject){

  var itemsToExpand, oldItem;

  itemsToExpand  = listObject.find('label').not('.is-checked').parents('li').slideDown('slow');
  oldItem        = listObject.find('label.is-checked').removeClass('is-checked');
  listObject.find('input:radio:checked').attr('checked', '');
  var radioObj = listObject.find('input');
  var radioLength = radioObj.length;
  for(var i = 0; i < radioLength; i++) {
    radioObj[i].checked = false;
  }

  listObject.find('.showList:visible').slideUp('slow');
}

$(document).ready(function(){

  var toolTips = $('.has-tooltip');
  var toolTipsLength = toolTips.length;
  //on focus and blur same as hover should occur
  if( toolTipsLength >= 0 ){
    toolTips.each(function(){
      var tempThis = $(this);
      var tempThisInput = tempThis.find('input:visible')
      tempThisInput.focus(function(){
        tempThis.addClass('hover');
      });
      tempThisInput.blur(function(){
        tempThis.removeClass('hover');
      });
    });
  }
  //add ie hover class for compatability
  if( $('html.ie').length >= 0 && toolTipsLength >= 0 ){
    toolTips.each(function(){
      var tempThis = $(this);
      tempThis.hover(function(){
        tempThis.addClass('hover');
      },function(){
        tempThis.removeClass('hover');
      });
    });
  }
  //form functions	
  var summaryMoreInfo = $('summary a.more-info');
  if(summaryMoreInfo.length > 0){
    summaryMoreInfo.live('click', function(){
      var tempThis = $(this);
      tempThis.parents("details").children().not('summary').slideDown();
      tempThis.parents("details").find('summary').slideUp();
      
    });
  }
  
  var summaryLessInfo = $('details a.less-info');
  if(summaryLessInfo.length > 0){
    summaryLessInfo.live('click', function(){
      var tempThis = $(this);
      tempThis.parents("details").children().not('summary').slideUp();
      tempThis.parents("details").find('summary').slideDown();
    });
  }

  $('.enhanced-input-list input').live('change', function(){
    //variable declarations
    var listObject, currentlySelectedItem, clickedItem, idToUpdate, allSelected, selectionName = '';

    listObject             = $(this).parents('.enhanced-input-list');
    currentlySelectedItem  = (listObject.find('label.is-checked').length <= 0 ) ? listObject.find('label.was-checked') : listObject.find('label.is-checked') ;
    idToUpdate             = listObject.attr('data-update-id');
    
    if(  currentlySelectedItem.next('input:not(:checked)').length > 0 ){
      currentlySelectedItem.removeClass('is-checked').removeClass('was-checked');
    }
    
    allSelected = listObject.find('input:checked');
    var loopLength =  allSelected.length;
    for(var i = 0; i < loopLength; i++){
      var tempSelected = $(allSelected[i]);
      if( tempSelected.is('input:radio') === true ){
        var pureVal = tempSelected.val();
        var modifiedVal = '/' + pureVal;
        selectionName = selectionName + modifiedVal;
        tempSelected.prev('label').addClass('is-checked');
      }
      if( tempSelected.is('input:checkbox') === true ){
        tempSelected.prev('label').addClass('was-checked');
      }
    }
    
    if(listObject.hasClass('radio') === true){
      collapseThisList(listObject);
    }

    
  });//END $('.enhanced-input-list input').live('change', function(){
  
  var isPreChecked = $('input:checked');
  if( isPreChecked.length > 0){
    isPreChecked.trigger('change');
  }

});

