CH.ns(function() {with(CH) {
	Toplist = Class.create({
		options: {}, elements: {}, response: null, short_name: null,
		
		initialize: function(short_name, options) {
			this.setOptions(options);
			this.short_name = short_name;
		},
		
		vote: function(winner, loser) {
			if(this.options.post_url != null) {
				url = this.options.post_url;
			} else {
				url = '/toplist/'+this.short_name+'/vote';
			}
			
			if(this.short_name != null) {
				new Req.ajax({
					url: url,
					options: {
						parameters: 'winner='+winner+'&loser='+loser,
						onSuccess: function(o) {
							eval('this.response='+o.responseText);
							
							$(this.options.matchup_container).update(this.response.matchup);
							
							if(this.options.history_container != null) {
								new Insertion.Top(this.options.history_container, this.response.history);
							}
							
							if(this.options.ranks_container != null) {
								$(this.options.rank_container).update(this.response.ranks);
							}
						}.bind(this)
					}
				});
			}
		},
		
		setOptions: function(options) {
			this.options = {
				matchup_container: 'matchup',
				history_container: null,
				ranks_container: null,
				post_url: null
			};
			Object.extend(this.options, options || {});
		}
	});
}});