$(function(){

	for(i=1;i<$(".h_menu_group li").length;i++)
	{
		var height = $('#nav'+i).height();
		if(height>15)
		{
			$('#nav'+i).css("margin-top", "-6px");
		}
		$('#nav'+i).css("height", "30px");
	}

    var $el, leftPos, newWidth,topPos
        $mainNav2 = $("#menu_horizontal");
    
    
    
    $mainNav2.append("<li id='magic-line-two'></li>");
    var $magicLineTwo = $("#magic-line-two");
    
    origColor = $(".current_item a").attr("rel")
    origColor = origColor.replace(/-/g,",")
    if ($.browser.msie)
    	origColor = "rgb("+origColor+")";
    else
    	origColor = "rgba("+origColor+")";
    $magicLineTwo
        .width($(".current_item").width())
        .height("31px")
        .css("left", $(".current_item a").position().left)
        .css("top", $(".current_item a").position().top)
		.data("origLeft", $(".current_item a").position().left)
        .data("origTop", $(".current_item a").position().top)
        .data("origWidth", $magicLineTwo.width())
        .data("origColor", origColor);
     
            
    $("#menu_horizontal li").find("a").click(function() {
    	
		    origColor = $(this).attr("rel")
		    origColor = origColor.replace(/-/g,",")
		    if ($.browser.msie)
		    	origColor = "rgb("+origColor+")";
		    else
		    	origColor = "rgba("+origColor+")";
	        
    	
    	$magicLineTwo
			.data("origLeft", $(this).position().left)
	        .data("origTop", $(this).position().top)
	        .data("origWidth", $magicLineTwo.width())
	        .data("origColor", origColor);
    });
    
    
    
    $("#menu_horizontal li").find("a").hover(function() {
        $el = $(this);
       
    	newColor = $el.attr("rel")
    	newColor = newColor.replace(/-/g,",")
    	if ($.browser.msie)
   			newColor = "rgb("+newColor+")";
   		else
   			newColor = "rgba("+newColor+")";
       
        leftPos = $el.position().left;
        topPos = $el.position().top;
        newWidth = $el.parent().width();
        $magicLineTwo.stop().animate({
            left: leftPos,
            top: topPos,
            width: newWidth,
            backgroundColor: newColor
        })
    }, function() {
	        $magicLineTwo.stop().animate({
	            left: $magicLineTwo.data("origLeft"),
	            top: $magicLineTwo.data("origTop"),
	            width: $magicLineTwo.data("origWidth"),
	            backgroundColor: origColor
	        }, {duration:1000});
    });
});
