
$(document).ready(function(){

	// First Fix some IE6 bugs
	if (document.all && /MSIE (5\.5|6)/.test(navigator.userAgent))
	{
		$(this).find('.fx_memu_item').css({'margin-left' : '23px'});
	}

	var fx_menu_counter_up = new Array();
	var fx_menu_counter_down = new Array();
	var fx_menu_bg_pos_down=new Array();
	var fx_menu_bg_pos_up=new Array();
	
	fx_menu_bg_pos_down[0] = new Array(-208, 0);
	fx_menu_bg_pos_down[1] = new Array(-156, 0);
	fx_menu_bg_pos_down[2] = new Array(-104, 0);
	fx_menu_bg_pos_down[3] = new Array(-52, 0);
	fx_menu_bg_pos_down[4] = new Array(0, 0);
	fx_menu_bg_pos_up[0] = new Array(0, 0);
	fx_menu_bg_pos_up[1] = new Array(-52, 0);
	fx_menu_bg_pos_up[2] = new Array(-104, 0);
	fx_menu_bg_pos_up[3] = new Array(-156, 0);
	fx_menu_bg_pos_up[4] = new Array(-208, 0);
	fx_menu_bg_pos_up[5] = new Array(-208, 2);
	fx_menu_bg_pos_up[6] = new Array(-208, 4);
	fx_menu_bg_pos_up[7] = new Array(-208, 2);
	
	$(".fx_memu_item_block").hover(function() 
	{		
		fx_menu_hovered=1;
		
		fx_menu_counter_up[this.id] = 0;
		fx_menu_counter_down[this.id] = 0;

		var fx_menu_id = this.id.replace('fx_memu_item_', '');
		var fx_menu_delta_h = (fx_menu_id - 1) * 37;
	
	fx_menu_call_back_up=function() 
	{ 			
		var count = fx_menu_counter_up[this.id];
		var pos = fx_menu_bg_pos_up[count][0] + 'px ' + (fx_menu_bg_pos_up[count][1] - fx_menu_delta_h) + 'px';
		
		//$(this).append("<pre>" + pos + "\n</pre>");		
		$(this).find('.fx_memu_item').css({'background-position' : pos});
		if (count >= 7)
		{
			$(this).stopTime('fx_memu_controlled_timer_up' + this.id);
			fx_menu_counter_up[this.id] = 0;
		}
		else
		{
			fx_menu_counter_up[this.id] = count + 1;
		}	
   };

	fx_menu_call_back_down=function() 
	{ 		
		if (fx_menu_counter_up[this.id] == 0)
		{
		var count = fx_menu_counter_down[this.id];
		var pos = fx_menu_bg_pos_down[count][0] + 'px ' + (fx_menu_bg_pos_down[count][1] - fx_menu_delta_h) + 'px';
		
		//$(this).append("<pre>" + pos + "\n</pre>");		
		$(this).find('.fx_memu_item').css({'background-position' : pos});

		if (count >= 4)
		{
			$(this).stopTime('fx_memu_controlled_timer_down' + this.id);
			fx_menu_counter_down[this.id] = 0;
		}
		else
		{
			fx_menu_counter_down[this.id] = count + 1;
		}
		}
	};

	$(this).everyTime("0.08s", 'fx_memu_controlled_timer_up' + this.id, fx_menu_call_back_up);

	},
	function() 
	{			
		if(typeof(fx_menu_call_back_down) !== 'undefined') 
		{			
			$(this).everyTime("0.08s", 'fx_memu_controlled_timer_down' + this.id, fx_menu_call_back_down);	
		}
	}
	
	);

});
