function preloadHoverImages() {
  $("img").each(function() {
  
    var src = $(this).attr("src");
    if(src && src.indexOf("base") != -1) {
    
      var img = new Image();
      img.src = src.replace(/base/, "hover");
    }
  });
} 

function preloadDetailImages() {
  $("img").each(function() {
  
    var src = $(this).attr("src");
    if(src && src.indexOf("thumbs") != -1) {
    
      var img = new Image();
      img.src = src.replace(/thumbs/, "details");
    }
  });
}

$(document).ready(function() {
  $(".sort-arrow").hover(function() {
    $(this).attr("src", "/images/arrow-up-selected.png");
  }, function() {
    $(this).attr("src", "/images/arrow-up.png");    
  });
})

//
// On Document Ready...
//
// ...roll over code for images
// 
$(document).ready(function() {
 
   // load the hover images
   preloadHoverImages();
   
   // load the images for the detail page
   preloadDetailImages();
   
   // assign the rollover code
   $(".ro").hover(
     function() {
     
       var src = $(this).attr("src");
       if (src) {
         $(this).attr("src", src.replace(/base/, "hover"));
       }
     },
     function() {
     
       var src = $(this).attr("src");
       if (src) {
         $(this).attr("src", src.replace(/hover/, "base"));
       }
     }
   );

 // "cleanup" of email addresses
 $("a").each(function() {
   
   var href = $(this).attr("href");
   if (href && href.indexOf(" [at] ") > 0) {
     href = href.replace(/ \[at\] /, "@");
     $(this).attr("href", href);
   }   
 });

 //Dynamic loading of cities
 $selectedState = '';
 $("#state").change(function(){
      $(this).children("option:selected").each(function() {
        $val = $(this).val();
        if($val && $val != '') {
          if($val != $selectedState) { 
            
            $.get('/_ajax/xmlCities', { 'state': $val }, function(xml) {
              $("#city").children().remove();
              $("#city").append('<option value="all">City</option>');
              $('city', xml).each(function() {
                var city = $(this).text();
                $("#city").append('<option value="'+ city +'">'+ city +'</option>');
              });
            });
            
            $.get('/_ajax/xmlCounties', { 'state': $val }, function(xml) {
              $("#county").children().remove();
              $("#county").append('<option value="all">County</option>');
              $('county', xml).each(function() {
                var county = $(this).text();
                $("#county").append('<option value="'+ county +'">'+ county +'</option>');
              });
            });            
            
          }
        } 
      });
 });
 
 $selectedCounty = '';
 $("#county").change(function(){
 
      $(this).children("option:selected").each(function() {
        $val = $(this).val();
        if($val && $val != '') {
          if($val != $selectedCounty) { 
            
            $.get('/_ajax/xmlCities', { 'county': $val, 'curState': $("#state").val() }, function(xml) {
              $("#city").children().remove();
              $("#city").append('<option value="all">City</option>');
              $('city', xml).each(function() {
                var city = $(this).text();
                $("#city").append('<option value="'+ city +'">'+ city +'</option>');
              });
            });
                    
          }
        } 
      });
 });
 
 //Clear default text from text box when clicked
 $('#content .col-left input').focus(function(){
  var defaultText = $(this).val();
  $(this).val('');
     //Reset default text from text box when deselected outside of box
    //$('#content .col-left input').blur(function(){
    // $(this).$val(defaultText);
    //});
 });

});




function toggleEditor(id) {
  if (!tinyMCE.get(id))
  tinyMCE.execCommand('mceAddControl', false, id);
  else
  tinyMCE.execCommand('mceRemoveControl', false, id);
}

