// CONTROLA SCROLL
$(document).ready(function(){
	$('.iOpcoes').jScrollPane(/*{scrollbarWidth:13}*/);
	$('.iOpcoesContainer').hide().css('visibility', 'visible');

	$(".iMostraOpcao a").click(function(){
		var bloco = $(this).parent().next();
		bloco.slideToggle('fast', habilitarBodyclick() );
	});
	
	$('.iOpcoes a').click(function(){
		var hidden = $(this).parent().parent().parent().parent().find('input');
		var valor = $(this).attr('title');
		var chamada = valor;
		//console.log(valor);
		
		
		if ($(this).attr('lang') !== undefined || $(this).attr('lang') !== '') {
			valor = $(this).attr('lang');
		}

		hidden.attr("value", valor);
		$(this).parent().parent().parent().prev().find('a').text(chamada);
		$(this).parent().parent().parent().hide('blind');
		$("body").unbind("click");
		
	});
});


function habilitarBodyclick(){										
	$("body").bind("click", function(e){
		var fecha = true;
		$('.iOpcoesContainer *, .iMostraOpcao * ').each(function()
		{
			if (e.target == $(this)[0]) 
			{
				fecha = false;
			}
		});
		
		if (fecha) {
			$('.iOpcoesContainer').hide();
			$("body").unbind("click");
			return false;
		}
	});
}
