/* 
* 	LICENSE
*	Quest'opera è stata rilasciata sotto la licenza Creative Commons Attribuzione-Condividi allo stesso modo 2.5 Italia.
*	Per leggere una copia della licenza visita il sito web http://creativecommons.org/licenses/by-sa/2.5/it/
*	o spedisci una lettera a Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA.
*/




(function ($) {

	// 
	//	ACCORDION function for nested Unordered list
	//	@required easing jQuery plugin
	//	http://www.learningjquery.com/2007/10/a-plugin-development-pattern

	(function () {

		$.fn.accordion = function (options) {
			defaults = {
				elem: ".accordion",
				open: -1,
				lnkel: "a",
				sliders: ".toggle",
				navigation: function () {
					return this.href.toLowerCase() == location.href.toLowerCase();
				}
			}
			var options = $.extend({}, defaults, options);

			esto = $(options.elem);

			var toggleElement = esto.children(options.sliders);
			var toggler = esto.children(options.lnkel);

			var current = options.open;
			$(esto).addClass(function (index) {
				if (index == current) {
					return 'attivo';
				}
			});

			toggleElement.not(":eq(" + options.open + ")").hide();
			toggler.click(function (e) {
				var target = $(e.target);
				if (target.nextAll(options.sliders).is(":hidden")) {
					toggleElement.slideUp({ duration: 700 }).parent().removeClass('attivo');
					target.nextAll(options.sliders).slideDown({ duration: 700 }).parent().addClass('attivo');

				}
				return false;
			});
		};



	})();
})(jQuery);
