// (C) DotComFast LLC 2005
function w(t) {document.write(t);}
function getElement(id) {
    if(document.getElementById) return document.getElementById(id);
    return eval(name);
}
//
var isIEfound=0;
function isIE() {
  if(isIEfound==0) { 
    isIEfound = navigator.userAgent.indexOf('MSIE')>-1?1:-1;
 }
 return isIEfound>0;
}
// general object registry. Allocating a unique id.
if(!jsObjects) var jsObjects = new Array();
function jsObject(t) {
   var n = jsObjects.length;
   jsObjects[n]=t;
   t.uuid='jsO_'+n+'_';
	t.objname="jsObjects["+n+"]";
	t.my = function(m) { // js to invoke a method or reference a field
	   return t.objname+"."+m+";";
   }
}
function parade_vertical(parade) {
    parade.preformat = function() {
        w("<table cellspacing=0 cellpadding=4 >");
        for(i=0;i<this.srcs.length;i++) {
            w("<tr id='"+this.uid+"BOTH"+i+"' style='display:none'>");
            w("<td id='"+this.uid+"IMAGE"+i+"' valign=top ></td>")
            w(this.getTextTD(i,""));
            w("</tr>");
        }
        w("</table>");
        this.atPosition=-1;
    }
    parade.move = function() {
        var i=this.atPosition;
        if(i>=0 && i<this.image.length) {
            this.id("BOTH"+i).style.display="none";
        }
        i+=this.change;
        if(i<0|| i>=this.image.length)i=0;
        this.atPosition=i;
        this.id("BOTH"+i).style.display=isIE()?'block':'table-row';
        return 1000; 
    }
}
function parade_fade(parade) {
    parade.preformat = function() {
        w("<table width=100% xheight=100% cellspacing=0 cellpadding=0 xstyle='background-image:url("
            +'"http://ehtest/jpg/background.jpg"'+");'>");
        w("<tr>");
        w("<td style='padding:1em;-moz-opacity:0.0;filter:alpha(opacity=0)' width=30% id='"+this.uid+"TEXT0'  ></td>");
        w("<td  valign=top><div id='"+this.uid+"IMAGE'  style='background-repeat:no-repeat' ></div></td>");
        w("<td id='"+this.uid+"IMAGE1' style='display:none' ></td>");
        
        w("<td id='"+this.uid+"TEXT1' style='display:none' ></td>");
        w("</tr>");
        w("</table>");
        this.atPosition=-1;
    }
    parade.setOpacity = function(style) {
         style.opacity=this.curOpacity/100;
         if(style.filter) style.filter="alpha(opacity="+this.curOpacity+")";
    }
    parade.stepto = function(tgt) {	
         //note("Tgt "+tgt+" @"+this.curOpacity)
         var dif = tgt-this.curOpacity;
         if(dif==0) {
             if(tgt==100) {
                 this.fadecontainer.style.backgroundImage="none";
                 this.intransition=false;
                 if(this.image.length==this.srcs.length)status("Viewing "+(1+this.atPosition)+" of "+this.srcs.length);
                 return;
             }    
              this.fadingimg.src =this.fadingimg.newsrc;
              tgt=100;
              dif=100;
              getElement(this.uid+"TEXT0").innerHTML=this.getText(this.atPosition);
                         
         }
         //var wDif = this.fadecontainer.offsetWidth-this.fadingimg.offsetWidth;
         //if(dif>0 && wDif>0) {
         //       note("fix container: "+this.fadecontainer.offsetWidth+">"+this.fadingimg.offsetWidth);
         //        this.fadecontainer.style.width=Math.max(this.fadingimg.offsetWidth,this.fadecontainer.offsetWidth-(wDif*dif/20)-1);
         //}   
         this.curOpacity += (dif<0?-10:5);
         this.setOpacity(this.fadingimg.style);
         this.setOpacity(getElement(this.uid+"TEXT0").style);
         
//         this.fadingimg.style.opacity=this.curOpacity/100;
//         if(this.fadingimg.style.filter) this.fadingimg.style.filter="alpha(opacity="+this.curOpacity+")";	
         var tm= this.my("stepto("+tgt+");");
         //note(" to "+this.curOpacity+" tm="+tm+" .objname"+this.objname);
         setTimeout(tm,50);
    }
    parade.fadeto =function(img) {
	 if(this.fadingimg) {
   	      this.fadecontainer.style.backgroundImage="url('"+this.fadingimg.src+"')";
	      this.fadingimg.newsrc=img;
              this.stepto(0);
	 } else  {
	    var imgname=this.uid+"Img";
	    this.fadecontainer.innerHTML='<img  style="margin:0;-moz-opacity:0.0;filter:alpha(opacity=0)" '
         +'  id='+imgname+' src="'+img+'">';
		 this.fadingimg=document.getElementById(imgname);
                 getElement(this.uid+"TEXT0").innerHTML=this.getText(this.atPosition); 
		 this.curOpacity=0;
		 this.stepto(100);
	 } 	 
  }
    
    parade.move = function() {
        if(this.intransition)return 500;
        this.intransition=true;
        var i=this.atPosition;
        i+=this.change;
        if(i>=this.image.length && this.image.length<this.srcs.length) return 500; // wiat for more images to load
        if(i<0|| i>=this.srcs.length)i=0;
        this.atPosition=i;
        this.fadecontainer = document.getElementById(this.uid+"IMAGE");
        this.fadeto(this.srcs[i]);
        var len = this.getText(i).length;
        if(this.stop_after_move) this.stopped=true;
        this.stop_after_move=false;
        return len<50?3000:len<200?5000:10000; 
    }
    parade.loadImage = function(n) {
        if(n<this.srcs.length) {
            this.image[n]=new ParadeImage(this, n);

            getElement(this.uid+"IMAGE1").innerHTML="<img src=\""+this.srcs[n]+"\""
				+" onload='"+this.uid+".nextImage("+(n)+");' "
				+" onclick='"+this.uid+".clicked("+(n)+");' "
				+"/>";		
            getElement(this.uid+"TEXT1").innerHTML=this.getText(n);
            status("Loaded "+n+" pictures");
        }
        return true;
    }
}
function Parade(uid) {
    jsObject(this);
    parades[parades.length]=this;
    this.uid=uid;
    this.moving = true;
    this.stopped=false;
    this.pausedTime=0;
    this.moused=false;
    this.mouseInPos=0;
    this.mouseOutPos=0;
    this.change=1;
    this.stop_after_move=false;
    this.srcs = new Array();
    this.text=new Array();
    this.add = function (image_src,text) {
        this.srcs[this.srcs.length]=image_src;
        this.text[this.text.length]=text;
    }
    this.insert= function (n) {
        //alert("insert:"+this.srcs.length);
        parade_fade(this);
        if(!document.getElementById) {
            this.currentImg = 0;
            w("<table cellspacing=0 cellpadding=4 ><tr>");
            var i = 0;
            w("<td id='"+this.uid+"IMAGE"+i+"' valign=top ><img id='"+this.uid+"IMG' src='"+this.srcs[i]+"'></td>");
            w("<td  valign=middle align=center >This page uses advanced browser features to provide a moving slide show."
            +"<br>Unfortunately your browser isn't up to date enough to do it. You can get " 
            +"an updated browser, for free, from:<br>"
            +"<br>Rediscover The Web: <a href='http://www.mozilla.com/firefox/' target=_blank>Download Firefox</a>"
            +"<br>Microsoft: <a href='http://www.microsoft.com/windows/ie/' target=_blank>Internet Explorer</a>" 
            +"</td>");
            w("</tr><tr>");
            w(this.getTextTD(i,this.getText(i)));
            w("</tr></table>");
            return;
        }


        this.preformat();

        w("<div id='notes' ></div>");

        this.image = new Array();
        setTimeout(this.uid+'.loadImage(0)',10);
    }
    this.preformat = function() {
        w("<div id='"+this.uid+"Container' "
        +" style='position:static;  display:block; overflow:scroll;  width:100% '"
                  +" onmouseover='"+this.uid+".mouseover();' "
                  +" onmouseout='"+this.uid+".mouseout();' "
                  +">");
        w("<div id='"+this.uid+"Scrollable' style='position:relative; top:0'>");
        w("<table cellspacing=0 cellpadding=4 ><tr>");
        for(i=0;i<this.srcs.length;i++) {
            w("<td id='"+this.uid+"IMAGE"+i+"' valign=top ></td>");
        }
        w("</tr><tr>");
        for(i=0;i<this.srcs.length;i++) {
            w(this.getTextTD(i,""));
        }
        w("</tr></table>");
        w("</div></div>");
    }
    this.id = function(label) {
        return getElement(this.uid+label);
    }
    this.loadImage = function(n) {
        if(n<this.srcs.length) {
            this.image[n]=new ParadeImage(this, n);

            getElement(this.uid+"IMAGE"+n).innerHTML="<img src=\""+this.srcs[n]+"\""
				+" onload='"+this.uid+".nextImage("+(n)+");' "
				+" onclick='"+this.uid+".clicked("+(n)+");' "
				+"/>";		
            getElement(this.uid+"TEXT"+n).innerHTML=this.getText(n);
        }
        return true;
    }
    this.getText = function(i) {
        return typeof this.text == 'undefined'?"":i<this.text.length?this.text[i]:"";
    }
    this.getTextTD = function(i,content) {
        return "<td id='"+this.uid+"TEXT"+i+"' valign=top align=center >"+content+"</td>"
    }
    this.rotate = function() {  
        if(this.stopped || this.srcs.length==0)return;
        if (document.getElementById) {
            this.container = getElement(this.uid+"Container");
            this.scrollable = getElement(this.uid+"Scrollable");
            var sleepFor=10;
            if(this.moving) {
		        sleepFor=this.move();
                this.pausedTime=0;
	        } else {
                this.moving=this.pausedTime>1000;
                sleepFor=1000;
                this.pausedTime=1+sleepFor; 
             }
             var timeOut = setTimeout(this.uid+'.rotate()',sleepFor);
	}
    }
    this.move = function() {
        var oldV =  this.container.scrollLeft;
        this.container.scrollLeft+=this.change;
        if(oldV== this.container.scrollLeft
        && (this.change==-1 || this.srcs.length==this.image.length)) this.change=-this.change;
        return 10;
    }
    this.nextImage = function(n) {
       if(n==0)setTimeout(this.uid+'.rotate()',10);
       //note("[image "+n+" loaded]");
            this.loadImage(n+1);
     }
     this.mouseover = function() {
        this.moving=false;
        if(this.container) {
             //note("mouseover:("+this.container.scrollLeft+")");
             this.mouseInPos=this.container.scrollLeft;	 
        }
     }
     this.mouseout = function() {
        this.moving=true;
        if(this.container) {	 
             //this.moused=false;
             if(this.mouseInPos<this.container.scrollLeft) this.change=1;
             if(this.mouseInPos>this.container.scrollLeft) this.change=-1;
             //note("mouseout:("+this.mouseInPos+","+this.container.scrollLeft+")"+this.change+".");
        }
     }
     this.clicked = function(n) {
        note("[click:"+n+"]");
     }
     // play, pause, prev, next -- for vcr_buttons
     this.play = function() {
         this.stopped=false;
         this.change=1;
         this.rotate();
     }
     this.pause = function() {
         this.stopped=true;
         this.rotate();
     }
     this.next = function() {
         this.change=1;
         this.stopped=false;
         this.stop_after_move=true;
         this.rotate();
     }
     this.prev = function() {
         this.change=-1;
         this.stopped=false;
         this.stop_after_move=true;
         this.rotate();
     }

}
function ParadeImage(parg,i) {
    this.img = new Image;
    this.img.src = parg.srcs[i];
    //note("Loading " + parg.srcs[i]);
}
var notesText = "";
function note(t) {
	 //return;
    if(notesText.length>1000) notesText="";
    notesText = notesText+"; "+t;
    getElement("notes").innerHTML=notesText;    
}
function status(t) {
    getElement("status").innerHTML=t;    
}