function swaptab(tabId, current, interval) {  
    this.tabId = tabId;
    this.swap(current);
    this.interval = parseInt(interval);
}

swaptab.prototype.tabId = '';
swaptab.prototype._timer = '';
swaptab.prototype.menuClass = 'menu';
swaptab.prototype.menuItemOnClass = 'on';
swaptab.prototype.menuItemOffClass = 'off';
swaptab.prototype.contentClass = 'content';
swaptab.prototype.current = 0;
swaptab.prototype.interval = 3000;
swaptab.prototype.swapMethod = 'show'
swaptab.prototype.swapSpeed = '';


swaptab.prototype.swap = function(current)
{    
    if(current == undefined){
        current = 0;
    }
    else{
        current--;
    }
    this.current = current+1;

    var itemCol = $("#"+this.tabId+" ."+this.menuClass+" a");
    var contentCol = $("#"+this.tabId+" ."+this.contentClass+" > div");

    for(var i=0 ; i < itemCol.length ; i++){
        if(current == i){
            $("#"+this.tabId+" ."+this.menuClass+" a:eq("+i+")").attr("class", this.menuItemOnClass);
        }
        else{
            $("#"+this.tabId+" ."+this.menuClass+" a:eq("+i+")").attr("class", this.menuItemOffClass);
        }        
    }

    for(var i=0 ; i < contentCol.length ; i++){
        if(current == i){
            if(this.swapMethod == 'show'){
                $("#"+this.tabId+" ."+this.contentClass+" > div:eq("+i+")").show(this.swapSpeed);
            }
            else if(this.swapMethod == 'fade'){
                $("#"+this.tabId+" ."+this.contentClass+" > div:eq("+i+")").fadeIn(this.swapSpeed);
            }
        }
        else{
            $("#"+this.tabId+" ."+this.contentClass+" > div:eq("+i+")").hide();
        }        
    }
}


swaptab.prototype.auto = function() {
    var self = this;
    
    function  update(){
        if($("#"+self.tabId+" ."+self.contentClass+" > div").length > self.current) {
		        self.current++; 
	      }
	      else {
		        self.current=1;
        }
        self.swap(self.current);
        self._timer = window.setTimeout ( update, self.interval );
    }

    this._timer = setTimeout(update, this.interval);    
}

swaptab.prototype.stop = function() {
    clearTimeout(this._timer);
}

