if (document.getElementById && document.getElementsByTagName) {
	if (window.addEventListener) window.addEventListener('load', init, false);
	else if (window.attachEvent) window.attachEvent('onload', init);
}

function init() {
      var picElements = getElementsByAttribute("class","img",document);
      if (!picElements) var picElements = getElementsByAttribute("className","img",document);
	for(var i=0; i<picElements.length; i++) {
		picElements[i].onmousemove = zoomPix;
		picElements[i].onmouseout = resetPix;

		picElements[i].initWidth=picElements[i].offsetWidth;
		picElements[i].initHeight=picElements[i].offsetHeight;

		picElements[i].aspect=picElements[i].offsetHeight/picElements[i].offsetWidth;

		picElements[i].newWidth=picElements[i].offsetWidth;
		picElements[i].newHeight=picElements[i].offsetHeight;

		if (!parseInt(picElements[i].name)) 
			picElements[i].finalWidth=picElements[i].initWidth*2;
		else
			picElements[i].finalWidth=parseInt(picElements[i].name);
	}
}

function enlarge(e){

	e.style.zIndex=900;
	
	if (e.newWidth > e.finalWidth || e.shrinkFunc){

		clearTimeout(e.enlargeFunc)
		e.enlargeFunc=false;

	} else {

		if (e.newWidth+32 < e.finalWidth) {
			e.newWidth+=32;
			e.newHeight+=e.aspect*32;
		} else if (e.newWidth+16 < e.finalWidth) {
			e.newWidth+=16;
			e.newHeight+=e.aspect*16;
		} else {
			e.newWidth+=1;
			e.newHeight+=e.aspect*1;		
		}

		e.style.width=e.newWidth + 'px';
		e.style.height=e.newHeight + 'px';
		
		margLeft=Math.abs(e.newWidth-e.initWidth)/2;
		margTop=Math.abs(e.newHeight-e.initHeight)/2;
	
		e.style.margin=(-margTop) + 'px 0 0 ' + (-margLeft) + 'px';
	
		e.enlargeFunc=window.setTimeout(function () { enlarge(e); }, 10);
		
	}
}

function shrink(e){

	e.style.zIndex=0;

	if(this.enlargeFunc){

		clearTimeout(this.enlargeFunc)
		this.enlargeFunc=false;

	}

	if (e.newWidth < e.initWidth){

		clearTimeout(e.shrinkFunc)
		e.shrinkFunc=false;

		var initWidth=e.initWidth;
		var initHeight=e.initHeight;

		e.newWidth=initWidth;
		e.newHeight=initHeight;
	
		e.style.width=initWidth + 'px';
		e.style.height=initHeight + 'px';
		e.style.margin='0 0 0 0';

	} else {

		if (e.newWidth-32 > e.initWidth) {
			e.newWidth-=32;
			e.newHeight-=e.aspect*32;	
		} else if (e.newWidth-16 > e.initWidth) {
			e.newWidth-=16;
			e.newHeight-=e.aspect*16;
		} else {
			e.newWidth-=1;
			e.newHeight-=e.aspect*1;	
		}

		e.style.width=e.newWidth + 'px';
		e.style.height=e.newHeight + 'px';
		
		margLeft=Math.abs(e.newWidth-e.initWidth)/2;
		margTop=Math.abs(e.newHeight-e.initHeight)/2;
	
		e.style.margin=(-margTop) + 'px 0 0 ' + (-margLeft) + 'px';
	
		e.shrinkFunc=window.setTimeout(function () { shrink(e); }, 10);

	}
}

function zoomPix(e){

	if(!this.enlargeFunc){
		enlarge(this);
	}

}

function resetPix(e){

	shrink(this);

}

function getElementsByAttribute(attr,val,container) {
	container = container||document
	var all = container.all||container.getElementsByTagName('*')
	var arr = [] 
	for(var k=0;k<all.length;k++){
		if(all[k].getAttribute(attr) == val){
			arr[arr.length] = all[k];
		}
	}
	if (arr.length == 1)
		return arr[0];
	else if(arr.length != 0)
		return arr;
	else
		return 0;
}












