// replace submit buttons by pictures
replaceSubmitButtons = function() {
  var img_btn_ok = $('<img src="http://www.environnement-online.com/img/btn/btn_ok_off.png" width="20" height="13" border="0" class="roll" alt="OK" />');
  $("input.ok_button").replaceWith($(img_btn_ok).addClass("submit"));
}

// handle submit event on pictures
attachSubmitEvent = function(imageSelector) {
  $(imageSelector).click(
    function(){ $(this).parents("form").submit() }
  );
}

// handle rollover events on pictures
attachRollOverEvent = function(imageSelector) {
  $(imageSelector).hover(
    function(){ $(this).attr("src", $(this).attr("src").split('_off.').join('_on.')) },
    function(){ $(this).attr("src", $(this).attr("src").split('_on.').join('_off.')) }
  );
  // preload the _on picture
  $.each($(imageSelector), function(i) {
    $("<img>").attr("src", $(this).attr("src").split('_off.').join('_on.'));
  });
}

$().ready(function() {
  replaceSubmitButtons();
  attachSubmitEvent("img.submit");
  attachRollOverEvent("img.roll");
});

