//
// * *****************************************************************
// * Name:		mainScripts.js
// * Descript:	This file contains all custom javascripts used in the 
//				site, including those for The Mapping Project.
// * *****************************************************************
//

// Global vars

// Event Handlers
var dropEventHandler, startDragMarkerHandler, endDragMarkerHandler, clickMarkerHandler, endZoomHandler
var startMoveHandler, endMoveHandler,  startDragHandler;
var mode = 'explore';

// The marker for the Where Are You drop functionality
var marker;

// Var for focusing on from the comments
var focusMarker;

// This array contains the details of the last map bounds
var lastBounds;


// Text for the drop functionality info box
var markerHTML = "<form><table>" +
				"<tr><td><strong>Great,</strong> we're just about to include </td></tr>" +
				"<tr><td>you on the map.</td><tr>" +
				"<tr><td>You can still zoom in and zoom out </td></tr>" +
				"<tr><td>to find your exact location.</td></tr>" +
				"<tr><td>Otherwise, click </td></tr>" +
				"<tr><td><center><input type='button' value='Add me!' onclick='xajax_startDemoInput(document.body.clientHeight, document.body.clientWidth);'/></center></td></tr></table></form>";

// An array of markers for the explore the map functionality
// It is actually a multi-value array, structured as:
//		aryExploreMarkers[marker_id][0] = handle to marker
//		aryExploreMarkers[marker_id][1] = handle to click on marker function
//		aryExploreMarkers[nextMarker][2] = handle info box opening event

var aryExploreMarkers = [];

// Var to control the show comment slide show
var commentShow_Timeout;

// Var to keep a record of the original AddMeTool innerHTML
var addMeToolInnerHTML;

// Google Maps Script

//<![CDATA[

	var map;
	
	var mapZoomControl = new GLargeMapControl();
	var mapTypeControl = new GMapTypeControl();
	
	// This function loads the map and assigns the required listeners
    function load(latitude, longitude, zoom) {
      if (GBrowserIsCompatible()) {
        map = new GMap2(document.getElementById("map"));
        map.setCenter(new GLatLng(latitude, longitude), 1);
		map.setZoom(zoom);
        
        // Add a control
		map.addControl(mapZoomControl);        		

		// Add map type control
		map.addControl(mapTypeControl);        		
		
		// Init last bounds
		lastBounds = map.getBounds();

		// Setup a handler which updates the markers when a zoom occurs
		endZoomHandler = GEvent.addListener(map, "zoomend", function() {
	    	// Update markers
	    	exploreButtonClick(0);
		}
		);

		// Setup a handler which takes a snapshot of the bounds when a move begins
		startMoveHandler = GEvent.addListener(map, "movestart", function() {
			// Grap a snapshot of the current bounds
			lastBounds = map.getBounds();
		}
		);	
		
		// Setup a handler which updates the markers when the map is navigated
		endMoveHandler = GEvent.addListener(map, "moveend", function() {
	    	// Update markers (unless the info window is open)
	    	if (map.getInfoWindow().isHidden()){
		    	exploreButtonClick(1);
	    	}
		}
		);
		
		// Event handler to close the info box when a move starts
		startDragHandler = GEvent.addListener(map, "dragstart", function() {
			map.getInfoWindow().hide();
		}
		);
		
		
		// Drop initial markers
    	setToExploreMap();	
		
      } else {
		alert("We're sorry, the Seventy Million Project takes advantage of the latest technology and needs a modern web browser to work.  We have detected your browser may not work properly with our site.  Please revisit with a modern web browser - we'd love to be able to show you our site!");      	
      }
    }

    //]]>

