/**
 * unsaveable.js 1.3 (08-Mar-2008)
 * (c) by Christian Effenberger 
 * All Rights Reserved
**/

function makeUnsaveable() {
	var image, object, canvas, context, display, sclass; 
	var classes = ''; var newClasses = ''; var i, j; 
	var children = document.getElementsByTagName('img'); 
	var theimages = new Array(); var child, classNames;
	var isIE = navigator.appName == 'Microsoft Internet Explorer' && navigator.userAgent.indexOf('Opera') < 1 ? 1 : 0;
	for (i=0;i<children.length;i++) {
		child = children[i]; sclass=isIE?'png':'unsaveable';
		classNames = child.className.split(' ');
		for (j=0;j<classNames.length; j++) {
			if (classNames[j] == sclass) {theimages.push(child); break; }
		}
	}	
	for (i=0;i<theimages.length;i++) {	
		image = theimages[i]; object = image.parentNode; newClasses = '';
		if(isIE) {
			image.style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="'+image.src+'",sizingMethod="image")';
			image.src = '/cvi/images/space.gif'; image.style.visibility = 'visible';
		}else {
			canvas = document.createElement('canvas');
			if(canvas.getContext) {
				classes = image.className.split(' ');
				for (j=0;j<classes.length;j++) {
					if (classes[j] != 'unsaveable') {
						if (newClasses) { newClasses += ' '; }
						newClasses += classes[j];
					}
				}
				canvas.className = newClasses;
				canvas.style.cssText = image.style.cssText;
				canvas.style.height = image.height+'px';
				canvas.style.width = image.width+'px';
				canvas.height = image.height;
				canvas.width = image.width;
				canvas.src = image.src; 
				canvas.alt = image.alt;
				if(image.id!='') canvas.id = image.id;
				if(image.title!='') canvas.title = image.title;
				if(image.getAttribute('onclick')!='') canvas.setAttribute('onclick',image.getAttribute('onclick'));
				context = canvas.getContext("2d");
				object.replaceChild(canvas,image);
				context.clearRect(0,0,canvas.width,canvas.height);
				context.fillStyle = 'rgba(0,0,0,0)';
				context.fillRect(0,0,canvas.width,canvas.height);
				context.drawImage(image,0,0,canvas.width,canvas.height);
				canvas.style.visibility = 'visible';
			}
		}
	}
}

var unsaveableOnload = window.onload;
window.onload = function () { if(unsaveableOnload) unsaveableOnload(); makeUnsaveable(); }