var map_info = {lat_left:0,lat_right:0, lng_top:0, lng_bottom:0};
var show_loader = true;
var map_groups = {};
var maps_more = new Array();
var map_markers = {};
var geocoder; 
var timer = null;
var information_windows = {};
var mini_maps = {};
var towns = {};
var selected_city = '';
var requested_data = {};
var mini_map_records;
var mini_map;
var states;
var labels = [];
var polys = [];

//var map_colors = new Array('#AAA443','#D5D678','#D3D07E','#B6BA46','#E6E6C4','#B8B946','#C9C850','#D6D775','#9E9D25','#D8D776','#A7A62D','#2554C7','#3BB9FF','#7D7C1F','#E6E6C4','#B6BA46','#797A24','#E9EAAC','#E7E8AE','#B6BA46');

var map_colors = new Array('#D1D18D','#D1D18D','#D1D18D','#D1D18D','#D1D18D','#D1D18D','#D1D18D','#D1D18D','#D1D18D','#D1D18D','#D1D18D','#D1D18D','#D1D18D','#D1D18D','#D1D18D','#D1D18D','#D1D18D','#D1D18D','#D1D18D','#D1D18D');



function getQuerystring(key, default_)
{
  if (default_==null) default_=""; 
  key = key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regex = new RegExp("[\\?&]"+key+"=([^&#]*)");
  var qs = regex.exec(window.location.href);
  if(qs == null)
    return default_;
  else
    return qs[1];
}



 

function textCounter(field, countfield, maxlimit) {
    if (field.value.length > maxlimit) {
        field.value = field.value.substring(0, maxlimit);
    } else { 
        countfield.value = maxlimit - field.value.length;
    }
}

function rewrite(text, target, validchars, separator) {
    var str = "";
    var i;
    var exp_reg = new RegExp("[" + validchars + separator + "]");
    var exp_reg_space = new RegExp("[ ]");
    text.toString();
    for (i=0; i < text.length; i++) {
        if (exp_reg.test(text.charAt(i))) {
            str = str+text.charAt(i);
        } else {
            if (exp_reg_space.test(text.charAt(i))) {
                if (str.charAt(str.length-1) != separator) {
                    str = str + separator;
                }
            }
        }
    }
    if (str.charAt(str.length-1) == separator) str = str.substr(0, str.length-1);
    document.getElementById(target).value = str.toLowerCase();
}

function newWindow(mypage,myname,w,h,features) {
    if(screen.width) {
          var winl = (screen.width-w)/2;
          var wint = (screen.height-h)/2;
      } else {
          winl = 0;wint =0;
      }

      if (winl < 0) winl = 0;
      if (wint < 0) wint = 0;

      var settings = 'height=' + h + ',';
      settings += 'width=' + w + ',';
      settings += 'top=' + wint + ',';
      settings += 'left=' + winl + ',';
      settings += features;
      settings += ' scrollbars=yes ';

      win = window.open(mypage,myname,settings);

      win.window.focus();
}

var timer_handles = [];    
function set_timer(id,code,time) {
    if(id in timer_handles) {
        clearTimeout(timer_handles[id]);
    }
    timer_handles[id] = setTimeout(code,time)
}

