var Application =  {
  lastId: 0,
  currentSampleNb: 0,

  getNewId: function() {
    Application.lastId++;
    return "window_id_" + Application.lastId;
  },
  
  add_vote: function(video_id) {
  	Application.make_vote('add', video_id);
  },
  
  sub_vote: function(video_id) {
  	Application.make_vote('sub', video_id);
  },
  
  make_vote: function(action, video_id) {
  	var url = '/make_vote.php?&video_id=' + video_id + '&action=' + action;
	var vote = new Ajax.Request(url, {
  									method: 'get',
  												onSuccess: function(transport) {
														$('add_vote').innerHTML = '+';
														$('sub_vote').innerHTML = '-';
													
														if (transport.responseText.length > 0) {
															$('rating_count').innerHTML = transport.responseText;
														}
		  											}
								});
  },
  
  add_comment_weight: function(message_id) {
  	Application.change_comment_weight('1', message_id);
  },
  
  sub_comment_weight: function(message_id) {
  	Application.change_comment_weight('-1', message_id);
  },
  
  change_comment_weight: function(value, message_id) {
	var url = '/change_comment_weight.php?&id=' + message_id + '&action=' + value;
	var weight = new Ajax.Request(url, {
  										method: 'get',
  												onSuccess: function(transport) {
																if (transport.responseText.length > 0) {
																	$('comment_' + message_id).innerHTML = transport.responseText;
																}
	  														}
										});
  },
  
  show_message_block: function(block_id) {
  	if ($(block_id).style.display == 'none')
		$(block_id).style.display = 'inline';
	else
		$(block_id).style.display = 'none';
  },

  show_block: function(block_id, link_id, title) {
  	var prev_title = $(link_id).innerHTML;
	$(link_id).onclick = function() {Application.show_block(block_id, link_id, prev_title);}
	$(link_id).innerHTML = title;
  	if ($(block_id).style.display == 'none') {
		$(block_id).style.display = 'inline';
	}
	else {
		$(block_id).style.display = 'none';
	}
	
  } 
}

