﻿/**
* LavaLamp - A menu plugin for jQuery with cool hover effects.
* @requires jQuery v1.1.3.1 or above
*
* http://gmarwaha.com/blog/?p=7
*
* Copyright (c) 2007 Ganeshji Marwaha (gmarwaha.com)
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*
* Version: 0.2.0
* Requires Jquery 1.2.1 from version 0.2.0 onwards. 
* For jquery 1.1.x, use version 0.1.0 of lavalamp
*/

(function($) {
    $.fn.divLavaLamp = function(o) {
        o = $.extend({ fx: "linear", speed: 500, click: function() { } }, o || {});

        return this.each(function() {
            var $selected;
            var firstRun = true;
            var me = $(this), noop = function() { },
            $back = $('<span class="back"></span>').appendTo(me),
           $li = $("li", this), curr = $($li[0]).addClass("current")[0];
            $li.removeClass('highlight')
            .find('a')
            .append('<span class="hover" />').each(function() {
                var $span = $('> span.hover', this).css('opacity', 0);
                var $selectedContent = $(".content .content" + $span.parent().parent().attr('id')).css('opacity', 0);
                if (firstRun) {
                    firstRun = false;
                    $selected = $span;
                    $span.stop().fadeTo(500, 1);
                    $selectedContent.stop().css({ display: "block" }).fadeTo(700, 1);
                }
                $(this).hover(function() {
                    $(".content .content" + $selected.parent().parent().attr('id')).stop().css({ display: "none" }).fadeTo(700, 0);
                    $selected.stop().fadeTo(500, 0);
                    move(this);
                    $selected = $span;
                    $span.stop().fadeTo(500, 1);

                    $(".content .content" + $span.parent().parent().attr('id')).stop().css({ display: "block" }).fadeTo(700, 1);
                   
                }, function() {
                    // off hover
                });
            });
            $li.not(curr).hover(function() {


            }, function() {
                //need to fade out class
            });

            $(this).hover(noop, function() {
                //disabled because last highlighted menu becomes current in move function
            });

            setCurr(curr);

            function setCurr(el) {
                $back.css({ "left": el.offsetLeft + "px", "width": el.offsetWidth + "px" });

                curr = el;

            };

            function move(el) {
                $back.each(function() {
                    $(this).dequeue();

                    setCurr(this);

                }
            ).animate({
                width: el.offsetWidth,
                left: el.offsetLeft
            }, o.speed, o.fx);
            };

        });
    };
})(jQuery);