$(document).ready(function(){
	$('div#section_loader').hide();
	$('div.section_content').show();
    $.ajaxSetup({
        error: function(x,e){
            if(x.status==0) {
                // Do nothing, this results in bad popups if changing pages fast
            } else if(x.status==404) {
                alert('Requested URL not found.');
            } else if(x.status==302) {
                window.location = x.responseText;
            } else if(x.status==500) {
                if(x.responseText == 'Bad Token') {
                    alert('Page timeout.  Please reload the page.');
                } else {
                    alert('Internel Server Error.');
                }
            } else if(e=='parsererror') {
               // alert('Error.\nParsing request failed.');
            } else if(e=='timeout') {
                alert('Request Time out.');
            } else {
                //alert('Unknow Error.\n'+x.responseText);
            }
        }
    });

	if ($('#home_map').size()) {
	 
	 initialize_home();
	
	}

	if ($('#city_map').size()) {
		var city = $('#city_map').attr('city');
		initialize_city(city);
	}

	$('input.map_groups').click(function() {
		var group = $(this).val();
		toggleGroup(group);
	});

	$('#map_groups').find('table.group_item').hide();
	$('#map_group_message').click(function() {
		$(this).hide();
		$('#map_groups').find('table.group_item').show();
	});

	$('div.holder_next, div.holder_prev').hover(function() {
		$(this).css('background-color', '#efefef');
	},
	function () {
		$(this).css('background-color', '');
	});
	$('div.map_tabs ul li').click(function() {
		$(this).parent().find('li').removeClass('active');
		$(this).addClass('active');
		set_group_active($(this));
	});
	
	
	/*$('div.holder_next, div.holder_prev').click(function() {
			var photo_holder = $(this).parents('.popular_photo_holder');
			var scroll_photo_holder = $(this).parents('.popular_photo_holder').find('.popular_photos');;
			var parent_width = $(scroll_photo_holder).parent().width();
			var current_margin = parseInt($(scroll_photo_holder).attr('current_margin'));
			var current_width = $(scroll_photo_holder).width();

			if ($(this).hasClass('holder_next')) {
				next_margin = current_margin - parent_width;
				margin_limit = (current_width - parent_width) * -1
				if (next_margin < margin_limit) next_margin = margin_limit;
				$(scroll_photo_holder).attr('current_margin', next_margin);
			}
			else {
				prev_margin = current_margin + parent_width;
				margin_limit = 0
				if (prev_margin > margin_limit) prev_margin = margin_limit;
				$(scroll_photo_holder).attr('current_margin', prev_margin);
			}
			$(scroll_photo_holder).animate({marginLeft: $(scroll_photo_holder).attr('current_margin')+'px'}, 1000);

	});*/

	/*if ($('div.popular_photos').size())	{
		$('div.popular_photos a').lightBox({
			overlayBgColor: '#FFF',
			overlayOpacity: 0.6,
			imageLoading: global_site_url+'/images/lightbox-ico-loading.gif',
			imageBtnClose: global_site_url+'/images/lightbox-btn-close.gif',
			imageBtnPrev: global_site_url+'/images/lightbox-btn-prev.gif',
			imageBtnNext: global_site_url+'/images/lightbox-btn-next.gif',
			containerResizeSpeed: 350,
			txtImage: 'Imagem',
			txtOf: 'de'
		});
	}*/


	if ($('.popular_photos').size())	{
		$('.popular_photos').css('visibility', 'visible');
		$('.popular_photos').find('ul.actual_photos li').hide();
		$('.popular_photos').find('ul.actual_photos li:first').show();
		$('.popular_photos').find('ul.actual_photos li:first').show();
		$('.popular_photos').attr('current_photo', '0');

		$('.popular_photos').find('ul#thumbs_photos li:first').addClass('current_thumb');

		timer = setTimeout(function() { init_slideshow();}, 3000);
		$('.popular_photos').mouseenter(function() {
			$(this).find('div#controls').animate({marginTop:'265px'}, 100);
		});
		$('.popular_photos').mouseleave(function() {
			if ($(this).find('div#thumbs').is(':hidden')) {
				$(this).find('div#controls').animate({marginTop:'300px'}, 100);
			}
		});

		$('div#controls div.play').click(function() {
				if ($(this).attr('state') == 'pause') {
					$(this).css('font-size', '25px');
					$(this).html('&#9654;');
					$(this).attr('state', 'play');
					$(this).addClass('enabled');
					init_slideshow();
				}
				else {
					$(this).css('font-size', '16px');
					$(this).html(' &#9612;&#9612;');
					$(this).attr('state', 'pause');
					$(this).removeClass('enabled');
					clearTimeout(timer);

				}
		});

		$('div#controls div.next').click(function() {
				clearTimeout(timer);
				init_slideshow();

		});
		$('div#controls div.prev').click(function() {
			clearTimeout(timer);
			var max = $('.popular_photos').find('ul.actual_photos li').length - 2;
			var current = parseInt($('.popular_photos').attr('current_photo'));
			var next = current-2;
			next = (next < 0) ? max : next;
			$('.popular_photos').attr('current_photo', next);
			init_slideshow();
		});

		$('div#controls div.preview').click(function() {
				if ($(this).attr('state') == 'show') {
					$(this).attr('state', 'hide');
					$('.popular_photos').find('div#thumbs').hide();
					$(this).removeClass('enabled');
				}
				else {
					$(this).attr('state', 'show');
					$('.popular_photos').find('div#thumbs').show();
					$(this).addClass('enabled');
				}
		});

		$('div#thumbs div.move_left, div#thumbs div.move_right').mouseenter(function() {
				$(this).parents('.popular_photos').attr('in_scroll', 'yes');
				$(this).css('opacity', '1');

				var left = $('#thumbs_photos').width() - (470+55);
				var right = 0;
				var current = parseInt($('#thumbs_photos').css('margin-left'));
				var dir = $(this).hasClass('move_left') ? 'right' : 'left';
				var move_time = (dir == 'left') ? ((left - current) * 25) : Math.abs(0 - current) * 25;
				if (dir == 'left') {
					$('ul#thumbs_photos').stop(true, false).animate({marginLeft:left * -1}, move_time);
				}
				else {
					$('ul#thumbs_photos').stop(true, false).animate({marginLeft:0}, move_time);
				}
		});

		$('div#thumbs div.move_left, div#thumbs div.move_right').mouseleave(function() {
			$(this).parents('.popular_photos').attr('in_scroll', 'no');
			$(this).css('opacity', '0.8');
			$('ul#thumbs_photos').stop(true);
		});

		$('ul#thumbs_photos li').click(function() {
			clearTimeout(timer);
			var index = $('ul#thumbs_photos li').index($(this)) - 1;
			$('.popular_photos').attr('current_photo', index);
			$('ul#thumbs_photos').stop(true, false);
			init_slideshow();
		});
		

	}
	
	$('.map_locator').click(function() {
		var m_long = $(this).attr('long');
		var m_lat = $(this).attr('lat');
		var lid = $(this).attr('listing_id');
		var point =	new GLatLng(m_lat,m_long);
		var infowindow = $(this).attr('infowindow');
		var marker = map_markers[lid];
        map.setCenter(point, 20);
		if (marker)	marker.openInfoWindowHtml(infowindow);

	});


	$('div.more_location_link').click(function() {
		$('#popular_locations').slideUp();
		$('#more_locations').slideDown();
		toggleGroup1('main_locations', 0);	
		toggleGroup1('more_locations', 1);	
	});
	$('div.back_location_link').click(function() {
		$('#more_locations').slideUp();
		$('#popular_locations').slideDown();
		toggleGroup1('more_locations', 0);	
		toggleGroup1('main_locations', 1);	
	});

	$('a.more_sub_link').click(function() {
		var section = $(this).attr('section');
		var url = global_site_url + '/' + get_requested_data('name');

		if (get_requested_data('loc')) {
			url += '/' + get_requested_data('loc');
		}

		url += '/' + section;

		location.href = url;

	});






	
	

/*	$('div.location').click(function() {

		
		
	
			
		
			//$("#mapStates").hide();
			//$("#map_holder").attr('margin-top', '0px');

				
		$("#showImageMap").hide();
		
		if ($(this).hasClass('back_location_link') || $(this).hasClass('more_location_link') || $(this).find('.location_info').is(':hidden')) return;

//		if ($(this).attr('state') == 'selected') {
//			
//			initialize_home2($(this).attr('search_name'),'');
//			
//			
//			return true;
//		}
		
		
		
		
			
			
		location_menu = this;	
		
		reorder_menu($(location_menu).parent());
 
		
		
		
		if ($(this).hasClass('back_location_link') || $(this).hasClass('more_location_link') || $(this).find('.location_info').is(':hidden')) return;
		$(location_menu).parent().prepend($(location_menu));
		var search_name = $(this).attr('search_name');
		var location_id = $(this).attr('location_id');
		var lat = $(this).attr('lat');
		var lng = $(this).attr('long');
		reset_requested_data();
		
		set_requested_data('name',  search_name);
		set_header();
		
		
		$('body').find('div.location').removeClass('selected').addClass('small_row').attr('state', 'not_selected');
		toggleGroup1('main_locations', 0);	
		toggleGroup1('more_locations', 0);	
		$(location_menu).addClass('selected').attr('state', 'selected');
		$(location_menu).parent().find('.sub_location').remove();
		$(location_menu).parent().find('.location').each(function() {
																															
			if (!$(this).hasClass('selected')) {
						
						$(this).hide();
		 
			}
		});  
		$('div#main_panel_home').find('div#map_holder').show();
		$('div#city_data, div#city_data_left').hide();
		$('h1#head_h1').show();
		
		
		if ($(this).parent().attr('id') == 'popular_locations') {
			$('div#destinos_label').html('Destinos populares');
		}
		else if ($(this).parent().attr('id') == 'more_locations') {
			$('div#destinos_label').html('Mais Destinos');
		}
		
		
		//showMarker_location_point(location_id, search_name, 'http://destinos.viajamos.com.br/'+search_name, lat, lut, null, null, 'town_locations', null, get_reviews_text(review_counts));
		
	 
		
		$.post(global_site_url +"/index.php?page=ajax&action=get_cities&location_id="+location_id+"&name="+search_name, {}, function(response) {
			//showAddress_ll(lat, lng, 13);
			$("#home_map").hide();
			
		
			initialize_home2(search_name,'');
			
			var backlink_html = '<div class="sub_location sub_back_location_link" style="margin-left:-14px; border-bottom: none; font-weight: bold"><div class="arrow" style="margin-left:0px">&lt;</div>&nbsp;&nbsp;&nbsp;&nbsp;Tr&aacute;s</div>';
			$(backlink_html).insertBefore(location_menu);
	
			for (i in response) {
				
				
				
				var name_t = response[i].name;
				var name_t_url = response[i].name_url;
				var lat_t1 = response[i].latitude;
				var long_t1 = response[i].longitude;
				var review_counts = response[i].review_counts;
				var city_name_url = response[i].city_name_url;
				
		
		
		
				//showAddress_marker_city(name_t+','+search_name+',Brazil');
				
				var href = global_site_url + '/' + get_requested_data('name') + '/' + name_t_url;

				var sub_location_row = $(location_menu).clone();
				$(sub_location_row).removeClass('location').removeClass('small_row').removeClass('selected').addClass('sub_location');
				
				
				//$("button:gt(1)").attr("disabled","disabled");
				
				
				$(sub_location_row).removeAttr('location_id');
				$(sub_location_row).removeAttr('state');
					$(sub_location_row).attr('alt', name);
				$(sub_location_row).attr('href', href);
				
				
			//	$(sub_location_row).find('.sub_location').attr('onclick', window.location=global_site_url+"/"+name_t_url+"/");
				
				//$(sub_location_row).attr('onclick', window.location=global_site_url+"/"+name_t_url+"/");
				
				//old working link------$(sub_location_row).attr("onclick","window.location='"+global_site_url+"/"+name_t_url+"/'");
				
				//$(sub_location_row).attr("onclick","window.location='\"+global_site_url+\"/\"+name_t_url+\"/'");
				
				$(sub_location_row).attr("onclick","window.location='http://www.google.com'");
				
				$(sub_location_row).trigger('click'); 
				
				//alert(city_name_url+'---- city name url start-----');
				var replace = $(sub_location_row).find('.location_info').text();
				replace = replace.replace('>','');
				city_name_url=city_name_url.replace("_"," ");
				city_name_url=city_name_url.replace("_"," ");
				city_name_url=city_name_url.replace("_"," ");
				var replace_text = $(sub_location_row).find('.location_info').html().replace(replace, city_name_url);
				
				//alert(city_name_url+'---- city name url end-----');
				
				$(sub_location_row).find('.location_info').html(replace_text);
				$(sub_location_row).find('.location_info').css({ "display":"block"});
				$(sub_location_row).insertAfter($(location_menu));
				
				showMarker_point(name_t, href, lat_t1, long_t1, null, null, null, null, get_reviews_text(review_counts),city_name_url );
				
			}

			init_go_back();

		}, "json");



	
	
	
	});
*/	
	
	


	$(document).ajaxStart(function() {
		if (show_loader === true) loader();
	});

	$(document).ajaxComplete(function() {
		if (show_loader === true) loader('hide');
	});

	$('div.location').mouseenter(function() {
		if (!$(this).find('.location_info').is(':hidden')) $(this).addClass('selected');
	});

	$('div.location').mouseleave(function() {
		if (!$(this).find('.location_info').is(':hidden') && $(this).attr('state') != 'selected') $(this).removeClass('selected');
	});
 
	if (selected_city != '') {
		//init_mini_map();
	}

	set_header();

});

