function Lojas()
{
	$('.replace.bt-brasil').click(function() 
	{
		$('#selPais').hide().val('');
		$('#selEstado').show();
		
		$('#selEstabelecimento').html('<option value="">Estabelecimento</option>');
		
		$(this).parent('li').parent('ul').children('li').removeClass('ativo');
		$(this).parent('li').addClass('ativo');
	});
	
	$('.replace.bt-outros-paises').click(function() 
	{
		$('#selPais').removeClass('hidden').show();
		$('#selEstado').hide().val('');
		
		$(this).parent('li').parent('ul').children('li').removeClass('ativo');
		$(this).parent('li').addClass('ativo');
		
		$('#selEstabelecimento').html('<option value="">Estabelecimento</option>');
	});
	
	$('#selPais').change(function() 
	{
		if($(this).val() !== '')
		{
			Lojas.CarregarEstabelecimento($(this).val());
		}
		
	});
	
	$('#selEstado').change(function() 
	{
		if($(this).val() !== '')
		{
			Lojas.CarregarEstabelecimento($(this).val());
		}
		
	});
	
	$('#selEstabelecimento').change(function() 
	{
		if($(this).val() !== '')
		{
			Lojas.CarregarLoja($(this).val());
		}		
	});
	
	$('#principal.lojas').removeClass('hidden').hide();
}

Lojas.CarregarEstabelecimento = function(MunicipioID)
{
	$('#selEstabelecimento').html('<option value="">Carregando...</option>');
	
	$.ajax({
		cache: false,
		success: function(retorno)
		{
			$("#selEstabelecimento").html(retorno);
		},
		data: {
			Acao: 'CarregarEstabelecimento',
			MunicipioID: MunicipioID
		},
		type: "post",
		url: "acao/Lojas.php"
	});
}
Lojas.CarregarLoja = function(LojaID)
{
	$('#principal.lojas').fadeOut();
	$.ajax({
		cache: false,
		success: function(retorno)
		{
			$('#principal').html(retorno);
			
			Lojas.ReiniciarCarrouselLojas();
		},
		data: {
			Acao: 'CarregarLoja',
			LojaID: LojaID
		},
		type: "post",
		url: "acao/Lojas.php"
	});
}

Lojas.ReiniciarCarrouselLojas = function()
{
	$('#principal.lojas').fadeIn(1000);
	$('.jcarousel-prev').unbind();
	$('.jcarousel-next').unbind();
	$("#carousel-lojas ul").jcarousel(
	{
		vertical: false,
		scroll: 1
    });		
}