// This function is executed when the user indicates they are ready to put
// themselves on the map.  It starts the process of droping a marker etc.    
function readyToDrop(){
	// Change the mouse cursor
    map.getDragObject().setDraggableCursor("crosshair");

    // Remove all of the markers on the map to present a clear map to the user
	var numMarkers = aryExploreMarkers.length;
	for (i = 0; i < numMarkers; i++){
		if (aryExploreMarkers[i][0] != null){
			map.removeOverlay(aryExploreMarkers[i][0]);
			// Drop click on marker events
//			GEvent.removeListener(aryExploreMarkers[i][1]);
//			GEvent.removeListener(aryExploreMarkers[i][2]);
		}
	}
	// Reset array
	aryExploreMarkers = [];

	
	// Stop events that occur after moves and zooms (i.e. those that update the shamrocks)
	GEvent.removeListener(endZoomHandler);
	GEvent.removeListener(startMoveHandler);
	GEvent.removeListener(endMoveHandler);
	
    // Add a listener that detects a single mouse click
    dropEventHandler = GEvent.addListener(map, "click", function(overlay, latlng) {
		// alert("You clicked the map at." +  latlng);

		// Setup icon to use for marker
		var iconShamrock = new GIcon(); 
		iconShamrock.image = '/wp-content/themes/seventymillion/images/shamrock-you.png';
		iconShamrock.shadow = '/wp-content/themes/seventymillion/images/shamrock-shadow.png';
		iconShamrock.iconSize = new GSize(25, 26);
		iconShamrock.shadowSize = new GSize((25/100)*182, (26/100)*100);
		iconShamrock.iconAnchor = new GPoint(12, 26);
		iconShamrock.infoWindowAnchor = new GPoint(5, 1);
		
		// Just in case there is already a marker on the screen, remove it
		if (marker != null){
			map.removeOverlay(marker);
		}
			
		// Drop the marker
		// marker = new GMarker(latlng, {draggable:true});		
		marker = new GMarker(latlng, {icon:iconShamrock, draggable:true});		
		map.addOverlay(marker);
		
		GEvent.removeListener(dropEventHandler);
		
		// Display the info Window
	    marker.openInfoWindow(markerHTML);

		// Make an ajax call to store the marker
		xajax_createMarker($('markerID').value, latlng.lat(), latlng.lng());

		// Add a new listeners, so that when the marker is moved, the Info Window moves with it
		startDragMarkerHandler = GEvent.addListener(marker, "dragstart", function() {
			marker.closeInfoWindow();
		}
		);

		endDragMarkerHandler = GEvent.addListener(marker, "dragend", function() {
	    	marker.openInfoWindow(markerHTML);
	    	latlng = marker.getLatLng();
	    	// Update where the marker is
	    	xajax_createMarker($('markerID').value, latlng.lat(), latlng.lng());
		}
		);

		// New listener so a click on the marker makes the info window appear
		clickMarkerHandler = GEvent.addListener(marker, "click", function() {
	    	marker.openInfoWindow(markerHTML);
		}
		);
	
		// Set cursor back
	    map.getDragObject().setDraggableCursor("hand");
		
    });

}

// Function To Freeze The Marker
function freezeMarker(){
	if (marker != null){
		marker.disableDragging()();
	}
}

// The user wants to drop a new marker, so we need to create a 
// new person for this user (locking out the old one)
function readyToDropNewMarker(){
	xajax_closePerson();
	readyToDrop();
	alert("Ok, move to where you live on the map and click the left mouse button to add yourself!")
}

// Function To Tidy Map After Questionnaire Is Completed
function tidyMap(cancel){
	// Get URL and cut off any args
	var url = location.href;
	urlArray = url.split('?');
	
	// If the user cancelled, warn them and remove marker
	if (cancel == 1){
		alert("Cancelling aborts the process, but don't worry, you can start again at any time.")

		// Redirect to homepage, this makes sure the shamrocks reappear and we are
		// really starting the process from scratch
		redirect(urlArray[0]);		
		
		// Remove the marker
//		if (marker != null){
//			if (!map.getInfoWindow().isHidden()){
//				marker.closeInfoWindow();
//			}
//			map.removeOverlay(marker);
			
			// Remove event listener
//			GEvent.removeListener(clickMarkerHandler);
	
			// Set to explore
//			setToExploreMap();

//		}

		// Redirect to homepage, as we are now a logged in user
		// redirect(location.href);


	} else {
		// Redirect to homepage, as we are now a logged in user
		redirect(urlArray[0]);		
	}
}

