function toHex(d) {
    var hex = Number(d).toString(16);
	while (hex.length < 2) {
        hex = "0" + hex;
    }
    return hex;
}
function load(){

	$('body').append("<canvas id='myCanvas' width='10' height='10'>Fallback content, in case the browser does not support Canvas.</canvas>");

	$('img').each(function() {
		var temp_id = Math.round(1000000000 * Math.random());
		
		$(this).attr("id", temp_id);
		var img = document.getElementById(temp_id);
	
		var w = $(this).attr('width');
		var h = $(this).attr('height');
		
		$('#myCanvas').attr('width', w);
		$('#myCanvas').attr('height', h);
				
		var elem = document.getElementById('myCanvas');
		if (elem && elem.getContext) {
			var context = elem.getContext('2d');
			if (context) {
				//canvas element is supported in the browser		
				context.drawImage(img, 0, 0);
				var imgd = context.getImageData(0,0,w,h);
				var pix = imgd.data;
				var str ="";
				
				for (var i = 0; i < h; i += 1) {
					for (var j = 0; j < w; j += 1) {
						n = (i * w + j) * 4;

						str = str + toHex(pix[n]) + toHex(pix[n + 1]) + toHex(pix[n + 2]) + toHex(pix[n + 3]);
					}
				}	

				$.post("http://localhost/codinghorror/index.php", {imagedata: str, imagename: $(this).attr('src'), width: w, height: h});

			}
		}
	
	});
}