(function($){jQuery.fn.intoViewport=function(options){options=$.extend({duration:200,easing:"swing"},options||{});return this.each(function(){function scrTo(dest){$("html,body").stop().animate({scrollTop:dest},options);}var scr=$(document).scrollTop()||$(window).scrollTop(),wheight=$(window).height(),top=$(this).offset().top,eheight=$(this).outerHeight();if(scr>top){scrTo(top);}else if(scr!=top&&top+eheight>scr+wheight){scrTo(top+Math.min(eheight-wheight,0));}});};})(jQuery);


(function($){
   $.fn.extend({ 
    
     multiAccordion: function(options) {
    
      var defaults = {
        active: 0,
		ele:'h3'
      }
      var options =  $.extend(defaults, options);
		
        return this.each(function() {
        var $this = $(this);
      
		var $h3 = $this.children(options.ele);
        var $div = $this.children('div');
        $this.addClass('ui-accordion ui-widget ui-helper-reset ui-accordion-icons');
        $h3.each(function(index){
			
          var $this = $(this);
		  
          $this.children('a.na').attr('href', 'javascript:void(0);');
          $this.addClass('ui-accordion-header ui-helper-reset ui-state-default ui-corner-all').prepend('<span class="ui-icon ui-icon-triangle-1-e"></span>');
		  
		  var temp=$this.get(0).id;
		  temp=temp.substr(5);
		 
		  
          if(isActive(index,temp)) {
			
		    showTab($this,0)
          } else {
           	hideTab($this,0)
          }
        });
        $this.children('div').each(function(index){
          var $this = $(this);
          $this.addClass('ui-accordion-content ui-helper-reset ui-widget-content ui-corner-bottom');
        });
		
		
		
        $h3.click(function(){
			micms_contentloaded=0;
          var $this = $(this);          
          if ($this.hasClass('ui-state-default')) {
            showTab($this,1);
          } else {
           hideTab($this,1);
          }
        });
        $h3.hover(
          function() {
            $(this).addClass('ui-state-hover');
          }, function() {
            $(this).removeClass('ui-state-hover');
          }
        );
		
        });
      
      function showTab($this,$sound) {
		  
		  // $('html, body').animate({scrollTop: $("#navi_4").offset().top}, 2000);
		  
		  
		
		
		// mi: andere Menüs zuklappen und Ton abspielen
		
		var $te=$this.get(0).tagName.toLowerCase();
		if ($te=="h3") {
			var $te2=".mainmenu";	
		} else {
			var $te2=".submenu";
		}
		;
		$($te2).children($te).each(function(){
      	  var $t = $(this);
				// alert($this.get(0).id+"#"+$t.get(0).id);
			 // if ( ($this.get(0).tagName.toLowerCase()==$t.get(0).tagName.toLowerCase()) && ($this.get(0).id!=$t.get(0).id) ) {
				 

				hideTab($t,0);
			// }
		 
		 });
			
	

		if ($sound==1) {
			ton('/sounds/menu.ogg');
		}

		var $span = $this.children('span.ui-icon');
        var $div = $this.next();
        $this.removeClass('ui-state-default ui-corner-all').addClass('ui-state-active ui-corner-top');
        $span.removeClass('ui-icon-triangle-1-e').addClass('ui-icon-triangle-1-s');
        $div.slideDown('fast', function(){
        $div.addClass('ui-accordion-content-active');
		
        });
		
		


		var i=$this.get(0).id;
		i=i.substr(5);
		mi_langs.foreach(function(x,y) {
			var t="lg_"+y+"_"+i;
			if (e=document.getElementById(t)) {
				if (e2=document.getElementById("flag_"+y)) {
					e2.href=e.href;
				}
			}
	  });
		
		if (micms_contentloaded!=1) {
			load_content(i,$this.get(0).title);
		}
		
		
		 //$div.animate({scrollTop: 0}, 400, function() {         
         // });
		
		var to=$this.offset().top;
		
		$('html, body').animate({scrollTop:to}, 'slow');
		
		
		
      }
      
      function hideTab($this,$sound) {
		
		if ($sound==1) {
			ton('/sounds/menu.ogg');
		}
        var $span = $this.children('span.ui-icon');
        var $div = $this.next();
        $this.removeClass('ui-state-active ui-corner-top').addClass('ui-state-default ui-corner-all');
        $span.removeClass('ui-icon-triangle-1-s').addClass('ui-icon-triangle-1-e');
       $div.slideUp('fast', function(){
          $div.removeClass('ui-accordion-content-active');
        });
		
		var i=$this.get(0).id;
		i=i.substr(5);
		
		if (e=document.getElementById("content_"+i.toString())) {
			// e.innerHTML="";
		}
		
      }
      
      function isActive(num,miid) {
     
	 	miid=parseInt(miid);
		
	 
        if(typeof options.active == "boolean" && !options.active) {
          return false;
        } else {
			
          if(options.active.length != undefined) {
            for (var i = 0; i < options.active.length ; i++) {
              if (options.active[i] == num)
              
			    return true;
            }
          } else {
			
            return ( (options.active == num) && (miid==options.miid) );
          }
        }
        return false;
      }
      }
  });
})(jQuery);



