
var moving = new Array( );

/**
 * Animate and resize html elements.
 *
 * @author Velvet
 * @version 0.3
 * @since 0.2
 *
 */

/**
 * Define class
 * 
 * @param string id target html element id tag
 * @returns void
 *
 */
function AnyMany( id )
{
    this.id         = id;
    this.animObj    = document.getElementById( this.id );
    this.animObjCSS = this.animObj.style;
    this.tweenObj   = 'tween_' + this.id;
    this.animation  = 'animation_' + this.id;
}

/**
 * --------------------------------------------------------------------------- *
 * FOLLOWING METHODS CAN BE USED TO SET ALL NECESSARY PARAMETERS FOR ANIMATION *
 * --------------------------------------------------------------------------- *
 */

/**
 * Set element display property to none
 *
 */
AnyMany.prototype.setHidden = function( )
{
    this.animObjCSS.display = 'none';
}

/**
 * Set element display property to visible
 *
 */
AnyMany.prototype.setVisible = function( )
{
    thid.animObjCSS.display = 'visible';
}

/**
 * Define x,y,w,h for animation start
 *
 */
AnyMany.prototype.defineInitValues = function( )
{
    this.initW = this.animObj.offsetWidth;
    this.initH = this.animObj.offsetHeight;
    this.initX = this.animObj.offsetLeft;
    this.initY = this.animObj.offsetTop;
}

/**
 * Set starting w,h,x,y for switch
 *
 * @param int W, H, X, Y
 * 
 */
AnyMany.prototype.setStartWHXY = function( W, H, X, Y )
{
    this.startW = W;
    this.startH = H;
    this.startX = X;
    this.startY = Y;
}

/**
 * Set animation speed, if this parameter is not defined, animation will not be used
 *
 * @param int speed distance that will be added to parameter after each loop
 *
 */
AnyMany.prototype.setSpeed = function( speed )
{
    this.speed = speed;
}

/**
 * Get width of target element
 *
 * @returns int width
 * 
 */
AnyMany.prototype.getW = function( )
{
    return this.animObj.offsetWidth;
}

/**
 * Get height of target element
 *
 * @returns int height
 *
 */
AnyMany.prototype.getH = function( )
{
    return this.animObj.offsetHeight;
}

/**
 * Get x of target element
 *
 * @returns int x
 *
 */
AnyMany.prototype.getX = function( )
{
    return this.animObj.offsetLeft;
}

/**
 * Get y of target element
 *
 * @returns int y
 *
 */
AnyMany.prototype.getY = function( )
{
    return this.animObj.offsetTop;
}

/**
 * Set width of target element
 *
 * @param int width
 *
 */
AnyMany.prototype.setW = function( width )
{
    this.animObjCSS.width = width + 'px';
}

/**
 * Set height of target element
 *
 * @param int height
 *
 */
AnyMany.prototype.setH = function( height )
{
    this.animObjCSS.height = height + 'px';
}

/**
 * ----------------------------------- *
 * SET TARGET PARAMETERS FOR ANIMATION *
 * ----------------------------------- *
 */

/**
 * Set object final w, h, x, y
 *
 * @param int W, H, X, Y
 *
 */
AnyMany.prototype.setFinalWHXY = function( W, H, X, Y )
{
    this.finalW = W;
    this.finalH = H;
    this.finalX = X;
    this.finalY = Y;
}

/**
 * Set direction for animation
 *
 * @param boolean left, top, right, bottom 
 * 
 */
AnyMany.prototype.setDirection = function( left, top, right, bottom )
{
    this.left   = left;
    this.top    = top;
    this.right  = right;
    this.bottom = bottom;
}

/**
 * --------------------------------------------------------------- *
 * USE FOLLOWING METHODS AFTER ALL REQUIRED PARAMETERS ARE DEFINED *
 * --------------------------------------------------------------- *
 */

/**
 * Define values to add ( x,y,w,h )
 *
 */
AnyMany.prototype.animate = function( )
{
    if( moving[this.id] )
    {
        return;
    }
    this.controlIfAnimationSpeed( );
    this.controlIfAnimationSpeedSigned( );
    moving[this.id] = true;
    this.execute( );
}

AnyMany.prototype.controlIfAnimationSpeedSigned = function( )
{
    if( this.bottom )
    {
        if( this.initH < this.finalH )
        {
            this._H = this.speed;
        }
        else
        {
            this._H = - ( this.speed );
        }
    }
}

AnyMany.prototype.controlIfAnimationSpeed = function( )
{
    if( !this._W )
    {
        this._W = 0;
    }
    if( !this._H )
    {
        this._H = 0;
    }
    if( !this._X )
    {
        this._X = 0;
    }
    if( !this._Y )
    {
        this._Y = 0;
    }
}

/**
 * Make switch for animations, that will react on second event
 *
 */
AnyMany.prototype.switchAnim = function( )
{
    if( this.getH( ) > this.startH )
    {
        this.finalH = this.startH;
        this.stateH = 'closed';
    }
    else
    {
        this.stateH = 'open';
    }
}

AnyMany.prototype.getStateH = function( )
{
    return this.stateH;
}

/**
 * Function that triggers animation itself
 *
 */
AnyMany.prototype.execute = function( )
{
    var self = this;
    
    self.animation = function( )
    {
        self.currH = self.getH( );
        self.currW = self.getW( );
        self.nextH = self.currH + self._H;
        self.nextW = self.currW + self._W;
        self.setH( self.nextH );
        //self.setW( self.nextW );

        if( self.currH == self.finalH )
        {
            moving[self.id] = false;			
            clearInterval( self.tweenObj );
			set_div();
        }
    }
    self.tweenObj = setInterval( self.animation, 5 );
}


function set_div(  )
{
	/*if( document.body.clientHeight ) {
		if( document.body.clientHeight > document.getElementById('cw').offsetHeight ) {
			var top = document.body.clientHeight + 20;
		} else if ( document.body.clientHeight < document.getElementById('cw').offsetHeight ){
			var top = document.getElementById('cw').offsetHeight + 20;
		} 
		document.getElementById('site_footer').style.position = 'absolute';
		document.getElementById('site_footer').style.top = ( top ) + 'px';
	} */
}



