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 home</i>";
	}
	

  
  // now initialize our starting UI
	//updateUI not needed for flash version
  updateUI(initialLocation, null);
	
	//swapScrollColor(0);
}

/** A simple method that updates our user
    interface using the new location. */
    
function updateUI(newLocation, historyData) {
  //alert ("update locaction");
  //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 = ProjectTitle;
	}    
  var message = "<b>Location:</b> " + newLocation + "<br /><b>History Data Storage:</b> " + historyMessage;                
 //;
}



function handleHistoryChange(newLocation, historyData) {
	

	
	// 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("gMovie")){
		
		thisMovie("gMovie").SetVariable("updateFlashHistory", dhtmlHistory.getCurrentLocation());

	} 
	

}


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);
	
	//GOOGLE TRACKER COMES HERE!!!
	//urchinTracker('/' + newLocation);
	PageTracker._trackPageview('/' + newLocation);
	
}

function getDeepLink(){
	
	return dhtmlHistory.getCurrentLocation();
}

function getPageTitle(){
	
	return document.title;
}

function setPageTitle(windowTitle){
	
	document.title = windowTitle;
}




function popup(url, w, h) {
	
	var wid = 600;
	var hi = 476;
	
	if (w != null) wid = w; 
	if (h != null) hi  = h; 
	
	var scroll = true;
	
	var winl = (screen.width-w)/2;
	var wint = (screen.height-h)/2;
	
	new_spec = wid + "_" + hi + scroll;
	scrolling = scroll? "yes": "no";
	if (scroll && document.all && (navigator.userAgent.indexOf("Mac") > -1)) wid = wid+17;
	newwin=window.open(url,new_spec,"WIDTH=" + wid + ",HEIGHT=" + hi + ",scrollBars=" + scrolling + ",resizable=no,screenX="+winl+",screenY="+wint+",left="+winl+",top="+wint);
	newwin.focus();
}

function doNothing() { return true; }
//window.onerror = doNothing;


function allSwfsMustDIE(){
	var objects = document.getElementsByTagName("OBJECT");
	
	//alert('destroy all ' + (objects.length) + ' swfs');
  for (var i=0; i < objects.length; i++) {
    for (var x in objects[i]) {
      if (typeof objects[i][x] == 'function') {
				//alert('destroying ' + objects[i][x]);
        objects[i][x] = null;
      }
    }
  }
	
	
	var divHolder = document.getElementById("gMoviewrapper");
	var divToKILL = document.getElementById("flashcontent");
	divHolder.removeChild(divToKILL);
	
	
	//alert('destroying flashcontent');
	//alert(divToKILL);
	
}

if (typeof window.onunload == 'function') {
  var oldunload = window.onunload;
  window.onunload = function() {
    allSwfsMustDIE();
    oldunload();
  }
} else {
  window.onunload = allSwfsMustDIE;
}


function scrollWindow(xScroll, yScroll){
	scroll(xScroll,yScroll);
	return true;
}