/**
 * @author	Sisdado Tecnologia
 * @link	www.sisdado.com.br
 */

$(function(){
	$('#slider').jcarousel({
		auto: 2.5,
		scroll: 1,
		wrap: 'circular',
		initCallback: optionCarousel,
		buttonNextHTML: null,
		buttonPrevHTML: null,
		animation: 500
	});

	horaEstrutura();

	newsletter();

	$('#print').click(function() {
		$('#boxAviso').hide();
//		$('#divPrint').hide();
		window.print();
	});

});

function optionCarousel(option) {
	$('.jcarousel-control a').bind('click', function() {
		option.scroll($.jcarousel.intval($(this).text()));
		return false;
	});

	$('.jcarousel-scroll select').bind('change', function() {
		option.options.scroll = $.jcarousel.intval(this.options[this.selectedIndex].value);
		return false;
	});

	$('#jcarousel-button-prev').bind('click', function() {
		option.prev();
		return false;
	});

	$('#jcarousel-button-next').bind('click', function() {
		option.next();
		return false;
	});

	option.buttonNext.bind('click', function() {
		option.startAuto(0);
	});

	option.buttonPrev.bind('click', function() {
		option.startAuto(0);
	});

	option.clip.hover(function() {
		option.stopAuto();
	}, function() {
		option.startAuto();
	});
}

function horaEstrutura(){
	$.ajax({
		url: 'index.php',
		data: 'action=jsReturnHora',
		success: function(resposta) {
			$('#horaEstrutura').html(resposta);
		}
	});

	setTimeout("horaEstrutura();", 30000);
}

function tempoEstrutura(){
	$.ajax({
		url: 'index.php',
		data: 'action=jsReturnTemperature',
		success: function(resposta) {
			$('#temperaturaEstrutura').html(resposta).attr('title', 'Temperatura média de: ' + resposta);
		}
	});
}

function newsletter(){
	$('.jsNewsletter').click(function(){
		var _nome = $('#nomeNewsletter').val();
		var _email = $('#emailNewsletter').val();

		$.ajax({
			url: 'index.php',
			data: 'action=jsNewsletter&nome=' + _nome + '&email=' + _email,
			success: function(resposta) {
				alert(resposta);

				return false;
			}
		});
	});
}
