$('document').ready(function(){

	$("#limit-slider").slider({
		min: 50,
		max: 150,
		value: $('#limit').val(),
		slide: function(event,ui) {
			$("#limit").val(ui.value);
			pollutionGraph.opts.limit = ui.value;
			pollutionGraph.draw();
		}
	});
	
	var pollutionGraph = new ExtremeGraph({
		legend: $('#extreme-graph-legend'),
		container: $("#extreme-graph"),
		limit: 75,  // using $('#limit').val() here breaks things (inexplicably)
		value: $('#value-select input:radio:checked').val()
	});

	$('#value-select input:radio').click(function(){
		pollutionGraph.opts.value = $(this).val();
		pollutionGraph.draw();
	})

	var graphPos = 9000;
	$('#chart-tabs')
		.tabs({selected: 1})
		.bind('tabsselect',function(event,ui){
			if( ui.index == 1 ) { graphPos = $('#extreme-graph').scrollLeft(); }
		})
		.bind('tabsshow', function(event, ui) {
			if( ui.index == 0 ) { $('#extreme-graph').scrollLeft(graphPos); }
		})
		.show();
});