// Set the map to where are you mode
function setToWhereAreYouMap(){
	mode = "whereareyou";	
	// Remove event handlers
	// GEvent.removeListener(endZoomHandler);
	// GEvent.removeListener(endMoveHandler);

	// Clear all markers from the map
	// var numMarkers = aryExploreMarkers.length;
	// for (i = 0; i < numMarkers; i++){
	//	map.removeOverlay(aryExploreMarkers[i][0]);
	//	// Drop click on marker events
	//	GEvent.removeListener(aryExploreMarkers[nextMarker][1]);
	//	GEvent.removeListener(aryExploreMarkers[nextMarker][2]);
	//}

	// Reset array
	//aryExploreMarkers = [];
}

// Set the map to explore mode
function setToExploreMap(){
	// Reset the map, at world level
    // map.setCenter(new GLatLng(globalLat, globalLng), map.getZoom());
	// map.setZoom(globalZoom);	
	mode = "explore";
	
	if (marker != null){
		marker.closeInfoWindow();
		// map.removeOverlay(marker);
	}	

	// Clear all markers from the map
	var numMarkers = aryExploreMarkers.length;
	for (i = 0; i < numMarkers; i++){
		if (aryExploreMarkers[i][0] != null){
			map.removeOverlay(aryExploreMarkers[i][0]);
			// Drop click on marker events
			GEvent.removeListener(aryExploreMarkers[i][1]);
			GEvent.removeListener(aryExploreMarkers[i][2]);
		}
	}

	// Reset array
	aryExploreMarkers = [];
	bounds = map.getBounds();

	// Plot country markers
	xajax_plotCountryMarkers(
		0,
		map.getZoom(), 
		bounds.getNorthEast().lat(), bounds.getNorthEast().lng(),
		bounds.getSouthWest().lat(), bounds.getSouthWest().lng(), 
		lastBounds.getNorthEast().lat(), lastBounds.getNorthEast().lng(),
		lastBounds.getSouthWest().lat(), lastBounds.getSouthWest().lng(), 				
		document.getElementById('explore-id-1').value,   
		null,  		
		document.getElementById('explore-id-3').value,
		document.getElementById('explore-id-3a').value,  		
		document.getElementById('explore-id-4').value,  		
		document.getElementById('explore-id-5').value,  		
		document.getElementById('explore-id-6').value,
		document.getElementById('explore-id-7').value, 
		document.getElementById('explore-id-8').value, 
		document.getElementById('explore-id-9').value
		);

		
	
}

