/**
* ÆÄÀÏ¸í: lib.rollover.js
* ¼³  ¸í: ·Ñ¿À¹ö ÀÚµ¿È­ ¶óÀÌºê·¯¸®
* ÀÛ¼ºÀÚ: jstoy project
* ³¯  Â¥: 2003-11-01
*
* 2002-11-05: °ÅÄ£¸¶·ç
* 2003-10-24: xtac.net
* 2003-10-29: laintt
* 2003-10-30: Çàº¹ÇÑ °í´Ï
***********************************************
*/

Roll = function() {
    this.outMark    = "_off";
    this.overMark   = "_on";
    if (!document.body.getAttribute) return false;
    this.outSearch= new RegExp(this.outMark + "(\.[^\.]+)$");
    this.init(document.images);
    if (document.getElementsByTagName) this.init(document.getElementsByTagName("input"));
}
Roll.prototype.init = function(imgs) {
    var classObj = this;
    var preload = new Array;
    for (var i=0, s=imgs.length; i<s; i++) {
        if (!imgs[i].getAttribute("oversrc") && imgs[i].getAttribute("roll")===null) continue;
        if (!imgs[i].getAttribute("oversrc")) imgs[i].setAttribute("oversrc", imgs[i].src.replace(this.outSearch, this.overMark+"$1"));
        if (imgs[i].getAttribute("oversrc")==imgs[i].src) continue;
        preload[i] = new Image;
        preload[i].src = imgs[i].getAttribute("oversrc");
        imgs[i].setAttribute("orgsrc", imgs[i].src);
        imgs[i].overAction = imgs[i].onmouseover;
        imgs[i].outAction  = imgs[i].onmouseout;
        imgs[i].onmouseover= function() {classObj.doOver(this);}
        imgs[i].onmouseout = function() {classObj.doOut(this);}
    }
}
Roll.prototype.doOver = function(img) {
    img.src = img.getAttribute("oversrc");
    if(typeof(img.overAction) != 'undefined') img.overAction();
}
Roll.prototype.doOut = function(img) {
    img.src = img.getAttribute("orgsrc");
    if(typeof(img.outAction) != 'undefined') img.outAction();
}