$(function() {
	$('#faq li label').click(toogleFaq)
	
	$('.forBusiness').click(showText)

	$('#enqueteForm').submit(enquete)

	$('.guide li, .guideForBuss li').click(toggleGuide)

	jQuery("#tips").jcarousel({
		scroll: 1,
		initCallback: tips_initCallback,
		// This tells jCarousel NOT to autobuild prev/next buttons
		buttonNextHTML: null,
		buttonPrevHTML: null
	});

	jQuery("#countries").jcarousel({
		scroll: 1,
		initCallback: countries_initCallback,
		// This tells jCarousel NOT to autobuild prev/next buttons
		buttonNextHTML: null,
		buttonPrevHTML: null
	});

	jQuery("#benefits").jcarousel({
		scroll: 1,
		initCallback: benefits_initCallback,
		// This tells jCarousel NOT to autobuild prev/next buttons
		buttonNextHTML: null,
		buttonPrevHTML: null
	});
});

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 toogleFaq(){
  $(this).toggleClass('less')
  $(this).siblings('p, .ico').slideToggle('fast')
}

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 toggleGuide(){
	$(this).siblings().removeClass('active')
	$(this).addClass('active')
	position = $(this).index()
	$('.guideContent li').hide()
	$('.guideContent').children('li').eq(position).show()
	$('.guideForBussContent li').hide()
	$('.guideForBussContent').children('li').eq(position).show()
}

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;
	});
};

function countries_initCallback(carousel) {
	jQuery('.countriesNumber').bind('change', function() {
		carousel.options.scroll = jQuery.jcarousel.intval(this.options[this.selectedIndex].value);
		return false;
	});

	jQuery('#countriesNext').bind('click', function() {
		carousel.next();
		return false;
	});

	jQuery('#countriesPrev').bind('click', function() {
		carousel.prev();
		return false;
	});
};

function benefits_initCallback(carousel) {
	jQuery('.benefitsNumber').bind('change', function() {
		carousel.options.scroll = jQuery.jcarousel.intval(this.options[this.selectedIndex].value);
		return false;
	});

	jQuery('#benefitsNext').bind('click', function() {
		carousel.next();
		return false;
	});

	jQuery('#benefitsPrev').bind('click', function() {
		carousel.prev();
		return false;
	});
};

function showText(){
	$('.forBusinessContent').slideUp('fast')
	position = $('.forBusiness').index(this)
	$('.forBusinessContent').eq(position).slideDown('fast')
}
