// JavaScript Document
if(typeof(SuperClass)=='function'){Resize.prototype = new SuperClass; /* héritage des méthodes */}

function Resize(element){
	if(typeof(SuperClass)!='function'){alert("fichier SuperClass.js manquant!");}
	else{
		/* héritage */
		this.classMere = SuperClass;  // classe parente
		this.classMere(); // appel du super constructeur
		delete this.classMere; // inutile de garder la classe parente	
		
		this.element=this.returnElement(element);
		this.frequence=40; // en millisecondes : 1000 ms/25(nb img par seconde) = 40 ms
	}
}


Resize.prototype.getWidth = function(){
	return parseInt(this.element.offsetWidth);
}
Resize.prototype.getHeight = function(){
	return parseInt(this.element.offsetHeight);
}
Resize.prototype.getCSSWidth = function(){
	var width=this.getCssStyleValue(this.element,"width");
	
	if(width=='auto' || typeof(width)=="undefined" || this.trim(width)=="" || width==null){
		width=this.getWidth()-this.widthDifference();
	}
	else{width=this.explode("px", width)[0];}
	return parseInt(width);
}
Resize.prototype.getCSSHeight = function(){
	var height=this.getCssStyleValue(this.element,"height");
	if(height=='auto' || typeof(height)=="undefined" || this.trim(height)=="" || height==null){
		height=this.getHeight()-this.heightDifference();
	}
	else{height=this.explode("px", height)[0];}
	return parseInt(height);
}

Resize.prototype.widthDifference = function(){
	width=this.getWidth();
	var tempNode=this.element.cloneNode(true);
	tempNode.style.visibility="hidden";
	tempNode.style.position="absolute";
	document.body.appendChild(tempNode);
	tempNode.style.width=width+'px';
	var newWidth=tempNode.offsetWidth;
	document.body.removeChild(tempNode);
	return (newWidth-width);
}
Resize.prototype.heightDifference = function(){
	height=this.getHeight();
	var tempNode=this.element.cloneNode(true);
	tempNode.style.visibility="hidden";
	tempNode.style.position="absolute";
	document.body.appendChild(tempNode);
	tempNode.style.height=height+'px';
	var newHeight=tempNode.offsetHeight;
	document.body.removeChild(tempNode);
	return (newHeight-height);
}

Resize.prototype.setWidth = function (w){
	this.element.style.width=w+"px";
}
Resize.prototype.setHeight = function (h){
	this.element.style.height=h+"px";
}


Resize.prototype.resizeTo = function(w_h, duree, callback){
	this.stop();
	var w=w_h[0];
	var h=w_h[1];

	var diff_w=w-this.getWidth();
	var diff_h=h-this.getHeight();
	
	
	pas_w=this.calculPas(duree,diff_w,this.frequence);
	pas_h=this.calculPas(duree,diff_h,this.frequence);
	
	//alert(diff_w+' '+diff_h+' '+pas_w+' '+pas_h);
	
	if(isNaN(w)==false){this.resize(w,0,pas_w,callback);}
	if(isNaN(w)==false && isNaN(h)==false){callback=function(){};}	
	if(isNaN(h)==false){this.resize(h,1,pas_h,callback);}
}

Resize.prototype.resize = function(finalSize,type,pas,callback){
	var size, cssSize;
	if(type==0){size=this.getWidth(); cssSize=this.getCSSWidth();}
	else if(type==1){size=this.getHeight(); cssSize=this.getCSSHeight();}
	cssSize+=pas;
	
	if( ((size+pas)<finalSize && pas>0) || ((size+pas)>finalSize && pas<0) && cssSize>0){
		if(type==0){this.setWidth(cssSize);}
		else if(type==1){this.setHeight(cssSize);}
		var localThis = this;
		this.timeout[this.timeout.length]=window.setTimeout(function(){localThis.resize(finalSize,type,pas,callback)}, this.frequence);
	}
	else{
		if(type==0){this.setWidth((finalSize-this.widthDifference()<0)?0:finalSize-this.widthDifference());}
		else if(type==1){this.setHeight((finalSize-this.heightDifference()<0)?0:finalSize-this.heightDifference());}
		
		this.stop();
		
		if(callback){callback();}
	}	
}

Resize.prototype.stop=function(){
	this.clearAllTimeout();
}
// JavaScript Document