$(document).ready(function() {

    function FeatureRotator() {
    
       this._featureTimer = null;
       this._isRunning = false;
       this._active = null;
       
       this.start = function(){
            var _self = this;
            clearInterval(this._featureTimer);   
             
            this._featureTimer = setInterval(function(){
                                    _self._paging();
                                    _self.rotate();
                                 }, 4000);  
                                                      
            this._isRunning = true;    
       };
       
       this.stop = function() {
            this._isRunning = false;
            clearInterval(this._featureTimer);
       };
       
       this._paging = function(){
		    this.active($('#featureRotator .bullets a.current').prev());
		    if ( this._active.length === 0) {
			    this.active($('#featureRotator .bullets a:last'));
		    }
       };
       
        this.rotate = function(){
            var triggerID 			= this._active.attr("rel") - 1; 
	        var panelHolderPosition	= -triggerID * this._featureWidth(); 

	        $('#featureRotator .bullets a').removeClass('current'); 
	        this._active.addClass('current');

	        //Slider Animation
	        $('#featureRotator .features').stop(true, true).animate({
		        marginLeft: panelHolderPosition
	        }, 300);
       };
       
       this._featureWidth = function(){
            return $('#featureRotator').width();
       };
       
       this.active = function( active ){
            this._active = active;
       };
     }  
     
    window.FeatureRotator = FeatureRotator;
});

