//var $ = jQuery.noConflict();



jQuery(document).ready(function($){



	$(".main-menu a").hover(function(){

		

		var $position = $(this).position();

		var $width = $(this).outerWidth();

		

		if($('.main-menu').find('#background-light').length != 0){



			$('#background-light').stop().animate({

				left : $position.left,

				width : $width

			}, 200);

		}

		else{

			var $item = $(this).createItem($('.current_page_item').children().position(), $('.current_page_item').children().outerWidth());

			

			$(".main-menu a").each(function(){

				if($(this).parent().hasClass('current_page_item')){

					$(this).parent().removeClass('current_page_item').addClass('active_hover');

				}

			})

			

			$item.stop().animate({

				left : $position.left,

				width : $width

			}, 200);

		}

		

									 

		

		//console.log($width+" "+$offset.left+" "+$offset.top);

		

	}, function(){

		var $position = $('.active_hover').position();

		var $width = $('.active_hover').outerWidth();

		

		

		

		$('#background-light').stop().animate({

			left : $position.left,

			width : $width

		}, 400);

	});



});




(function ($) {

  $.fn.createItem = function($position, $width){



	  $('.main-menu').append("<span id='background-light'></span>");

	  return $('.main-menu').find('#background-light').css({'width' : $width, 'left' : $position.left});

  };

})(jQuery);
