window.Votes = {
	
	isvote : 0,
	type : 0,

	setCookie : function(category_id){
		var self = this;
		var sputnikLaunch = new Date()
		var hour = sputnikLaunch.getHours();
		var diff = 24 - hour;
		var howmuch = diff/24;
		var myCookie = Cookie.write('item_' + category_id, '1', {duration: howmuch});
	},

	checkCookie : function(category_id){
		var self = this;
		var myCookie = Cookie.read('item_' + category_id);

		if (myCookie){
			self.isvote = true;
		}
		else {
			self.isvote = false;
		}
	},

	send : function(category_id){
		var self = this;
		
		var hp_kis = $('all_votes').getElements('input[rel="vt"]');
		
		var vote_value = 0;
		hp_kis.each(function(item, index){
			if (item.checked) {
				vote_value = item.value;
			}
		});
		
		if (vote_value && category_id) {
			self.checkCookie(category_id);
			if (self.isvote) {
				alert('Извините, голосовать можно раз в сутки');
			}
			else {
				self.setCookie(category_id);
				var myRequest = new Request({method: 'get', url: '/ajax/votes', onComplete:
				function(response) {
						var list = JSON.decode(response);
						if (list.ok){
							$('all_votes').set('html', list.tpl);
						}
						
					}
				});

				myRequest.send('category_id=' + category_id + '&item_id=' + vote_value);
			}
		}
		return false;
	},

	init : function(type){
		var self = this;
		self.type = type;
	}
};
