onLoad(startCanvasEngine)

function emptyEvent(eventName) {
    alert('robin please implement the event ' + eventName)
    
    
}

var initFlashControls

function startCanvasEngine() {
    // create necessary drawy things
    notesInit()
   
    // TODO: right here add flash as a subchild of canvas
	function getFlash()
	{ 
		var result;
		if(navigator.appName.indexOf("Microsoft") != -1) { 
			result = window['flashID'];
		} else { 
			result = window.document['flashID'];
		}
		return result;
	}
	
    setFgColourEvent = function(color) {
    	var flash = getFlash();
		flash.setFGColor(color);
	}
	
    setBgColourEvent = function(color) {
    	var flash = getFlash();
		flash.setBGColor(color);
	}
	
    setLocationEvent = function(x, y) {
		var flash = getFlash();
		flash.setPosition(x, y);
	}
	
    modeEvent = function(mode) {
		var flash = getFlash();
		flash.setMode(mode);
	}
	
    moveEvent = function(dx, dy) {
		var flash = getFlash();
		flash.changePosition(dx, dy);
	}
    
    setZoomEvent = function(zoom) {
		var flash = getFlash();
		
	    mapWidth = canvasWidth / (tileWidth * zoom)
    	mapHeight = canvasHeight / (tileHeight * zoom)
		//mapWidth = 8/zoom
		//mapHeight = 8/zoom
		flash.setZoom(zoom);
    }

	autoSaveEvent = function (autosave) {
		var flash = getFlash();
		flash.setAutoSave(autosave);
	}
	
	saveEvent = function() {
		var flash = getFlash();
		flash.saveNow();
	}
	
	clearEvent = function() {
		var flash = getFlash();
		flash.clearNow();
	}
    
    initFlashControls = function()
    {
    	initControls();
    	var flash = getFlash();
    	flash.initComplete();
		//flash.setPosition(mapX, mapY);
    }
    
    // document.getElementById('flash').onmousedown = mouseDownOnFlashCanvas
   	//initFlashControls()
}

// function mouseDownOnFlashCanvas(e) {
//     // if (! e) e = window.event
//     // flash.onModifierKey(e.shiftKey, e.altKey, e.ctrlKey)
// }