// This function gathers information from the DB via 
// xajax calls and then displays the information on
// the map
function plotMarker(type, lat, lng, width, height, image, infoText){
		// If the type is set to 'you' we set the marker rather than the aryExploreMarkers
		// set of marker arrays
		if (type == 'you'){
			if (marker != null){
				map.removeOverlay(marker);
				GEvent.removeListener(clickMarkerHandler);
			}
			var iconShamrock = new GIcon(); 
			iconShamrock.image = '/wp-content/themes/seventymillion/images/' + image;
			iconShamrock.shadow = '/wp-content/themes/seventymillion/images/shamrock-shadow.png';
			iconShamrock.iconSize = new GSize(width, height);
			iconShamrock.shadowSize = new GSize((width/100)*182, (height/100)*100);
			iconShamrock.iconAnchor = new GPoint(width/2, height);
			iconShamrock.infoWindowAnchor = new GPoint(width/2, height/2);

			marker = new GMarker(new GLatLng(lat, lng), {icon:iconShamrock});		
			map.addOverlay(marker);	
			
			// New listener so a click on the marker makes the info window appear
			clickMarkerHandler = GEvent.addListener(marker, "click", function() {
	    		marker.openInfoWindow(infoText);
			});
			
		} else {
	
			// Setup icon to use for marker
			var iconShamrock = new GIcon(); 
			iconShamrock.image = '/wp-content/themes/seventymillion/images/' + image;
			iconShamrock.shadow = '/wp-content/themes/seventymillion/images/shamrock-shadow.png';
			iconShamrock.iconSize = new GSize(width, height);
			iconShamrock.shadowSize = new GSize((width/100)*182, (height/100)*100);
			iconShamrock.iconAnchor = new GPoint(width/2, height);
			iconShamrock.infoWindowAnchor = new GPoint(width/2, height/2);
					
			// Drop the marker
			var nextMarker = aryExploreMarkers.length;
			aryExploreMarkers[nextMarker] = [];
			aryExploreMarkers[nextMarker][0] = new GMarker(new GLatLng(lat, lng), {icon:iconShamrock});		
			map.addOverlay(aryExploreMarkers[nextMarker][0]);	
		
			// Add event handler for when the marker is clicked on
			aryExploreMarkers[nextMarker][1] = GEvent.addListener(aryExploreMarkers[nextMarker][0], "click", function() {
				// First stop markers being redrawn, as this closes the info box when the
				// map auto moves
				aryExploreMarkers[nextMarker][0].openInfoWindow(infoText);
			}
		);
		}
}

// After the user has clicked on the explore button this functon is executed.
// It clears the map of markets and refreshes it with the markers that are
// relevant to the user's search criteria
function exploreButtonClick(refreshMode){
	// If there is a focusMarker infobox on the screen, close it
	if (focusMarker != null){
		focusMarker.closeInfoWindow();		
	}
	
	// Depending on the mode, we remove all markers or just some
	if (refreshMode == 0){
		// Clear all markers from the map
		var numMarkers = aryExploreMarkers.length;
		for (i = 0; i < numMarkers; i++){
			if (aryExploreMarkers[i][0] != null){
				map.removeOverlay(aryExploreMarkers[i][0]);
			}
		}

		// Reset array
		aryExploreMarkers = [];
		
	} else {
		var numMarkers = aryExploreMarkers.length;
		for (i = 0; i < numMarkers; i++){
			bounds = map.getBounds();
			if (aryExploreMarkers[i][0] != null){
				// alert ("HERE: " + map.getBounds() + " - " + aryExploreMarkers[i][0].getPoint());
				if (!bounds.contains(aryExploreMarkers[i][0].getLatLng())){
					// Remove marker
					map.removeOverlay(aryExploreMarkers[i][0]);
					aryExploreMarkers[i][0] = null;					
				}
			}
		}
	}

	// Plot with search criteria
	bounds = map.getBounds();
	
	// Plot country markers
	if (mode != 'explore'){
	xajax_plotCountryMarkers(
		refreshMode,
		map.getZoom(), 
		bounds.getNorthEast().lat(), bounds.getNorthEast().lng(),
		bounds.getSouthWest().lat(), bounds.getSouthWest().lng(), 
		lastBounds.getNorthEast().lat(), lastBounds.getNorthEast().lng(),
		lastBounds.getSouthWest().lat(), lastBounds.getSouthWest().lng(), 		
		null,   
		null,  		
		null,   
		null,   
		null,   
		null,   
		null,   
		null,   
		null,   
		null
		);
	} else {
	xajax_plotCountryMarkers(
		refreshMode,
		map.getZoom(), 
		bounds.getNorthEast().lat(), bounds.getNorthEast().lng(),
		bounds.getSouthWest().lat(), bounds.getSouthWest().lng(), 
		lastBounds.getNorthEast().lat(), lastBounds.getNorthEast().lng(),
		lastBounds.getSouthWest().lat(), lastBounds.getSouthWest().lng(), 		
		document.getElementById('explore-id-1').value,   
		null,  		
		document.getElementById('explore-id-3').value,
		document.getElementById('explore-id-3a').value,  		
		document.getElementById('explore-id-4').value,  		
		document.getElementById('explore-id-5').value,  		
		document.getElementById('explore-id-6').value,
		document.getElementById('explore-id-7').value, 
		document.getElementById('explore-id-8').value, 
		document.getElementById('explore-id-9').value
		);
	}	
}

