// JavaScript Document

$(document).ready(init)

var currentBlock
var totalBlocks

function init(){
	
	totalBlocks = $('ul.areas-atuacao-home li').length
	weCanHelpShowBlock(0)
	$('#weCanHelpNext').click(weCanHelpNextHandler)
	$('#weCanHelpPrev').click(weCanHelpPrevHandler)
	
	var fancyboxConfig = {
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'speedIn'		:	600, 
		'speedOut'		:	200
	}
	
	//$('.videos li a').fancybox(fancyboxConfig);
	//$('.portfolio-home li a').fancybox(fancyboxConfig);
}

function weCanHelpNextHandler(evt){
	weCanHelpShowBlock(currentBlock+4)
}

function weCanHelpPrevHandler(evt){
	weCanHelpShowBlock(currentBlock-4)
}

function weCanHelpShowBlock(from){
	var list = $('ul.areas-atuacao-home li')
	
	if(from < 0)
		from = 0
	
	if(from > totalBlocks-4)
		from = totalBlocks-4
	
	for(var i=0; i<totalBlocks; i++){
		if(i>=from && i<from+4)
			$(list[i]).show('fade')
		else
			$(list[i]).hide()
		}
	
	currentBlock = from
	validateWeCanHelpControls()
}

function validateWeCanHelpControls(){
	if(currentBlock <= 0)
		$('#weCanHelpPrev').attr('disabled', 'disabled')
	else
		$('#weCanHelpPrev').removeAttr('disabled')
	
	if(currentBlock >= totalBlocks-4)
		$('#weCanHelpNext').attr('disabled', 'disabled')
	else
		$('#weCanHelpNext').removeAttr('disabled')	
}
