Cufon.replace('#home_words h3');

//Abas e Conteúdo
function changeContent(navItem){

	//Lidar com content
		var thisId = $j(navItem).parent().attr('id');
		thisId = thisId.split("_")[1];
		thisBox = $j(navItem).parents('.box');
		$j(thisBox).find('.item_content').fadeOut(400);//removeClass('active');
		$j(thisBox).find('#content_'+thisId).fadeIn(400);//addClass('active');

	//Lidar com itens de navegação
		//Remover item ativo anterior
		var oldActive = $j(navItem).parents('ul').find('.active');
		var oldText = $j(oldActive).find('span').html();
		$j(oldActive).removeClass('active').html("<a href='javascript://' title='"+oldText+"'>"+oldText+"</a>");
		//Definir novo item ativo
		var thisText = $j(navItem).html();
		$j(navItem).parent().addClass('active').html("<span>"+thisText+"</span>");

}

function selectTriggerPrev(el){
	$j(el).find('.increase').click(function(){
		var valor = $j(el).find('.select_value .value');
		$j(valor).text(parseInt($j(valor).text())+1);
	});
	$j(el).find('.decrease').click(function(){
		var valor = $j(el).find('.select_value .value');
		if ($j(valor).text()!='0') $j(valor).text(parseInt($j(valor).text())-1);
	});
}
function changeTriggerValCartao(el,str){
	$j('#opcao_cartao').val(str);
	$j(el).closest('form').attr('action',str);
}
function selectTriggerCartao(el){
	$el=$j(el);
	$el.find('a').click(function(){
		var $selected = $el.find('.select_value span:visible');

		var $next;
		if($j(this).is('.decrease')) {
			$next=$selected.next();
			if (!$next.length) $next = $el.find('.select_value span:first');
		} else{
			$next=$selected.prev();
			if (!$next.length) $next = $el.find('.select_value span:last');
		}

		$selected.hide();
		$next.show();
		changeTriggerValCartao(el,$next.find('a').attr('href'));
	});
}

$j(document).ready(function(){

	//Sombras
	$j('#home_top .title, #home_top .subtitle').dropShadow({left:1,top:1,blur:1,opacity:1});

	$j('.box_top a').live('mouseover', function(){changeContent(this)});	

	//Select trigger - Previdência
	if ($j('body').hasClass('home_previdencia')){
		var el='#select_idade';
		selectTriggerPrev(el);
	} else if($j('body').hasClass('home_cartao')){
	//Select trigger - Cartão
		var el='#select_cartao';
		selectTriggerCartao(el);
		changeTriggerValCartao(el, $j(el).find('.select_value span:visible a').attr('href'));
	}

	//Botão buscar - cote e compare
	$j('#bt_buscar').click(function(){
		var txtVal=$j('#compare_precos .input_text').val();
		if(txtVal=='Compare preços de produtos'||txtVal=='') return false;
	});

	//Caixa de palavras ser clicável
	/*
	$j('#home_words li').each(function(){
		$j(this).click(function(){
			document.location.href=$j(this).find('a').attr('href');
		});
	});*/
});
