// demo-specific code - not needed for general use


//PRELOAD IMAGES:-
            
            //storing money
            b06a = new Image();
            b06a.src = "images/button_06a.gif";
            b06b = new Image();
            b06b.src = "images/button_06b.gif";
            b06c = new Image();
            b06c.src = "images/button_06c.gif";
            
            //understanding money
            b01a = new Image();
            b01a.src = "images/button_01a.gif";
            b01b = new Image();
            b01b.src = "images/button_01b.gif";
            b01c = new Image();
            b01c.src = "images/button_01c.gif";
            
            //saving money
            b08a = new Image();
            b08a.src = "images/button_08a.gif";
            b08b = new Image();
            b08b.src = "images/button_08b.gif";
            b08c = new Image();
            b08c.src = "images/button_08c.gif";
            
            //opening an account
            b07a = new Image();
            b07a.src = "images/button_07a.gif";
            b07b = new Image();
            b07b.src = "images/button_07b.gif";
            b07c = new Image();
            b07c.src = "images/button_07c.gif";
            
            //changing money
            b12a = new Image();
            b12a.src = "images/button_12a.gif";
            b12b = new Image();
            b12b.src = "images/button_12b.gif";
            b12c = new Image();
            b12c.src = "images/button_12c.gif";
            
            //paying bills
            b11a = new Image();
            b11a.src = "images/button_11a.gif";
            b11b = new Image();
            b11b.src = "images/button_11b.gif";
            b11c = new Image();
            b11c.src = "images/button_11c.gif";
            
            //financial products
            b16a = new Image();
            b16a.src = "images/button_16a.gif";
            b16b = new Image();
            b16b.src = "images/button_16b.gif";
            b16c = new Image();
            b16c.src = "images/button_16c.gif";
            
            //understanding tax
            b13a = new Image();
            b13a.src = "images/button_13a.gif";
            b13b = new Image();
            b13b.src = "images/button_13b.gif";
            b13c = new Image();
            b13c.src = "images/button_13c.gif";
            
            //protecting customers
            b15a = new Image();
            b15a.src = "images/button_15a.gif";
            b15b = new Image();
            b15b.src = "images/button_15b.gif";
            b15c = new Image();
            b15c.src = "images/button_15c.gif";
            
            //using money
            b03a = new Image();
            b03a.src = "images/button_03a.gif";
            b03b = new Image();
            b03b.src = "images/button_03b.gif";
            b03c = new Image();
            b03c.src = "images/button_03c.gif";
            
            //using currency
            b04a = new Image();
            b04a.src = "images/button_04a.gif";
            b04b = new Image();
            b04b.src = "images/button_04b.gif";
            b04c = new Image();
            b04c.src = "images/button_04c.gif";
            
            //dealing with organizations
            b18a = new Image();
            b18a.src = "images/button_18a.gif";
            b18b = new Image();
            b18b.src = "images/button_18b.gif";
            b18c = new Image();
            b18c.src = "images/button_18c.gif";
            
            //financial organizations
            b17a = new Image();
            b17a.src = "images/button_17a.gif";
            b17b = new Image();
            b17b.src = "images/button_17b.gif";
            b17c = new Image();
            b17c.src = "images/button_17c.gif";
            
            //knowing your rights
            b14a = new Image();
            b14a.src = "images/button_14a.gif";
            b14b = new Image();
            b14b.src = "images/button_14b.gif";
            b14c = new Image();
            b14c.src = "images/button_14c.gif";
            
            //needing money
            b02a = new Image();
            b02a.src = "images/button_02a.gif";
            b02b = new Image();
            b02b.src = "images/button_02b.gif";
            b02c = new Image();
            b02c.src = "images/button_02c.gif";
            
            //managing money
            b05a = new Image();
            b05a.src = "images/button_05a.gif";
            b05b = new Image();
            b05b.src = "images/button_05b.gif";
            b05c = new Image();
            b05c.src = "images/button_05c.gif";
            
            //spending wisely
            b09a = new Image();
            b09a.src = "images/button_09a.gif";
            b09b = new Image();
            b09b.src = "images/button_09b.gif";
            b09c = new Image();
            b09c.src = "images/button_09c.gif";
            
            //planning spending
            b10a = new Image();
            b10a.src = "images/button_10a.gif";
            b10b = new Image();
            b10b.src = "images/button_10b.gif";
            b10c = new Image();
            b10c.src = "images/button_10c.gif";
            
            //Generic change of image state
            function changeState(imgDocID, imgObjName){
		document.images[imgDocID].src = eval(imgObjName + ".src");
            }

            //store cookie of visited course
            function storeCookie(imgDocID, imgObjName) {
                var cookie_name = imgDocID;
                var options = { path: '/', expires: 90 };
                $.cookie(cookie_name, 'imgObjName', options);
                markVisitedLinks();
                
            }
            
           //visited links are remembered using cookies as page loads
           function markVisitedLinks() {
              var visited_links = document.cookie.split(';');
              var image = null;
              var image2 = null;
  	      for (var i = 0; i < visited_links.length; i++) {
                    var cookie = jQuery.trim(visited_links[i]);
                    var elems = new Array();
                    elems[i] = cookie.substring(0,3);
                    image = elems[i];
                    image2 = image + "c";
                    document.images[image].src = eval(image2 + ".src");
                    
              }
           }

	  function changeState2(imgDocID, imgObjName)
	    {
		document.images[imgDocID].src = eval(imgObjName + ".src");
		markVisitedLinks();
		
	    }
	  
	 function autoResize(id) {
		parent.document.getElementById(id).style.height = "414px";
	 }
	 function autoResize2(id) {
		parent.document.getElementById(id).style.height = "514px";
	 }



