//
// On Document Ready...
//
// ...roll over code for images
// 
$(document).ready(function() {
   // load the checked images
   preloadCheckedImages();
   
   // code to swap hover image with checked image
   $(".ro").toggle(
     function() {
       var src = $(this).attr("src");
       $(this).attr("src", src.replace(/hover/, "checked"));

       //Click corresponding hidden checkbox when image is checked
       $src = $(this).attr("src");
       $fname = $src.substr($src.indexOf('checked/') + 8);
       $cbox = $fname.substr(0, $fname.length - 4); 
       
       $("#"+$cbox).click();
     },
     function() {
       var src = $(this).attr("src");
       $(this).attr("src", src.replace(/checked/, "hover"));

       //click corresponding hidden checkbox when image is unchecked
       $src = $(this).attr("src");
       $fname = $src.substr($src.indexOf('hover/') + 6);
       $cbox = $fname.substr(0, $fname.length - 4); 
       
       $("#"+$cbox).click();
     }
   );

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