﻿



	var entrouGmaps = false;

	function loadGmapsHome(){

		$('#home_banner').hide();

		$('#mapwrap_home').css({'position': 'relative', "top": "0px"});		

		if(entrouGmaps == false){

			loadMaps("container_gmaps_home", true);

			entrouGmaps = true;

			

			var postData = {

				acao: "Filtrar",

				get_bairros: 0,

				get_filiais: 0,

				get_parceiros: 1,

				somenteParcerios: true

			};

			loadGmapsEstabelecimentos(postData);				

		}

	}
/*	$("#btn_gmaps_close").click(function(){
		$('#home_banner').show();
		
		$('#mapwrap_home').css({'position': 'absolute', "top": "-1000px"});
		
		bannerHome();
	});		*/

	

	function loadGmapsEstabelecimentos(dataPost){

		 $.ajax({

			type: "GET",

			url: site_url + "home/gmaps",

			data: dataPost,

			dataFilter: function(data) {

				return jsonParse(data);

			},

			success: function(data){

				if(dataPost.clear != undefined && dataPost.clear == true){

					clearMarkers();					

				}



				if(data.filiais != undefined && data.filiais != null)

					jsonPontos.filiais = data.filiais;

				

				if(data.bairros != undefined && data.bairros != null)	

					jsonPontos.bairros = data.bairros;

	

				if(data.parceiros != undefined && data.parceiros != null)

					jsonPontos.parceiros = data.parceiros;

				

				temFiltro = data.tem_filtro;

				setupGmapsMarkers(dataPost.somenteParcerios);

				$("#ajax_loading_home").hide();

				fechaBox('busca');

			}

		 });		

	}

			
	function resizeHome(){
		var blockResize = false;

		var heightMaximizeMap 	= 650;

		var heightNormalMap 	= 369;	

		var mapsHeight;

	

		if(blockResize == false){

			blockResize = true;

			if($('#mapwrap_home').height() < heightMaximizeMap){

				mapsHeight = heightMaximizeMap;

			}else{

				mapsHeight = heightNormalMap;

			}	

			$("#mapwrap_home, #container_gmaps_home").animate({ height: mapsHeight+"px" }, 'normal', 'swing', function() {

				

				// a função callback esta sendo chamanda duas vezes, por causa dos dois paremetros (#mapwrap_home, #container_gmaps_home)

				// condicao para entar uma vez no callback

				if(blockResize == true){

					blockResize = false; 

					map.checkResize();

					if($("#img_btn_resize").attr("src").indexOf("_up") == -1){

						$("#img_btn_resize").attr("src", $("#img_btn_resize").attr("src").replace("_down", "_up"));

					}else{

						$("#img_btn_resize").attr("src", $("#img_btn_resize").attr("src").replace("_up", "_down"));	

					}

				}

			});

			$('.gmaps_home_rodape').each(function(i, val) {

				var newTop;	

				var myTop = parseInt($(val).css("top"));

				if(mapsHeight == heightMaximizeMap){

					newTop = myTop + (heightMaximizeMap - heightNormalMap);

				}else{

					newTop = myTop - (heightMaximizeMap - heightNormalMap);

				}

				$(val).animate({ "top": (newTop)+"px" }, 'normal', 'swing');

			});
			
			$('#div_img_btn_resize').each(function(i, val) {

				var newTop;	

				var myTop = parseInt($(val).css("top"));

				if(mapsHeight == heightMaximizeMap){

					newTop = myTop + (heightMaximizeMap - heightNormalMap);

				}else{

					newTop = myTop - (heightMaximizeMap - heightNormalMap);

				}

				$(val).animate({ "top": (newTop)+"px" }, 'normal', 'swing');

			});

		}
		return false;
	}

	

	function abreBox(tipo){

		if(tipo == 'busca'){		
			$("#gmaps_home_legenda").slideUp('def', function(){

				$("#gmaps_home_busca").slideToggle();				

			});

		}else{

			$("#gmaps_home_busca").slideUp('def', function(){

				$("#gmaps_home_legenda").slideToggle();				

			});

		}

	}	

	

	function fechaBox(tipo){

		if(tipo == 'busca'){

			$("#gmaps_home_busca").slideUp();

		}else{

			$("#gmaps_home_legenda").slideUp();			

		}

	}