function init_go_back() {
	init_sub_location_links();	

	$('div.sub_back_location_link').unbind('click').bind('click', function() {
		

		$("#showImageMap").show();
				
				
		initialize_home()	;
		
		 
		 
																																				 
		var parent_div = $(this).parent();
		$(parent_div).find('.sub_location').remove();
		$(parent_div).find('div.location').removeClass('selected').addClass('small_row').attr('state', 'not_selected');
		$(parent_div).find('div.location').show();
		reorder_menu($(parent_div));
		$(this).remove();
		//reset_map($(parent_div).attr('id'));
	});

}

function init_sub_location_links() {
	$('div.sub_location').unbind('click').bind('click', function() {
		
		
 
				
 		var hrefVar = $(this).attr('href');
		var getStateCity = hrefVar.split('/');


	//	initialize_home2(getStateCity[5],getStateCity[6]);
 
  
 		//redirect($(this).attr('href'));
	});

}
function reset_map(id) {
	toggleGroup1('town_locations', 0);
	$('#map_info').hide();
	showAddress('Brazil', 4);
	
	if (id == 'popular_locations') {
		toggleGroup1('main_locations', 1);	
		toggleGroup1('more_locations', 0);
	}
	else if (id == 'popular_locations') {
		toggleGroup1('main_locations', 0);	
		toggleGroup1('more_locations', 1);
	}
}

function redirect(url) {
	location.href = url;
}
function set_group_active(tab) {
    var main_group = $(tab).attr('icon_group');
	var real_group = $(tab).attr('group_name');
	$(tab).parent().find('li').each(function() {
	    var group = $(this).attr('icon_group');
		toggleGroup1(group, (main_group == 'All') ? 1 : 0);

	});
	if (main_group != 'All') {
		toggleGroup1(main_group, 1);
		current_sub = real_group;
	}
	else {
		current_sub = '';
	}
	get_data(main_group);
	
}


