$("#weather-box").css("overflow", "hidden");

$(".forw, .last-next").click(function(){
	return false;
});

$(".prev, .last-prev")
	.click(function(){return false;})
	.fadeTo("fast",0.5)
	.css("cursor", "default");


$(".day span").text($("#weather1").attr("alt"));

$(".forw").mouseover(function()
{
	$(".prev").css("cursor", "pointer");

	$("#weather-box ul").animate({left:-230}, 400, function(){
		$(".day span").text($("#weather2").attr("alt"));
		$(".forw").fadeTo("fast", 0.5).css("cursor", "default");
		$(".prev").fadeTo("fast", 1);
	});
});

$(".prev").mouseover(function()
{
	$(".forw").css("cursor", "pointer");
	$("#weather-box ul").animate({
		left: 0
	}, 400, function(){
		$(".day span").text($("#weather1").attr("alt"));
		$(".forw").fadeTo("fast", 1);
		$(".prev").fadeTo("fast", 0.5).css("cursor", "default");
	});
});

$('#weather_location').change(function(){
	$.ajax({
		url: ajax_url,
		data: {cat: $($('.weather a.weather_cat.active').get(0)).attr('id').replace('weather_',''), 'loc' : $('#weather_location').val(), method : 'get_weather_by_location'},
		success : function(data)
		{
			$(".forw").fadeTo("fast", 1);
			$(".prev").fadeTo("fast", 0.5).css("cursor", "default");

			$('#weather-box').toggle(500, function(){
				$('#weather-box').html(data).toggle(500, function(){$(".day span").text($("#weather1").attr("alt"));});

			});
		},
		dataType: 'html'
	});
});

$('.weather_cat').click(function()
{
	var elem = $(this);
	var weather_location_select = $('#weather_location').get(0);

	if(elem.hasClass('active')) {
		return
	}

	$('.weather_cat').removeClass('active');
	elem.addClass('active');

	$.ajax({
		url: ajax_url,
		data: {cat: $($('.weather a.weather_cat.active').get(0)).attr('id').replace('weather_',''), method : 'get_weather_cities'},
		success : function(json)
		{

			var values = json.cities
			weather_location_select.options.length = 0;

		    if (values.length)
		    {
			    for (var i = 0; i < values.length; i++) {
			    	weather_location_select.options[weather_location_select.options.length] = new Option(values[i].name, values[i].name);
			    }
		    }
		    setTimeout(function(){$('#weather_location').trigger('change');});
		},
		dataType: 'json'
	});
});