// This is the implementation of SimpleSwap
// by Jehiah Czebotar (modified by Stefan Pantiru July 25, 2005)
// Version 1.1 - June 10, 2005
// Distributed under Creative Commons
//
// Include this script on your page
// then make image rollovers simply by adding a image_over.jpg in
// the directory where you hold image.jpg. Note: it'll have to be
// in the toolbars directory when supposely you keep your toolbar buttons
// which need swapping
//
// http://jehiah.com/archive/simple-swap
//


function SimpleSwap(el,which){
    var current_img = el.getAttribute("src");
    if (which == "oversrc"){
        if (current_img.indexOf("over")==-1)
        el.src = current_img.substring(0,current_img.length-4)+"_over.jpg";
    } else {
        if (current_img.indexOf("over")>-1)
        el.src = current_img.substring(0,current_img.length-9)+".jpg";
    }
}

function SimpleSwapSetup(){
  var x = document.getElementsByTagName("img");
  var i=0;

  for (i=0;i<x.length;i++){
    var oversrc = x[i].getAttribute("src");
    // feel free to change "toolbars" with the dir where you have the
    // xxxx.yyy and xxxx_over.yyy images
    if (oversrc.indexOf("toolbars")==-1)
        continue;

    oversrc = oversrc.substring(0,oversrc.length-4)+"_over.jpg";

    // preload image
    // comment the next two lines to disable image pre-loading
    x[i].oversrc_img = new Image();
    x[i].oversrc_img.src=oversrc;
    // set event handlers
    x[i].onmouseover = new Function("SimpleSwap(this,'oversrc');");
    x[i].onmouseout = new Function("SimpleSwap(this);");
  }
}

var PreSimpleSwapOnload =(window.onload)? window.onload : function(){};
window.onload = function(){PreSimpleSwapOnload(); SimpleSwapSetup();}

