var RollLoadAction=window.onload;
window.onload=function(){
  try {RollLoadAction();}
  catch (e) {}
  new Roll;
}
Roll=function(){
  this.outMark="_off";this.overMark="_on";this.selectMark="_sel";
  if(!document.body.getAttribute)return false;
  this.outSearch=new RegExp(this.outMark+"(\.[^\.]+)$");
  this.imgs=document.images;
  if(document.getElementsByTagName){
    for(var i=0;i<document.getElementsByTagName("input").length;i++)
      this.imgs[this.imgs.length]=document.getElementsByTagName("input")[i];
  }this.init();
}
Roll.prototype.init=function(){
  var classObj=this;
  var preload=new Array;
  for (var i=0,s=this.imgs.length;i<s;i++) {
    this.imgs[i].setAttribute("orgsrc",this.imgs[i].src);
    if(this.imgs[i].getAttribute("oversrc")||this.imgs[i].getAttribute("roll")!==null) {
      if(!this.imgs[i].getAttribute("oversrc"))this.imgs[i].setAttribute("oversrc",this.imgs[i].src.replace(this.outSearch,this.overMark+"$1"));
      if(this.imgs[i].getAttribute("oversrc")==this.imgs[i].src)continue;
      var preload_next=preload.length;
      preload[preload_next]=new Image;
      preload[preload_next].src=this.imgs[i].getAttribute("oversrc");
      this.imgs[i].overAction=this.imgs[i].onmouseover;
      this.imgs[i].outAction=this.imgs[i].onmouseout;
      this.imgs[i].onmouseover=function(){classObj.doOver(this);}
      this.imgs[i].onmouseout=function(){classObj.doOut(this);}
    }
    if(this.imgs[i].getAttribute("group")!=null){
      if(!this.imgs[i].getAttribute("selsrc"))this.imgs[i].setAttribute("selsrc",this.imgs[i].src.replace(this.outSearch,this.selectMark+"$1"));
      var preload_next=preload.length;
      preload[preload_next]=new Image;
      preload[preload_next].src=this.imgs[i].getAttribute("selsrc");
      if(this.imgs[i].getAttribute("selected") !== null){
        this.imgs[i].setAttribute("fl_select",1);
        this.imgs[i].src=this.imgs[i].getAttribute("selsrc");
      }
      //this.imgs[i].clickAction=this.imgs[i].onclick;
      //this.imgs[i].onclick=function(){classObj.doClick(this);}
    }
  }
}
Roll.prototype.doOver=function(img){
  if(img.getAttribute("fl_select")!=1)img.src=img.getAttribute("oversrc");
  if(typeof img.overAction!='undefined')img.overAction();
}
Roll.prototype.doOut=function(img){
  if(img.getAttribute("fl_select")!=1)img.src=img.getAttribute("orgsrc");
  if(typeof img.outAction!='undefined')img.outAction();
}
Roll.prototype.doClick=function(img){
  for(var i=0,s=this.imgs.length;i<s;i++){
    if(this.imgs[i].getAttribute("group")==img.getAttribute("group")&&this.imgs[i].getAttribute("fl_select")==1){
      this.imgs[i].setAttribute("fl_select",0);
      this.imgs[i].src=this.imgs[i].getAttribute("orgsrc");
    }
  }
  img.setAttribute("fl_select",1);img.src=img.getAttribute("selsrc");
  if(typeof img.clickAction!='undefined')img.clickAction();
}
