var interval;
var index;

var TabbedContent = {
    init: function () {
        $(".tab_item:first").addClass('active');


        $(".tab_item").mouseover(function () {

            clearInterval(interval);
            TabbedContent.doAnimate(this);

        });
        //end mouseover function

        $(".tab_item").mouseout(function () {

            index = jQuery.inArray(this, $(".tab_item")) + 1;
            interval = setInterval('autoScroll()', 3000);

        });

    },


    doAnimate: function (obj) {
        //mouseover function


        var background = $(obj).parent().find(".moving_bg");

        $(background).stop().animate({
            left: $(obj).position()['left']
        }, {
            duration: 300
        });
        $(obj).addClass('active');
        $(obj).siblings().removeClass('active');

        TabbedContent.slideContent($(obj));


    },

    slideContent: function (obj) {

        var margin = $(obj).parent().parent().find(".slide_content").width();
        margin = margin * ($(obj).prevAll().size() - 1);
        margin = margin * -1;

        $(obj).parent().parent().find(".tabslider").stop().animate({
            marginLeft: margin + "px"
        }, {
            duration: 300
        });
    }
}



function autoScroll() {
if (index >= $(".tab_item").length) {
    index = 0;
       }
    TabbedContent.doAnimate($(".tab_item").get(index));
    index = index + 1;
}



$(document).ready(function () {
    TabbedContent.init();

    index = 1;

    interval =  setInterval('autoScroll()', 3000);


    // default 10px round corner
    $('.slide div').corner();

});
