jQuery.noConflict();

// Document Ready Event
jQuery(document).ready(function(){
	
	// Define Variables
	var startpos = 42;
	var wrapwidth = 960;
	var menu = jQuery('.wpn_menu > ul');
	var totalwidth = 0;
	var menuitems = jQuery(menu).children('li');
	
	// Calculate the total width of all of the <li> elements
	jQuery(menuitems).each(function(i,item) {
		totalwidth += jQuery(item).outerWidth(true);
	});
	
	// Left menu button events
	jQuery('#menu-lbutton').mouseenter(function() {
		// Don't animate if the amount its going to scroll is smaller then the items there are
		if(wrapwidth < totalwidth) {
			jQuery(menu).animate({left: startpos}, 2000);
		}
	}).mouseleave(function() {
		// Stop the animation if the mouse leaves the button
		jQuery(menu).stop();
	}).mousedown(function() {
		// Mousedown to speed up
		if(wrapwidth < totalwidth) {
			jQuery(this).preventDefault();
			jQuery(menu).stop();
			jQuery(menu).animate({left: startpos}, 1000);
		}
	}).mouseup(function() {
		// Mouseup to slow back down
		jQuery(menu).stop();
		jQuery(menu).animate({left: startpos}, 2000);
	});
	
	// Right menu button events
	jQuery('#menu-rbutton').mouseenter(function(){
		// Don't animate if the amount its going to scroll is smaller then the items there are
		if(wrapwidth < totalwidth) {
			jQuery(menu).animate({left: -(totalwidth)-startpos+wrapwidth-1}, 2000);
		}
	}).mouseleave(function() {
		// Stop the animation if the mouse leaves the button
		jQuery(menu).stop();
	}).mousedown(function() {
		// Mousedown to speed up
		if(wrapwidth < totalwidth) {
			jQuery(menu).stop();
			jQuery(menu).animate({left: -(totalwidth)-startpos+wrapwidth-1}, 1000);
		}
	}).mouseup(function() {
		// Mouseup to slow back down
		jQuery(menu).stop();
		jQuery(menu).animate({left: -(totalwidth)-startpos+wrapwidth-1}, 2000);
	});
});