var resizedImageIDPrefix = "resizedImage_";

function resizeImages(){

	var images = document.getElementsByTagName("img");
	
	var imageNode;
	var l = images.length;
	
	for (var i = 0; i < l; i++){
		imageNode = images[i];
		
		if (imageNode.getAttributeNode("class").nodeValue == "content_img"){
			
			var imgWidth = imageNode.width;
			var imgHeight = imageNode.height;

			var copy = imageNode.cloneNode(true);
			copy.title = "Klick!";
			
			var newID = resizedImageIDPrefix + i;

			var aNode = document.createElement("a");
			aNode.href = "javascript:swapImageSize('" + newID + "', '" + imgWidth + "', '" + imgHeight + "');";
			aNode.target = "_self";
			aNode.appendChild(copy);
			aNode.id = newID;
			
			imageNode.parentNode.replaceChild(aNode, imageNode);
			
			swapImageSize(newID, imgWidth, imgHeight);
		}
	}
}

function swapImageSize(aNodeId, imgWidth, imgHeight){
	
	var aNode = document.getElementById(aNodeId);
	var imgNode = aNode.firstChild;
	
	var hasOrginSize = (imgWidth == imgNode.width);
	if (hasOrginSize){
		var factor = 2;
		
		imgNode.width = Math.floor(imgNode.width / factor);
		imgNode.height = Math.floor(imgNode.height / factor);
		
	} else {
		imgNode.width = imgWidth;
		imgNode.height = imgHeight;
	}
	
}