(function($) { 
  $(function() {

	//<![CDATA[


	var map;
	var geoCenter = new GLatLng(38.805, -104.82);
	var geoHome = new GLatLng(38.79121, -104.848978);
	var zoomInitial = 12;

	var polyline = new GPolyline([
		new GLatLng(28.333017, -81.520872),
		new GLatLng(28.334226, -81.520915),
		new GLatLng(28.338325, -81.522052),
		new GLatLng(28.340761, -81.523275),
		new GLatLng(28.343103, -81.523619),
		new GLatLng(28.351072, -81.520722),
		new GLatLng(28.352394, -81.519799),
		new GLatLng(28.353753, -81.517739),
		new GLatLng(28.355642, -81.510637),
		new GLatLng(28.355132, -81.502655),
		new GLatLng(28.353432, -81.498857),
		new GLatLng(28.353225, -81.497655),
		new GLatLng(28.353395, -81.496131),
		new GLatLng(28.354433, -81.494629)
		], '#0000ff', 10);

	var baseIcon = new GIcon();
	baseIcon.shadow = 'images/marker-shadow.png';
	baseIcon.iconSize = new GSize(12, 20);
	baseIcon.shadowSize = new GSize(22, 20);
	baseIcon.iconAnchor = new GPoint(4, 20);
	baseIcon.infoWindowAnchor = new GPoint(4, 23);
	baseIcon.infoShadowAnchor = new GPoint(18, 25);

	var geoEpcot = new GLatLng(28.373881, -81.549282);
	var geoSeaWorld = new GLatLng(28.405519, -81.471348);
	var geoDisney = new GLatLng(28.371125, -81.515508);
	var geoFalcon = new GLatLng(28.34399, -81.504307);
	var geoUniversal = new GLatLng(28.477858, -81.469975);
	var geoCityWalk = new GLatLng(28.473482, -81.465168);
	var geoAirport = new GLatLng(28.431827, -81.307969);
	var geoOutlets = new GLatLng(28.389399, -81.491647);
	var geoBayHill = new GLatLng(28.466352, -81.510744);
	var geoChampionsGate = new GLatLng(28.263377, -81.624727);
	var geoInternational = new GLatLng(28.333017, -81.520872);
	
	var markers = new Array();
	markers[0] = {'point':geoHome,'color':'red','zoom':13,'blowupOffsetX':0,'blowupOffsetY':-110,'mapOffsetX':0,'mapOffsetY':40};
	/*markers[1] = {'point':geoEpcot,'title':'Epcot Center','url':'http://disneyworld.disney.go.com/wdw/parks/parkLanding?id=EPLandingPage','color':'yellow','zoom':15};
	markers[2] = {'point':geoSeaWorld,'title':'SeaWorld Adventure Park','url':'http://4adventure.com/seaworld/fla','color':'yellow','zoom':14,'blowupOffsetX':-100,'blowupOffsetY':75};
	markers[3] = {'point':geoDisney,'title':'Walt Disney World','url':'http://disneyworld.disney.go.com','color':'yellow','zoom':14,'blowupOffsetX':40,'blowupOffsetY':0};
	markers[4] = {'point':geoFalcon,'title':'Falcons Fire Golf Club','url':'http://www.falconsfire.com','color':'yellow','zoom':14,'blowupOffsetX':20,'blowupOffsetY':0};
	markers[5] = {'point':geoUniversal,'title':'Universal Studios','url':'http://www.universalorlando.com','color':'yellow','blowupOffsetX':-20,'blowupOffsetY':-50,'mapOffsetX':-20,'mapOffsetY':50};
	markers[6] = {'point':geoCityWalk,'title':'Universal Studios CityWalk','url':'http://www.citywalkorlando.com','color':'yellow','zoom':15,'blowupOffsetX':35,'blowupOffsetY':-70,'mapOffsetX':-20,'mapOffsetY':50};
	markers[7] = {'point':geoAirport,'title':'Orlando International Airport','url':'http://www.orlandoairports.net','color':'yellow','zoom':12,'blowupOffsetX':0,'blowupOffsetY':-30,'mapOffsetX':-20,'mapOffsetY':50};
	markers[8] = {'point':geoOutlets,'title':'Orlando Premium Outlets','url':'http://www.premiumoutlets.com/orlando','color':'yellow','zoom':14,'blowupOffsetX':20,'blowupOffsetY':-100};
	markers[9] = {'point':geoBayHill,'title':'Bay Hill Club &amp; Lodge','url':'http://www.bayhill.com','color':'yellow','blowupOffsetX':0,'blowupOffsetY':-50};
	markers[10] = {'point':geoChampionsGate,'title':'ChampionsGate Golf Club','url':'http://www.championsgategolf.com','color':'yellow','blowupOffsetX':-100,'blowupOffsetY':-140,'zoom':15};
	markers[11] = {'point':geoInternational,'title':'International Drive','color':'yellow','blowupOffsetX':-60,'blowupOffsetY':75,'polyline':true};*/

	function init() {
		if ($("#map")){
			if (GBrowserIsCompatible()) {
				map = new GMap2(document.getElementById('map'));
				map.setCenter(geoCenter, zoomInitial);
				map.addControl(new GLargeMapControl());
				map.addControl(new GScaleControl(100));
				map.addControl(new GOverviewMapControl());
				map.enableContinuousZoom();
				for (var i=0,j=markers.length;i<j;i++) {
					createMarker(markers[i]);
				}
				//map.addOverlay(polyline);
			}
			else {
				alert("Sorry, but your browser does not support the Google Maps API.");
			}
		}
	}
	
	function createMarker(pt) {
		var html = pt['htmlOnly'] || '';
		var zoom = pt['zoom'] || 13;
		var icon = new GIcon(baseIcon);
		icon.image = 'images/marker-'+pt['color']+'.png';
		var marker = new GMarker(pt['point'],icon);
		GEvent.addListener(marker, 'click', function() {
			if (pt['htmlOnly']) {
				marker.openInfoWindowHtml(pt['htmlOnly']);
			}
			else {
				var html = '';
				if (pt['title']) {
					html += '<h3>'+pt['title']+'</h3>';
				}
				html += '<div id="blowup-'+pt['point']+'" class="map-blowup">&nbsp;</div>';
				if (pt['url']) {
					html += '<a href="'+pt['url']+'" target="_blank">Visit Website</a>';
				}
				marker.openInfoWindowHtml(html, {maxHeight:240} );
				var blowup = new GMap2(document.getElementById("blowup-"+pt['point']));
				blowup.setCenter(pt['point'], zoom);
				blowup.addControl(new GSmallMapControl());
				if (pt['blowupOffsetX']||pt['blowupOffsetY']) {
					blowup.panBy(new GSize(pt['blowupOffsetX'],pt['blowupOffsetY']));
				}
				if (pt['polyline']) {
					blowup.addOverlay(polyline);
				}
				
				if (pt['mapOffsetX']||pt['mapOffsetY']) {
					temp = GEvent.addListener(map, 'moveend', function() {
						map.panBy(new GSize(pt['mapOffsetX'],pt['mapOffsetY']));
						GEvent.removeListener(temp);
					});
				}
			}
		});
		map.addOverlay(marker,icon);
		if (pt['opened']) marker.openInfoWindowHtml(html);
		return marker;
	}

	init();

  });  
})(jQuery);
