﻿Type.registerNamespace("Demo");

Demo.SlideShow=function()
{
    this._slides=new Array();
    this._slideType=new Array();
    this._video=new Array();
    // 1=First, 2=Previous, 3=Pause, 4=Play, 5=Next, 6=Last, Default is Play (4)
    this._buttonClicked= 4;
    this._delay=10;
    this._currentIndex=0;
    this._pause=false;
}

Demo.SlideShow.prototype=
{
    get_Slides:function()
    {
        return this._slides;
    },
    
    set_Slides:function(value)
    {
        //alert(value.length);
        var newArraySize = value.length/2;
        //alert(newArraySize);
        var pathArray = new Array(newArraySize); //value.split(",");
        var typeArray = new Array(newArraySize);
        var i = 0;
        var j = 0;
        while (i < value.length-1)
        {
            pathArray[j] = value[i];
            typeArray[j] = value[i+1];
            i = i + 2;
            j++;
        }
        //alert(pathArray);
        //alert(typeArray);
        this._slides=pathArray;
        this._slideType=typeArray;
        //this._slides=value;
    },
    
    get_Delay:function()
    {
        return this._delay;
    },
    
    set_Delay:function(value)
    {
        this._delay=value;
    },
    
    get_CurrentIndex:function()
    {
        return this._currentIndex;
    },
    
    set_CurrentIndex:function(value)
    {
        if(value<0)
        {
            this._currentIndex=this._slides.length-1;
            return;
        }
        if(value>=this._slides.length)
        {
            this._currentIndex=0;
        }
        else
        {
            this._currentIndex=value;
        }
    },
    
    get_IsPaused:function()
    {
        return this._pause;
    },
    
    set_IsPaused:function(value)
    {
        this.pause=value;
    },
    
    Pause:function()
    {
        this._pause=true;
        this._buttonClicked = 3;
        //alert(this.get_CurrentIndex());
    },
    
    Play:function()
    {
        this._pause=false;
        this._buttonClicked = 4;
        var flshObj = $get("preview");
        //alert(flshObj.style.display);
        if (flshObj.style.display != "block")
        {
            window.setTimeout("slideshow.ShowImage()",this.get_Delay());
        }
        else
        {
            var imgObj = $get("Image1");
            imgObj.style.display = "block";
            var flshObj = $get("preview");
            flshObj.style.display = "none";
            var curInd =this.get_CurrentIndex();
            var imgs=this.get_Slides();
            imgObj.src=imgs[curInd];
            this.set_CurrentIndex(curInd);
            window.setTimeout("slideshow.ShowImage()",this.get_Delay());
        }
    },
    
    ShowFirst:function()
    {
        if(this.get_IsPaused()==false)
        {
            this._pause=true;
            //slideshow.Pause();
        }    
        this._currentIndex=0;
        this._buttonClicked = 1;
        this.ShowImage();
    },
    
    ShowLast:function()
    {
        if(this.get_IsPaused()==false)
        {
            this._pause=true;
            //slideshow.Pause();
        }    
        this._currentIndex=this._slides.length-1;
        this._buttonClicked = 6;
        this.ShowImage();
    },
    
    ShowNext:function()
    {
        if(this.get_IsPaused()==false)
        {
            this._pause=true;
            var newIndex=this._currentIndex;
            //slideshow.Pause();
        }
        else
        {
            if (this._buttonClicked == 3)
                var newIndex=this._currentIndex;
            else
                 var newIndex=this._currentIndex +1;
        }
        this._buttonClicked = 5;
        this.set_CurrentIndex(newIndex);
        this.ShowImage();
    },
    
    ShowPrevious:function()
    {
        if(this.get_IsPaused()==false)
        {
            this._pause=true;
            var newIndex=this._currentIndex -2;
            //slideshow.Pause();
        }    
        else
        {
            var newIndex=this._currentIndex -1;
        }
        
        this._buttonClicked = 2;
        //alert(newIndex);
        this.set_CurrentIndex(newIndex);
        this.ShowImage();
    },
    
    ShowImage:function()
    {
        if (this._buttonClicked != 3)
        {        
            var img=$get("Image1");
            //var currType = $get("currentType");
            if(img.style.visibility=="hidden")
            {
                img.style.visibility="visible";
            }
            var slides=this.get_Slides();
            var curIndex=this.get_CurrentIndex();
            var cType = $get("currentType");
            cType.value = this._slideType[curIndex];
            if (cType.value == "i")
            {
                var imgObj = $get("Image1");
                imgObj.style.display = "block";
                var flshObj = $get("preview");
                flshObj.style.display = "none";
                //alert("in here");
            }        
            img.src=slides[curIndex];
            if(this.get_IsPaused()==false)
            {
                this.set_CurrentIndex(curIndex+1);
                this.Play();
            }
        }
    }
}


Demo.SlideShow.registerClass("Demo.SlideShow");

var slideshow=new Demo.SlideShow();


