
FBLeaderboards = function(game_id, id, type, gameplay_id)
{
	this.gp_id = gameplay_id;
	this.game_id = game_id;
	this.lb_id = id;
	this.lb_type = type;

	this.num_users = 100;
	this.row_height = 18;
	this.scrolling = {
		pos: {
			weekly: 0,
			daily: 0
		},
		step: 10,
		scrolling: false
	};

	this.update = function(daily_id, weekly_id)
	{
		var self = this;

		new Ajax.Request(
			'/users/actions/update_leaderboard.php',
			{
				parameters: {
					gameplay_id: this.gp_id,
					id: this.lb_id,
					type: this.lb_type
				},
				method:'post',
				onComplete:function(){
					self.update_leaders(daily_id, weekly_id);
				}
			}
		);

		return true;
	};

	this.show_leaderboard = function(which)
	{
		other = which == "daily" ? "weekly" : "daily";

		$("leaderboard_"+other+"_container").style.display = "none";
		$("tab_"+other).style.backgroundPosition = "top";
		$("tab_"+other).style.color = "#174EA8";

		$("leaderboard_"+which+"_container").style.display = "block";
		$("tab_"+which).style.backgroundPosition = "bottom";
		$("tab_"+which).style.color = "#FF6305";
	};

	this.scroll = function(which,dir)
	{
		if( !this.scrolling.scrolling )
		{
			if( dir == 'down' ){
				if( this.scrolling.pos[which] < this.num_users - this.scrolling.step ){
					this.scrolling.scrolling = true;
					new Effect.MoveBy('leaders_'+which+'_contents',-this.scrolling.step*this.row_height,0,{ duration: 0.8, transition: Effect.Transitions.sinoidal, queue: 'end' });
					this.scrolling.pos[which] += this.scrolling.step;
				};
			}
			else{
				if( this.scrolling.pos[which] >= this.scrolling.step ){
					this.scrolling.scrolling = true;
					new Effect.MoveBy('leaders_'+which+'_contents',this.scrolling.step*this.row_height,0,{ duration: 0.8, transition: Effect.Transitions.sinoidal, queue: 'end' });
					this.scrolling.pos[which] -= this.scrolling.step;
				};
			};
			this.scrolling.scrolling = false;
		}
	};

	this.update_leaders = function(daily_id, weekly_id)
	{
		new Ajax.Updater(
			daily_id,
			'/partials/playgame_leaders.php?g='+this.game_id+'&s=0&d=0&id='+this.lb_id+'&t='+this.lb_type+'&c=leaders_daily_contents'
		);

		new Ajax.Updater(
			weekly_id,
			'/partials/playgame_leaders.php?g='+this.game_id+'&s=0&d=7&id='+this.lb_id+'&t='+this.lb_type+'&c=leaders_weekly_contents'
		);
	}
};


