$(function() {
	$('#enqueteForm').submit(enquete)
	$('#faq li label, #cartilha li label, #glossario li label').click(toogleFaq)
	jQuery("#miniTips").jcarousel({
		scroll: 1,
		initCallback: benefits_initCallback,
		// This tells jCarousel NOT to autobuild prev/next buttons
		buttonNextHTML: null,
		buttonPrevHTML: null
	});
	jQuery("#tips").jcarousel({
		scroll: 1,
		initCallback: tips_initCallback,
		// This tells jCarousel NOT to autobuild prev/next buttons
		buttonNextHTML: null,
		buttonPrevHTML: null
	});
});

function benefits_initCallback(carousel) {
	jQuery('.minitipsNumber').bind('change', function() {
		carousel.options.scroll = jQuery.jcarousel.intval(this.options[this.selectedIndex].value);
		return false;
	});

	jQuery('#minitipsNext').bind('click', function() {
		carousel.next();
		return false;
	});

	jQuery('#minitipsPrev').bind('click', function() {
		carousel.prev();
		return false;
	});
};
function tips_initCallback(carousel) {
	jQuery('.miniTipsNumber').bind('change', function() {
		carousel.options.scroll = jQuery.jcarousel.intval(this.options[this.selectedIndex].value);
		return false;
	});

	jQuery('#miniTipsNext').bind('click', function() {
		carousel.next();
		return false;
	});

	jQuery('#miniTipsPrev').bind('click', function() {
		carousel.prev();
		return false;
	});
};


function simulator(){

  input = "rendaprev"
  $('#'+input).html('0')
  $("."+input).each(function(i) {
    af = $('#'+input).html();
    be = $("."+input).eq(i).val();
    if (af && be){
      $('#'+input).html( parseFloat(af) + parseFloat(be) );
    }
  });

  input = "rendarec"
  $('#'+input).html('0')
  $("."+input).each(function(i) {
    af = $('#'+input).html();
    be = $("."+input).eq(i).val();
    if (af && be){
      $('#'+input).html( parseFloat(af) + parseFloat(be) );
    }
  });

  input = "despprev"
  $('#'+input).html('0')
  $("."+input).each(function(i) {
    af = $('#'+input).html();
    be = $("."+input).eq(i).val();
    if (af && be){
      $('#'+input).html( parseFloat(af) + parseFloat(be) );
    }
  });

  input = "desprec"
  $('#'+input).html('0')
  $("."+input).each(function(i) {
    af = $('#'+input).html();
    be = $("."+input).eq(i).val();
    if (af && be){
      $('#'+input).html( parseFloat(af) + parseFloat(be) );
    }
  });

  prev = $('#rendaprev').html()
  rec = $('#despprev').html()
  $('#totalprev').html( parseFloat(prev) - parseFloat(rec) )

  prev = $('#rendarec').html()
  rec = $('#desprec').html()
  $('#totalrec').html( parseFloat(prev) - parseFloat(rec) )

}

function popUp(URL) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=415px,height=120px,left = NaN,top = NaN');");
}

function enquete(){
	ender = $("#enqueteForm").attr("action") + "?callback=?&" + $(this).serialize();
	$.getJSON(ender, function(data){
		$("#enqueteForm").children('p').animate({
				height: 'toggle'
			},
			250, function() {
				$('#enqueteForm').children('p').eq(0).html('Obrigado, seu voto foi computado.');
		});

		$("#enqueteForm").children('p').eq(0).animate({
			height: 'toggle'
		}, 250, function() {});
	});
	return false
}

function toogleFaq(){
  $(this).toggleClass('less')
  $(this).siblings('p, .ico').slideToggle('fast')
}

function tips_initCallback(carousel) {
    jQuery('.tipsNumber').bind('change', function() {
        carousel.options.scroll = jQuery.jcarousel.intval(this.options[this.selectedIndex].value);
        return false;
    });

    jQuery('#tipsNext').bind('click', function() {
        carousel.next();
        return false;
    });

    jQuery('#tipsPrev').bind('click', function() {
        carousel.prev();
        return false;
    });
};