function popuplar_init() {
	$('.popular_photos').css('visibility', 'visible');
	$('.popular_photos').find('ul.actual_photos li').hide();
	$('.popular_photos').find('ul.actual_photos li:first').show();
	$('.popular_photos').find('ul.actual_photos li:first').show();
	$('.popular_photos').attr('current_photo', '0');

	$('.popular_photos').find('ul#thumbs_photos li:first').addClass('current_thumb');

	timer = setTimeout(function() { init_slideshow();}, 3000);
	$('.popular_photos').unbind('mouseenter').bind('mouseenter', function() {
		$(this).find('div#controls').animate({marginTop:'265px'}, 100);
	});
	$('.popular_photos').unbind('mouseleave').bind('mouseleave', function() {
		if ($(this).find('div#thumbs').is(':hidden')) {
			$(this).find('div#controls').animate({marginTop:'300px'}, 100);
		}
	});

	$('div#controls div.play').unbind('click').bind('click', function() {
			if ($(this).attr('state') == 'pause') {
				$(this).css('font-size', '25px');
				$(this).html('&#9654;');
				$(this).attr('state', 'play');
				$(this).addClass('enabled');
				init_slideshow();
			}
			else {
				$(this).css('font-size', '16px');
				$(this).html(' &#9612;&#9612;');
				$(this).attr('state', 'pause');
				$(this).removeClass('enabled');
				clearTimeout(timer);

			}
	});

	$('div#controls div.next').unbind('click').bind('click', function() {
			clearTimeout(timer);
			init_slideshow();

	});
	$('div#controls div.prev').unbind('click').bind('click', function() {
		clearTimeout(timer);
		var max = $('.popular_photos').find('ul.actual_photos li').length - 2;
		var current = parseInt($('.popular_photos').attr('current_photo'));
		var next = current-2;
		next = (next < 0) ? max : next;
		$('.popular_photos').attr('current_photo', next);
		init_slideshow();
	});

	$('div#controls div.preview').unbind('click').bind('click', function() {
			if ($(this).attr('state') == 'show') {
				$(this).attr('state', 'hide');
				$('.popular_photos').find('div#thumbs').hide();
				$(this).removeClass('enabled');
			}
			else {
				$(this).attr('state', 'show');
				$('.popular_photos').find('div#thumbs').show();
				$(this).addClass('enabled');
			}
	});

	$('div#thumbs div.move_left, div#thumbs div.move_right').unbind('mouseenter').bind('mouseenter', function() {
			$(this).parents('.popular_photos').attr('in_scroll', 'yes');
			$(this).css('opacity', '1');

			var left = $('#thumbs_photos').width() - (470+55);
			var right = 0;
			var current = parseInt($('#thumbs_photos').css('margin-left'));
			var dir = $(this).hasClass('move_left') ? 'right' : 'left';
			var move_time = (dir == 'left') ? ((left - current) * 25) : Math.abs(0 - current) * 25;
			if (dir == 'left') {
				$('ul#thumbs_photos').stop(true, false).animate({marginLeft:left * -1}, move_time);
			}
			else {
				$('ul#thumbs_photos').stop(true, false).animate({marginLeft:0}, move_time);
			}
	});

	$('div#thumbs div.move_left, div#thumbs div.move_right').unbind('mouseleave').bind('mouseleave', function() {
		$(this).parents('.popular_photos').attr('in_scroll', 'no');
		$(this).css('opacity', '0.8');
		$('ul#thumbs_photos').stop(true);
	});

	$('ul#thumbs_photos li').unbind('click').bind('click', function() {
		clearTimeout(timer);
		var index = $('ul#thumbs_photos li').index($(this)) - 1;
		$('.popular_photos').attr('current_photo', index);
		$('ul#thumbs_photos').stop(true, false);
		init_slideshow();
	});
		
}
function get_data(main_group) {
	$('.review_box').each(function() {
		var sub = $(this).attr('id').replace('box_', '');
		if ($(this).attr('id') != 'box_' + main_group && main_group != 'All') {
			$(this).hide();
		}
		else {
			if (main_group == 'All') { 
				$('#content_'+sub).html('<img src="'+global_site_url+'/images/lightbox-ico-loading.gif" />');
				$.get(global_site_url+'/?page=ajax&name='+current_city+'&action=getinfo&sub='+sub+'&default=1', function(response) {

					$('#content_'+sub).html(response);
				}, "html");
				$(this).show();
			}
			else {
				$('#content_'+sub).html('<img src="'+global_site_url+'/images/lightbox-ico-loading.gif" />');
				$.get(global_site_url+'/?page=ajax&name='+current_city+'&action=getinfo&sub='+sub, function(response) {
					$('#content_'+sub).html(response);
				}, "html");
				$(this).show();
			}
		}
	});

}

function get_reviews_text(review_counts) {
	var titles = new Array('Hot&eacute;is','Restaurantes','Praias');
	var counts = review_counts.split('-');
	var text = '';
	for (i=0;i<counts.length;i++) {
		if (counts[i] != 0) text += titles[i] + ': '+ counts[i] + '<br />'; 
	}
	if (text != '') {
		text = '<small><b>Listagens</b><br />'+text+'</small>' ;
	}
	return text;
}

function showStateList(val)
{
	
	
	
 
  
	
	
}
// Call this function when the page has been loaded

function viewCity(state,city)
{
	
	initialize_home2(state,city);
}

function viewCities(state){
	
 
		$("#showImageMap").hide();
								
						//var location_id=185;
						var org_index=0;
						var search_name=state;
						
						set_requested_data('name',  search_name);
						set_header();
						
						initialize_home2(search_name,'');
						
		
						 $.ajax({
								 type: "POST",
								 url: global_site_url +"/index.php",
								 data: "page=ajax&action=get_cities&name="+search_name+"&status=manual",
								 success: function(getResponse){
										
										
										
									$("#destinosPor").hide();
									$("#destinosList").hide();
									
									$("#locations_panel2").html(getResponse).show();
									 
									var showHtml=$("#locations_panel2").html();
									 
									$(showHtml).find('div.sub_location').each(function() {
												
											if($(this).attr('search_name') != undefined )
											{
												var href = global_site_url + '/'  + $(this).attr('nameurl');
												
											 showMarker_point($(this).attr('city_name_org'), href, $(this).attr('latitude'),  $(this).attr('longitude'), null, null, null, null,get_reviews_text($(this).attr('review_counts')),$(this).attr('city_name_url'));  
											
											}
									
									});
									 
								 }
							 });
						 
						 $("div#overlay").hide();


}

