$j(function() {
	//Site.popfloat();
	$j('#popup').fancybox().trigger('click');
	$j('#banner-rotativo ul').jcarousel({
		scroll: 1, auto: 5, wrap: 'last',
		initCallback: mycarousel_initCallback
	});	
});

/* Corrosel de imagens para banners */
function mycarousel_initCallback(carousel) {
	$j('.jcarousel-control a').bind('click', function() {
		carousel.scroll(jQuery.jcarousel.intval(jQuery(this).text()));
		return false;
	});

	// 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();
	});
}

var Site = {	
	popfloat:function(acao) {
		if(acao == 0) {
			$j('#banner-aviso').fadeOut();	
		} else if(location.href.indexOf('?') == -1) {
			$j('#banner-aviso').fadeIn();
			setTimeout(function() { $j('#banner-aviso').fadeOut(); }, 240000);
		}
	},
	calcular:function(form){		
		if($Form.validar(form)) {
			$j('#total-consumo').show().html('Calculando, aguarde...');
			
			$j.ajax({url: 'acoes.php?calcular', type:'post', data:$j(form).serialize(), 
				success:function(response) { //
					$j('#total-consumo').html(response);
				}
			});
		}
		return false;
	},	
	cadastrar:function(form){
		if($Form.validar(form)) {
			$j.alert({ type:'loading', html:'Enviando cadastro, aguarde...', modal:true, width:240 });
			
			$j.ajax({
				url:'acoes.php?cadastrar', type:'post', data:$j(form).serialize(),
				success:function(response) { //alert(response);
					if(response == ''){
						$j(form)[0].reset();
						$j.alert({ type:'success', html:'Seu cadastro foi enviado com sucesso!', width:280 });
					}else{
						$j.alert({type:'error', html:'Não foi possível enviar seu cadastro!'});
					}
				}
			});
		}
		return false;
	}
}