// This function makes sure the Map unloads when the window unloads,
// it is important to preventing memory leaks in IE.
window.onunload = function () {
	GUnload();
}

// This function is called after a question's answer has been changed
function handler_Question(questionID){
	// Get the question text
	var questionText = $('q-' + questionID + '-text').value;

	// Get the existing answer ID, if there is one
	var answerID = $('q-' + questionID + '-answerID').value;
	
	// Get the answer text
	var answerText = $('q-' + questionID + '-input').value;
	
	// Hand this off to the ajax handler
	xajax_questionChanged(questionID, answerID, questionText, answerText);
}

// This function is called after a question's answer has been changed (for radio button types)
function handler_QuestionRadio(questionID, questionValueSource){

	// Get the question text
	var questionText = $('q-' + questionID + '-text').value;

	// Get the existing answer ID, if there is one
	var answerID = $('q-' + questionID + '-answerID').value;
	
	// Get the answer text
	var answer = document.getElementById(questionValueSource);
	var answerText = answer.value;
	
	// Hand this off to the ajax handler
	xajax_questionChanged(questionID, answerID, questionText, answerText);
}

// This function is called when the Next button is clicked
function handler_NextPage(page){
	if (page == 1){
		// Make sure the country is updated
		handler_Question(2);
		// Make sure the place is updated
		handler_Question(3);
	}
	
	xajax_pageDemoInput(page, page + 1);			
}

// This function is called when the Previous button is clicked
function handler_PreviousPage(page){
	xajax_pageDemoInput(page, page - 1);
}

// This action 'activates' (turns from grey to black) a textbox
function activateTextbox(id){
	// Clear current value
	$(id).value = "";
	$(id).style.color = '#000';
}

// Sets the focus on a given component
function setFocus(id){
	$(id).focus();
}

// As the explore born country is changed, we appear or fade the county drop down
function exploreBornCountyToggle(){
	var countryBorn = document.getElementById('explore-id-3');
	if (countryBorn.value == 'Ireland' && countryBorn.value != 'Select Country'){
		MochiKit.Visual.appear('born-in-county');
	} else {
		MochiKit.Visual.fade('born-in-county');
	}
}

// As the heritage queston is changed, we appear or fade the irish relative birth county
function exploreRelativeBornCountyToggle(){
	var heritage = document.getElementById('explore-id-1');
	if (heritage.value != 'Birth' && heritage.value != 'Select Irish Heritage'){
		MochiKit.Visual.appear('relative-born-in');
		MochiKit.Visual.appear('relative-left-decade');
	} else {
		MochiKit.Visual.fade('relative-born-in');
		MochiKit.Visual.fade('relative-left-decade');
	}
	// toggle birth country
	if (heritage.value != 'Birth'){
		MochiKit.Visual.appear('born-in');
	} else {
		MochiKit.Visual.fade('born-in');		
	}
	
}

function focusOnMarker(lat, lng, infotext){
	// Focus on new marker position
	map.setCenter(new GLatLng(lat, lng), 1);
	map.setZoom(2);

	// Display marker
	var iconShamrock = new GIcon(); 
	iconShamrock.image = '/wp-content/themes/seventymillion/images/shamrock-trans.png';
	// iconShamrock.shadow = 'http://labs.google.com/ridefinder/images/mm_20_shadow.png';
	iconShamrock.iconSize = new GSize(25, 26);
	// iconShamrock.shadowSize = new GSize(22, 20);
	iconShamrock.iconAnchor = new GPoint(12, 26);
	iconShamrock.infoWindowAnchor = new GPoint(5, 1);
		
	// Just in case there is already a marker on the screen, remove it
	if (focusMarker != null){
		map.removeOverlay(focusMarker);
	}
			
	// Drop the marker
	// marker = new GMarker(latlng, {draggable:true});		
	focusMarker = new GMarker(new GLatLng(lat, lng), {icon:iconShamrock, draggable:true});		
	map.addOverlay(focusMarker);
		
	// Display the info Window
	focusMarker.openInfoWindow(infotext);
	

}