function initialize_home() {

//		 if (GBrowserIsCompatible()) {
	
				// === A method for testing if a point is inside a polygon
				// === Returns true if poly contains point
				// === Algorithm shamelessly stolen from http://alienryderflex.com/polygon/ 
				/*GPolygon.prototype.Contains = function(point) {
					var j=0;
					var oddNodes = false;
					var x = point.lng();
					var y = point.lat();
					for (var i=0; i < this.getVertexCount(); i++) {
						j++;
						if (j == this.getVertexCount()) {j = 0;}
						if (((this.getVertex(i).lat() < y) && (this.getVertex(j).lat() >= y))
						|| ((this.getVertex(j).lat() < y) && (this.getVertex(i).lat() >= y))) {
							if ( this.getVertex(i).lng() + (y - this.getVertex(i).lat())
							/  (this.getVertex(j).lat()-this.getVertex(i).lat())
							*  (this.getVertex(j).lng() - this.getVertex(i).lng())<x ) {
								oddNodes = !oddNodes
							}
						}
					}
					return oddNodes;
				}*/
	
	
	
				// Display the map, with some controls and set the initial location 
			
		
		
		//map.setUIToDefault();
		map = new GMap2(document.getElementById("home_map"));
		var zoomControl = new GLargeMapControl3D();
		map.addControl(zoomControl);
		//showAddress('Brazil', 4);
		//disableScrollWheelZoom();
		//map.disableScrollWheelZoom(); 
	
	

$("#showImageMap").show();
$("#home_map").hide();
	// IF QUERY STRING PRESENT
	var loc_value = getQuerystring('locstr');


	if(loc_value != '')
	{
		
		
		$("#showImageMap").hide();
			
										
								//var location_id=185;
								var org_index=0;
								var search_name=loc_value;
								
								set_requested_data('name',  search_name);
								set_header();
							
							
								/* replaced underscore to space start, it will work if underscore finds in the cityname*/
								search_name=search_name.replace("_"," ");
								search_name=search_name.replace("_"," ");
								search_name=search_name.replace("_"," ");
							
							
								initialize_home2(search_name,'');
 								
							
								 $.ajax({
										 type: "POST",
										 url: global_site_url +"/index.php",
										 data: "page=ajax&action=get_cities&name="+search_name+"&status=manual",
										  
										 success: function(getResponse){
											 	
 												$("#destinosPor").hide();
												$("#destinosList").hide();
												
												 
								// 
											 $("#locations_panel2").html(getResponse).show();
											 
											 var showHtml=$("#locations_panel2").html();
											 
											 $(showHtml).find('div.sub_location').each(function() {
														
													if($(this).attr('search_name') != undefined )
													{
														var href = global_site_url + '/'  + $(this).attr('nameurl');
														
													 showMarker_point($(this).attr('city_name_org'), href, $(this).attr('latitude'),  $(this).attr('longitude'), null, null, null, null,get_reviews_text($(this).attr('review_counts')),$(this).attr('city_name_url'));  
													
													}
													
												});
											 
										 }
									 });
								 
								 $("div#overlay").hide();
				}

	//$("#home_map").show();
	
	
	//		map = new GMap2(document.getElementById("home_map"));

	
	
					// Read the data from states.xml
				
	
//			}
//			
//    // display a warning if the browser was not compatible
//    else {
//      alert("Sorry, the Google Maps API is not compatible with this browser");
//    }
//
	

	
 }


function showAllState(){
	
	
	
	var loc_value = getQuerystring('locstr');
	if(loc_value != '')
	{
		window.location=global_site_url;	
	}
	
	
	
	
	$("#destinosList").show();
	$("#destinosPor").show();
	$("#locations_panel2").hide();

	$("#showImageMap").show();
	
	
	
	
	
	
	initialize_home()
	
	
}


				
function showAddress_marker_city(address) {

					geocoder.getLatLng(
						address,
						function(point) {
							if (!point) {
								//alert(address + " not found");
							} else {
								//map.setCenter(point, 8);
								var marker = new GMarker(point);
								//map.addOverlay(marker);
								//marker.openInfoWindowHtml(address);
							}
						}
					);
					$("div#overlay").show();
				}				

function showAddress_marker(address) {
					geocoder.getLatLng(
						address,
						function(point) {
							if (!point) {
								//alert(address + " not found");
							} else {
								map.setCenter(point, 13);
								var marker = new GMarker(point);
								//map.addOverlay(marker);
								
								
							}
						}
					);
					$("div#overlay").show();
				}
				
