var timeout    = 500;
var closetimer = 0;
var ddmenuitem = 0;

function fix_position()
{ 
   var p = $(this).find('a').first().position();
   var w = $(this).find('ul').first().width();
  
   if(p && (p.left + w ) > $("#header").width()){
	 	$(this).find('ul').first().css('right', '0px');
	
		$(this).bind('mouseover',function(){	
			$(this).find('a').first().css('borderLeft', 'none');
			$(this).find('a').first().css('borderRight', '1px solid #ccc');
		});
		$(this).bind('mouseout',function(){
			$(this).find('a').first().css('borderRight', 'none');
		});
	} else {
		$(this).find('ul').first().css('left', p.left + 'px');
	}
	
}

$(document).ready(function()
{  $('#nav > li').bind('mouseover', fix_position);
});


