/*
Up down slideshow Script
By Dynamic Drive (www.dynamicdrive.com)
For full source code, terms of use, and 100's more scripts, visit http://www.dynamicdrive.com
*/

///////configure the below four variables to change the style of the slider///////
//set the scrollerwidth and scrollerheight to the width/height of the LARGEST image in your slideshow!
var scrollerwidth='180px';
var scrollerheight='60px';
//3000 miliseconds=3 seconds
var pausebetweenimages=3000;


///////Do not edit pass this line///////////////////////

function ImageSlider(simg, arg){

    this.ie = document.all;
    this.dom = document.getElementById;
    this.prefix = arg.prefix;
    this.simg = simg;
    
    var thisRef = this;

    var i=0;
    if (simg.length>2) {i=2} else {i=0};

    this.move1 = function(whichlayer)
    {
        var tlayer=whichlayer;
        
        if (tlayer.top>0 && tlayer.top<=5)
        {
            tlayer.top=0;
            setTimeout(function(){
                thisRef.move1(tlayer);
            }, pausebetweenimages);
            //setTimeout("move1(tlayer)",pausebetweenimages);
            
            setTimeout(function(){
                thisRef.move2(document[thisRef.prefix+"main"].document[thisRef.prefix+"second"]);
            }, pausebetweenimages);
            //setTimeout("move2(document.main.document.second)",pausebetweenimages);
            
            return;
        }
        
        if (tlayer.top>=tlayer.document.height*-1)
        {
            tlayer.top-=5;
            setTimeout(function(){
                thisRef.move1(tlayer);
            }, 50);
            //setTimeout("move1(tlayer)",50);
        }
        else
        {
            tlayer.top=parseInt(scrollerheight);
            tlayer.document.write(simg[i]);
            tlayer.document.close();
            if (i==simg.length-1)
                i=0;
            else
                i++;
        }
    }

    this.move2 = function(whichlayer)
    {
        var tlayer2=whichlayer;
        if (tlayer2.top>0 && tlayer2.top<=5)
        {
            tlayer2.top=0;
            setTimeout(function(){
              thisRef.move2(tlayer2);  
            }, pausebetweenimages);
            //setTimeout("move2(tlayer2)",pausebetweenimages)
            
            setTimeout(function(){
                thisRef.move1(document[thisRef.prefix+"main"].document[thisRef.prefix+"first"]);
            }, pausebetweenimages);
            //setTimeout("move1(document.main.document.first)",pausebetweenimages)
            return;
        }
        
        if (tlayer2.top>=tlayer2.document.height*-1)
        {
            tlayer2.top-=5;
            setTimeout(function(){
                thisRef.move2(tlayer2);
            }, 50);
            //setTimeout("move2(tlayer2)",50)
        }
        else
        {
            tlayer2.top=parseInt(scrollerheight);
            tlayer2.document.write(thisRef.simg[i]);
            tlayer2.document.close();
            if (i==thisRef.simg.length-1)
                i=0;
            else
                i++;
        }
    }

    this.move3 = function(whichdiv)
    {
        var tdiv=whichdiv;
        
        if (parseInt(tdiv.style.top)>0 && parseInt(tdiv.style.top)<=5)
        {
            tdiv.style.top=0+"px";
            setTimeout(function(){
                thisRef.move3(tdiv);
            }, pausebetweenimages);
            //setTimeout("move3(tdiv)",pausebetweenimages)
            
            setTimeout(function(){
                thisRef.move4(thisRef.second2_obj);
            }, pausebetweenimages);
            //setTimeout("move4(second2_obj)",pausebetweenimages)
            
            return;
        }
    
        if (parseInt(tdiv.style.top)>=tdiv.offsetHeight*-1)
        {
            tdiv.style.top=parseInt(tdiv.style.top)-5+"px";
            setTimeout(function(){
                thisRef.move3(tdiv);
            }, 50);
            //setTimeout("move3(tdiv)",50)
        }
        else
        {
            tdiv.style.top=scrollerheight;
            tdiv.innerHTML=thisRef.simg[i];
            if (i==thisRef.simg.length-1)
                i=0;
            else
                i++;
        }
    }

    this.move4 = function(whichdiv)
    {
        var tdiv2=whichdiv;
        
        if (parseInt(tdiv2.style.top)>0&&parseInt(tdiv2.style.top)<=5)
        {
            tdiv2.style.top=0+"px"
            setTimeout(function(){
                thisRef.move4(tdiv2);
            }, pausebetweenimages);
            //setTimeout("move4(tdiv2)",pausebetweenimages)
            setTimeout(function(){
                thisRef.move3(thisRef.first2_obj);
            }, pausebetweenimages);
            //setTimeout("move3(first2_obj)",pausebetweenimages)
            return;
            
        }
        
        if (parseInt(tdiv2.style.top)>=tdiv2.offsetHeight*-1)
        {
            tdiv2.style.top=parseInt(tdiv2.style.top)-5+"px";
            setTimeout(function(){
                thisRef.move4(thisRef.second2_obj);
            }, 50);
            //setTimeout("move4(second2_obj)",50);
        }
        else
        {
            tdiv2.style.top=scrollerheight;
            tdiv2.innerHTML=thisRef.simg[i];
            if (i==thisRef.simg.length-1)
                i=0;
            else
                i++;
        }
    }

    this.startscroll = function()
    {
        if (thisRef.ie||thisRef.dom){
        
            thisRef.first2_obj = document.getElementById(thisRef.prefix+"first2");
            thisRef.second2_obj = document.getElementById(thisRef.prefix+"second2");
            
            thisRef.move3(thisRef.first2_obj);
            
            thisRef.second2_obj.style.top=scrollerheight;
            thisRef.second2_obj.style.visibility='visible';
        }
        else if (document.layers)
        {
            document[thisRef.prefix+"main"].visibility='show';
            thisRef.move1(document[thisRef.prefix+"main"].document[thisRef.prefix+"first"]);
            
            document[thisRef.prefix+"main"].document[thisRef.prefix+"second"].top=parseInt(scrollerheight)+5;
            document[thisRef.prefix+"main"].document[thisRef.prefix+"second"].visibility='show';
        }
    }

    var funcTemp = window.onload;
    if (funcTemp==undefined)
        window.onload=thisRef.startscroll;
    else
        window.onload=function(){
            funcTemp();
            thisRef.startscroll();
        };

    document.write("<ilayer id=\"" + thisRef.prefix+"main" + "\" width=&{scrollerwidth}; height=&{scrollerheight}; visibility=hide>");
    document.write("<layer id=\"" +thisRef.prefix+ "first\" left=0 top=1 width=&{scrollerwidth};>");
    
    if (document.layers)
        document.write(simg[0]);
    
    document.write("</layer>");

    document.write("<layer id=\"" +thisRef.prefix+ "second\" left=0 top=0 width=&{scrollerwidth}; visibility=hide>");

    var dyndetermine = 1;
    if (document.layers)
        document.write(simg[dyndetermine=(simg.length==1)? 0 : 1])

    document.write("</layer></ilayer>");

    if (thisRef.ie||thisRef.dom){
        document.writeln('<div id="' +thisRef.prefix+ 'main2" style="position:relative;width:'+scrollerwidth+';height:'+scrollerheight+';overflow:hidden;">')
        document.writeln('<div style="position:absolute;width:'+scrollerwidth+';height:'+scrollerheight+';clip:rect(0 '+scrollerwidth+' '+scrollerheight+' 0);left:0px;top:0px">')
        document.writeln('<div id="' +thisRef.prefix+ 'first2" style="position:absolute;width:'+scrollerwidth+';left:0px;top:1px;">')
        document.write(simg[0])
        document.writeln('</div>')
        document.writeln('<div id="' +thisRef.prefix+ 'second2" style="position:absolute;width:'+scrollerwidth+';left:0px;top:0px;visibility:hidden">')
        document.write(simg[dyndetermine=(simg.length==1)? 0 : 1])
        document.writeln('</div>')
        document.writeln('</div>')
        document.writeln('</div>')
    }
};
