function mycarousel_initCallback(carousel) {
    // Disable autoscrolling if the user clicks the prev or next button.
    carousel.buttonNext.bind('click', function(){carousel.startAuto(0);});
    carousel.buttonPrev.bind('click', function(){carousel.startAuto(0);});

    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
};

$(document).ready(function() {

	$('#carousel-outdoors').fadeSlideShow({
		width:'100%', // width of the slideshow
		//height:448, // height of the slideshow
		speed:'slow', // animation speed
		interval:10000 // image change interval
	});

	$('#mundo-diversao').fadeSlideShow({
		width:151, // width of the slideshow
		height:114, // height of the slideshow
		speed:'fast', // animation speed
		interval:3000 // image change interval
	});

	jQuery('#carousel-banners').jcarousel({
		scroll: 1,
		auto: 7,
		wrap: 'circular',
		initCallback: mycarousel_initCallback
	});

	$('#posts li').remove();

	jQuery.ajax({
		type: "get",
		dataType: "json",
		url: 'obtem-posts.php',
		success: function(retorno) {

			//console.log(retorno);
			if(retorno.status) {
				for(var i = 0; i < retorno.dados.length; i++) {
					$('#posts')
						.append(
							$('<li>')
								.append(
									$('<a>')
									.attr('href', retorno.dados[i].url)
									.attr('target', '_blank')
									.text(retorno.dados[i].titulo)
								)
						)
				}
			} else {
				$('#posts')
					.append(
						$('<li>')
							.text(retorno.message)
					)
			}
		},
		error: function(XMLHttpRequest, textStatus, errorThrown) {
			$('#posts')
				.append(
					$('<li>')
						.text("Erro ao obter os dados, tente atualizar a página.")
				)
		}
	});

	obtemTwitts()
	window.setInterval("obtemTwitts();", 60000);

});

function obtemTwitts() {
	$('#twitts li').remove();

	jQuery.ajax({
		type: "get",
		dataType: "json",
		url: 'obtem-twitts.php',
		success: function(retorno) {
			//console.log(retorno);
			if(retorno.status) {
				for(var i = 0; i < retorno.dados.length; i++) {
					$('#twitts')
						.append(
							$('<li>')
								.append(
									$('<a>')
										.attr('href', retorno.dados[i].url)
										.attr('target', '_blank')
										.text(retorno.dados[i].text)
										.prepend(
											$('<strong>')
												.text('@betocarrero: ')
										)
								)
						)
				}
			} else {

				$('#twitts')
					.append(
						$('<li>')
							.text(retorno.message)
					)
			}
		},
		error: function(XMLHttpRequest, textStatus, errorThrown) {
			$('#twitts')
				.append(
					$('<li>')
						.text("Erro ao obter os dados, tente atualizar a página.")
				)
		}
	});
}

