// conduit3d.js
// (C) 2008 Roundhouse Technologies and Licensed to Conduit
// Permission is granted to use and modify as needed, but may not be redistributed

var map;
var markerIcon;

var lastEvent;

ConduitEvent.prototype.show = function () {

	var myMarker = new FE.Pushpin(new FE.LatLng(this.latitude, this.longitude), markerIcon);
	map.addOverlay(myMarker);
	
	map.panTo(myMarker._location, 2,'easeinoutquint');
	if (this.isExtended) {
		lastEvent = this;
		lastMarker = myMarker;
		setTimeout('display_popup()', 1000);
/*		FE.Event.addListener(myMarker, 'click', createOnClick(this.infoWindowText(),275,110) );
		lastMarker = myMarker;
		setTimeout("lastMarker.dispatch('click');", 1100);
		setTimeout("$('#infoWindow').hide(); map.closeInfoWindow();", 3000);	*/	
	}
	setTimeout(function () { map.removeOverlay(myMarker); }, 45000);
}

function display_popup()
{
		FE.Event.addListener(lastMarker, 'click', createOnClick(lastEvent.infoWindowText(),275,110) );
		//lastMarker = myMarker;
		setTimeout("lastMarker.dispatch('click');", 450);
		setTimeout("$('#infoWindow').hide(); map.closeInfoWindow();", 3000);
}

function createOnClick(html, pw, ph) {
	return function(marker) {
		marker.openInfoWindowHtml("<div id='infoWindow' class='threed'>" + html + "</div>", parseInt(pw)+40, parseInt(ph)+80);
	}
}

function startMap () {
	var h = getWindowWidthHeight().height;
	
	this.getLayerManager().addLayer(new FE.Layer.DayNight());
  map.setTargetLatLng(new FE.LatLng(39,-76));
	map.zoomTo(20000000);
	map.toggleDashboard();
	map.toggleStars();
	window.onresize = sizeMap;
	sizeMap();
	
	// Initialize Individualized Icons for the different event types
	// Conduit.icons = {};
	// for (key in Conduit.type_prefixes) {
	// 	prefix = Conduit.type_prefixes[key];
	// 	Conduit.icons[prefix] = new FE.Icon('http://www.conduitvision.com/images/infowindows/'+ prefix + '_icon.png',1.0,2.0);
	// }
	markerIcon = new FE.Icon('http://www.conduitlive.com/images/xxx_icon.png',1.0,2.0);
	showEvents();
}

function sizeMap () {
	dims = getWindowWidthHeight();
	map.resize(dims.width-40, dims.height-140);
};

function loadMap () {
	map = new FE.Map(document.getElementById('map'),  { includeBaseLayers : false });
	map.onLoad = startMap;
	map.load();
};

