$(document).ready(function() {	

	//Background color, mouseover and mouseout
	var colorOver = '#31b8da';
	var colorOut = '#1f1f1f';

	
		
	//Animate the LI on mouse over, mouse out
	$('#menu2 li').click(function () {	
		//Make LI clickable
		window.location = $(this).find('a').attr('href');
		
	}).mouseover(function (){
		
		//mouse over LI and look for A element for transition
		$(this).find('a')
		.animate( { paddingLeft: padLeft, paddingRight: padRight}, { queue:false, duration:100 } )
		.animate( { backgroundColor: colorOver }, { queue:false, duration:200 });

	}).mouseout(function () {
	
		//mouse oout LI and look for A element and discard the mouse over transition
		$(this).find('a')
		.animate( { paddingLeft: defpadLeft, paddingRight: defpadRight}, { queue:false, duration:100 } )
		.animate( { backgroundColor: colorOut }, { queue:false, duration:200 });
	});	
	
	//Scroll the menu2 on mouse move above the #sidebar2 layer
	$('#sidebar2').mousemove(function(e) {

		//sidebar2 Offset, Top value
		var s_top = parseInt($('#sidebar2').offset().top);		
		
		//sidebar2 Offset, Bottom value
		var s_bottom = parseInt($('#sidebar2').height() + s_top);
	
		//Roughly calculate the height of the menu2 by multiply height of a single LI with the total of LIs
		var mheight = parseInt($('#menu2 li').height() * $('#menu2 li').length);
	
		//I used this coordinate and offset values for debuggin
		$('#debugging_mouse_axis').html("X Axis : " + e.pageX + " | Y Axis " + e.pageY);
		$('#debugging_status').html(Math.round(((s_top - e.pageY)/100) * mheight / 2));
			
		//Calculate the top value
		//This equation is not the perfect, but it 's very close	
		var sidebar2_height = $('#sidebar2').height();
var menu2_height = $('#sidebar2 ul').height();
top_value = Math.round(( ((e.pageY - s_top) / sidebar2_height * ((sidebar2_height - menu2_height))))); 
if(menu2_height < sidebar2_height) {
top_value = 0;
} 
		
		//Animate the #menu2 by chaging the top value
		$('#menu2').animate({top: top_value}, { queue:false, duration:500});
	});

	
});

