(function(){
	'use strict';

	var obj = this;
	var net = null;
	var listeners = {};

	var Server = function(){
		net = io();
		net.on('connect', onConnect);
		net.on('gameID', onGameID);
		net.on('addPlayer', onAddPlayer);
		net.on('jump', onJump);
	}

	Server.prototype.on = function(type, callback){
		if(!listeners.hasOwnProperty(type))
			listeners[type] = callback;
	};

	function sendEvent(type, args){
		var callback = listeners[type];
		if(callback)callback.apply(callback, args);
	}
	
	var onConnect = function(){
		net.emit('type', 'game');
	}
	var onGameID = function(ID){
		sendEvent('gameID', [ID]);
	}
	var onAddPlayer = function(user){
		sendEvent('addPlayer', [user]);
	}
	var onJump = function(user){
		sendEvent('jump', [user]);
	}

	obj.Server = Server;

}).call(this);
