/* fix flash content */
jQuery.fx.prototype.originalCustom = jQuery.fx.prototype.custom;
jQuery.fx.prototype.custom = function(from,to,unit) {
	if (this.prop=='height') { 
		to = to || 1;
		from = from || 1; 
	}
	this.originalCustom(from,to,unit);
}
/* function delay */
$.fn.delay = function(time,func){
	this.each(function() {
		setTimeout(func,time);
	});	
	return this;
};
 
$.fn.droppy = function(options) {
    
  options = $.extend({speed: 300}, options || {});
  
  this.each(function() {
    
    var root = this, zIndex = 1000;
        
    function getSubnav(ele) {
      if (ele.nodeName.toLowerCase() == 'li') {
        var subnav = $('> ul', ele);
        return subnav.length ? subnav[0] : null;
      } else {
        return ele;
      }
    }
    
    function getActuator(ele) {
      if (ele.nodeName.toLowerCase() == 'ul') {
        return $(ele).parents('li')[0];
      } else {
        return ele;
      }
    }
    
    function hide() {
      var niveau1 = this;
      var subnav = getSubnav(this);
      $.data(this, 'cancelHide', false);
      if (!subnav)
      {
		$(niveau1).removeClass('hover'); $('> a', niveau1).removeClass('hover');
		return;
	  }	  
      
      setTimeout(function() {
        if (!$.data(niveau1, 'cancelHide')) {
          $(subnav)
			.slideUp( options.speed , function(){ if (!$.data(niveau1, 'cancelHide')) { $(niveau1).removeClass('hover'); $('> a', niveau1).removeClass('hover'); } } );
        }
      }, 500);
     
    }

    function show() { 
	  $(this).addClass('hover'); $('> a', this).addClass('hover');
      $.data(this, 'cancelHide', true);
      var subnav = getSubnav(this);
      if (!subnav) { return; }
      $(subnav).css({zIndex: zIndex++}).slideDown(options.speed);          
    }

	/* niveau 1 */    
    $('> li', this).not('li.topmenu-separ').hover(show, hide);
    /* niveau 2 */
    $('> li > ul > li', this).hover(
      function() { $(this).addClass('hover'); $('> a', this).addClass('hover'); },
      function() { $(this).removeClass('hover'); $('> a', this).removeClass('hover'); }
    );
    
  });
  
};
