﻿// JScript File


var satLink = "http://www.ibiseye.com/KML/ibiseye/rainbow.aspx//";
var loadedActive = false;

var map;
//first, listen to the window load so we can load our map
Event.observe(window, 'load', createMap);
//function to create the google map, initialize all layout stuff here.
function createMap(){
    getVersion();
    //create map
    map = new GMap2($("map"));
    //center map so Florida and most of Atlantic is in view
    map.setCenter(new GLatLng(27.336523, -82.535636), 3);

	// Add the map controls
    map.addControl(new GSmallZoomControl());
    //enable zooming animation
    map.enableContinuousZoom();
    //enable new double click feature
    map.enableDoubleClickZoom();
    //and enable the scrollwheel
    map.enableScrollWheelZoom();
    
    loadedActive = checkActive();
    if(!loadedActive){
       poiManager = new POIManager();
       $("descriptor").innerHTML = "Points of Interest";
    }
    initToolTips();
    checkURL();
    addWeatherKML();
    
}


var alertsVersion;
var lastServerAlertUpdate;
var serverTime;
var updateSeconds;

function getVersion(){
    $("startUp").style.display = 'none';
    alertsVersion = $("startUpVersion").innerHTML;
    lastServerAlertUpdate = $("startUpUpdated").innerHTML;
    serverTime = $("startUpNow").innerHTML;
    updateSeconds = $("startUpNextUpdate").innerHTML;

}


function checkURL(){
    var params = location.search.toQueryParams();
   
    if( (parseInt(params.width) < 250) || (parseInt(params.height) < 250) ){
        $("map").style.display = "none";
        $("error").style.display = "block";
    }                     
   
    if(params.width){
        $("map").style.width = params.width+"px";
    }
    
    if(params.height){
        $("map").style.height = params.height+"px";
    }
    
    map.checkResize();
       
    
    
    if(params.lat && params.lng){
	    var lat = parseInt(params.lat);
	    var lng = parseInt(params.lng);
		map.setCenter(new GLatLng(params.lat, params.lng));
		
    }else{
        map.setCenter(new GLatLng(27.336523, -74.535636));
    }
	
	if(params.zoom){
			var z = parseInt(params.zoom);
	        map.setZoom(z);
	}
	
	if(!params.nooverlay && !loadedActive){
	   //var link = satLink + Math.floor(Math.random() * 1000000) + "/still";
	   //var satOverlay = new GGeoXml(link);
	   //map.addOverlay(satOverlay);
	  
	}
	
	  
      map.checkResize(); 
}






//global tooltip variable  
var tooltip;

/**
 * initialies a tooltip within the map. Contains hardcoded styling for now... Probably to fix an IE bug.
 * @param (map): the google map to append the tooltips to. 
 **/
function initToolTips(){
    tooltip = document.createElement("div");
    $("map").appendChild(tooltip);
	tooltip.style.zIndex = "100000000";
	tooltip.style.opacity = "95";
	tooltip.style.filter = "alpha(opacity=95)";
	tooltip.style.color = "#333333";
	tooltip.style.border = "1px solid black";
    tooltip.style.visibility="hidden";
	tooltip.style.position = "absolute";
}
/**
 * shows a tooltip within the map
 * @param (marker): the marker that was hovered over on the map
 * @param (map): the map that the marker is in
 **/
function showTooltip(marker, map) {
    tooltip.innerHTML = marker.tooltip;
	var point=map.getCurrentMapType().getProjection().fromLatLngToPixel(map.getBounds().getSouthWest(),map.getZoom());
	var offset=map.getCurrentMapType().getProjection().fromLatLngToPixel(marker.getPoint(),map.getZoom());
	//var anchor=marker.getIcon().iconAnchor;
	var anchor = new Object();
	anchor.x = 3;
	anchor.y = 17;
	//var width=marker.getIcon().iconSize.width;
	width = 5;
	var pos = new GControlPosition(G_ANCHOR_BOTTOM_LEFT, new GSize(offset.x - point.x - anchor.x + width,- offset.y + point.y +anchor.y)); 
	pos.apply(tooltip);
	//believe it or not, doing nothing sometimes fixes a weird IE bug. IE sucks.
	randomNothing();
	tooltip.style.visibility="visible";
 }
 
//does nothing
function randomNothing(){
	
} 