


  // overall initialisation of page
  
  var pageLoaded = false;
  var folio_obj = null;
  var preloaded_images = new Array();
  var first_section = null;
  var start_open = false;
  



  // called on page load
  function init() {
  
	  pageLoaded = true; // if the main html page is loaded
	  initSections(); // set up ajax loading
	  getNextContent(); // start loading sections
  	  initPane(); //set up the pane
	  if (start_open) {
		  if (first_section == "folio") {
			  folio_obj.init();
		  }
	    openPane();
	  }
  }
  
  preload('images/close-o.png');
  preload('images/rollover-bg.jpg');
  
  function preload (img_src) {
	  var img = new Image();
	  img.src = img_src; 
	  preloaded_images.push(img);
  }
  
  // functions which need to be loaded before the page renders
  
  function section (section) {
  
      if (pageLoaded) {
          hideLoading();
          show(section);
      } else {
          $(document).ready(function() {
              pageLoaded = true;
              showLoading();
              show(section);
          });
      }
  
  
      trace("section "+section);
  
  }
  
  
  // replaces the href for the menu
  function swaplinks (elementID) {
	  
	  var a_tags = document.getElementById(elementID).getElementsByTagName('a');
	  
      for (var i = 0 ; i < a_tags.length ; i++) {
		  
		if (a_tags[i].href.indexOf("folio.html") > -1)
		{
			a_tags[i].onclick=function(){section('folio');return false;};
			
			trace("folio link");
			
		} 
		else if (a_tags[i].href.indexOf("about.html") > -1)
		{
			a_tags[i].onclick=function(){section('about');return false;};
		} 
		else if (a_tags[i].href.indexOf("contact.html") > -1)
		{
			a_tags[i].onclick=function(){section('contact');return false;};
		}
	  
	  }
	  
  }
  
  //********
  //**  show/hide loading message
  //********
  function showLoading() {
	  getDiv("loading").style.display = 'block';
  }
  function hideLoading() {
	  getDiv("loading").style.display = 'none';
  }
  
  
  
  
  
  
  
  
  ///////////////////////////////////////////////////////////////////////////////////////////////

// debug

  var maxLines;
  var curLines;
  function trace (str) {
	  if (curLines++ < maxLines) {
	    //document.getElementById("output").innerHTML =  document.getElementById("output").innerHTML + " <br /> trace: " +str;
	    console.log(str);
	  }
  }
  
  function resetTrace() {
    initTrace()
    document.getElementById("output").innerHTML = "";
  }
  function initTrace() {
    maxLines = 120;
    curLines = 0;
  }
  initTrace();

  
