/**
  toggle menu items
  @author Christian Niedrich @farbwahl
  @mail christian.niedrich@highgain.de
  @date   10.2010

**/

(function($) {
  
  /*
		toggler: this plugin is for toggling behavior on kde site
		@param
			@settings (object)-> 
				fn -> function that has to be executed, when click-event was fired
	*/
  $.fn.toggler = function(settings) {
    
	settings = jQuery.extend({
		fn 	: null	
	},settings);
	
	return this.each(function(){
		
		var e = $(this);
		
		/* click me, for opening the sub */
		e.click(function(){
			var e = $(this);
			var p = e.parent();
			
			/* action for close sub */
			if(p.hasClass('open')){
				p.removeClass('open');
				e.removeClass('open');				
			}
			else{
				/* close all open */
				p.parent().find('.open').removeClass('open');
				
				/* open sub */
				p.addClass('open');
				e.addClass('open');
			}
			
			//fire settings function
			if(typeof(settings.fn) === "function")
				settings.fn(e);
			
		});

	});
  };


})(jQuery);