// This function validates the email address and then calls the xajax_emailSignup function
// to send the email etc..
function emailSignup(){
	var emailAddress = document.getElementById('emailAddress');
	
	// Check for @ symbol
	var emailAddr = emailAddress.value;
	if (emailAddr.search(/@/) > -1){
		xajax_emailSignup(emailAddr);
	} else {
		alert("Unfortunately your email address is not valid. Did you hit the wrong key?");
	}
}

// This function issues call to fetch the contacts importer
function importerFetch(){
	var emailAddress = document.getElementById('emailAddressImporter');
	var password = document.getElementById('passwordImporter');	
	
	// Check for @ symbol
	var emailAddr = emailAddress.value;
	var pass = password.value;
	
	if (emailAddr.search(/@/) > -1){
		if (pass.length > 0){
			xajax_importFetcher(emailAddr, pass);
		}
	} else {
		alert("Unfortunately your email address is not valid. Did you hit the wrong key?");
	}	
}

// Used by contact importer
function toggleAll(cb) {
    var val = cb.checked;
	var frm = document.f1;
	var len = frm.elements.length;
	var i=0;
	for( i=0 ; i<len ; i++) {
		if (frm.elements[i].name=='emails[]') {
			frm.elements[i].checked=val;
		}
	}
}

// Pull together the email fields and call xajax function to send invites
function sendInvites(){
	var emailAddress = document.getElementById('emailAddressImporter');

	// Check for @ symbol
	var emailAddr = emailAddress.value;
	
	if (emailAddr.search(/@/) > -1){
		var frm = document.f1;
		var len = frm.elements.length;
		var emails = [];
	
		var i=0;
		for (i = 0 ; i < len ; i++) {
			if (frm.elements[i].name=='emails[]') {
				if (frm.elements[i].checked){
					var nextEmail = emails.length;
					emails[nextEmail] = frm.elements[i].value;
				}
			}
		}
		// Call xajax function
		xajax_sendInvites(emailAddress.value, emails, 'contactListDiv');
	} else {
		alert("Unfortunately your email address is not valid. Did you hit the wrong key?");
	}		
	
}

// Send invites for manually entered emails
function sendInvitesManual(){
	var emailAddress = document.getElementById('emailAddressManual');

	// Check for @ symbol
	var emailAddr = emailAddress.value;
	
	if (emailAddr.search(/@/) > -1){
		var frm = document.f1;
		var len = frm.elements.length;
		var emails = [];
	
		var i=0;
		for (i = 0 ; i < len ; i++) {
			if (frm.elements[i].name=='emails[]') {
				if (frm.elements[i].value != ''){
					if (frm.elements[i].value.search(/@/) < 0){
						alert("Unfortunately email address " + (i + 1) + " is not valid. Did you hit the wrong key?");
						return;
					}
					var nextEmail = emails.length;
					emails[nextEmail] = frm.elements[i].value + ':::' + frm.elements[i].value;
				}
			}
		}
		// Call xajax function
		xajax_sendInvites(emailAddress.value, emails, 'contactListDivManual');
	} else {
		alert("Unfortunately your email address is not valid. Did you hit the wrong key?");
	}		
	
}

// Function to redirect the use to a new page, used when the user changes state  
// like when they have finished adding a marker
function redirect(url){
	window.location = url;	
}

// This is the comment show activity function
function doCommentShow(){
	// Zoom to a random comment
	var mode = $('commentShowControlsMode');
	if (mode.value == 'running'){
		xajax_commentShow();
		
		// Queue up the next random comment
		clearTimeout(commentShow_Timeout);
		commentShow_Timeout = setTimeout("doCommentShow()",7000);

		// Make text pulsate
		//MochiKit.Visual.pulsate('commentShowText', {pulses:10});
	}
}

