/** Copyright (C) 2009  Simon ANDRE
 *
 *   This program is free software: you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation, either version 3 of the License, or
 *    (at your option) any later version.
 *
 *    This program is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */


/** Ce framework est fait par moi même afin de bien comprendre les mecanisme 
 * 	des autres framework javascript. Si vous avez des amelioration, des idées, des recommandations n'hesitez
 * 	à me les faire parvenir à elsilent.hunter[at]gmail.com
 * merçi
 */

/*
 * resizeDiv est une fonction de redimenssionement d'objet html div
 * il faut que width et height soit aussi defeni en px
 * Les argument quel prend sont
 * id: reference vers la div que l'on veut bouger
 * targetW et targetH taille de la div
 * vitess rapidite du mouvenent
 * amort un chiffre en virgule flotante entre 0 et 2
 * si >1 acceleration
 * si <1 decceleration
 * si =1 mouvement lineaire
 */
var resizeDiv = function(id,targetW,targetH,vitess,amort){
	/*#FIXME verifier si la div est en absolu et si les coordonne width et height sont bien defini*/
	//nom de la div qui bouge
	this.div = id;
	//this.id = id;
	//But du trajet
	this.vitess = vitess;
	this.targetW = parseInt(targetW);
	this.targetH = parseInt(targetH);
	this.amort = amort;
	//recuperation dom de la div
	//Recuperation des coordonnes de la div
	this.originW = parseInt(this.div.style.width.split("px",1));
	this.originH = parseInt(this.div.style.height.split("px",1));
	this.goW = this.originW;
	this.goH =this.originH;
	this.doResize(); /*preparation du redimensionement*/
};
resizeDiv.prototype.ChangeW = function()
{
	if(this.stepW > 0)
	{
		if(this.goW < this.targetW )
		{
			this.goW += this.stepW;
			
			this.div.style.width = this.goW + "px";
			
			return true;
		}else
		{
			return false;
		}
		
	}else
	{
		if(this.goW > this.targetW )
		{
			this.goW += this.stepW;
			
			this.div.style.width = this.goW + "px";
			
			return true;
		}else
		{
			return false;
		}
	}
};
resizeDiv.prototype.ChangeH = function()
{
	if(this.stepH > 0)
	{
		if(this.goH < this.targetH )
		{
			this.goH += this.stepH;
			this.div.style.height = this.goH + "px";
			return true;
		}else
		{
			return false;
		}
	}
	else
	{
		if(this.goH > this.targetH )
		{
			this.goH += this.stepH;
			this.div.style.height = this.goH + "px";
			return true;
		}else
		{
			return false;
		}
	}
};
resizeDiv.prototype.action = function (){
	this.stepW = this.stepW * this.amort;
	this.stepH = this.stepH * this.amort;
	var w = this.ChangeW();
	var h = this.ChangeH();
	if( !h && !w){return false;}else{return true;}
};
resizeDiv.prototype.doResize = function()
{
    // Check if reference to menu was lost due
    // to ajax manipulations  #FIXME 
   /* if (!this.div)
    {
        div = $(id);
    }*/
    this.stepW = (this.targetW - this.originW)/ this.vitess ;
    this.stepH = (this.targetH - this.originH )/ this.vitess;
};
resizeDiv.prototype.init = function()
{
	this.originW = parseInt(this.div.style.width.split("px",1));
	this.originH = parseInt(this.div.style.height.split("px",1));
	this.goW = this.originW;
	this.goH =this.originH;
	this.doResize(); /*preparation du redimensionement*/
};




