﻿$.fn.dropdown = function(options) {
    var settings = jQuery.extend({ timeout: 0.3 }, options);
    var closetimer = null;
    var ddmenuitem = null;
    var currli = null;
    var images = null;
    var active = false;
    $(this).children('li').hover(dropdown_open, dropdown_timer);

//    $(this).children('li').find('ul:empty').each(function() {
//        $(this).hide();
//    });

    function dropdown_open() {
        dropdown_canceltimer();
        dropdown_close();
        if ($('div', this).children().size() > 0) {
            ddmenuitem = $('div', this).css('display', 'block');
            currli = $(this);
            currli.addClass("hover");
        }
    }

    function dropdown_close() {
        if (ddmenuitem) {
            ddmenuitem.css('display', 'none');
            currli.removeClass("hover");
        }
    }

    function dropdown_timer() { closetimer = window.setTimeout(dropdown_close, settings.timeout * 1000); }
    //function dropdown_timer() { }

    function dropdown_canceltimer() {
        if (closetimer) {
            window.clearTimeout(closetimer);
            closetimer = null;
        }
    }

    return this;
}

