// JavaScript Document


(function( $ ){
					
	var settings = {
		'speed' : 'slow'
	};
	
	var methods = {
		//Alle Menuepunkte lassen sich oeffnen und bleiben offen bis man ein zweites mal den Menuepunk klickt
		slideAll : function(){
									var element = $(this);
									//Submenue Liste mit <span class="hidden"></span> umschliessen
									var target = element.children('li').children('ul');
									target.wrap('<span class="hidden"></span>');
									
									
									//Klasse .open muss gesetzt werden wenn der menuepunkt nach klicken auf einen szbmenuepunkt offen bleiben soll
									if($('.open').parent('span').css('display')=='inline'){
										$('.open').parent('span').css('display','none');
									}
									$('.open').parent('span').css('display','inline');
								
									var opener = element.children('li').children('a');//HauptmenuePunkte
									$(opener).click(function(){
														
										$(this).next('span').slideToggle(settings['speed']);
										
										
										event.preventDefault();
														
									})
							},
		//Es lässt sich nur ein Punkt oeffnen beim klick auf einen neuen werden alle anderen geschlossen
		slideOne : function(){
									var element = $(this);
									
									var target = element.children('li').children('ul');
									target.wrap('<span class="hidden"></span>');
									/*if(target.attr('class') == 'hilfe_show'){
										target.parent('span').css('display', 'block');
									}else{
										target.parent('span').css('display', 'none');
									}*/
									//Klasse .open muss gesetzt werden wenn der menuepunkt nach klicken auf einen szbmenuepunkt offen bleiben soll
									if($('.open').parent('span').css('display')=='inline'){
										$('.open').parent('span').css('display','none');
									}
									$('.open').parent('span').css('display','inline');
			
									var opener = element.children('li').children('a');//HauptmenuePunkte
									
									$(opener).click(function(event){
																					 event.preventDefault();
															var tmp_block = $(this).next('span').css('display');
															//Pruefen ob menuePunkt aufgeklappt ist
															if(tmp_block =='inline'){
																$(this).next('span').slideToggle(settings['speed']);
															}else{
																opener.next('span').css('display','none');
															 	
															 	$(this).next('span').slideToggle(settings['speed']);
																$(this).next('span').css('display','inline');
															}
														})
									
							},
			fadeIn : function(){
									var element = $(this);
			
									var target = element.children('li').children('ul');
									target.wrap('<span class="hidden"></span>');
									
									//Klasse .open muss gesetzt werden wenn der menuepunkt nach klicken auf einen szbmenuepunkt offen bleiben soll
									$('.open').parent('span').css('display','block');
			
										var opener = element.children('li').children('a');
										$(opener).click(function(){
											var tmp_block = $(this).next('span').css('display');
											
											if(tmp_block =='inline'){
												$(this).next('span').css('opacity',1.0);
												$(this).next('span').animate({'height':'hide','opacity' :0.0},settings['speed']);
												opener.next('span').css({'display':'none'});
															
											}else{
												
												$(this).next('span').css('opacity',0.0);
												$(this).next('span').animate({'opacity' :1.0, 'height':'show'},settings['speed']);
												opener.next('span').css({'display':'none'});
												$(this).next('span').css('display','inline');
											}
										})
							}
		
	};
	
  $.fn.slideMenue = function(method,options) {
		 // Method calling logic
     return this.each(function() {
		 
		 if ( options) { 
        $.extend( settings, options );
      }

		
		if ( methods[method] ) {
      return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 ));
    } else if ( typeof method === 'object' || ! method ) {
      return methods.init.apply( this, arguments );
    } else {
      $.error( 'Method ' +  method + ' does not exist on slideMenue' );
    }  
		
															 });

  	/*return this.each(function(f){
			var element = $(this);
			
			var target = element.children('li').children('ul');
			target.wrap('<span class="hidden"></span>');
			
			var opener = element.children('li');
			$(opener).click(function(){
															 $(this).children('span').slideToggle('slow');
															 });

  })*/}
})( jQuery );
