

$(document).ready(function()
{

	if(   $.browser.msie && $.browser.version == 8.0){
		var minoffset = 24;
		//alert(' < ie 9');
	}else if($.browser.msie && $.browser.version == 7.0){
			var minoffset = 20;
	}else if(   $.browser.msie && $.browser.version > 8){
	var minoffset = 24;	
	//	alert(' > ie 8 ');
	}else if($.browser.mozilla){
		var minoffset = 24;	
	}else
		var minoffset = 24;	
		
var timeout    = 300;
var closetimer = 0;
var ddmenuitem = 0;
//find longest ul and take his height
var theheight = 0;
  $("nav ul#nav").find('ul').each(function(index) {
	 obj = $(this).parent(this);
	

	 
	$(this).css('left',(parseInt(((obj.position().left - minoffset)),10)));
	 
	
	
	 if(parseInt($(this).css('height'),10) > theheight){
	  	theheight = parseInt($(this).css('height'),10);
	  }
  });
  theheight =	theheight + 100;

function jsddm_open()
{  


 if($('.navBackground').css('display') == 'none' ){ //is the background busy or open?
     $('.navBackground').css('opacity',0);
   $('.navBackground').show();
    $('.navBackground').animate({
    height: theheight + 'px',
	opacity: 1
  }, 300, function() {
    $("ul#nav").find('ul').fadeIn("fast");
	 $("ul#nav").find('ul').height(theheight -91)
	
  });
  }
 
 }

function jsddm_close()
{ 
 
  $("ul#nav ul").hide();
   
    $('.navBackground').animate({
    height: '0px',
	opacity: 0
  }, 150, function() {
   $('.navBackground').hide();
   //$('.navBackground').css('height','0px'); //just for sure 
   $("ul#nav ul").hide(); //just for sure
  });

}

function jsddm_timer()
{  closetimer = window.setTimeout(jsddm_close, timeout);}

function jsddm_canceltimer()
{  
if(closetimer)
   {
    window.clearTimeout(closetimer);
   closetimer = null;
	}
}

    //event handlers  
	 $('#nav li').mouseenter(function(){
		 if(!$(this).find('a').first().hasClass('first'))
		 	jsddm_open();jsddm_canceltimer(); 
		 
		 });
	  
	  
	$('#nav li a').mouseenter(function(){jsddm_canceltimer(); });
   $('#nav li a.sub').mouseenter(function(){window.setTimeout(jsddm_open,0)});
   $('.navBackground').mouseenter(function(){jsddm_canceltimer()});
   $('.navBackground').mouseleave(function(){jsddm_timer() });
   $('#nav ul').mouseenter(function(){jsddm_canceltimer()});
   $('#nav ul').mouseleave(function(){jsddm_timer()});
   $('#container').click(jsddm_close());

});



