var gradualZoom={}

gradualZoom.basezoom=0.05; //set base zoom when mouse isn't over element (decimal below 1)
gradualZoom.increment=0.05; //amount of zoom to increase after each iteration (suggestion: 0.1 or 0.2)

gradualZoom.setzoom=function(obj, value){ //Sets the zoom of targetobject based on the passed in value setting (0 to 1 and in between)
	var targetobject=obj
	if (targetobject)
	{
		targetobject.style.width=parseInt(targetobject.originalwidth)*value + "px";
		targetobject.style.height=parseInt(targetobject.originalheight)*value + "px";
	}
	targetobject.currentzoom=value
}

gradualZoom.zoomupdown=function(obj, direction){
	var targetobject=obj
	var zoomamount=(direction=="zoomup")? this.increment : -this.increment
	if (targetobject && (direction=="zoomup" && targetobject.currentzoom<1 || direction=="zoomdown" && targetobject.currentzoom>this.basezoom)){
		this.setzoom(obj, targetobject.currentzoom+zoomamount)
		window["zoomzoom"+obj._zoomorder]=setTimeout(function(){gradualZoom.zoomupdown(obj, direction)}, 50)
	}
}

gradualZoom.clearTimer=function(obj){
if (typeof window["zoomzoom"+obj._zoomorder]!="undefined")
	clearTimeout(window["zoomzoom"+obj._zoomorder])
}

gradualZoom.isContained=function(m, e){
	var e=window.event || e
	var c=e.relatedTarget || ((e.type=="mouseover")? e.fromElement : e.toElement)
	while (c && c!=m)try {c=c.parentNode} catch(e){c=m}
	if (c==m)
		return true
	else
		return false
}

gradualZoom.zoominterface=function(obj, e, direction){
	if (!this.isContained(obj, e)){
		gradualZoom.clearTimer(obj)
		gradualZoom.zoomupdown(obj, direction)
	}
}

gradualZoom.collectElementbyClass=function(classname){ //Returns an array containing DIVs with specified classname
	var classnameRE=new RegExp("(^|\\s+)"+classname+"($|\\s+)", "i") //regular expression to screen for classname within element
	var pieces=[]
	var alltags=document.all? document.all : document.getElementsByTagName("*")
	for (var i=0; i<alltags.length; i++){
		if (typeof alltags[i].className=="string" && alltags[i].className.search(classnameRE)!=-1)
			pieces[pieces.length]=alltags[i]
	}
	return pieces
}

gradualZoom.init=function(){
	var targetobjects=this.collectElementbyClass("gradualzoom")
	for (var i=0; i<targetobjects.length; i++){
		targetobjects[i].originalwidth=targetobjects[i].style.width;
		targetobjects[i].originalheight=targetobjects[i].style.height;
		targetobjects[i]._zoomorder=i
		this.setzoom(targetobjects[i], this.basezoom)
		targetobjects[i].onmouseover=function(e){gradualZoom.zoominterface(this, e, "zoomup")}
		targetobjects[i].onmouseout=function(e){gradualZoom.zoominterface(this, e, "zoomdown")}
	}
}
