$(document).ready(function(){
	
	var currentDRP=null;
	var outCounter=0;
	var speed=100;
	var outIntervalID;
	var maxOutLimit=1;
	
	
	//$('.mattblackmenu').append("<input id='rt' type='text'/>");
	$(".mattblackmenu a").each(function(n){
									   		if($(this).attr('rel').length>0)
											{
											  	
											}
									    
									     });	
	
	$(".mattblackmenu a").css('display','block');
	$(".mattblackmenu a").css('height',35);
	//$(".mattblackmenu a").css('background','#ff0000');
	$('.mattblackmenu a').bind('mouseover',dropdownopener);
	$('.mattblackmenu a').bind('mouseout',dropdowncloser);
	$('.mattblackmenu a').each(function(n){$(this).attr('serial',n)})
	
	
	
	$(".dropDownMenu").each(function(n){$(this).attr('id','drp'+n)})
	
	$(".dropDownMenu .option_container").each(function(n){
													   														 
														  $(this).attr('openHeight',(22*($(this).find('li').length)))
														  $(this).find('a').bind('mouseout',function(){ start_COUNTER();});
														  $(this).find('a').bind('mouseover',function(){stop_COUNTER();});
														  
													   
													   
													     });
	
	
	
	
	function dropdowncloser()
	{
		//resetAll();
	}
	
	function dropdownopener()
	{
	 
	  resetAll();
	  var c = $(this).attr('rel').split('dropdown')[1]-1;
	  var left_amt=215;
	  var W = $(window).width();
	  if(W>1000)
	  {
		left_amt = ((W-1000)/2)+left_amt;
		
	  }
	  
	  left_amt = left_amt+(($(this).attr('serial'))*112);
	  
	  
	  
	  
	  
	  var drpdwn = $(".dropDownMenu").eq(c);
	  drpdwn.css('left',left_amt+50);
	  
	  drpdwn.animate({opacity:1,left:left_amt},800);
	  drpdwn.show();
	  drpdwn.animate({opacity:1},700);
	  var theMenuPanel = $(".dropDownMenu").eq(c).find(".option_container");
	  var h = $(".dropDownMenu").eq(c).find(".option_container").attr('openHeight');
	  theMenuPanel.animate({height:h},{duration:'slow',easing: 'swing'},2000);
	  
	  
	  
	  currentDRP = drpdwn;	  
	}
	
	function resetAll()
	{
		clearInterval(outIntervalID);
		outCounter=0;
		if(currentDRP!=null)
		{
		currentDRP.hide('fast');
		}
	}
	
	function start_COUNTER()
	{
		clearInterval(outIntervalID);
		outCounter=0;
		outIntervalID = setInterval(out_incr,speed);
	}
	
	function stop_COUNTER()
	{
		clearInterval(outIntervalID);
		outCounter=0;
	}
	
	function out_incr()
	{
	  if(outCounter<maxOutLimit)
	  {	outCounter++; }
	  else
	  { 
	    clearInterval(outIntervalID);
		outCounter=0;
		currentDRP.hide('fast');
	  }
	  
	  //$('#rt').html(outCounter);
	}
	
	
	
	
						   
});
