var MAG = Object.extend({}, MAG || {});
MAG.Sport = {
	Init: function(options)
	{
		this.options = {};
		Object.extend(this.options, options || {});
	},

	initMostReadAndCommented: function() {

		$$('ul.tabs a').each(function(el){
		el.observe('click', function(e){
			var el = Event.element(e);
			switch($$('ul.tabs a').indexOf(el))
			{
				case 1:
					$(el.parentNode.parentNode).addClassName('second');
				break;
				default:
					$(el.parentNode.parentNode).removeClassName('second');
				break;
			}
			});
		});

		$('tab_most_read').observe('click',MAG.Sport.show_most_read_content);
		$('tab_most_commented').observe('click',MAG.Sport.show_most_commented_content);

	},

	show_most_read_content: function() {
		$("tab_most_commented_container").hide();
		$("tab_most_read_container").show();

	},

	show_most_commented_content: function() {
		$("tab_most_read_container").hide();
		$("tab_most_commented_container").show();

	},

	changeTab: function(id) {
		/*$$('a.tabchangers').each(function(e, i) {
			$(e.id + '_container').toggle();
		});
		*/
		//$('tab_most_read_container', 'tab_most_commented_container').invoke('toggle');
	},

	submit_vote : function() {
		var poll_id = $F('poll_id');
		var section_id = $F('section_id');

		$$('.radio').each(function(e,i){
			if(e.checked ) {
				var answer = $F(e);
				new Ajax.Updater('results',  MAG.Sport.options.url, {
					method: 'get',
					parameters: {method: 'ajax_vote', poll_answer_id: answer, id:poll_id, section_id:section_id},
					insertion: Insertion.Bottom
				})
				$('poll_form').hide();
			}

		});
	},

	calculate: function()
	{
		var poll_id = $F('poll_id');
		var section_id = $F('section_id');
		new Ajax.Updater('results',  MAG.Sport.options.url, {
			method: 'get',
			parameters: {method: 'calculate_poll_results', id: poll_id, section_id: section_id},
			insertion: Insertion.Bottom
		})

		$('poll_form').hide();
	}

}

function results(){

	MAG.Sport.calculate();
}

function vote() {

	MAG.Sport.submit_vote();
}





