function SimpleVote() {}
SimpleVote.prototype = {
/*
	init: function(container,url) {
		this.url = url;
		this.container = container;
		this.id = this.container.id.replace("voteid","");
		
		this.addEvents();
	},
	addEvents: function() {
		as.e.click(this.container,this.clickHandler,this);	
	},
	clickHandler: function() {
		if (this.done) {
			this.showError("Вы уже голосовали за это видео!");
			return;
		}
		this.done = true;		
		as.ajax(this.url+this.id,as.bind(this.updater,this));
	},
	updater: function(result) {
		try {
			result = eval("(" + result + ")");
			this.container.innerHTML = result.rating;
		}
		catch(e) { this.showError("Только зарегистрированные пользователи могут принять участие в голосовании"); }
	},
	showError: function(error) {
		alert(error);	
	}
        */
}

function SongVote() {}
SongVote.prototype = {
	init: function(container,url) {
		this.container = container;
		this.url = url;
		this.vars = as.filter(as.$("input",this.container),function(input) { return input.type == "radio" });
		this.items = as.$("li",this.container);
		this.voter = as.$$("a.voting",this.container);
		
		this.addEvents();
		this.checkCurrent();
	},
	addEvents: function() {
		as.e.click(this.voter,this.clickHandler,this);
		as.foreach(this.vars,as.bind(function(input){
			as.e.change(input,this.changeHandler,this);
		},this));
	},
	clickHandler: function(e) {
		e.preventDefault();
		if (this.done) {
			this.showError("Вы уже голосовали за это видео!");
			return;
		}
		this.done = true;
		as.ajax(this.url+this.current.value);
		this.onlyOne(this.current);
	},
	changeHandler: function(e) {
		this.changeCurrent(e.target);
	},
	changeCurrent: function(input) {
		input.checked = true;
		this.current = input;
		as.foreach(this.items,function(itm) {itm.className = itm.className.replace(/\bactive\b/,"")});
		as.parent(this.current,"li").className += " active";
	},
	checkCurrent: function() {
		for (var i=0,l=this.vars.length;i<l;i++) {
			if (this.vars[i].checked) {
				this.changeCurrent(this.vars[i]);
				return;
			}
		}
		this.changeCurrent(this.vars[0]);
	},
	onlyOne: function(current) {
		var toFade = [], active = as.parent(this.current,"li");
		as.foreach(this.vars,function(input) {
			if (input == current) return;
			toFade.push(as.parent(input,"li"));
		});
		as.foreach(toFade,as.bind(function(li){
			as.fadeOut({
				element: li,
				callback: as.bind(function() {
					as.remove(li);
					active.className = active.className.replace(/\bactive\b/,"");
					as.remove(current);
					as.remove(this.voter);
				},this)
			});
		},this));
	},
	showError: function(error) {
		alert(error);	
	}
}

function vote() {
	as.foreach(as.$("div.estimate span"),function(span){
		new SimpleVote().init(span,"/ising/vote/");
	});
	as.foreach(as.$("div.next-tour form"),function(form){
		new SongVote().init(form,"/ising/rvote/");
	});
}

//as.ready(vote);