_spotlight = {
    _bTmpPaused : false, 
    _nItemWidth : null, 
    _nCurrentId: 1,
    _nMaxItems: 1,
    _nActive: 0,
    _bQueueAdvance : false,
    _bPlaying: false,
    _bAutoPlay: true,
    _xTimer: null,
    _nTimeout: 10000,
    _nSpeed: 800, 
    _nMinContentHeight: 140,
    _bAnimating: false,
    _sDivHolder: null,

init : function (p_sDiv,p_nWidth){
    this._sDivHolder = p_sDiv;
    this._nItemWidth = parseInt(p_nWidth);
    this._nMaxItems = parseInt($('#'+this._sDivHolder+' .display-holder .item').length);
 
    if($.browser.msie && $.browser.version < 8)
        document.getElementById('spotlight').attachEvent('onselectstart', _spotlight.fixSelect); 
 
    $('#'+this._sDivHolder+' .menu .nav').click( function(){ _spotlight.viewItem(  parseInt($(this).attr('id').substr($(this).attr('id').lastIndexOf('_')+1,2)) );return false; });
    $('#'+this._sDivHolder+' a.pause').click( function(){_spotlight.pauseFeature();return false; });
    $('#'+this._sDivHolder+' a.play').click( function(){_spotlight.viewItem(_spotlight._nCurrentId+1); _spotlight.playFeature();return false; });
    $('#'+this._sDivHolder+' .nav').hover( function(){ $(this).addClass('hover');},function(){ $(this).removeClass('hover');});

    setTimeout( function(){ _spotlight.fixContentArea();  }, 200);
    setTimeout( function(){ _spotlight.fixContentArea(1);  }, 500);
     
    $('#nav_'+_spotlight._nCurrentId).addClass('nav_'+_spotlight._nCurrentId + '-act');
    setTimeout( function(){ (_spotlight._bAutoPlay ) ? (_spotlight.playFeature()) : _spotlight.pauseFeature();  }, 10);
},

fixSelect : function(){ return false;},
 
fixContentArea : function(p_nVal){
    $('#'+this._sDivHolder+' .display-holder .item').each( function() { 
        if( $(this).children('.content-holder').length ){
            var l_xHolder = $(this).children('.content-holder');
            var l_xImage = $(this).find('.main-image');
            var l_nHolderHeight = parseInt(l_xHolder.height());
            if(l_nHolderHeight < _spotlight._nMinContentHeight){
                l_nHolderHeight = _spotlight._nMinContentHeight;
                l_xHolder.height(l_nHolderHeight);
            }
            var l_xImageHeight = parseInt(l_xImage.attr('height'));
            if( !l_xImageHeight > 0)
            l_xImageHeight = parseInt(l_xImage.height());

            var l_nDiff = parseInt( parseInt($(this).height()) - l_xImageHeight - l_nHolderHeight);  
            if(l_nDiff < 0){
                l_xHolder.css('top',(l_nDiff));
                l_xHolder.css('position','relative');
            }
        }
    }); 

    $('#'+this._sDivHolder+' .display-holder').width(this._nItemWidth*2);

    if(p_nVal == 1){
        if ( ($.browser.msie && $.browser.version <= 8)){
            this.hideAllExcept(_spotlight._nCurrentId); 
            $('#'+this._sDivHolder+' .spotlight-wrapper').css('overflow','visible'); 
        }
    }
},

viewItem: function (p_nVal){
    _spotlight._bQueueAdvance = false;
    p_nVal = parseInt(p_nVal);
    if(p_nVal == this._nCurrentId)return;

    if(!this._bAnimating){

    this._bAnimating = !this._bAnimating;
    $('#'+this._sDivHolder+' .menu .nav').removeClass('nav_1-act');    
    $('#'+this._sDivHolder+' .menu .nav').removeClass('nav_2-act');     
    $('#'+this._sDivHolder+' .menu .nav').removeClass('nav_3-act');     
    $('#'+this._sDivHolder+' .menu .nav').removeClass('nav_4-act');    
    $('#'+this._sDivHolder+' .menu .nav').removeClass('nav_5-act');    
    $('#'+this._sDivHolder+' .menu .nav').removeClass('nav_' + p_nVal+ '-act');      
    $('#'+this._sDivHolder+' .spotlight-wrapper').css('overflow','hidden');

    var l_nSpecialCase = -1;

    if(p_nVal > this._nMaxItems)
        l_nSpecialCase = 1;
    else if(p_nVal <= 0)
        l_nSpecialCase = this._nMaxItems;
  
    if(l_nSpecialCase != -1){
        this._nCurrentId = l_nSpecialCase;
        (l_nSpecialCase == 1) ? l_nMultiplier = 1 : l_nMultiplier = -1;
        $('#'+this._sDivHolder+' .display-holder #spotlight-item-'+this._nCurrentId).css('position','absolute').css('left',( l_nMultiplier * this._nItemWidth) ).show();
        $('#'+this._sDivHolder+' .display-holder').css('left', 0).animate( { 'left': -(( l_nMultiplier * this._nItemWidth)) }, _spotlight._nSpeed, function(){ _spotlight.finishedAnimationOverRotation() });
        $('#nav_'+this._nCurrentId).addClass('nav_'+this._nCurrentId + '-act');
        return;
    }
 
    $('#nav_'+p_nVal).addClass('nav_'+p_nVal + '-act');

    (p_nVal > this._nCurrentId) ? l_nDirection = -1 : l_nDirection = 1; 
 
    $('#'+this._sDivHolder+' .display-holder .item').each( function() { 
        var l_nPosition = parseInt($(this).attr('id').substr( $(this).attr('id').lastIndexOf('-')+1,1));
        if(l_nDirection < 0){
            if( l_nPosition != _spotlight._nCurrentId && l_nPosition > _spotlight._nCurrentId)
            $(this).hide();
        }else{
            if( l_nPosition != _spotlight._nCurrentId && l_nPosition < _spotlight._nCurrentId)
            $(this).hide();
        }
    });
  
    this._nCurrentId = p_nVal;
    $('#'+this._sDivHolder+' .display-holder #spotlight-item-'+this._nCurrentId).show();
    var l_nNewPosition = -(this._nItemWidth);
    if(l_nDirection > 0){
        $('#'+this._sDivHolder+' .display-holder').css('left', -this._nItemWidth);
        l_nNewPosition = 0;
    } 
    $('#'+this._sDivHolder+' .display-holder').animate( { 'left': l_nNewPosition }, _spotlight._nSpeed, function(){ _spotlight.finishedAnimation() });
    }
},

hideAllExcept : function(p_nVal){
    $('#'+this._sDivHolder+' .display-holder .item').each( function() {  
        var l_nPosition = parseInt($(this).attr('id').substr( $(this).attr('id').lastIndexOf('-')+1,1));
        if( l_nPosition != p_nVal)  $(this).hide();
    });
},

finishedAnimation: function (p_nVal){
    this.hideAllExcept(_spotlight._nCurrentId);
    if( parseInt($('#'+this._sDivHolder+' .display-holder').css('left')) != 0){
        $('#'+this._sDivHolder+' .display-holder').css('left', 0);
    }
    if ( ($.browser.msie && $.browser.version < 7)){
        $('#'+this._sDivHolder+' .spotlight-wrapper').css('overflow','visible'); 
    }
    this._bAnimating = false;
    this.setPlayTimer();
},

finishedAnimationOverRotation: function (){
    this.hideAllExcept(_spotlight._nCurrentId);
    $('#'+this._sDivHolder+' .display-holder #spotlight-item-'+_spotlight._nCurrentId).css('position','').css('left','');
    $('#'+this._sDivHolder+' .display-holder').css('left', 0);
    if ( ($.browser.msie && $.browser.version < 7)){
        $('#'+this._sDivHolder+' .spotlight-wrapper').css('overflow','visible'); 
    }
    this._bAnimating = false;
    this.setPlayTimer();
},

playFeature : function(){
    $('#'+this._sDivHolder+' .pause').show();
    $('#'+this._sDivHolder+' .play').hide();
    this._bPlaying = true;
    this.setPlayTimer();
},

pauseFeature : function(){
    _spotlight._bQueueAdvance = false;
    this._bTmpPaused = false;
    this._bPlaying = false;
    $('#'+this._sDivHolder+' .pause').hide();
    $('#'+this._sDivHolder+' .play').show();
    clearTimeout(this._xTimer);
},
 
 
tmpPauseFeature : function(){if(this._bAutoPlay){this._bTmpPaused = true;}},

revertFeature : function(){
    _spotlight._bTmpPaused = false;
    setTimeout(function(){
        if( !_spotlight._bTmpPaused ){
            if( _spotlight._bQueueAdvance ){
                _spotlight._bQueueAdvance = false;
                _spotlight.viewItem(_spotlight._nCurrentId+1);
                _spotlight.playFeature();
            } else
                _spotlight._bTmpPaused = false;
        }
    },200);
},


setPlayTimer: function(){
    if(this._bPlaying){
        clearTimeout(this._xTimer);
        this._xTimer = setTimeout(function(){
            if( _spotlight._bTmpPaused )
                _spotlight._bQueueAdvance = true;
            else
                _spotlight.viewItem(_spotlight._nCurrentId+1);
        }, this._nTimeout);
    }
},

hideControls : function(){},
showControls : function(){}
 
}




