$(document).ready(function(){
  function addMega(){
    $(this).addClass("hovering");
  }

  function removeMega(){
    $(this).removeClass("hovering");
  }

  var megaConfig = {
    interval: 50,
    sensitivity: 1,
    over: addMega,
    timeout: 200,
    out: removeMega
  };

  $("li.mega").hoverIntent(megaConfig).find("a").removeAttr("title");

  //$("li.mega div.content").corner("6px cc:transparent keep");

  $(".mega div.close").click(function(){
    $(this).parents("li").removeClass("hovering");
  });
  
  
  /* fast search */
  //
  $("#fastsearch li .radio").click(function(){
    var st_class = $(this,":checked").val().toLowerCase();

    // reset all options to not selected
    // $("#fastsearch .towns select option").removeAttr("selected");
  
    // select all town select menus
    $("#fastsearch .towns select")
    // remove name attribute from all
    .removeAttr("name") // remove name attribute to prevent duplicate values
    .hide() // hide all towns select menus

    .filter("." + st_class) // selects only the chosen state
    .attr("name","_areas[]") // add back name attribute
    .show(); // display

    // select default option. Needed for safari and chrome browsers
    // $("select."+st_class+" option:first").attr("selected","selected");
  
  });
  
  $("#fastsearch li.towns .radio:checked").click();
  
  
  /* map search hover effects */
  var el_class = "";
  // hoverIntent config for map overs
  var mapConfig = {
     interval: 10,
     sensitivity: 1,
     over: mapOver,
     timeout: 1,
     out: mapOut
  };
  
   function mapOver() { // in
    el_class = $(this).attr("class").toLowerCase();
    $("#region-hovers ." + el_class).show();
  }
  
  function mapOut() { // out
    el_class = $(this).attr("class").toLowerCase();
    $("#region-hovers ." + el_class).fadeOut(400);
  }
  
  // bind hover effect to map areas and text links
  $("#ne-map-img-map area, ul.regions a").hoverIntent(mapConfig);
  
  // do the slideshow
  $('#imageContainer').cycle({
    fx:     'fade',
    timeout: 4000
  });
  
  $('#pauseButton').click(function() {
    $('#imageContainer').cycle('pause');
  });
  
});

