/**
 * @author max
 * zoomer
 * ver. 1.0.0.0
 */

function initObj() { // create objects
	my_object1=new create("div1")
	maxWidth=800 // max width of image
	minWidth=400 // min width of image
}

function create(id) { //define properties, pass id
	this.id=id
	this.width=document.getElementById(this.id).width
	this.pos=parseInt(document.getElementById(this.id).style.left)
	this.start_pos=this.pos
	this.timer=null
	this.running=0
	this.delay = 10
	
	this.actn = true
	
	this.start=function(num) {
		if (this.actn == true) {
			this.actn = false
			this.chk_status(num, "zIn") // zIn
		}
		else if (this.actn == false) {
			this.actn = true
			clearTimeout(this.timer)
			this.chk_status(num, "zOut") // zOut
		}
	}
	
	this.chk_status=function(num, d){ // method & its properties, pass div number as argument
		this.dir = d
		if(this.dir == "zOut") {
			this.running = 0
		}
		if(this.dir == "zIn" && this.running == 1) {
			return
		}
		this.running = 1
		this.step=1 // -------------STEP---------------
		window["my_object"+num].animate('my_object'+num)
	}

	this.animate = function(myobject) { // method & its properties, pass object name as argument
		if(this.dir=="zIn") {
			this.width += this.step
			this.pos -= this.step/2
		}
		else {
			this.width -= this.step
			this.pos += this.step/2
		}
		
		this.timer=setTimeout(myobject+".animate('"+myobject+"')", this.delay) //-----------TIMER---------
		
		if(this.dir == "zIn" && this.width > maxWidth - this.step) {
			this.width = maxWidth
			this.running = 0
			clearTimeout(this.timer)
		}
		if(this.dir == "zOut" && this.width <= minWidth + this.step){
			this.width = minWidth
			this.pos = this.start_pos
			this.running = 0
			clearTimeout(this.timer)
		}
		document.getElementById(this.id).style.width = this.width
		document.getElementById(this.id).style.left = document.getElementById(this.id).style.top = this.pos
		//document.getElementById(this.id).style.top = this.pos
	}

	this.stop=function() {
		clearTimeout(this.timer)
	}
}
