// JavaScript Document
// ** Requires jQuery > 1.0 **
var imageCue = new Array();

function registerImage( id, sourceFile, destination, callback ){
	var thisImage = new Array();
	thisImage = {"destination" : destination, "source" : sourceFile, "callback" : callback};
	imageCue.push(thisImage);
	$("#debug").append("<br>Image registered: " + sourceFile);
}

function loadRegsisteredImages() {
	var i = 0;
	
	if( imageCue.length ){
		for( i = 0; i < imageCue.length; i++){
			loadImage( imageCue[i] );
		}
	} else {
		
	}
}

function loadImage( thisImage ){
	var img = new Image();
	
	$(img)
		.load( function() {
			$(this).hide();
			$("#" + thisImage['destination'] ).empty();
			$("#" + thisImage['destination'] ).append(this);
			$(this).fadeIn("normal", function(){
				if( typeof( thisImage['callback'] ) != 'undefined' ){
					thisImage['callback']();
				}
			});
		})
		.error(function(){
			$("#" + destination).html("error loading file");
		})
		.attr('src', thisImage['source'] );
}