// 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 markerArrays = []; //an array of all the events we put on map
var lastEvent;
var eventsOnMap = 100; //the nubmer of total events to be on the map



ConduitEvent.prototype.show = function() {

    var myMarker = new FE.Pushpin(new FE.LatLng(this.latitude, this.longitude), markerIcon);
    if (markerArrays.length == eventsOnMap) {
        var x = markerArrays.shift();
        map.removeOverlay(x);
    }
    map.addOverlay(myMarker);
    markerArrays.push(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);
    }    
}

// this function shows the events on startup, they don't have a popup window or zoom in effect.
function Show2(latitude, longitude, index) {   
    var myMarker = new FE.Pushpin(new FE.LatLng(longitude,latitude), markerIcon);
    if (markerArrays.length < eventsOnMap) {
        map.addOverlay(myMarker);
        markerArrays.push(myMarker);
    }   
}

function display_popup()
{
    FE.Event.addListener(lastMarker, 'click', createOnClick(lastEvent.infoWindowText(), 275, 110));
    //$('#FE_InfoWindow').css({ 'top': '120px', 'left': '400px' });
		//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('images/xxx_icon_s.png', 1.0, 2.0);	
	GetData(true);
	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();	
};

