(function($) {
  var cache = [];
  // Arguments are image paths relative to the current page.
  $.preLoadImages = function() {
    var args_len = arguments.length;
    for (var i = args_len; i--;) {
      var cacheImage = document.createElement('img');
      cacheImage.src = arguments[i];
      cache.push(cacheImage);
    }
  }
})(jQuery)

var loader = $("<img />").attr({
	"src" : "../images/loader.gif",
	"class" : "loader"
})

$(window).load(function () {
  $('#popupindex').trigger('click');
});


$(document).ready(function(){								 
    $('#sobre-cidade li:last').css('background', 'none');
		
		$("#ano").change(function() {
		$("#contas").html(loader);
		$("#contas").load("../ajax/contas.php?ano=" + $(this).val());
	});
	
	$('.openpopup').fancybox({
		'autoScale'			: false,
		'transitionIn'		: 'fade',
		'transitionOut'		: 'fade'
	});


    $("#slider").easySlider({
			auto: true,
			continuous: true,
			numeric: true
		});

    $.preLoadImages('../img/fundo1.jpg', '../img/fundo2.jpg', '../img/fundo3.jpg', '../img/fundo4.jpg', '../img/logo-ilopolis.png', '../img/logo-ilopolis-preto.png');
});

function mudaFundo(fundo)
{
    if(fundo == 1)
    {
        $('body').css('background-image', 'url(../img/fundo1.jpg)');
				$('#logo_img').attr('src', '../img/logo-ilopolis.png');
    }

    else if(fundo == 2)
    {
        $('body').css('background-image', 'url(../img/fundo2.jpg)');
				$('#logo_img').attr('src', '../img/logo-ilopolis-preto.png');
    }
		
		else if(fundo == 3)
    {
        $('body').css('background-image', 'url(../img/fundo3.jpg)');
				$('#logo_img').attr('src', '../img/logo-ilopolis-preto.png');
    }

    else if(fundo == 4)
    {
        $('body').css('background-image', 'url(../img/fundo4.jpg)');
				$('#logo_img').attr('src', '../img/logo-ilopolis.png');
    }

    else {
        return false;
    }

    $.cookie('fundo', fundo, { expires: 360 });
}

function enviaEvento()
{
    document.getElementById('formmes').submit();
}


function valida_newsletter()
{
    var nome = document.getElementById('nome');
    var email = document.getElementById('email');

    if(nome.value == nome.defaultValue || nome.value == '')
    {
        alert("Digite seu nome!");
        return false
    }

    else if(email.value == email.defaultValue || email.value == '')
    {
        alert("Digite seu email!");
        return false
    }

    return true;
}