function initialize_home2(stateName,cityname) {
	
//		 if (GBrowserIsCompatible()) {
	
				// === A method for testing if a point is inside a polygon
				// === Returns true if poly contains point
				// === Algorithm shamelessly stolen from http://alienryderflex.com/polygon/ 
/*				GPolygon.prototype.Contains = function(point) {
					var j=0;
					var oddNodes = false;
					var x = point.lng();
					var y = point.lat();
					for (var i=0; i < this.getVertexCount(); i++) {
						j++;
						if (j == this.getVertexCount()) {j = 0;}
						if (((this.getVertex(i).lat() < y) && (this.getVertex(j).lat() >= y))
						|| ((this.getVertex(j).lat() < y) && (this.getVertex(i).lat() >= y))) {
							if ( this.getVertex(i).lng() + (y - this.getVertex(i).lat())
							/  (this.getVertex(j).lat()-this.getVertex(i).lat())
							*  (this.getVertex(j).lng() - this.getVertex(i).lng())<x ) {
								oddNodes = !oddNodes
							}
						}
					}
					return oddNodes;
				}
*/	
	
	
	
			// Display the map, with some controls and set the initial location 
//			map = new GMap2(document.getElementById("home_map"));
			//map.setUIToDefault();
//			var zoomControl = new GLargeMapControl3D();
//			map.addControl(zoomControl);
		//	showAddress('Brazil', 4);
	
			//map.setCenter(new GLatLng(-9.0237964, -70.8119953), 15);
			
			//showAddress('Acre, Brazil', 7);
 
			
 	$("div#overlay").show();
		$("#loader").hide();	
			
		if(cityname=='')
		{
				
			
 			if(stateName=='Ceara')
			{
				showAddress_ll(-3.99578,-37.133789,6);
				
				
			}
 
 			else if( stateName=='Amapa')
			{
				
				//showAddress_marker(stateName + ', Brazil');
	
				showAddress(stateName + ', Brazil', 7);	
				
			}
			else if(stateName=='Sergipe' || stateName=='Alagoas'  )
			{
				
				
				//showAddress_marker(stateName + ', Brazil');
	
				showAddress(stateName + ', Brazil', 8);	

			}
			
			else if(stateName=='Goias')
			{

					showAddress_ll(-16.720385,-49.262695,10);
			}
			
			else if(stateName=='Parana')
			{

					showAddress_ll(-24.126702,-51.767578,7);
			}
			
			else if(stateName=='Santa Catarina')
			{

			showAddress_ll(-26.88288,-48.691406,9);
			}
			

			else if(stateName=='Sao Paulo')
			{

					showAddress_ll(-23.84565,-46.230469,9);
			}
			
			else if(stateName=='Bahia')
			{

					showAddress_ll(-13.453737,-39.462891,7);
			}
		
			else if(stateName=='Rio Grande do Norte')
			{
					
					showAddress_ll(-6.140555,-35.288086,9);
				
			}
			else if(stateName == 'Paraiba')
			{
				
				showAddress_ll(-6.970049,-35.112305,9);
				
			}
			else if(stateName == 'Pernambuco')
			{
				
				showAddress_ll(-8.146243,-35.57373,9);
			}
			else if(stateName == 'Espirito Santo')
			{
				
				showAddress_ll(-20.330205,-40.306091,10);
				//showAddress('-22.666738,-44.824219 + ', Brazil', 8);		
			}
			
			else if(stateName == 'Rio de Janeiro')
			{


				showAddress_ll(-22.895153,-43.093872,8);
			
			}
			else if(stateName == 'Para')
			{
			
				showAddress_ll(-1.345701,-48.47168,10);
			
			}
			
				else if(stateName == 'Rio Grande do Sul')
			{
			
				showAddress_ll(-29.649869,-51.196289,9);

			
			}
			else if(stateName == 'Minas Gerais')
			{

				showAddress_ll(-19.47695,-46.142578,7);

			
			}
			else if(stateName == 'Acre')
			{

				showAddress_ll(-9.31899,-69.785156,7);

			
			}
			else if(stateName == 'Amazonas')
			{


			showAddress_ll(-4.127285,-63.061523,7);

			}
			
			else if(stateName == 'Roraima')
			{


			showAddress_ll(2.284551,-60.776367,7);

			}
			
			else if(stateName == 'Rondonia')
			{


			showAddress_ll(-9.31899,-63.500977,7);

			}
			else if(stateName == 'Mato Grosso')
			{


			showAddress_ll(-15.24179,-56.030273,7);

			}
			else if(stateName == 'Maranhao')
			{


			showAddress_ll(-2.855263,-44.560547,7);

			}
			else if(stateName == 'Mato Grosso do Sul')
			{


			showAddress_ll(-18.271086,-56.25,7);

			}
			
			else if(stateName == 'Tocantins')
			{


			showAddress_ll(-10.09867,-48.427734,6);

			}
			

			
		
			else
			{
							 
								//marker.openInfoWindowHtml(address);
				//showAddress_marker(stateName + ', Brazil');
 
				showAddress(stateName + ', Brazil', 5);	
			
			}

$("#home_map").show(); 
	

/*				 var point=marker.getLatLng(stateName + ', Brazil');
alert(point);
				 
 				
			map.addOverlay(new GMarker(point));*/
		}
		if(cityname != '')
		{
			//showAddress(cityname + ','+ stateName + ', Brazil', 11);		
			
			//alert(cityname);
			redirect('http://destinos.viajamos.com.br/'+cityname+'/');
		}
	 
			
			


 
			
//		}	else {
//    
//			alert("Sorry, the Google Maps API is not compatible with this browser");
//    
//		}


	
 
}



function initialize_city(city) {
	map = new GMap2(document.getElementById("city_map"));
	var zoomControl = new GLargeMapControl3D();
	map.addControl(zoomControl);
	var moveListener = GEvent.addListener(map, "moveend", function() {
		show_loader = false;
		$('div#map_holder div#map_load').show();
		var bounds = map.getBounds();
		var southWest = bounds.getSouthWest();
		var northEast = bounds.getNorthEast();

		var bounds = map.getBounds();
	  var southWest = bounds.getSouthWest();
	  var northEast = bounds.getNorthEast();
	  var lat_left = southWest.lat();
	  var lat_right = northEast.lat();
	  var lng_top = northEast.lng();
	  var lng_bottom = southWest.lng();
	  map_info.lat_left = lat_left;
	  map_info.lat_right = lat_right;
	  map_info.lng_top = lng_top;
	  map_info.lng_bottom = lng_bottom;
		var url = global_site_url + '?page=ajax&action=get_listings&sub='+current_sub+'&lat='+lat_left+'|'+lat_right+'&lng='+lng_top+'|'+lng_bottom;
		
		$.post(url, {}, function(response) {
			maps = response;
			initialize_city_map_markers();
			$('div#map_holder div#map_load').hide();
			show_loader = true;

		}, "json");
		init_sub_location_links();

	});
	//showAddress(city + ', Brazil', 7);
	
}

function initialize_city_map_markers() {
	for (key in maps) {
	  var data = maps[key];
	  showMarker_point((data.place + ' - ' + data.type), data.href, data.latitude, data.longitude, data.icon, null, data.group, data.listing_id, data.address,null);
	}
}


function showAddress(address,zoom) {

  geocoder = new GClientGeocoder();
  geocoder.getLatLng(
    address,
    function(point) {
      if (!point) {
       // alert(address + " not found");
      } else {
			 
        map.setCenter(point, zoom);
      }
    }
  );
	
	
}

function showAddress_ll(lat,lng,zoom) {
	var point =	new GLatLng(lat,lng);
    map.setCenter(point, zoom);
}


function showAddress_location_ll(location_id, lat,lng,zoom) {
	var point =	new GLatLng(lat,lng);
    mini_maps[location_id].setCenter(point, zoom);
}
function showMarker(address) {
 geocoder = new GClientGeocoder();
  geocoder.getLatLng(
    address,
    function(point) {
      if (!point) {
		  
      } else {
          var marker = new GMarker(point);
		  map.addOverlay(marker);
      }
    }
  );
}

function showMarker_point(name, href, lat, long, icon, new_window, group, listing_id,address,name_url) {
	
	 

 	var point =	new GLatLng(lat,long);
	var marker;

	if (icon && icon != 'default'){
		var Icon = new GIcon();
		Icon.image = global_site_url +"/images/icons/"+icon+'.gif';
		Icon.iconSize = new GSize(37, 50);
		Icon.iconAnchor = new GPoint(18, 50);
		Icon.infoWindowAnchor = new GPoint(6, 1);
	    marker = new GMarker(point, Icon);
	}
	else {

		// Create our "tiny" marker icon
		var blueIcon = new GIcon(G_DEFAULT_ICON);
		blueIcon.image = "http://maps.google.com/intl/en_us/mapfiles/ms/micons/blue-dot.png";
		blueIcon.iconSize = new GSize(32, 32);	
		blueIcon.iconAnchor = new GPoint(16, 32);
		// Set up our GMarkerOptions object
		markerOptions = { icon:blueIcon };

	    marker = new GMarker(point, markerOptions);
	}
	if (!map_groups[group]) map_groups[group] = new Array();
	if (listing_id) map_markers[listing_id] = marker;
	

	map_groups[group].push(marker);
	
	
	

	GEvent.addListener(marker, "mouseover", function() {
																									 
	name_url=name_url.replace("_"," ");
	name_url=name_url.replace("_"," ");
	name_url=name_url.replace("_"," ");
	
	name_url_link=name_url.replace(" ","_");
	name_url_link=name_url_link.replace(" ","_");
	name_url_link=name_url_link.replace(" ","_");

	
	
	
marker.openInfoWindowHtml('<div class="popup_location_name"><a href="http://destinos.viajamos.com.br/'+name_url_link+'/">'+name_url.replace("_"," ")+ '</a></div>'+((address) ? '<a href="http://destinos.viajamos.com.br/'+name_url+'/">'+address+'</a>' : ''));
			
	 });
	 /*GEvent.addListener(marker, "mouseout", function() {
		  marker.closeInfoWindow();
	 });*/
	 if (href != '')  {
		 GEvent.addListener(marker, "click", function() {
			 if (new_window) {
				window.open(href);
			 }
			 else {
				 location.href = 'http://destinos.viajamos.com.br/'+name_url+'/';
			 }
		 });
	 }
	map.addOverlay(marker);

}


 

