﻿var activeQuote = -1;
var rotatorElements = [];
jQuery.fn.quotesRotate = function() {
    
    this.find('table').each(function() {
        rotatorElements.push($(this));
        $(this).hide();
    });
    
    if(rotatorElements.length == 1)
        rotatorElements[0].show();
    
    if (rotatorElements.length > 1)
        RotateQuote();
};

function RotateQuote() {
    var nextActiveQuoteIndex = activeQuote + 1 < rotatorElements.length ? activeQuote + 1 : 0;
    var nextElement = rotatorElements[nextActiveQuoteIndex];
    if (activeQuote > -1)
        rotatorElements[activeQuote].fadeOut('fast', function() { nextElement.fadeIn('fast'); });
    else
        nextElement.fadeIn('fast');
    activeQuote = nextActiveQuoteIndex;
    setTimeout('RotateQuote();', 8000);
}

jQuery.fn.profileMenu = function(menuList) {
    $(menuList).hide();
    this.click(function() {
        if ($(menuList).is(':hidden')) {
            $(menuList).show('fast', function() {
                $(document).bind('click.profileMenu', function() {
                    if (!$(menuList).is(':hidden'))
                        $(menuList).hide('fast');
                        $(document).unbind('click.profileMenu');
                });
            });
            $(menuList).css('position', 'absolute');
            var offset = $(this).offset();
            $(menuList).offset({ top: offset.top + 20, left: offset.left });

        }
        else {
            $(menuList).hide('fast');
            $(document).unbind('click.profileMenu'); 
        }
    });
}

