(function()
{
	var Event = YAHOO.util.Event, 
	Dom = YAHOO.util.Dom,
	slider,
	anim,
	viewPortDelta,
	bg = "slider", 
	thumb = "thumb",
	timer = null,
	topConstraint = 0,
	bottomConstraint = 735-202;	
	
	Event.onDOMReady(function()
	{
		
		slider = YAHOO.widget.Slider.getHorizSlider(bg, thumb, topConstraint, bottomConstraint, 0);

		viewPortDelta = 2040 - 725;
		
		slider.P = function()
		{
			return Math.floor(this.getValue()/bottomConstraint*100);
		};

		var currentX = 0.0;
		var firstFrame = true;
		slider.$tick = function()
		{

			var p = slider.P();
			var c = -p * viewPortDelta / 100;
			
			currentX += (c-currentX) * 0.05;
			if(firstFrame){
				currentX = c;
			}
			if ( Math.abs(c-currentX) < 0.1 )
			{
				currentX = c;
			}

			Dom.setStyle('secondary-menu-slider', 'margin-left', String(Math.round(currentX))+"px");
			firstFrame = false;
		};

		slider.$start = function()
		{
			if (!timer)
			{
				timer = setInterval(slider.$tick, 20);
			}
		};

		slider.$stop = function()
		{
			if (timer) clearInterval(timer);
			timer = null;
		};

		slider.subscribe("slideStart", function()
		{
			slider.$start();
		});

		onRightButtonPressed = function (e)
		{
			slider.setValue(slider.getValue()+(bottomConstraint/22)*12);
			//console.log("onRightButtonPressed");
		};

		onLeftButtonPressed = function (e)
		{
			slider.setValue(slider.getValue()-(bottomConstraint/22)*12);
			//console.log("onLeftButtonPressed");
		};
		
		if(parseInt(sportId)>=1 && parseInt(sportId)<=34){	
			var num = (bottomConstraint/22)*(parseInt(sportId)-6);
			slider.setValue(num, true);
		}
		
		//alert((bottomConstraint/22) + " | " + num);

		YAHOO.util.Event.addListener("rightArrow", "click", onRightButtonPressed);
		YAHOO.util.Event.addListener("leftArrow", "click", onLeftButtonPressed);
	});
})();
