﻿/*
	TODO: IMPLEMENTARE VERSIONE CON CSS3 TRANSITIONS (CON MODERNIZR)
	.csstransitions ul.listaespandibile ul { overflow: hidden; height: 0; margin: 0; }
	.csstransitions ul.listaespandibile.open > ul, .csstransitions ul.listaespandibile.open ul > ul { height: auto; margin: inherit; }
*/


(function ($) {
    $.fn.expandingList = function (options) {

        var settings = $.extend({
            'openonhover': false
        }, options);

        this.find("ul:not(.open)").hide();
        this.find("li").has("ul").css('cursor', 'pointer').find("ul").css('cursor', 'default');
        this.find("li.selected").parents("ul").show().prevAll("li").addClass("open");
        this.find("li.selected").next("ul").show();
        if (settings.openonhover) {
            this.find("> li, > li > ul > li")
	    .mouseenter(function () {
	        $(this).find("ul").first().stop(true, true).slideDown();
	    })
	    .mouseleave(function () {
	        $(this).find("ul").stop(true, true).slideUp();
	    });
        } else {
            this.find("> li, > li > ul > li").click(function (event) {
                event.stopPropagation();
                $(this).find("> ul").slideToggle();
                $(this).has("ul").toggleClass("open");
            });
        }

        return this;
    };
})(jQuery);
