jQuery.fn.delay = function(time, callback){
    // Empty function:
    jQuery.fx.step.delay = function(){};
    // Return meaningless animation, (will be added to queue)
    return this.animate({delay:1}, time, callback);
}

jQuery(document).ready(function(){

var scroll_m = false;

/* show/hide drop down navigation */
	jQuery("#dropdown_list_container").hide(); 	

  jQuery(document).click(function(el) {
    var elm = el.target;
    var kind = jQuery(elm).parents('#dropdown_list_container');
    
    if (jQuery(elm).attr('id') != 'navigation_trigger' && kind.length == 0) {
      if(jQuery('#navigation_trigger').hasClass('nav_active')) {
        jQuery("#dropdown_list_container").fadeOut(500);
        jQuery('#navigation_trigger').removeClass("nav_active");
      }
    }
  })

	jQuery("#navigation_trigger").click(function () {
    	if(jQuery(this).hasClass('nav_active')) {
			jQuery("#dropdown_list_container").fadeOut(500);
		}
		else {
			jQuery("#dropdown_list_container").fadeIn(500);
		}
		jQuery(this).toggleClass("nav_active");
    });

/* show/hide drop down navigation image */
	jQuery(".nav_content_image").hide();
  
  /* Hover ueber Ueberschriften */
  jQuery('.nav_content_trigger').hover(function() {
    jQuery(this).find('*').css({
      'color':'#000',
      'font-weight':'bold'
    });
  }, function() {
    if (jQuery(this).next('.nav_content_image').css('display') == 'none') {
      jQuery(this).find('*').css({
        'color':'#545454',
        'font-weight':'normal'
      });
    }
  });

	$('ul#dropdown_list li').hoverIntent(function() {

  if (scroll_m == false) {

    if(jQuery(this).hasClass('li_active')) {

    } else {
      	jQuery("li.li_active").children(".nav_content_image").slideToggle(850);
      	jQuery("li.li_active").removeClass("li_active");
    		jQuery(this).toggleClass("li_active");		
    		jQuery(this).children(".nav_content_image").slideToggle(850);	


      jQuery('.nav_content_trigger').parent('li').each(function() {
        if (!jQuery(this).hasClass('li_active')) {
          jQuery(this).find('.nav_content_trigger *').css({
              'color':'#545454',
              'font-weight':'normal'
            })
        }
      })

    }
    
  }

		jQuery("ul").animate({'height':'330px'},850);
        return false;
	}, function() {
	
  });

//jQuery('#previous_li').append('<div class="prev_li" style="position:absolute; top:0; left:0; height:30px; width:300px;"></div>');
//jQuery('#next_li').append('<div class="next_li" style="position:absolute; top:-10px; left:0; height:10px; width:300px;"></div>');

//Scrollen mit dem Mausrad
var interval = '';
var MNextInterval = '';
$('#dropdown_list_container').mousewheel(function(event,delta) {
  event.preventDefault(); //Verhindern das die Seite gescrollt wird
  
  if (!scroll_m) {
  	scroll_m = true;
  	if (delta > 0) {
  		//Hoch

		var speed = 100;
		var werte = 0;
		function moveUp(){
  		werte++;
      if (werte >= 3) {
        clearInterval(interval);
        scroll_m = false;
        werte = 0;
      }
		
			jQuery("#next_li").animate({opacity: 1.0},150);
 			if(!jQuery('#dropdown_list li:first').hasClass('first')) {
				var current_first = jQuery("li.first");	
				jQuery(current_first).prev().addClass("previous_first_li");
				jQuery("li.first").removeClass("first");
				jQuery("li.previous_first_li").removeClass("hidden_li").removeClass("previous_first_li").addClass("first");

				} else {
			 		jQuery("#previous_li").animate({opacity: 0.3},150);
			  }
	 		}
  		interval = setInterval(moveUp, speed);
  	  return false;

  	} else {
  		//Runter
	
		var speed = 100;
		var werte = 0;
		function moveDown(){
      werte++;
  		if (werte >= 3) {
        clearInterval(MNextInterval);
        scroll_m = false;
        werte = 0;
      }
		var total_remaining_list_items = $("li.first").nextAll("li").length;
   		if(total_remaining_list_items <= 9) {
   			jQuery("#next_li").animate({opacity: 0.3},150);
   		} else {
     		if(!jQuery('#dropdown_list li:last').hasClass('first')) {
  				var current_first = jQuery("li.first");
  				jQuery(current_first).next().addClass("next_first_li");
  				jQuery(current_first).addClass("hidden_li").removeClass("first");
  				var next_first = jQuery("li.next_first_li");
  				jQuery(next_first).addClass("first").removeClass("next_first_li");
  		  	    if(jQuery('#dropdown_list li:first').hasClass('first')) {
       				jQuery("#previous_li").animate({opacity: 0.3},150);
       			}
       			else {
            			jQuery("#previous_li").animate({opacity: 1.0},150);
       			   }
    	  }
		  }	
	  }
	  MNextInterval = setInterval(moveDown, speed);
	  return false;

  	}
  }
});

var NextInterval = '';

/* mouse over to move list up and down */
	jQuery("#dropdown_list li:first").addClass("first");
	jQuery("#dropdown_list li:last").addClass("last");
    
	jQuery("#next_li").bind("mouseenter",function(){
		var speed = 200;
		function moveDown(){
		var total_remaining_list_items = $("li.first").nextAll("li").length;
     		if(total_remaining_list_items <= 9) {
     			jQuery("#next_li").animate({opacity: 0.3},150);
     		}
			else {
     			if(!jQuery('#dropdown_list li:last').hasClass('first')) {
				var current_first = jQuery("li.first");
				jQuery(current_first).next().addClass("next_first_li");
				jQuery(current_first).addClass("hidden_li").removeClass("first");
				var next_first = jQuery("li.next_first_li");
				jQuery(next_first).addClass("first").removeClass("next_first_li");
		  	    if(jQuery('#dropdown_list li:first').hasClass('first')) {
     				jQuery("#previous_li").animate({opacity: 0.3},150);
     			}
     			else {
          			jQuery("#previous_li").animate({opacity: 1.0},150);
     			   }
		  	    }
		     }	
	  	   }
		NextInterval = setInterval(moveDown, speed);
  	  return false;
	});
    
	jQuery("#next_li").bind("mouseleave",function(){
		clearInterval(NextInterval);
 	  return false;
	});
    
    
     if(jQuery('#dropdown_list li:first').hasClass('first')) {
     	jQuery("#previous_li").animate({opacity: 0.3},150);
     }

  var PrevInterval = '';
    
	jQuery("#previous_li").bind("mouseenter",function(){

    var speed = 200;
		function moveUp(){
			jQuery("#next_li").animate({opacity: 1.0},150);
 			if(!jQuery('#dropdown_list li:first').hasClass('first')) {
				var current_first = jQuery("li.first");	
				jQuery(current_first).prev().addClass("previous_first_li");
				jQuery("li.first").removeClass("first");
				jQuery("li.previous_first_li").removeClass("hidden_li").removeClass("previous_first_li").addClass("first");

				}
			else {
			 		jQuery("#previous_li").animate({opacity: 0.3},150);
			   }
	 		}
		PrevInterval = setInterval(moveUp, speed);
  	  return false;
	});
    
    
	jQuery("#previous_li").bind("mouseleave",function(){
		clearInterval(PrevInterval);
 	 return false;
	});

});
