//tab effects
var mtimer;
var mtarget;

var mTabbedContent = {
    cookiename: '',
    init: function (cookiename) {
        this.cookiename = cookiename;
        $(".mtab_item").mouseover(function (event) {
            mtarget = $(this);
            mtimer = setTimeout("mTabbedContent.runAnim(300)", 500);
        });
        $(".mtab_item").click(function (event) {
            mtarget = $(this);
            clearTimeout(mtimer);
            mTabbedContent.runAnim(300);
        });
        $(".mtab_item").mouseout(function () {
            clearTimeout(mtimer);
        });

        var hash = $.cookie(cookiename) ? $.cookie(cookiename).substr(1).toLowerCase() : '';
        if (window.location.hash.substr(1))
            hash = window.location.hash.substr(1).toLowerCase();

        if (hash) {
            var obj = $('#' + this.cookiename);
            var tabs = obj.find('.mtab_item').each(function (i) {

                if ((cookiename + hash).toLowerCase() == $(this).attr('id').toLowerCase()) {
                    // we got a winner, pass it on
                    mtarget = $(this);
                    mTabbedContent.runAnim(0);
                }
            });
        }
    },

    runAnim: function (duration) {
        // set the cookie for this id
       
        var obj = $('#' + this.cookiename);
        window.location.hash = '#' + mtarget.attr('id').replace(this.cookiename, '');
        $.cookie(this.cookiename, window.location.hash);

        var margin = obj.find(".mslide_content").width();
        var tabNo = (mtarget.prevAll().size() - 1) / 2;
        var aContent = obj.find('UL')[tabNo];

        margin = 0 - (margin * tabNo);

        obj.find(".mmoving_bg").stop().animate({ left: mtarget.position()['left'] }, { duration: duration });
        obj.find(".mtabslider").stop().animate({ marginLeft: margin + "px" }, { duration: duration });
        obj.find(".mslide_content").stop().animate({ height: $(aContent).height() }, { duration: duration });
        //obj.find(".mslide_content").stop().animate({ height: $(aContent).height() }, { duration: 50 });

    }
}

$(document).ready(function () {
    mTabbedContent.init('tabNirvana2');
});