// Pause comment show (starts and stops it basically)
function pauseCommentShow(){
	var pauseButton = $('commentShowControlsPause');
	var mode = $('commentShowControlsMode');
	var moveText = $('commentShowText');
	var addMeTool = $('addMeTool');	
	
	if (mode.value == 'running'){
		clearTimeout(commentShow_Timeout);
		pauseButton.style.background = "url('/wp-content/themes/seventymillion/images/movie_play.gif') no-repeat top";	
		mode.value = 'stopped';
		moveText.innerHTML = 'The movie is paused.';
		
	} else {
		// Reset the explore form fields
		var expform = $('exploreForm');
		expform.reset();
		
		MochiKit.Visual.fade('relative-born-in');
		MochiKit.Visual.fade('relative-left-decade');
		MochiKit.Visual.fade('born-in-county');
		
		clearTimeout(commentShow_Timeout);
		
		// Hide Controls
		// MochiKit.Visual.fade('addMeTool');
		if (addMeTool.innerHTML != ''){
			addMeToolInnerHTML = addMeTool.innerHTML;
			addMeTool.innerHTML = '';
		}
		
		map.removeControl(mapZoomControl);        		
		map.removeControl(mapTypeControl);        				
		
		commentShow_Timeout = setTimeout("doCommentShow()",1000);	
		pauseButton.style.background = "url('/wp-content/themes/seventymillion/images/movie_pause.gif') no-repeat top";	
		
		mode.value = 'running';		
		moveText.innerHTML = 'Movie Playing...';		
	}
}

// This function deactives the 'what comment show' function
function deactivateCommentShow(){
	var addMeTool = $('addMeTool');
	
	// Stop the comment show
	clearTimeout(commentShow_Timeout);

	// Make sure controls are not displayed
	//MochiKit.Visual.shrink('commentShowControls');

	// Redisplay map controls
	// MochiKit.Visual.appear('addMeTool');
	addMeTool.innerHTML = addMeToolInnerHTML;

	// Add a control
	map.addControl(mapZoomControl);        		

	// Add map type control
	map.addControl(mapTypeControl); 

	// Set mode
	var mode = $('commentShowControlsMode');
	mode.value = 'stopped';	

	// Set text
	var moveText = $('commentShowText');
	moveText.innerHTML = 'Click on the play button to play our comment movie.';
	
	// Set play button
	var pauseButton = $('commentShowControlsPause');
	pauseButton.style.background = "url('/wp-content/themes/seventymillion/images/movie_play.gif') no-repeat top";	
	
	
	// var commentShowControls = $('commentShowControls');
	// commentShowControls.style.display = 'none';
}


/* 
* You may use this code for free on any web page provided that
* these comment lines and the following credit remain in the code. 
* TopLeft Floating Div from http://www.javascript-fx.com 
*/
function JSFX_FloatTopLeft()
{
	var startX = 0, startY = 100;
	var ns = (navigator.appName.indexOf("Netscape") != -1);
	var d = document;
	var px = document.layers ? "" : "px";
	function ml(id)
	{
		var el=d.getElementById?d.getElementById(id):d.all?d.all[id]:d.layers[id];
		if(d.layers)el.style=el;
		el.sP=function(x,y){this.style.left=x+px;this.style.top=y+px;};
		el.x = el.x; el.y = startY;
		return el;
	}
	window.stayTopLeft=function()
	{
		var pY = ns ? pageYOffset : document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop;
		var dY = (pY > startY) ? pY : startY;
		ftlObj.y += (dY - ftlObj.y)/8;
		ftlObj.y += 1;
		ftlObj.sP(ftlObj.x, ftlObj.y);
		setTimeout("stayTopLeft()", 5);
	}
	ftlObj = ml("demographics");
	stayTopLeft();
}
