﻿// JScript File

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


function clickButton(e, buttonid){ 
     var bt = document.getElementById(buttonid); 
     if (typeof bt == 'object'){ 
           if(navigator.appName.indexOf("Netscape")>(-1)){ 
                 if (e.keyCode == 13){ 
                       bt.click(); 
                       return false; 
                 } 
           } 
           if (navigator.appName.indexOf("Microsoft Internet Explorer")>(-1)){ 
                 if (event.keyCode == 13){ 
                       bt.click(); 
                       return false; 
                 } 
           } 
     }
}
  
    /*
    The BIS(BetterImageSlideshow) javascript object is not documented anywhere so here's a short list of fields and methods:
    ---Fields---
    this.A : Array with the image names.
    this.B : Base of the images there url
    this.bF : Boolean telling if we use filters
    this.C : Counter keep track of which image is on.
    this.I : The html image element where to show the images.
    this.M : Ammount of millisecond between slides.
    this.P : Params added to the images there url.
    this.T : Timer object.

    ---Methods---
    this.GE(el) : Short version of document.getElementById(el) returns an Element
    this.IF(iT, iTD) : Initialize filter iT with a duration of iTD. Returns a boolean telling whether or not a filter is applied.
    this.SS : Sets the image to this.C
    this.Ne : Goto next image
    this.Pr : Goto previous image
    this.Pl : Play. Set's the timer (this.T) to do this.NE after this.M seconds.
    this.St : Stop. Clears this.T
    this.PF : Preload al the images in this.A
    */

    function adjustBehaviour()
    {
        writeImgProp(this.I);
        addImagesToDropDownList(this.A);
        setText("count", this.A.length);
        
        this.I['onload'] = function(){
            writeImgProp(this);
        }

        var oldPlayFunc = this.Pl;
        this.Pl = function(){
            oldPlayFunc.call(this);
            this.GE('spinner').style.visibility = "visible";
        }

        var oldStopFunc = this.St;
        this.St = function(){
            oldStopFunc.call(this);
            this.GE('spinner').style.visibility = "hidden";
        }

        var oldSSFunc = this.SS;
        this.SS = function(){
            oldSSFunc.call(this);
            this.GE('ddlSelectImage').selectedIndex = this.C;
        }

        function writeImgProp(img)
        {
            var imgName = stripFileName(img.src);
            var imgSize = (img.fileSize)? " " + (Math.round(100*(img.fileSize/1024))/100) + "kB":"";
            setText("imgprop", imgName + imgSize);
        }

        function stripFileName(src)
        {
            var indexofSlash = src.lastIndexOf("%2f");
            
            if(indexofSlash > 0)
                indexofSlash += 3;
            
            var indexofHash = src.indexOf("\&",indexofSlash);
            return src.substring(indexofSlash,indexofHash);
        }

        function setText(objId, text)
        {
            var obj = document.getElementById(objId);
            var textNode = document.createTextNode(text);

            (obj.firstChild)?obj.replaceChild(textNode, obj.firstChild):obj.appendChild(textNode);
        }
        
        function addImagesToDropDownList(imgs)
        {
            var ddl = document.getElementById("ddlSelectImage");
            for(i=0;i<imgs.length;i++)
	        {
		        ddl.options[i] = new Option(i+1,i);
	        }
        }
    }

    function setSpeed(sender)
    {
        objAutoSlideshow1.M = sender.value;
    }
    
    function setSlide(sender)
    {
        objAutoSlideshow1.C = parseInt(sender.value);
        objAutoSlideshow1.SS();
    }
    
