

var NavCycleConfig =
{
    'default' :
        [
             { 'imgpath' : 'http://www.cccit.co.uk/furniture/nvc/1.gif' ,  'duration' : 6 , 'link' : '' }, 
	     { 'imgpath' : 'http://www.cccit.co.uk/furniture/nvc/4.gif' ,  'duration' : 6 , 'link' : '' },   
             { 'imgpath' : 'http://www.cccit.co.uk/furniture/nvc/2.gif' ,  'duration' : 6 , 'link' : '' }

        ],
    'services' :
        [
             { 'imgpath' : 'http://www.cccit.co.uk/furniture/nvc/4.gif' ,  'duration' : 6 , 'link' : '' },
	     { 'imgpath' : 'http://www.cccit.co.uk/furniture/nvc/1.gif' ,  'duration' : 6 , 'link' : '' },
             { 'imgpath' : 'http://www.cccit.co.uk/furniture/nvc/2.gif' ,  'duration' : 6 , 'link' : '' },
	     { 'imgpath' : 'http://www.cccit.co.uk/furniture/nvc/3.gif' ,  'duration' : 6 , 'link' : 'http://www.cccit.co.uk' }
           
        ],
    'testimonials' :
        [
             { 'imgpath' : 'http://www.cccit.co.uk/furniture/nvc/2.gif' ,  'duration' : 6 , 'link' : '' },
	     { 'imgpath' : 'http://www.cccit.co.uk/furniture/nvc/4.gif' ,  'duration' : 6 , 'link' : '' },
             { 'imgpath' : 'http://www.cccit.co.uk/furniture/nvc/1.gif' ,  'duration' : 6 , 'link' : '' },
	     { 'imgpath' : 'http://www.cccit.co.uk/furniture/nvc/3.gif' ,  'duration' : 6 , 'link' : 'http://www.cccit.co.uk' }
        ]
}






NavCycle = function()
    {
        
        //define vars
        
        this.targetEl       = null; // the placeholder image to replace with a and img
        this.targetLink     = null;
        this.confArray      = null;  
        this.timer          = null;
        this.currentElement = null;
        this.imageArray     = null;
        this.confIndex      = 0;
        this.objRef         = this;
    }
    
NavCycle.prototype.init = function( targetElementId , pageName )
    {
       this.getTargetElement( targetElementId );
       this.getConfig( pageName );
       
        
        this.loadImages();
        this.insertLink();
        this.showImage();
    }
    
NavCycle.prototype.getTargetElement = function( targetElementId )
    {
        this.targetEl = document.getElementById(targetElementId);
        this.targetEl.objRef = this;
    }
    
NavCycle.prototype.getConfig = function( pageName )
    {
       this.confArray = NavCycleConfig[ pageName ];
       
       if( this.confArray == null )
       {
            this.confArray = NavCycleConfig[ 'default' ];
       }
    }

NavCycle.prototype.loadImages = function()
    {
        var nr = this.confArray.length;
        this.imageArray = new Array();
        for ( var i = 0 ; i < nr ; i++)
        {
            this.imageArray[i] = document.createElement('img');
            this.imageArray[i].src    = this.confArray[i].imgpath;
        }
    }


NavCycle.prototype.insertLink = function()
    {
         var par = this.targetEl.parentNode;
         this.targetEl.parentNode.removeChild( this.targetEl );
         this.targetLink = document.createElement('a');
         this.targetLink.appendChild( this.targetEl );
         par.appendChild( this.targetLink );
    }

NavCycle.prototype.startTimer = function()
    {
        thisObj = this;
        this.timer   =  setTimeout(function() { thisObj.handleTimer(); }, (this.confArray[this.confIndex].duration * 1000));
    }
    
NavCycle.prototype.stopTimer = function()
    {
        clearTimeout( this.timer );
    }
    
NavCycle.prototype.handleTimer = function(  )
    {
        //alert('timer')
        this.showImage();
    }
   
NavCycle.prototype.showImage = function()
    {
        
        this.targetEl.src = this.imageArray[ this.confIndex ].src;
       
        if( this.confArray[ this.confIndex ].link != '' )
        {
            this.targetLink.href  = this.confArray[ this.confIndex ].link;
            
        }
        else
        {
            this.targetLink.href = '';
            this.targetLink.removeAttribute('href')
        }
           
        this.confIndex++;
        
        if(this.confIndex == this.confArray.length  )
        {
            this.confIndex = 0;
        }
        this.startTimer();
        
     
        this.targetEl.onmouseover = function(  )
        {
            this.objRef.stopTimer();
        }
        
      this.targetEl.onmouseout = function( thisObj )
        {
             this.objRef.startTimer();
        }
    }

