autoTabCarosel = {
    TabTarget: '',
    TabSwitcher: '',
    items: '',
    active: '',
    timer: '',
    timeOut: 5000,
    blend: 750,
    
    makeTab: function(tabSwitcher, tabTarget){ 
       autoTabCarosel.TabSwitcher = tabSwitcher;
       autoTabCarosel.TabTarget = tabTarget;
        var frTabs = $(autoTabCarosel.TabSwitcher);
        if(frTabs.length){
            autoTabCarosel.items = frTabs.length;
            frTabs.each(function(i) {
              var link = frTabs.eq(i).children('div').children('a').attr('href');
              if(i<1){ 
                frTabs.eq(i).addClass('ui-state-active')
                autoTabCarosel.active = i;
                } else {
                    $(link).addClass('ui-tabs-hide');
                };
                $(link).attr('rel', i)
                frTabs.eq(i).attr('rel', i)
            });
            $(autoTabCarosel.TabSwitcher).click(function () {
                //clearTimeout(autoTabCarosel.timer);
                autoTabCarosel.moveTo($(this).attr('rel'));
                return false;
            });
            autoTabCarosel.timer = setTimeout("autoTabCarosel.moveNext()", autoTabCarosel.timeOut);
        }
    },
    moveTo: function(clicked){
        var sel = (clicked*1)
        clicked = $(autoTabCarosel.TabSwitcher + '[rel=' + sel + ']');
        var target = clicked.children('div').children('a').attr('href');
        autoTabCarosel.active = sel;
        $('.ui-state-active').removeClass('ui-state-active');
        $(clicked).addClass('ui-state-active');
        $(autoTabCarosel.TabTarget).fadeOut(autoTabCarosel.blend);
        $(target).fadeIn(autoTabCarosel.blend);
    },
    moveNext: function() {
        if(autoTabCarosel.active < (autoTabCarosel.items - 1)){
            autoTabCarosel.active = autoTabCarosel.active + 1 ;
        }else{
            autoTabCarosel.active = 0;
        };
        autoTabCarosel.moveTo(autoTabCarosel.active);
        autoTabCarosel.timer = setTimeout("autoTabCarosel.moveNext()", autoTabCarosel.timeOut);
    }
};

htmlCarousel = {
    init: function(){
        var tabSwitcher = '.tabsNav li';
        var tabTarget = '.tabItems';
        myAutoTab = new autoTabCarosel.makeTab(tabSwitcher, tabTarget);
    }
};

$(document).ready(function(){
	htmlCarousel.init();
});
