window.onload = initialize;
function initialize() {
  dhtmlHistory.initialize();	
  
  dhtmlHistory.addListener(handleHistoryChange);
  
  // gdje se nalazimo
  var initialLocation = dhtmlHistory.getCurrentLocation();
  
  if (initialLocation == ""){
    initialLocation = "<i>home</i>";
	}
	
  //updateUI not needed for flash version
  updateUI(initialLocation, null);
	
	
}

function updateUI(newLocation, historyData) {
  var historyMessage;
  if (historyData != null){
    historyMessage = historyData.message;
		document.title = historyData.message;
	} else {
		// ovo sam ja komentirao jel izgleda da se izvrsava uvijek!?
		//historyMessage = "<i>No History</i>";
		//document.title = "FINVEST Corp.";
	}    
  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() {
	if(thisMovie("main").navigiraj){
		thisMovie("main").navigiraj(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 setAddressLink(newLocation, historyMessage){	
	var historyData = {message:historyMessage};
	//debugMsg("setDeepLink() called");
	// use the history data to update our UI
  updateUI(newLocation, historyData);
	//Add to the dhtml history
	dhtmlHistory.add(newLocation, historyData);
	
	}

function getAddressLink(){
	//debugMsg("getDeepLink() called - " + dhtmlHistory.getCurrentLocation());
	return dhtmlHistory.getCurrentLocation();
}

function getPageTitle(){
	//debugMsg("getPageTitle() called - " + document.title);
	return document.title;
}

function setPageTitle(windowTitle){
	//debugMsg("setPageTitle() called - " + windowTitle);
	document.title = windowTitle;
}

function doNothing() { return true; }
//window.onerror = doNothing;

function scrollWindow(xScroll, yScroll){
	scroll(xScroll,yScroll);
	return true;
}