var Comparison =
{
	init : function()
	{
		Comparison.form.init();
		Comparison.timeband.init();
		Comparison.calendar.init();
		Comparison.charts.init();
	},
	charts :
	{
		init : function()
		{
			$('.chart-charts input[type=checkbox]').
				bind('change', Comparison.charts.change);
		},
		change : function()
		{
			var parent = $(this).parent();
			if ($(this).attr('checked') == true)
				parent.addClass('checked');
			else
				parent.removeClass('checked');
		}
	},
	form :
	{
		init : function()
		{
			$('.chart-charts').
				bind('submit', Comparison.form.submit);
		},
		submit : function()
		{
			$('.chart-charts .button').
				addClass('disabled');
			$('#submit-button').
				attr('disabled', true).
				after('<div class="clear"></div><div id="compare-throbber"><img src="/images/compare-throbber.gif"> Updating charts...</div>');
			
			$.ajax({
				url : Comparison.form.url,
				type : 'POST',
				data : 'ajax=1&update=1&' + $('.chart-charts').serialize(),
				cache : false,
				success : Comparison.form.success
			});
			return false;
		},
		success : function($html)
		{
			$('.main-content').html($html);
			$('#compare-throbber').remove();
			$('.chart-charts .button').removeClass('disabled');
			$('#submit-button').attr('disabled', false);
		},
		url : ''
	},
	timeband :
	{
		init : function()
		{
			$('#timeband-custom').html(Comparison.timeband.html);
			
			$('#select-timeband').
				bind('change', Comparison.timeband.change);
			
			$('#timeband-slider').
				slider({
					range: true,
					min: 1,
					max: 24,
					values: [Comparison.timeband.start, Comparison.timeband.end],
					slide: Comparison.timeband.slide
				});
		},
		slide : function($e, $ui)
		{
			$('#timeband-start').val($ui.values[0]);
			$('#timeband-end').val($ui.values[1]);
			$('#timeband-output').html($ui.values[0] + ':00 to ' + $ui.values[1] + ':00');
		},
		show : function()
		{
			$('#timeband-custom').show();
		},
		hide : function()
		{
			$('#timeband-custom').hide();
		},
		change : function()
		{
			var value = $(this).val();
			if (value == '4')
				Comparison.timeband.show();
			else
				Comparison.timeband.hide();
		},
		selected : 0,
		start : 6,
		end : 19,
		html : ''
	},
	calendar :
	{
		init : function()
		{
			//$('#select-calendar').append(Comparison.calendar.html);
			$('#select-calendar').
				bind('change', Comparison.calendar.change);
				
			$('#calendar-start, #calendar-end').
				addClass('calendar-datepick');
				
			$('#calendar-start, #calendar-end').datepicker({
				dateFormat : 'dd-mm-yy',
				minDate : new Date(2009, 8, 1),
				maxDate : '-1d',
				showAnim : 'fadeIn',
				onSelect : Comparison.calendar.onSelect
			});
		},
		onSelect : function($date)
		{
			/*var which = $(this).attr('id');
			console.log(which);
			console.log($date);
			if (which == 'calendar-end')
			{
				$('#calendar-start').datepicker('option', 'minDate', $date);
			}
			else
			{
				$('#calendar-end').datepicker('option', 'maxDate', $date);
			}*/
		},
		show : function()
		{
			$('#calendar-custom').show();
		},
		hide : function()
		{
			$('#calendar-custom').hide();
		},
		change : function()
		{
			var value = $(this).val();
			if (value == '0')
				Comparison.calendar.show();
			else
				Comparison.calendar.hide();
		},
		start : '',
		end : ''
	}
};