// JavaScript Document
/*
*	This is JavaScript functions that adds callbacks and deep linking to a Flash Map.  The 
*	flash map needs to have an id of "dynamicMap" in ordor to work with this file.  Otherwise
*	the references in this file need to be updated.
*
*	7/10/2009
*	Scott Field 
*/

/*
*	setLocation sets the state or city in the pasquinelliMap.swf.
*	The format is "2 - letter state abbrev"/"city name".
*/
function setLocation(_id, _strLoc) {
    getMovie(_id).setLocation(_strLoc);
}

/*
*	getMovie is a helper function that selects a Flash movie by its ID.
*/
function getMovie(movieName) {
    if (navigator.appName.indexOf("Microsoft") != -1) {
        return window[movieName];
    } else {
        return document[movieName];
    }
}

/*
*	mapLocationChange is called from the pasquinelliMap.swf Flash to 
*	notify when a change has occured in Flash.
*/
function mapLocationChange(_view, _state, _city) {
	switch(_view) {
		case "country":
			dhtmlHistory.add("US");
			break;
		case "state":
			dhtmlHistory.add(_state);
			break;
		case "city":
			//alert("Switched to " + _state + " -> " + _city);
			dhtmlHistory.add(_state + "/" + _city);
			break;
	}
}

/*
*	stateSelected is a function that is called when the drop down for a state has changed.
*	It adds an entry into the dhtmlHistory object and notifies the SWF file to update.
*/
function stateSelected() {
	dhtmlHistory.add(document.form1.stateSelect.value);
	setLocation('dynamicMap', document.form1.stateSelect.value);
}

/*
*	citySelected is a function is called when the drop down for a city has changed.
*	It adds an entry into the dhtmlHistory object and notifies the SWF file to update.
*/
function citySelected() {
	dhtmlHistory.add(document.form1.citySelect.value);
	setLocation('dynamicMap', document.form1.citySelect.value);
}

/*
*	stateSelected is a function is called when the drop down for a state has changed.
*	It adds an entry into the dhtmlHistory object and notifies the SWF file to update.
*/
function stateSelectedValue(val) {
	dhtmlHistory.add(val);
	setLocation('dynamicMap', val);
}

/*
*	citySelected is a function is called when the drop down for a city has changed.
*	It adds an entry into the dhtmlHistory object and notifies the SWF file to update.
*/
function citySelectedValue(val) {
	dhtmlHistory.add(val);
	setLocation('dynamicMap', val);
}

/*
*	handleHistoryChange is an event called from the dhtmlHistory object when a history change
*	is detected from the browser moving forward or back.
*/
function handleHistoryChange(newLocation, historyData) {
	//document.getElementById("debug").innerHTML = "<p>" + newLocation + "</p>";
	setLocation('dynamicMap', newLocation);
}

/*
*	initialize creates the dhtmlHistory object and passes an initial location to
*	the SWF file.
*/
function initialize() {
	// initialize RSH
	dhtmlHistory.initialize();
	
	// add ourselves as a listener for history
	// change events
	dhtmlHistory.addListener(handleHistoryChange);
	
	// determine our current location so we can
	// initialize ourselves at startup
	var initialLocation = dhtmlHistory.getCurrentLocation();
	
	window.dynamicMap = document.getElementById("dynamicMap");
	if(window.dynamicMap.setLocation == undefined) {
		window.dynamicMap.setLocation = function(_id, _loc){
			string1 = "<invoke name=\"setLocation\" returntype=\"javascript\"><arguments><string>"+_id+"</string><string>"+_loc+"</string></arguments></invoke>";
			return window.dynamicMap.CallFunction(string1);
		};
	}
	
	// if no location specified, use the default
	if (initialLocation == null || initialLocation == "") {
		initialLocation = "#";
	} else {
		setLocation('dynamicMap', initialLocation);
	}
	
	// now initialize our starting UI
	//updateUI(initialLocation, null);
}

// Set the initialize function to be called onLoad
window.onload = initialize;

