Function.prototype.bind=function(object){
  var method=this;
  return function(){
    return method.apply(object,arguments);
  }
}

function ImageConstruct(){
	this.imgId = arguments[0];
	this.divId = arguments[1];
	this.imgOffsetHeight = document.getElementById(this.imgId).offsetHeight;
	this.imgOffsetWidth = document.getElementById(this.imgId).offsetWidth;
	this.cursor = '+';
	this.timer = null;
	this.animationSpeed = 10;
	this.imgStep = 5;
	
	
	if (navigator.userAgent.indexOf ("MSIE 6")!=-1)this.koef = this.imgOffsetWidth / this.imgOffsetHeight;
	
	this.imgHeight = this.imgOffsetHeight;
	this.imgHeightStoper = this.imgOffsetHeight/2;
	this.imgTopPos = 0;
	
	this.divIdStep = document.getElementById(this.divId).offsetWidth / (this.imgHeightStoper / this.imgStep);	
	this.divIdLeftPos = document.getElementById(this.divId).offsetLeft;
	this.divIdLeftPos1 = document.getElementById(this.divId).offsetLeft;
}

ImageConstruct.prototype.start = function (){
	window.clearInterval(this.timer);
	this.timer = null;
	if(arguments[0]!=null){	
		this.cursor = arguments[0];	
		this.timer = window.setInterval(function(){this.move()}.bind(this),this.animationSpeed);
	}	
}

ImageConstruct.prototype.move = function (){
	
	
	if(this.cursor=='+'){
		if((this.imgHeight - this.imgStep)>=this.imgHeightStoper){
			this.imgHeight = this.imgHeight - this.imgStep;
			this.imgTopPos = this.imgTopPos + this.imgStep/2;
			this.divIdLeftPos = this.divIdLeftPos + this.divIdStep;
			document.getElementById(this.imgId).style.height = this.imgHeight+'px';
			if (navigator.userAgent.indexOf ("MSIE 6")!=-1)document.getElementById(this.imgId).style.width = this.imgHeight*this.koef+'px';
			document.getElementById(this.imgId).style.marginTop = Math.round(this.imgTopPos)+'px';
			document.getElementById(this.divId).style.left = this.divIdLeftPos+'px';
		}
		else{
			window.clearInterval(this.timer);
			this.timer = null;
			this.imgTopPos = this.imgOffsetHeight/4;
			document.getElementById(this.divId).style.left = 0+'px';
		}
	}
	else{
		if((this.imgHeight + this.imgStep)<=this.imgOffsetHeight){
			this.imgHeight = this.imgHeight + this.imgStep;
			this.imgTopPos = this.imgTopPos - this.imgStep/2;
			this.divIdLeftPos = this.divIdLeftPos - this.divIdStep;
			document.getElementById(this.imgId).style.height = this.imgHeight+'px';
			if (navigator.userAgent.indexOf ("MSIE 6")!=-1)document.getElementById(this.imgId).style.width = this.imgHeight*this.koef+'px';
			document.getElementById(this.imgId).style.marginTop = Math.round(this.imgTopPos)+'px';
			document.getElementById(this.divId).style.left = this.divIdLeftPos+'px';
		}
		else{
			window.clearInterval(this.timer);
			this.timer = null;
			this.imgTopPos = 0;
			document.getElementById(this.divId).style.left = this.divIdLeftPos1+'px';
		}
	}	
}

function imageCreate(){
	if(document.getElementById(arguments[0]).imageAnimation==null){
		document.getElementById(arguments[0]).imageAnimation = new ImageConstruct(arguments[0],arguments[1]);
	}
	document.getElementById(arguments[0]).imageAnimation.start('+');
}