function showMarker_location_point(location_id, name, href, lat, long, icon, new_window, group, listing_id,address) {
	


	
	var point =	new GLatLng(lat,long);
	var marker;

	if (icon && icon != 'default'){
		var Icon = new GIcon();
		Icon.image = global_site_url +"/images/icons/"+icon+'.gif';
		Icon.iconSize = new GSize(37, 50);
		Icon.iconAnchor = new GPoint(18, 50);
		Icon.infoWindowAnchor = new GPoint(6, 1);
	    marker = new GMarker(point, Icon);
	}
	else {

		// Create our "tiny" marker icon
		var blueIcon = new GIcon(G_DEFAULT_ICON);
		blueIcon.image = "http://maps.google.com/intl/en_us/mapfiles/ms/micons/blue-dot.png";
		blueIcon.iconSize = new GSize(32, 32);	
		blueIcon.iconAnchor = new GPoint(16, 32);
		// Set up our GMarkerOptions object
		markerOptions = { icon:blueIcon };

	    marker = new GMarker(point, markerOptions);
	}

	GEvent.addListener(marker, "mouseover", function() {
																								                          
//		  marker.openInfoWindowHtml('<div class="popup_location_name">'+name + '</div>'+((address) ? address : ''));
		 
		/* infoBox.set_content('<a href="'+href+'"><div class="popup_location_name" onclick="window.location.href=\''+href+'\'" style="color: #03487d; cursor: pointer;"><a href="'+href+'">'+name + '</a></div><div style="font-family: arial,helvetica,serif; padding-left: 10px; border-left: 1px solid #C9CBCC; border-right: 1px solid #C9CBCC; background: #ffffff; color: #03487d"><a href="'+href+'">'+((address) ? address : ''+'</a></div</a>' );
    infoBox.open(map, marker);*/
		
		
		 
//           marker.openExtInfoWindow(
//              map,
//              "extInfoWindow_coolBlues",
//              '<a href="'+href+'"><div class="popup_location_name" onclick="window.location.href=\''+href+'\'" style="color: #03487d; cursor: pointer;"><a href="'+href+'">'+name + '</a></div><div style="font-family: arial,helvetica,serif; padding-left: 10px; border-left: 1px solid #C9CBCC; border-right: 1px solid #C9CBCC; background: #ffffff; color: #03487d"><a href="'+href+'">'+((address) ? address : ''+'</a></div</a>'),
//              {beakOffset: 2}
//            ); 

marker.openExtInfoWindow(
              map,
              "extInfoWindow_coolBlues",
              "<div>With some clever use of gradients, widths, and the "+
              "GIcon.infoWindowAnchor position, we can make a cool info window "+
              "with a beak pointing to the Lat / Lon on the map</div>",
              {beakOffset: 1}
            ); 


   });
	
	 GEvent.addListener(marker, "mouseout", function() {
		  marker.closeInfoWindow();
	 });


	 
	 if (href != '')  {
		 GEvent.addListener(marker, "click", function() {
			 if (new_window) {
				window.open(href);
			 }
			 else {
				 location.href = href;
			 }
		 });
		 
		 
	 }
	mini_map.addOverlay(marker);

}

UTF8 = {
	encode: function(s){
		for(var c, i = -1, l = (s = s.split("")).length, o = String.fromCharCode; ++i < l;
			s[i] = (c = s[i].charCodeAt(0)) >= 127 ? o(0xc0 | (c >>> 6)) + o(0x80 | (c & 0x3f)) : s[i]
		);
		return s.join("");
	},
	decode: function(s){
		for(var a, b, i = -1, l = (s = s.split("")).length, o = String.fromCharCode, c = "charCodeAt"; ++i < l;
			((a = s[i][c](0)) & 0x80) &&
			(s[i] = (a & 0xfc) == 0xc0 && ((b = s[i + 1][c](0)) & 0xc0) == 0x80 ?
			o(((a & 0x03) << 6) + (b & 0x3f)) : o(128), s[++i] = "")
		);
		return s.join("");
	}
};


function init_city_load(city_name) {
	$('#more_link').unbind('click').bind('click', function() {
		location.href = $(this).attr('href') + city_name;
		return false;
	});

	popuplar_init();

	
}

function toggleGroup(type) {
	return;
      for (var i = 0; i < map_groups[type].length; i++) {
        var marker = map_groups[type][i];
        if (marker.isHidden()) {
          marker.show();
        } else {
          marker.hide();
        }
      } 
 }




function toggleGroup1(type, show_or_hide) {
	if (typeof map_groups[type] == 'undefined') return;
 
       for (var i = 0; i < map_groups[type].length; i++) {
        var marker = map_groups[type][i];
        if (show_or_hide == 1) {
          marker.show();
        } else {
          marker.hide();
        }
      } 
 }

 function init_slideshow() {
	var max = $('.popular_photos').find('ul.actual_photos li').length - 1;
	var current = parseInt($('.popular_photos').attr('current_photo'));
	var next = ((current + 1) > max) ? 0 : current + 1;
	$('.popular_photos').find('ul.actual_photos li').each(function() {
		var index = $('ul#thumbs_photos li').index($(this));
		if (index != current && index != next) {
			$(this).hide();
		}
	});
	$('.popular_photos').find('ul.actual_photos li').eq(current).fadeOut(1000);
	$('.popular_photos').find('ul.actual_photos li').eq(next).fadeIn(1000);
	$('.popular_photos').attr('current_photo', next);
	$('#current_photo').text(next+1);
	$('.popular_photos').find('ul#thumbs_photos li').removeClass('current_thumb');
	$('.popular_photos').find('ul#thumbs_photos li').eq(next).addClass('current_thumb');
	if ($('.popular_photos').attr('in_scroll') != 'yes') {
		center_thumbs(next);
	}
	timer = setTimeout(function() {init_slideshow();}, 4000);
}

