// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
$(document).ready(function() {
    $("div.selector div.selection").hover(
        function () {
            $(this).addClass("hover");
        },
        function () {
            $(this).removeClass("hover");
        }
        );

    $("div.selector div.selection").click(
        function () {
            $(this).addClass("active");
            $(this).siblings().removeClass("active");
            $(this).siblings("input").val($(this).attr("preference"));
        }
        );

    $("#test_header").addClass("ui-corner-all")
});


function setupSelectors(){
  $("div.selector div.selection").hover(
        function () {
            $(this).addClass("hover");
        },
        function () {
            $(this).removeClass("hover");
        }
        );

    $("div.selector div.selection").click(
        function () {
            $(this).addClass("active");
            $(this).siblings().removeClass("active");
            $(this).siblings("input").val($(this).attr("preference"));
        }
        );
}
function log(){
  if(window.console) {
    console.log.apply(console, arguments);
  }
}

function overlayHeight(element){
  if($('div#'+element+' img').height()==0){
    div_height = $('div#'+element+' a.action.reject').offset().top - $('div#'+element+' a.action.reject').height() - 10
  }
  else{
    div_height = $('div#'+element+'').height() - $('div#'+element+' a.action.reject').height()
  }
  $('div#'+element+' div.incomplete-overlay').css({height: div_height})
}

function ajax_form_errors(error_message){
  close = "<div class='right ajax_error_close'>click to close</div>"
  $('.ajax_form_notification').html("Error: " + error_message + close).slideDown()
  .click(function(){$(this).stop().slideUp()})
  .effect("highlight", {color: '#F9D4A7'}, 3000)
}

   
function clearForm(form) {

    form = $(form);
   
    // iterate over all of the inputs for the form
   
    // element that was passed in
   
    $(':input', form).each(function() {
   
        var type = this.type;
   
        var tag = this.tagName.toLowerCase(); // normalize case
   
        // it's ok to reset the value attr of text inputs,
   
        // password inputs, and textareas
   
        if (type == 'text' || type == 'password' || tag == 'textarea')
  
            this.value = "";
  
        // checkboxes and radios need to have their checked state cleared
  
        // but should *not* have their 'value' changed
  
        else if (type == 'checkbox' || type == 'radio')
  
            this.checked = false;
  
        // select elements need to have their 'selectedIndex' property set to -1
  
        // (this works for both single and multiple select elements)
  
        else if (tag == 'select')
  
            this.selectedIndex = -1;
  
    });
  
};
