// JavaScript Document



  imagesQ = {
	  onComplete: function(){} // Fires when all finished loading
	  ,onLoaded: function(){} // Fires when an image finishes loading
	  ,current: null // Last loaded image (Image Object)
	  ,images: [] // Loaded images (array of Image Object)
	  ,queue:[] // Waiting to be processed (array of strings (urls for Image SRC))
	  ,queue_images: function(){ // gets multiple arguments each can be either an image src or an array of image src (you can mix).
		  for (var i=0;i<arguments.length;i++){
			  if (arguments[i].constructor === Array){
				  this.queue= this.queue.concat(arguments[i]); // add to queue, do not empty it!
			  }else if(typeof arguments[i]==='string'){
				  this.queue.push(arguments[i]);
			  }
		  }				
	  }
	  ,process_queue: function() { // start loading images from the queue
		  this.load_image(this.queue.shift()); //pull the next image off the top and load it
	  }
	  ,load_image: function(imageSrc){ // load a single by a url and continue to process the queue
		  var this_ref = this;
		  var imgObj = new Image;
		  imgObj.onload = function(){ // After user agent has the image
			  this_ref.current = imgObj; // set the current
			  this_ref.images.push(imgObj); // add the image to the stack
			  (this_ref.onLoaded)(); //fire the onloaded
			  if(this_ref.queue.length == 0){ // all images loaded?
				  (this_ref.onComplete)(); // call callback
			  }else{// if queue is not empty 
				  this_ref.process_queue(); // load the next image
			  }
		  }
		  imgObj.src = imageSrc; // Tell the User Agent to GET it
	  }
  }

