﻿// JScript File

slideshowtop = function()
{
    this.Initialize();
}
slideshowtop.prototype = 
{
    Initialize : function()
    {
      this.showInterval = MX.Delegate(this,this.show_xfade);
      this.gotoInterval = MX.Delegate(this,this.goto_slide);
       this.d=document;
       this.timeoutid = 0;
       this.imgs = [];
       this.zInterval = null;
       this.current = 0;
       this.docs = [];
       this.topStories = [] ;
       this.setIndex = 0;
       this.locked = false;
       this.timeoutid_goto = 0;                  
      
       if(!this.d.getElementById || !this.d.createElement)return;
       if(this.d.getElementById('rotator') == null) return;
       
       this.imgs = this.d.getElementById('rotator').getElementsByTagName('img');
       for(var i=1;i<this.imgs.length;i++) this.imgs[i].xOpacity = 0;
       
       this.docs = this.d.getElementById('rotator').getElementsByTagName('div');
       this.topStories =  this.d.getElementById('topstories').getElementsByTagName('a')
       
       this.playlink = this.d.getElementById('playlink');
	   this.pauselink =this.d.getElementById('pauselink')
       
       
       this.imgs[0].style.display = 'block';
	   this.imgs[0].xOpacity = .80;
	   this.docs[0].style.display = 'block';
       this.play(); 

    }
    ,play:function()
    {

         this.setIndex = 0;
         if (this.timeoutid != 0) 
         {
           clearTimeout(this.timeoutid);
           this.timeoutid = 0;
         }
         this.timeoutid = setTimeout(this.showInterval,5000);
         this.playlink.style.display="none";
         this.pauselink.style.display="block";    
    }
    ,show_xfade:function()
    {
	    cOpacity = this.imgs[this.current].xOpacity;
	    nIndex = this.imgs[this.current+1]?this.current+1:0;
	    nOpacity = this.imgs[nIndex].xOpacity;

	    cOpacity-=.05;
	    nOpacity+=.05;
	    
	    
	    this.imgs[this.current].xOpacity = cOpacity;
	    this.imgs[nIndex].xOpacity = nOpacity;

	    this.setOpacity(this.imgs[this.current]);
	    this.setOpacity(this.imgs[nIndex]);
	    
	    if(cOpacity<=0)
        {
            this.topStories[this.current].className="off";
            this.topStories[nIndex].className="on";
            
	        this.imgs[nIndex].style.display = 'block';
	        this.docs[this.current].style.display = 'none';
	        this.docs[nIndex].style.display = 'block';
	    
            this.imgs[this.current].style.display = 'none';
            this.current = nIndex;
            
            this.timeoutid = setTimeout(this.showInterval,5000);
        }
        else
        {
	        this.timeoutid = setTimeout(this.showInterval,50);
        }
    }
    ,setOpacity:function(obj)
    {
         if(obj.xOpacity>.99)
		    {
			    obj.xOpacity = .99;
			    return;
		    }
		    obj.style.opacity = obj.xOpacity;
		    obj.style.MozOpacity = obj.xOpacity;
		    obj.style.filter = 'alpha(opacity=' + (obj.xOpacity*100) + ')';
    }
    ,pause:function()
    { 
        this.setIndex = 0;
        if (this.timeoutid != 0) 
        {
          clearTimeout(this.timeoutid);
          this.timeoutid = 0;
        }
        this.playlink.style.display="block";
        this.pauselink.style.display="none";
        
        this.setIndex = this.current;
        this.timeoutid = setTimeout(this.gotoInterval,100);       

    }
    ,show_it:function(obj)
    {    
        this.pause();
        var  n = obj.innerHTML - 1;
        if (n < this.imgs.length && n >= 0) 
        {
            this.setIndex = n;
            this.timeoutid = setTimeout(this.gotoInterval,100);       
        }
    }
    ,goto_slide:function()
    {
        cOpacity = this.imgs[this.current].xOpacity;
	    nIndex = this.setIndex;
	    nOpacity = this.imgs[nIndex].xOpacity;

	    cOpacity-=.05;
	    nOpacity+=.05;
	    
	    this.imgs[this.current].xOpacity = cOpacity;
	    this.imgs[nIndex].xOpacity = nOpacity;
        
	    this.setOpacity(this.imgs[this.current]);
	    this.setOpacity(this.imgs[nIndex]);
	    if(cOpacity<=0)
        {
            this.topStories[this.current].className="off";
            this.topStories[nIndex].className="on";

            this.docs[this.current].style.display = 'none';
	        this.docs[nIndex].style.display = 'block';
	        this.imgs[nIndex].style.display = 'block';
	       
	    
            this.imgs[this.current].style.display = 'none';
            this.current = nIndex;
            
            this.timeoutid = 0;
        }
        else
        {
	        this.timeoutid = setTimeout(this.gotoInterval,50);
        } 
    }
  
        
}

slideshowtop = new slideshowtop();