function center_thumbs(index) {
	var width = parseInt($('ul#thumbs_photos').css('width'));
	var center = (470/2)+(61/2)
	var current_point = index * 61;
	var des = (current_point*-1) + (center-55);
	var max_left = (width * -1)	+ 470;
	des = (des < max_left) ? max_left : des;
	des = (des > 0) ? 0 : des;
	$('ul#thumbs_photos').stop().animate({marginLeft:des}, 1000);
}

function show_min_map(location_id) {
	$('div.location').addClass('small_row');
	var location_menu = $('#location_'+location_id);
	reorder_menu($(location_menu).parent());

	var search_name = $(location_menu).attr('search_name');
	var lat = $(location_menu).attr('lat');
	var lng = $(location_menu).attr('long');
	$('#head_h1').html('Destionos - <small>'+search_name+'</small>');
	$('.city_content_box').parents('.box').show();
	$('.city_content_box').html('<center><img src="'+global_site_url +'/images/lightbox-ico-loading.gif" style="margin-left:-25px"/></center>');
	$('.city_content_box_nopadding').html('<center><img src="'+global_site_url +'/images/lightbox-ico-loading.gif"/></center>');
	$('div#main_panel_home').find('div#map_holder').hide();
	$('div#city_data, div#city_data_left').show();

	if (!towns[location_id]) {
		var add = '';
		add += '&loc='+get_requested_data('loc');
		add += '&sub='+get_requested_data('sub');
		$.post(global_site_url +"/index.php?page=ajax&action=get_towns&location_id="+location_id+"&name="+search_name+add, {}, function(response) {
			towns[location_id] = response;

			for (i in response) {
				var lat_t= response[i].lat;
				var long_t =  response[i].long;
				var name_t = response[i].name;
				var href = global_site_url + '/' + get_requested_data('name') + '/' + name_t;
				var review_counts = response[i].review_counts;

				showMarker_location_point(location_id, name_t, href, lat_t, long_t, null, null, 'town_locations', null, get_reviews_text(review_counts));
			}
			showAddress_location_ll(location_id, lat, lng, 11);
			$(location_menu).removeClass('small_row').removeClass('selected').attr('state', 'not_selected');
			$.post(global_site_url +"/index.php?page=ajax&action=get_html&name="+search_name+add, {}, function(response) {
			
				for (key in response) {
					if ($('#city_content_'+key).size()) {
						if (response[key]) {
							$('#city_content_'+key).html(response[key]);
						}
						else {
							$('#city_content_'+key).parents('.box').hide();
						}
						
					}
				}

				init_city_load(search_name);
			}, 'json');
			
		}, "json");
	}	
	else {
			$(location_menu).removeClass('small_row');
			init_city_load(search_name);
	}
	$('#popular_locations').prepend($(location_menu));
}


function reorder_menu(list) {
	
	
 
 var total = $(list).find('.location').size();
 
 

	for (i=0;i<total ; i++) {
		obj = get_menu($(list), i);
		$(list).append($(obj));
	}
}

function get_menu(parent, index) {
	var obj;
	$(parent).find('.location').each(function() {
		if ($(this).attr('org_index') == index) {
			obj = this;
		}
	});

	return $(obj);
}


function loader(action) {
	if (action == 'hide') {
		$('div#loader').hide();
		$('div#overlay').hide();
	}
	else {
		var body_width = $('body').width() - 80;
		var body_height = $(window).height();
		var left = (body_width / 2) -  (100 /2);
		var top = (window.pageYOffset || document.documentElement.scrollTop || 0) + (body_height/2);
		$('div#loader').css('left', left);
		$('div#loader').css('top', top);
		$('div#loader').show();
		$('div#overlay').height($(document).height());
		$('div#overlay').show();
	}
}


var requested_data = {};

function set_requested_data(label, data) {
	if (typeof label != 'string') {
		for (l in label) {
			label[l] = label[l].replace(/_/gi, ' ');
			requested_data[l] = label[l];
		}
	}
	else {
		data = data.replace(/_/gi, ' ');
		requested_data[label] = data;
	}
}

function get_requested_data(label) {
	return (requested_data[label]) ? requested_data[label] : '';
}

function set_header() {
	html = 'Top Destinos';
	crumbHtml='';
	
	if (get_requested_data('name')) {
		html += ' - <small>'+get_requested_data('name')+'</small>';
		
		crumbHtml +='&nbsp; > &nbsp; <font color="#00467a">'+get_requested_data('name')+'</font>';
	}

	if (get_requested_data('loc')) {
		html += '&nbsp;<small class="smaller">('+get_requested_data('loc')+')</small>';
		
		crumbHtml +='&nbsp; > &nbsp; <font color="#00467a">'+get_requested_data('loc')+'</font>';
	}

	if (get_requested_data('sub')) {
		html += '&nbsp;-&nbsp;<small class="smaller"><i>'+get_requested_data('sub')+'</i></small>';	
		
		crumbHtml +='&nbsp; > &nbsp; <font color="#00467a">'+get_requested_data('sub')+'</font>';
	}
	
	$(document).attr('title', 'Destinos - ' + $(html).text());
	$('#head_h1').html(html);
	
	
	$('#showLink').html(crumbHtml);
	
	
	
	
	
		 
	
	
}

function reset_requested_data() {
	requested_data = {};
}

function init_mini_map() {
	var lat = $('#popular_locations').find('.location').attr('lat');
	var lng = $('#popular_locations').find('.location').attr('long');
	mini_map = new GMap2(document.getElementById("mini_map"));
	var point =	new GLatLng(lat,lng);
    mini_map.setCenter(point, 11);

	for (i in mini_map_records) {
		var lat_t= mini_map_records[i].lat;
		var long_t =  mini_map_records[i].long;
		var name_t = mini_map_records[i].name;
		var href = global_site_url + '/' + get_requested_data('name') + '/' + name_t;
		var review_counts = mini_map_records[i].review_counts;
		var location_id = '';
		showMarker_location_point(location_id, name_t, href, lat_t, long_t, null, null, 'town_locations', null, get_reviews_text(review_counts));
	}
	init_sub_location_links();	
}
