﻿//Image rollover

//image filenames must be in the format 'filename.ext' and 'filename-on.ext'

 

Rollover = function()

{

      //empty constructor

}

 

//Static function turns on the rollover image

Rollover.turnOn = function(element)

{

      //Get the image element

      var img = element;

 

      //Get the filename portion minus the extension

      var filename = img.src.substr(0, img.src.lastIndexOf('.'));

 

      //Get the extension portion

      var extension = img.src.substr(img.src.length - 4, 4);

 

      //insert '-on' between the filename and extension and set it as the new src

      img.src = filename + '-on' + extension;

}

 

//Static function turns off the rollover image

Rollover.turnOff = function(element)

{

      // //Get the image element

      var img = element;

 

      //Get the filename portion minus the extension, also removed the '-on'

      var filename = img.src.substr(0, img.src.lastIndexOf('.') - 3);

 

      //Get the extension portion

      var extension = img.src.substr(img.src.length - 4, 4);

 

      //Set the combined name as the new img src

      img.src = filename + extension;

}

