var IE4 = (document.all);
var NS4 = (document.layers);

function moveLayerTo(layerID,x,y) {
  if (IE4) {
    document.all[layerID].style.pixelLeft=x;
    document.all[layerID].style.pixelTop=y;
  }
  else {
    document.layers[layerID].moveTo(x,y);
  }
}
//----------------------------------------------------------------
// Functions to get anchor locations in the document.
// make sure to call this function after the page loads
//----------------------------------------------------------------
function IG_getLeft(ll) {
  if (ll.offsetParent){return (ll.offsetLeft + IG_getLeft(ll.offsetParent));}
  else {return (ll.offsetLeft);}
}

function IG_getTop(ll) {
  if (ll.offsetParent){return (ll.offsetTop + IG_getTop(ll.offsetParent));}
  else {return (ll.offsetTop);}
}

function IG_getAnchorPos(anchorName, valNeeded){
  if (anchorName==null && valNeeded==null && (this)){
	anchorName = this.anchorName;
	this.anchorObj = (IE4) ? eval("document.all['"+anchorName+"']") : 	eval("document.anchors['"+anchorName+"']");

    if (IE4){
        this.topanchorPos = IG_getTop(this.anchorObj);
        this.leftanchorPos = IG_getLeft(this.anchorObj);
    }
    if (NS4){
        this.topanchorPos = this.anchorObj.y;
        this.leftanchorPos = this.anchorObj.x;
    }
    return;
  }
  anchorObj = (IE4)? eval("document.all['"+anchorName+"']") : 	eval("document.anchors['"+anchorName+"']");
  if (valNeeded=="left"){return (IE4)? IG_getLeft(anchorObj) : anchorObj.x;}
  if (valNeeded=="top"){return (IE4)? IG_getTop(anchorObj) : anchorObj.y;}
}

function showLayer(_layerID,_top,_left,_width,_height,_zIndex,_layerHTML,IEstyleExtra) {

if(IEstyleExtra==null)IEstyleExtra="";
  if (IE4) {
    document.body.insertAdjacentHTML("BeforeEnd",('<div id="'+_layerID+'" style="position:absolute; '+IEstyleExtra+' top:'+_top+'; left:'+_left+'; width:'+_width+'; height:'+_height+'; clip:rect(0px,'+_width+'px,'+_height+'px,0px); visibility:visible; z-index:'+_zIndex+';">'+_layerHTML+'</div>'));
  }
  else {
    document.layers[_layerID]=new Layer(_width);
    with (document.layers[_layerID]) {
      height=_height;
      top=_top; left=_left;
      clip.top=0; clip.left=0; clip.bottom=_height; clip.right=_width;
      zIndex=_zIndex;
      document.open("text/html"); document.writeln(_layerHTML); document.close();
      visibility="show";
    }
  }
}
function hideLayer(layerID) {
  if (IE4) {
    document.all[layerID].style.visibility="hidden";
  }
  else {
    document.layers[layerID].visibility="hide";
  }
}



