function addLoadEvent(func) {
	var oldonload = window.onload;
	if(typeof window.onload != 'function'){
		window.onload = func;
	}else{
		window.onload = function(){
			if(oldonload){
				oldonload();
			}
			func();
		}
	}
}
function myZoom(a, b, c , d, e){
	var self = this;
	self.zid = a;
	self.pic = b;
	self.pzm = e;
	self.initialWidth = self.currentWidth = c;
	self.currentHeight = self.initialHeight = d;
	self.newWidth = self.newHeight = 0;
	self.timeout;
	self.auto = 0;
	self.stepW = 0;
	self.stepH = 0;
	self.resizeStep = 4;
	self.maxFactor = 1.1;
	self.targetWidth = Math.floor(c * self.maxFactor);
	self.targetHeight = Math.floor(d * self.maxFactor);
	self.resizeMe = function(){
		with(self){
			self.pzm.style.background = 'transparent url(fake.gif) no-repeat scroll bottom right';
			if(stepH == 0){ stepH = 1; }
			if(stepW == 0){ stepW = 1; }
			if(targetWidth >= currentWidth || targetHeight >= currentHeight){
				if((currentWidth + stepW) >= targetWidth || (currentHeight + stepH) >= targetHeight){
					newWidth = targetWidth;
					newHeight = targetHeight;
					clearTimeout(self.timeout);
					if(self.auto == 1){
						self.shrink();
					}
				}else{
					newWidth = Math.ceil(currentWidth + stepW);
					newHeight = Math.ceil(currentHeight + stepH);
					self.timeout = window.setTimeout(function(){ self.resizeMe(); }, 10);
				}
			}else{
				if((currentHeight - stepH) <= targetHeight || (currentWidth - stepW) <= targetWidth){
					newWidth = targetWidth;
					newHeight = targetHeight;
					clearTimeout(self.timeout);
					self.pzm.style.background = 'transparent url(bullet_go.gif) no-repeat scroll bottom right';
				}else{
					newWidth = Math.floor(currentWidth - stepW);
					newHeight = Math.floor(currentHeight - stepH);
					self.timeout = window.setTimeout(function(){ self.resizeMe(); }, 25);
				}
			}
			if(newWidth == initialWidth){
				pic.parentNode.style.zIndex = 1;
			}else{
				pic.parentNode.style.zIndex = Math.round((newWidth - initialWidth) / (initialWidth * maxFactor) * 200);
			}
			pic.style.width = newWidth + 'px';
			pic.style.height = newHeight + 'px';
			pic.style.marginLeft = Math.round((initialWidth - newWidth)/2) + 'px';
			pic.style.marginTop = Math.round((initialHeight - newHeight)/2) + 'px';
			currentHeight = newHeight;
			currentWidth = newWidth;
		}
	}
	self.setTargetSize = function(f){
		with(self){
			targetWidth = Math.floor(initialWidth * f);
			targetHeight = Math.floor(initialHeight * f);
			stepW = Math.abs(Math.round((targetWidth - currentWidth) / resizeStep));
			stepH = Math.abs(Math.round((targetHeight - currentHeight) / resizeStep));
			resizeMe();
		}
	}
	self.shrink = function(){
		self.auto = 0;
		self.pic.parentNode.style.zIndex = 140;
		self.setTargetSize(1);
	}
	self.grow = function(){
		self.auto = 0;
		self.pic.parentNode.style.zIndex = 150;
		self.setTargetSize(self.maxFactor);
	}
	self.autozoom = function(){
		self.auto = 1;
		self.pic.parentNode.style.zIndex = 150;
		self.setTargetSize(self.maxFactor);
	}
}
/*
	Copyright Robert Nyman, http://www.robertnyman.com
	Free to use if this text is included
*/
function getElementsByAttribute(oElm, strTagName, strAttributeName, strAttributeValue){
	var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
	var arrReturnElements = new Array();
	var oAttributeValue = (typeof strAttributeValue != "undefined")? new RegExp("(^|\\s)" + strAttributeValue + "(\\s|$)") : null;
	var oCurrent;
	var oAttribute;
	for(var i=0; i<arrElements.length; i++){
		oCurrent = arrElements[i];
		oAttribute = oCurrent.getAttribute && oCurrent.getAttribute(strAttributeName);
		if(typeof oAttribute == "string" && oAttribute.length > 0){
			if(typeof strAttributeValue == "undefined" || (oAttributeValue && oAttributeValue.test(oAttribute))){
				arrReturnElements.push(oCurrent);
			}
		}
	}
	return arrReturnElements;
}
// ---
if(typeof Array.prototype.push != "function"){
	Array.prototype.push = ArrayPush;
	function ArrayPush(value){
		this[this.length] = value;
	}
}
var zoomer;
var pixquant;
var popo;
function goRotateZoom(Num){
	var zoomLength = zoomer.length - 1;
	zoomer[Num].autozoom();
	if(Num+1 <= zoomLength){
		popo = setTimeout("goRotateZoom("+(Num+1)+")", 200);
	}
}
function setPicZoom(){
	zoomer = new Array();
	// var pix = getElementsByClassName("zoomable", "img", document);
	var pix = getElementsByAttribute(document, "img", "alt", "zoomable");
	pixquant = pix.length;
	for(var i = 0; i < pixquant; i++){
		
		var pnode_r = document.createElement('DIV');
		pnode_r.style.position = 'relative';
		pnode_r.style.overflow = 'visible';
		pnode_r.style.height = pix[i].offsetHeight + 'px';
		pnode_r.style.width = pix[i].offsetWidth + 'px';
		
		var ppix = pix[i].cloneNode(false);
		ppix.style.position = 'absolute';
		ppix.style.left = 0;
		ppix.style.top = 0;
	
		pnode_r.appendChild(ppix);

		var pzoomer = document.createElement('DIV');
		zoomer[i] = new myZoom(i, ppix, pix[i].offsetWidth, pix[i].offsetHeight, pzoomer);

		pzoomer.setAttribute('id', 'zoom' + i);
		pzoomer.style.position = 'absolute';
		pzoomer.style.display = 'block';
		pzoomer.style.margin = 0;
		//pzoomer.style.background = 'transparent url(bullet_go.gif) no-repeat scroll bottom right';
		pzoomer.style.zIndex = 150;
		pzoomer.style.height = pix[i].offsetHeight + 'px';
		pzoomer.style.width = pix[i].offsetWidth + 'px';
		pzoomer.style.left = pzoomer.style.top = 0;
		pzoomer.onmouseover = zoomer[i].grow;
		pzoomer.onmouseout = zoomer[i].shrink;
		pnode_r.appendChild(pzoomer);
		
		pix[i].parentNode.replaceChild(pnode_r, pix[i]);
		
		zoomer[i].shrink();

	}
	if(zoomer.length > 0){
		goRotateZoom(0);
	}
}
addLoadEvent(setPicZoom); 
