//Gradual Elements lifter- By Mati
//modified from -- Gradual Elements Fader- By Dynamic Drive at http://www.dynamicdrive.com

var gradualLifter={}
var itemheight = 50;

gradualLifter.increment=1 //amount of height to increase after each iteration (suggestion: 0.5 OR 1)

gradualLifter.setheight=function(obj, value){ //Sets the opacity of targetobject based on the passed in value setting (0 to 1 and in between)
	var targetLobject=obj
	if (targetLobject && typeof targetLobject.style.height!="undefined") //Standard opacity syntax
	  targetLobject.style.height=itemheight+"px"
  targetLobject.height=itemheight
}

gradualLifter.muudakorgust=function(obj, value, suund){
	var targetLobject=obj
  korgus = eval(targetLobject.style.height.replace(/px/,"")) +  value
  targetLobject.style.height=korgus+"px"
  targetLobject.height=korgus

  ylevalt = eval(targetLobject.style.marginTop.replace(/px/,"")) - value
  targetLobject.style.marginTop=ylevalt+"px"
}

gradualLifter.libista=function(obj, direction){
	var targetLobject=obj
	var fadeamount=(direction=="fadeup")? this.increment : -this.increment

	if (targetLobject && (direction=="fadeup" && targetLobject.height<70 || direction=="fadedown" && targetLobject.height>itemheight)){
		this.muudakorgust(obj, fadeamount, direction)
		window["heightlifter"+obj._fadeorder]=setTimeout(function(){gradualLifter.libista(obj, direction)}, 50)
	}
}

gradualLifter.clearTimer=function(obj){
//The JavaScript typeof can be used to determine the type of the data type.
//Whether it’s an object, array, string or something else.
if (typeof window["heightlifter"+obj._fadeorder]!="undefined")
	clearTimeout(window["heightlifter"+obj._fadeorder])
}

gradualLifter.isContained=function(m, e){
	var e=window.event || e
//relatedTarget property is for mouseover and mouseout events. 
//This contains the element the mouse came from in case of mouseover, or the element it goes to in case of mouseout.
//Microsoft:
//    * fromElement refers to the element the mouse comes from. This is interesting to know in case of mouseover.
//    * toElement refers to the element the mouse goes to. This is interesting to know in case of mouseout.
  var c=e.relatedTarget || ((e.type=="mouseover")? e.fromElement : e.toElement)
/* on võrdne:
if (e.relatedTarget) {
  c = e.relatedTarget
} else {
  if (e.type=="mouseover") { 
    c = e.fromElement; 
  } else { 
    c = e.toElement; 
  } 
}  
*/
//parentNode väljastab elemendi kus sees see element asub
//kuni on c ja c ei ole võrdne m-iga 
	while (c && c!=m)try {c=c.parentNode} catch(e){c=m}
	if (c==m)
		return true
	else
		return false
}

gradualLifter.fadeinterface=function(obj, e, direction){
	if (!this.isContained(obj, e)){
		gradualLifter.clearTimer(obj)
		gradualLifter.libista(obj, direction)
	}
}

gradualLifter.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
}

gradualLifter.init=function(){
	var targetLobjects=gradualFader.collectElementbyClass("menypilt")
	for (var i=0; i<targetLobjects.length; i++){
		targetLobjects[i]._fadeorder=i
    //määrab igale elemendile algkõrguse
		this.setheight(targetLobjects[i], itemheight)
		targetLobjects[i].onmouseover=function(e){gradualLifter.fadeinterface(this, e, "fadeup")}
		targetLobjects[i].onmouseout=function(e){gradualLifter.fadeinterface(this, e, "fadedown")}
	}
}