//Meter version 1---------------------------------
function checkload(){

if(this.LB_imageNUM==this.nImages){this.hideMeterLayer();clearTimeout(this.meterTimer);return;}

	if(this.imageArray[this.LB_imageNUM]){
	  if(this.imageArray[this.LB_imageNUM].complete){
	   	this.LB_imageNUM++;
		//this.dispbars();
		this.updateTextView();
	    setTimeout(this.Name+".checkload()", 100);
	  }
	  else{setTimeout(this.Name+".checkload()", 100);}
	}

}
function loadSlides(){
  if(document.images){
  	if (!this.timer){
	  
      this.xposition=IG_getAnchorPos(this.Anchorname,"left");
      this.yposition=IG_getAnchorPos(this.Anchorname,"top");
	  
	  this.clockX=this.xposition+this.clockRadius;
	  this.clockY=this.yposition+this.clockRadius;
	  
	  this.setMeterLayer();
	  this.moveMeter();
	  //this.timer= new meterTimer(this.Name,xposition,yposition,speed);
	}  
  
    for(i=0; i<this.nImages; i++){
	   this.imageArray[i]=new Image;
	   this.imageArray[i].src=this.ImgArray[i];
	}

    setTimeout(this.Name+".checkload()" ,100);
  }
}
function setMeterLayer() {
  showLayer("clock",this.clockY-this.clockSpace,this.clockX-this.clockSpace,this.clockSize,this.clockSize,3,'<img src="'+this.clockImage.src+'" width='+this.clockSize+' height='+this.clockSize+' border=0 align=top>');
  showLayer("meter",this.clockY-this.clockSpace-this.meterRadius,this.clockX-this.clockSpace-this.meterRadius,this.meterSize,this.meterSize,3,'<img src="'+this.meterImage.src+'" width='+this.meterSize+' height='+this.meterSize+' border=0 align=top>');
  showLayer("loadText",this.clockY-this.clockRadius,this.clockX+this.clockRadius+this.clockSpace+2,100,15,5,'<font size=1 face="Verdana" color="#0033FF">'+this.loadingText+' '+this.LB_imageNUM+'/'+this.nImages+'</font>');
}
function hideMeterLayer(){
  hideLayer("clock");
  hideLayer("meter");
  hideLayer("loadText");
}
function updateTextView(){
  var textLayer=(IE4)? eval("document.all.loadText") : eval("document.layers['loadText']");
  if(IE4){
    textLayer.innerHTML='<font size=1 face="Verdana" color="#0033FF"><nobr>'+this.loadingText+' '+this.LB_imageNUM+'/'+this.nImages+'</nobr></font>';
  }
  if(NS4){
   with (textLayer){
    document.open("text/html"); document.writeln('<font size=1 face="Verdana" color="#0033FF">'+this.loadingText+' '+this.LB_imageNUM+'/'+this.nImages+'</font>'); document.close();
   }
  }
}

function moveMeter() {
  this.meterStep=(this.meterStep>0) ? this.meterStep-1 : this.meterSlice-1;
  moveLayerTo("meter",this.clockX+this.meterOffset[this.meterStep].x-this.meterRadius,this.clockY-this.meterOffset[this.meterStep].y-this.meterRadius);

  /*if (this.meterStep==this.meterCenter) {
	this.meterTimer=setTimeout(this.parentSlideshow+".timer.moveMeter()",(this.meterTimeout*1000)/this.meterSlice);
  }
  else{*/
    this.meterTimer=setTimeout(this.Name+".moveMeter()",(this.meterTimeout*1000)/this.meterSlice);
	
}

function newMeter(meterIndex,radianUnit,clockRadius) {
  this.x=Math.round(Math.cos(meterIndex*45*radianUnit)*clockRadius);
  this.y=Math.round(Math.sin(meterIndex*45*radianUnit)*clockRadius);
}
function setMeter() {
  for (var i=0; i<this.meterSlice; i++)
    this.meterOffset[i]=new newMeter(i,this.radianUnit,this.clockRadius);
}
function meterLoader(Name,Anchor,ImgPrefix,LoadingText,speed,ImgArray){
this.Name = Name;
this.Anchorname=Anchor;
this.loadingText=LoadingText;
this.clockSize=29;
this.clockRadius=7;
this.clockSpace=this.clockSize-(2*this.clockRadius);
this.clockImage=new Image(this.clockSize,this.clockSize);
this.clockImage.src=ImgPrefix+"clock.gif";

this.radianUnit=Math.PI/180;

this.meterSize=5;
this.meterRadius=2;
this.meterImage=new Image(this.meterSize,this.meterSize);
this.meterImage.src=ImgPrefix+"meter.gif";

this.meterTimer=0;
this.meterSlice=8;
this.meterCenter=2;
this.meterStep=1;
this.meterTimeout=speed;
this.meterOffset=new Array();

this.imageArray = new Array();
this.ImgArray = ImgArray;
this.nImages = this.ImgArray.length;
this.LB_imageNUM = 0;

//define methods
this.setMeter=setMeter;
this.moveMeter=moveMeter;
this.loadSlides = loadSlides;

this.newMeter=newMeter;
this.setMeterLayer=setMeterLayer;
this.updateTextView=updateTextView;
this.checkload=checkload;
this.hideMeterLayer=hideMeterLayer;
//start meter
this.setMeter();
//this.setMeterLayer();

var LM_OtherOnLoad = (window.onload) ? window.onload :  new Function;
eval("window.onload = function(){"+this.Name+".loadSlides();LM_OtherOnLoad()}");
}
