/**
 * Opens a window to display a picture, or URL
 */ 

function openWindow( url, width, height ) {
	var rnd_num = Math.ceil( 1000 * Math.random() );
	window.open( url, 'demowindow'+rnd_num, 'height='+height+', width='+width+', toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, directories=no, status=no');
	return false;
}

/**
 * Gets the contact email address
 */ 

function getMailLink() {
	var atSym = '@'; var mai = 'mai';	var name = 'hel' + 'lo';
	var dom1 = 'teamc';	var period = '.'; var loc = 'co';
	var dom2 = 'ooper';	var country = 'uk';	var lto = 'lto:';
	return '<a href="' + mai + lto + name + atSym + dom1 + dom2 + period + loc + period + country + '">' + name + atSym + dom1 + dom2 + period + loc + period + country + '</a>';
}

/**
 * Opens a new AJAX page. Called from the flash, or when a link is clicked.
 */ 

function openPage( newSection, newSubSection, newPage ) {

	// set the current page data
	section = newSection;
	subsection = newSubSection;
	page = newPage;

	// build the destination url
	var destination = '/';
	if (page) {
		destination = '/' + section + '/' + subsection + '/'+page+'/';
	} else if (subsection) {
		destination = '/' + section + '/' + subsection + '/';
	} else if (section) {
		destination = '/' + section + '/';
	}
	
	// simple jQuery to load content into the main div
	$("#divAjaxContent").load( destination, {jc: 1}, function(){
		
		// slide the map to the new location when ajax call complete
		thisMovie('isometric_map').gotoLocation( section, subsection, page, false );
		
		// write an email address if there is one
		writeEmail();
		
	} );
	
	// tell google analytics to track the page click
	if (typeof pageTracker != "undefined" && typeof pageTracker._trackPageview == "function") {
		//alert('Track: ' + destination );
		pageTracker._trackPageview( destination );
	}
	
	//
	return false;
}


 /**
  * Records a view of the intro video
  */ 
function recordVideoVisit( ) {
	if (typeof pageTracker != "undefined" && typeof pageTracker._trackPageview == "function") {
		pageTracker._trackPageview( "/introVideo/" );
	}
}


 /**
  * Tries to find a tag with a 'mail' id to write and email address into
  */ 

function writeEmail() {
	// if we are in the contact section
	if(section == 'contact') {
		var mail_para = document.getElementById( 'mail' );
		if( mail_para ) {
			mail_para.innerHTML = getMailLink();
		}
	}
}

  /**
   * Grabs a reference to the specified flash movie
   */ 

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