var p;
var n;
function mySlide(theImages,theDesc,theWidth,theHeight,theContainer){
  this.theImages=theImages;
  this.theDesc = theDesc;
  this.curImage=0
  this.curDisplay=0;
  this.autoInterval=5000;
  this.blendTime=2000;
  if(theContainer=='')
    theContainer='islide';
  document.getElementById(theContainer).innerHTML='<div onclick="myobj.nextI();" style="background-image: url('+theImages[0]+'); background-repeat: no-repeat; width: '+theWidth+'px; height: '+theHeight+'px;" id="blenddiv">   <img  src="'+theImages[0]+'" style="width: '+theWidth+'px; height: '+theHeight+'px; border: 0 none; filter: alpha(opacity=0); -moz-opacity: 0; opacity: 0;" id="blendimage" alt="" /></div>';
  this.doDesc(0);

  if(document.getElementById('ipages'))
      this.buildPages();

if((autoSlide==1)&&(this.theImages.length>1))
setTimeout("myobj.nextI()",this.autoInterval/2);
}
mySlide.prototype.buildPages=function(){
var temp="";
  for(i=1;i<=this.theImages.length;i++){
    if(i==1)
      active='class="active" ';
    else 
      active='';
    temp+='<a id="p'+(i-1)+'" '+active+' href="javascript:myobj.gotoI(\''+(i-1)+'\')">'+i+'</a> '
  }

  document.getElementById('ipages').innerHTML=temp;
}
mySlide.prototype.doDesc=function(iNum){

  if(this.theDesc[iNum]){
    if(document.getElementById('info'))

    document.getElementById('info').innerHTML=this.theDesc[iNum];
    document.getElementById('blendimage').alt=this.theDesc[iNum];
    document.getElementById('blendimage').title=this.theDesc[iNum];
  }else{
    document.getElementById('blendimage').alt='';
    document.getElementById('blendimage').title='';
    if(document.getElementById('info')) document.getElementById('info').innerHTML='';
  }
}
mySlide.prototype.gotoI=function(iNum){

  if(document.getElementById('ipages')) {
  document.getElementById('p'+this.curImage).className='';
  document.getElementById('p'+iNum).className='active';
}
  this.curImage=parseInt(iNum);
  this.doDesc(iNum);
  this.blendimage('blenddiv','blendimage',this.theImages[iNum],this.blendTime);
}
mySlide.prototype.nextI=function(){
  var iNum=0
  clearTimeout(n);
  if(this.curImage<this.theImages.length-1) 
    iNum=this.curImage+1;
  this.gotoI(iNum);
  clearTimeout(p);
if(autoSlide==1)
  n=setTimeout("myobj.nextI()",this.autoInterval);
}
mySlide.prototype.prevI=function(){
  var iNum=iNum=this.theImages.length-1;
  clearTimeout(p);
  if(this.curImage>0) 
    iNum=this.curImage-1;
  this.gotoI(iNum);
  clearTimeout(n);
if(autoSlide==1)
  p=setTimeout("myobj.prevI()",this.autoInterval);

}

function changeOpac(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
}
mySlide.prototype.opacity=function(id, opacStart, opacEnd, millisec) {
    //speed for each frame
    var speed = Math.round(millisec / 100);
    var timer = 0;

    //determine the direction for the blending, if start and end are the same nothing happens
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    }
} 
mySlide.prototype.blendimage=function(divid, imageid, imagefile, millisec) {
    var speed = Math.round(millisec / 100);
    var timer = 0;
    
    //set the current image as background
    document.getElementById(divid).style.backgroundImage = "url(" + document.getElementById(imageid).src + ")";
    
    //make image transparent
    changeOpac(0, imageid);
    
    //make new image
    document.getElementById(imageid).src = imagefile;

    //fade in image
    for(i = 0; i <= 100; i++) {
        setTimeout("changeOpac(" + i + ",'" + imageid + "')",(timer * speed));
        timer++;
    }
} 
