/**
 * 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;
}

/**
 * Writes the email address to the document,
 * If element param provided, Trys to find a tag with a 'mail' id to write the email address into
 */ 

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

/**
 * Called when the contact form is submitted.
 * Tracks the adwords conversion tracking by preloading the relevant image URL
 * Also tells analytics that the form has been submitted.
 */

function contactFormSubmitted(){
	// first tell adwords it's been submitted
	//var image = new Image(1,1);
	//image.src = "http://www.googleadservices.com/pagead/conversion/1065133309/?label=8-0ACPvw7gEQ_cny-wM&amp;guid=ON&amp;script=0";
	
	// now tell analytics it's been submitted
	_gaq.push(['_trackPageview', '/contact/submitted/']);
	return;
}

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

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