  //Config object
  var Config = {
    //XML file to grab configuration details from
    _configFile: 'xml/config.xml',
    
    //Data object to store config XML
    _data: '',
    
    //XML file to grab configuration details from
    _cmsFile: '/xml/content1.xml',
    
    //Data object to store CMS XML
    _cmsData: '',
    
    //Array of navigation elements
    _projects: [],
    
    //Determines whether all data has been loaded from the config file
    _is_dataLoaded: false,
    
    //Initialise config
    init: function() {
      this.loadConfigData();
    },
    
    //Get a naviation item object
    getNavItem: function(sItem) {
      var oItem;
      
      //Determine whether to select the name or id
      var attSelector = isNaN(sItem) ? "name='" + sItem + "'" : "id='" + sItem + "'";
      
      //Find the node matching the selector
      $(_data).find("nav > item[" + attSelector + "]").each(function() {
        oItem = new Config.NavItem({
	  id: $(this).attr("id"), 
	  deeplink: $(this).attr("deeplink_value"), 
	  name: $(this).attr("name"), 
	  content_type: $(this).attr("content_type")
        });
      });
      
      return oItem;
    },
    
    //Populate the config object with all the projects
    populateProjects: function() {
	    
      var config = this;
      var project, arrImages = [], thumbnail = "", type = "", date = "", dateString = "", url = "";
      config._projects = [];
      
      //Loop through all the projects
      $(_data).find("nav > item[name='Projects']").children().each(function() {     
        //Get the thumbnail image from the CMS data for the current project
        $(config._cmsData).find("Site [PageListingID='" + $(this).attr("id") + "']").each(function() {
	  thumbnail = $(this).attr("Resource1");
	  
	  //Get other info	  
          type = $(this).attr("ProjectType");	
          industry = $(this).attr("Industry");		  
          url = ($(this).attr("AlternateURL").indexOf('http://') > 0) ? $(this).attr("AlternateURL") : ($(this).attr("AlternateURL") == '') ? '' : 'http://' + $(this).attr("AlternateURL");	
	  date = $(this).attr("DisplayDate");
	  dateString = convertToDate($(this).attr("DisplayDate"));
	});

        //Get the images from the CMS data for the current project
        $(config._cmsData).find("Site [PageListingID='" + $(this).attr("id") + "']").children().each(function() {
	  arrImages.push($(this).attr("Resource1"));
	});

        //Create a new projects
        project = new config.Project({
          id: $(this).attr("id"),
          name: $(this).attr("name"),
          deeplink: $(this).attr("deeplink_value"),
	  thumbnail: thumbnail,
          images: arrImages,
	  type: type,
	  industry: industry,
	  date: date,
	  dateString: dateString,	  
	  url: url
        });

        //Add the project
        config._projects.push(project);
	
        //Cleanup;
        arrImages = [];
	thumbnail = "";	
      });
      
      //Dispatch an event for config initialisation complete
      Events.dispatchEvent(ConfigEvent.INIT);
    },
    
    //Method to load in data from config xml file
    loadConfigData: function() {
      $.ajax({
	type: "GET",
        url: this._configFile,
	context: this,
	dataType: "xml",
	success: function(data) {
	  _data = data;

	  this.loadCMSData();
	}
      });
    },
    
    //Method to load in data from config xml file
    loadCMSData: function() {
      $.ajax({
	type: "GET",
        url: this._cmsFile,
	context: this,
	dataType: "xml",
	success: function(data) {
	  this._is_dataLoaded = true;
	  this._cmsData = data;
	  this.bindNavigation();
	}
      });
    },
    
    bindNavigation: function() {
      var about_us = Config.getNavItem("About Us");
      var contact_us = Config.getNavItem("Contact Us");
      
      //Bind the click function to the about us link
      $('#about').bind('click', function() {
        //Set the deeplink value & make sure the URL maintains the deeplink
        SWFAddress.setValue(about_us.deeplink); this.blur(); return false;
      });
      
      //Bind the click function to the cotnact link
      $('#contact').bind('click', function() {
        //Set the deeplink value & make sure the URL maintains the deeplink
        SWFAddress.setValue(contact_us.deeplink); this.blur(); return false;
      });

      this.populateProjects();
    },

    //An object containing the structure for a navigation item
    NavItem: function (oItem) {
      this.id = oItem.id || 0;
      this.deeplink = oItem.deeplink || '';
      this.name = oItem.name || '';
      this.content_type = oItem.content_type || '';
    },
    
    //An object containing the structure for a project
    Project: function (oItem) {
      this.id = oItem.id || 0;
      this.name = oItem.name || '';
      this.deeplink = oItem.deeplink || '';
      this.thumbnail = oItem.thumbnail || '';      
      this.images = oItem.images || [];
      this.type = oItem.type || '';
      this.industry = oItem.industry || '';      
      this.date = oItem.date || '';
      this.dateString = oItem.dateString || '';      
      this.url = oItem.url || '';
    }
  }
  
  //Example of waiting for config to load
  //**********************************
  checkDataLoaded = function () {
    if (!Config._is_dataLoaded) {
      alert("Still loading data");
      setTimeout("checkDataLoaded()", 2000);
    } else {
      alert("Loaded now");
    }
  };
  
  convertToDate = function(sqldate) {
    //Get other info	  
    //var sqlDate = '2010-10-10T00:00:00';
    if(sqldate == '' || typeof(sqldate) == 'undefined') return 'No Date';
    
    var m_names = new Array("January", "February", "March", 
    "April", "May", "June", "July", "August", "September", 
    "October", "November", "December");    
    
    var year = sqldate.substring(0, 4);
    var month = sqldate.substring(5, 7);
    var day = sqldate.substring(8, 10);	  
    var date = new Date();  
    date.setFullYear(year,month,day);  
    return m_names[date.getMonth()] + ' ' + date.getFullYear()
  };

