window.onload = initialize;
function initialize() {
  dhtmlHistory.initialize();	
  
  dhtmlHistory.addListener(handleHistoryChange);
  
  // determine our current location so we can
  // initialize ourselves at startup
  var initialLocation = dhtmlHistory.getCurrentLocation();
  
  // set the default
  if (initialLocation == ""){
    initialLocation = "<i>terios.com.ve</i>";
	}
  
  // now initialize our starting UI
	//updateUI not needed for flash version
  updateUI(initialLocation, null);
}

/** A simple method that updates our user
    interface using the new location. */
function updateUI(newLocation, historyData) {
  //var output = document.getElementById("output");
  
  // simply display the location and the
  // data
  var historyMessage;
  if (historyData != null){
    historyMessage = historyData.message;
		document.title = historyData.message;
	} else {
		historyMessage = "<i>No History Data - init history</i>";
		document.title = "terios.com.ve";
	}    
  var message = "<b>Location:</b> " + newLocation + "<br /><b>History Data Storage:</b> " + historyMessage;                
  //output.innerHTML = message;
}

/*
function debugMsg(msg) {
	var debugMsg = document.getElementById("debugMsg");
	debugMsg.innerHTML = msg;
}
*/

function handleHistoryChange(newLocation, historyData) {
	
	// this is updating the temp html debug message
	//debugMsg("handleHistoryChange() called");
	// this is updating the temp html UI changes
  updateUI(newLocation, historyData);
	//JS function to call back to flash
	
	//alert('history change');
	callExternalInterface();
	
	
}

function callExternalInterface() {
	//target the swf by id
	//updateFlashHistory is the ExternalInterface addCallback methodName
	//Followed by the JS method to be called

  if(thisMovie("wbla").updateFlashHistory){
		thisMovie("wbla").updateFlashHistory(dhtmlHistory.getCurrentLocation());
		//alert('method exists - call Flash');
	} else {
		//alert('method doesn\'t exist yet, don\'t call Flash');
		return true;
	}
}


function thisMovie(movieName) {
    if (navigator.appName.indexOf("Microsoft") != -1) {
        return window[movieName]
    }
    else {
        return document[movieName]
    }
}


function setDeepLink(newLocation, historyMessage){	
	var historyData = {message:historyMessage};
	// use the history data to update our UI
  updateUI(newLocation, historyData);
	//Add to the dhtml history
	dhtmlHistory.add(newLocation, historyData);	
}

function getDeepLink(){
	return dhtmlHistory.getCurrentLocation();
}

function getPageTitle(){
	return document.title;
}

function setPageTitle(windowTitle){
	document.title = windowTitle;
}

function setURL(val){
	window.location = "#"+val;
}

function doNothing() { return true; }
//window.onerror = doNothing;
