$(document).ready(function () {

	$("select#links").each(function() {
			$.get(base_url+"links/", function(data) {
			$("select#links").html(data);
			$('select#links option:first').attr('selected', 'selected');
		});
	});

	$("select#links").change(function() {
		if($(this).val())
			window.open($(this).val());
		return false;
	});

	$('.paginacao').each(function() {
		$(this).find('.bloco:first').show();
	});

	$('.pag-anterior').click(function() {
		bl = $(this).parents('div:first').find('.bloco:visible');
		if(bl.prev('.bloco').html() != null) {
			n = parseInt($(this).parents('ul').find('span').html());
			$(this).parents('ul').find('span').html(--n);
			bl.hide();
			bl.prev('.bloco').show();
		}
	});

	$('.pag-proximo').click(function() {
		bl = $(this).parents('div:first').find('.bloco:visible');
		if(bl.next('.bloco').html() != null) {
			n = parseInt($(this).parents('ul').find('span').html());
			$(this).parents('ul').find('span').html(++n);
			bl.hide();
			bl.next('.bloco').show();
		}
	});

	$('ul.noticia li a').click(function() {
		var	img 	= $(this).parents('div:first').find('.bloco:visible').attr('img');
		var legenda = $(this).parents('div:first').find('.bloco:visible').attr('legenda');
		var credito = $(this).parents('div:first').find('.bloco:visible').attr('credito');

		if(img == $('#imgChange').attr('src')) {return;}

		$('#divImgChange').addClass('imgLoading');

		$('.imgLegenda').fadeTo('normal', 0, function () {

			$('#imgChange').fadeTo('normal', 0, function() {
				imgloader = new Image();  
				$(imgloader).load(function () {
					$('#divImgChange').removeClass("imgLoading");
					$('#imgChange').attr('src', img);
	
					if(credito!="")
						$('.imgLegenda').html(legenda+'<br /><span class="imgCredito">Cr&eacute;dito: '+credito+'</span>');
					else
						$('.imgLegenda').html(legenda);
	
					$('#imgChange').fadeTo('normal', 1, function() {
						$('.imgLegenda').fadeTo('normal', 1);
					});
	
				}).error(function () { // não foi possível encontrar a img
				}).attr('src', img);

			});

		});

	});

	$(".toggle_container").hide();
 
	$("h2.trigger").toggle(function(){
		$(this).addClass("active"); 
		}, function () {
		$(this).removeClass("active");
	});
	
	$("h2.trigger").click(function(){
		$(this).next(".toggle_container").slideToggle("slow");
	});

});