// create map object
var map;
// create geocoder object
var geocoder;
// current region
// check the official documentation to change region
// http://code.google.com/apis/maps/documentation/v3/services.html#CountryCodes
// requires a ccTLD (county code top-level domain)
// for a list of ccTLD's visit: http://en.wikipedia.org/wiki/CcTLD
var region = 'uk';
// array of all markers on Map
var markers = new Array();

$(document).ready(function() 
{		
	$("#anuncio").mouseenter(entradaImg).mouseleave(salidaImg);

	$('#mapa').click(abreMapa);
	creaMapa(); 
	verificaURL();
});

function verificaURL()
{
	url = window.location.href;
	enc = url.indexOf('#');
	if(enc >0)
	{
		id = url.split('#')[1];
		if(id=='mapa') abreMapa();
	}	
}

function entradaImg()
{
	altura = [$('#anuncio').find('p').height() +16 ]* -1;
	
	$('#anuncio').find('p').animate({
		'margin-top' : altura
	},500);
	//console.log(altura);
}

function salidaImg()
{
	$('#anuncio').find('p').animate({
		'margin-top' : 0
	},500);
}

function abreMapa()
{
	$('#map_canvas').animate({
		"margin-top" : 0
		
	},700);
}

function creaMapa() 
{
	// show ajax loading image
	$('#map_canvas').html("<img src='./img/ajax-loader.gif' alt='Ajax Loading Image' />");

	var lat = 20.688887;
	var lng = -103.377746;

	// create new geocoder object
	geocoder = new google.maps.Geocoder();

	// create new lat/long object
	//var localidad = new google.maps.LatLng(lat,lng);
	var localidad = new google.maps.LatLng(lat, lng);
								
	// set map options
	var myOptions = {
		zoom: 16,
		center: localidad,
		mapTypeId: google.maps.MapTypeId.ROADMAP
	};

	// display map
	map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
	
	
	// clear all markers
	jQuery.each(markers,function(k,v){ v.setMap(null); });
	

	// Instantiate an info window to hold step text.
	var info = new google.maps.InfoWindow({									
		maxWidth: "400",
		content: ""
	});
	
	
	var marker = new google.maps.Marker(
	{
		map: map,
		position: new google.maps.LatLng(lat, lng),
		title: 'La Noche Azul' ,
		icon:"./img/marker.png"
	});
	
	markers.push(marker);

	divInfo = creaInfo();		
	//console.log(divInfo);

	info.setContent(divInfo);
	info.open(map, marker);
	
	google.maps.event.addListener(marker, 'click', function()
	{
		info.setContent(divInfo);
		info.open(map, marker);
	});
		
}

function creaInfo()
{
	var div ='<div class="maps_popup"> \
			<h1>La Noche Azul</h1> \
			<h2>Av. L&oacute;pez Mateos Norte No. 800</h2> \
			<p class="horario">Horario: Lunes a S&aacute;bado de 1:30 de la tarde a 12 de la noche <br /> y los Domingos &uacute;nicamente para comer de 1:30pm a 6:00pm</p> \
			<p class="tel">Reservaciones al (33) 3630 0337</p> \
			<p class="email">Email: <a href="mailto:hola@lanocheazul.com.mx">hola@lanocheazul.com.mx</a></p>\
		</div>';
	return div;
}