// refer to bottom for initialisation and soundManager tie-ins, however!

var MONEY = function() {
  var self = this;
  this.idPrefix = 'btn-'; // HTML ID prefix
  this.statusWidth = 6;
  this.progressWidth = 256;
  this.isSafari = (navigator.userAgent.toString().toLowerCase().indexOf('safari')+1);

  // scope within these event handler methods: "this" = SMSound() object instance (see SMSound() in soundmanager.js for reference) 

  this.showProgress = function() {
    // sound is loading, update bytes received using this.bytesLoaded / this.bytesTotal
    if (self._getButton(this.sID).className != 'loading') self._getButton(this.sID).className = 'loading'; // a bit inefficient here..
    self._showStatus(this.sID,this.bytesLoaded,this.bytesTotal);
  }

  this.onid3 = function() {
    soundManager._writeDebug('money.onid3()');
    var oName = null;
    for (var oName in this.id3) {
      soundManager._writeDebug(oName+': '+this.id3[oName]) // write out name/value ID3 pairs (eg. "artist: Beck")
    }
  }

  this.onfinish = function() {
    self._getButton(this.sID).className = '';
    self._reset(this.sID);
  }

  this.onplay = function() {
    self._getButton(this.sID).className = 'active';
    if (self.isSafari) self._getButton(this.sID).style.clip = 'rect(0px 0px 0px 0px)';
  }

  this.whileplaying = function() {
    self._showStatus(this.sID,this.position,this.duration);
  }

  this._showStatus = function(sID,n1,n2) {
    var o = self._getButton(sID).getElementsByTagName('div')[0];
    var offX = (n2>0?(-self.progressWidth+parseInt((n1/n2)*o.offsetWidth)):-self.progressWidth);
    if (self.isSafari) o.style.clip = 'rect(0px '+parseInt((n1/n2)*o.offsetWidth)+'px auto 0px)'; // because safari appears to suck, refuses not to tile background images..
    o.style.backgroundPosition = offX+'px 0px';
  }

  this._getButton = function(sID) {
    return document.getElementById(self.idPrefix+sID);
  }

  this._reset = function(sID) {
    var id = sID;
    self._showStatus(sID,1,1);
    setTimeout(function(){self._showStatus(sID,0,0);},200);
  }

  this.init = function() {
    document.onkeydown = self._keyHandler;
  }

}

var money = new MONEY();

soundManager.flashVersion = (window.location.toString().match(/#flash8/i)?8:9);
if (soundManager.flashVersion != 8) {
  soundManager.useHighPerformance = true;
  soundManager.useFastPolling = true;
}
soundManager.url = 'swf/'; // path to load SWF from (overriding default)
soundManager.debugMode = false;
soundManager.consoleOnly = false;

soundManager.onready(function() {

  // This is the "onload" equivalent which is called when SoundManager has been initialised (sounds can be created, etc.)

  //money.init();

  // set up some default options / event handlers - so all sounds created are given these handlers

  soundManager.defaultOptions.autoLoad = true;
  soundManager.defaultOptions.whileloading = money.showProgress;
  soundManager.defaultOptions.onid3 = money.onid3;
  soundManager.defaultOptions.onload = money.onload;
  soundManager.defaultOptions.onplay = money.onplay;
  soundManager.defaultOptions.whileplaying = money.whileplaying;
  soundManager.defaultOptions.onfinish = money.onfinish;

  // get drumkit sounds from XML file (as opposed to using createSound)

  soundManager.loadFromXML('audio-mappings.xml');

  /*

   You can also create sounds using Javascript methods, instead of XML.
   Options can also be set on a per-file basis, with specific option overrides.
   (Options not specified here will inherit defaults as defined in soundManager.defaultOptions.)

   eg.

   soundManager.createSound({
    id: 'mySound',
    url: '/path/to/some.mp3',
    stream: true,
    autoPlay: true,
    multiShot: false,
    whileloading: function() { alert('sound '+this.sID+': '+this.bytesLoaded+' of '+this.bytesTotal+' bytes loaded.'); } // event handler: "this" is scoped to SMSound() object instance for easy access to methods/properties
   });

   - OR -

   If you just want a sound with all default options, you can also specify just the required id and URL as string parameters:

   soundManager.createSound('mySound','/path/to/some.mp3');

  */
});

