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>default</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 = pageTitle;
	}    
  var message = "<b>Location:</b> " + newLocation + "<br /><b>History Data Storage:</b> " + historyMessage;                
  //output.innerHTML = message;
}



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
	
	//alert('callExternalInterface');
  if(thisMovie("admadSite").updateFlashHistory){
		thisMovie("admadSite").updateFlashHistory(dhtmlHistory.getCurrentLocation());
		//alert('method exists - call Flash');
	} else {
		//alert('method doesn\'t exist yet, don\'t call Flash');
		return true;
	}
}


function setDeepLink(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);
	
	//urchinTracker('/' + newLocation);
  var _gaq = window._gaq || [];
  _gaq.push(['_setAccount', 'UA-883039-1']);
  _gaq.push(['_trackPageview', "/" + newLocation]);

  if ( window.gTrackId ) {
	  _gaq.push(['_setAccount', window.gTrackId]);
//	  _gaq.push(['_setDomainName', 'none']);
//	  _gaq.push(['_setAllowLinker', true]);
	  _gaq.push(['_trackPageview', "/" + newLocation]);
  }
}

function getDeepLink(){
	//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 thisMovie(movieName) {
    if (navigator.appName.indexOf("Microsoft") != -1) {
        return window[movieName]
    }
    else {
        return document[movieName]
    }
}

