function getstyle(elem, prop) {
		if(document.defaultView)
		{
			return document.defaultView.getComputedStyle(elem, null).getPropertyValue(prop);
		}
		else if(elem.currentStyle)
		{
			var prop = prop.replace(/-(\w)/gi, function($0,$1)
			{
				//return $0.charAt($0.length - 1).toUpperCase();
				return $1.toUpperCase();
			});
			return elem.currentStyle[prop];
		}
		else return null;
	}

function fun(x,n) {
    if (x>n) return 0;
    else
    return 1;
}

function getsize(size) {
var re =[];

if (size=="auto") {
re[0] = 100;
re[1] = "%";
}
else {
re[0] = parseInt(size);
re[1] = size.replace(/\d+/,"");
}

return re;
}

function $(id) {
var $ =  (typeof id  =="string") ? document.getElementById(id) : id;
$.start = {};

$.resizex=function(settings,callbk) {

 var _this = this;
    var width = getstyle(_this,"width");
    var height =  getstyle(_this,"height");

    _this.start.width = getsize(width)[0];
    _this.widthunit = getsize(width)[1];

    _this.start.height = getsize(height)[0];
    _this.heightunit = getsize(height)[1];

    if (settings.to.width == _this.start.width&&settings.to.height == _this.start.height) {
        return;
    }
    else if (settings.to.width == _this.start.width) { // x
      var pos = "height";
    }

     else if (settings.to.height == _this.start.height) { // x

       var pos = "width";
    }


   (function(pos) {

        var descend = (settings.to[pos] > _this.start[pos]) ? false : true;
        var s = Math.min(_this.start[pos],settings.to[pos]);
        var d = Math.max(_this.start[pos],settings.to[pos]);
        _this.speed = (d -s)/settings.delay;
           // document.getElementById('demo').innerHTML = "";
            for (i = s; i <= d; i++) {
              var delay = (descend==true) ? (d-i)*settings.delay/(d - s) : (i-s)*settings.delay/(d - s);

              (function(j) {
                    setTimeout(function() {
                         _this.style[pos] = j+"px";
                        //document.getElementById('div_compareunsecured').style.height = d-j+"px";
                         if (descend==false&&j==s){
                            _this.style.display ="block";
                            if (callbk!=undefined) {callbk.call(_this);}
                         }
                         if (descend==true&&j==s){
                            if (s==0) _this.style.display ="none";
                            if (callbk!=undefined) {callbk.call(_this);}
                         }

                          },delay);
                })(i);
            }
   })(pos);
};

$.resize=function(settings,callbk) {

 var _this = this;
    var width = getstyle(_this,"width");
    var height =  getstyle(_this,"height");

    _this.start.width = getsize(width)[0];
    _this.widthunit = getsize(width)[1];

    _this.start.height = getsize(height)[0];
    _this.heightunit = getsize(height)[1];

    var st = _this.start;
    if (_this.kk) {
       settings.to.height = parseInt(_this.kk*settings.to.width);
    }
    if (settings.to.width == _this.start.width&&settings.to.height == _this.start.height) {
        return;
    }

    else if (settings.to.width == _this.start.width) { // y
        var descend = (settings.to.height>_this.start.height) ? false : true;
        var s = Math.min(_this.start.height,settings.to.height);
        var d = Math.max(_this.start.height,settings.to.height);
        _this.speed = (d -s)/settings.delay;
            for (i = s; i <= d; i++) {
              var delay = (descend==true) ? (d-i)*settings.delay/(d - s) : (i-s)*settings.delay/(d - s);

              (function(j) {
                    setTimeout(function() {
                         _this.style.height = j+_this.heightunit;
                         if (descend==false&&j==s){
                            _this.style.display ="block";
                            if (callbk!=undefined) {callbk.call(_this);}
                         }
                         if (descend==true&&j==s){
                            if (s==0) _this.style.display ="none";
                            if (callbk!=undefined) {callbk.call(_this);}
                         }

                          },delay);
                })(i);
            }
    }

    else if (settings.to.height == _this.start.height) { // x

        var descend = (settings.to.width>_this.start.width) ? false : true;
        var s = Math.min(_this.start.width,settings.to.width);
        var d = Math.max(_this.start.width,settings.to.width);
        _this.speed = (d -s)/settings.delay;
            for (i = s; i <= d; i++) {
              var delay = (descend==true) ? (d-i)*settings.delay/(d - s) : (i-s)*settings.delay/(d - s);

              (function(j) {
                    setTimeout(function() {
                         _this.style.width = j+_this.widthunit;
                        if (descend==false&&j==s){
                            _this.style.display ="block";
                            if (callbk!=undefined) {callbk.call(_this);}
                         }
                         if (descend==true&&j==s){
                            if (s==0) _this.style.display ="none";
                            if (callbk!=undefined) {callbk.call(_this);}
                         }
                          },delay);
                })(i);
            }
    }

    else {   // x y

        var descend = (settings.to.width>_this.start.width) ? false : true;
        var s = Math.min(_this.start.width,settings.to.width);
        var d = Math.max(_this.start.width,settings.to.width);
        _this.speed = (d -s)/settings.delay;

       if (!_this.kk) _this.kk  = _this.start.height/_this.start.width;

            for (i = s; i <= d; i++) {
              var delay = (descend==true) ? (d-i)*settings.delay/(d - s) : (i-s)*settings.delay/(d - s);

              (function(j) {
                    setTimeout(function() {
                         _this.style.width = j+_this.widthunit;
                          _this.style.height = _this.kk*j+_this.heightunit;
                        if (descend==false&&j==s){
                            _this.style.display ="block";
                            if (callbk!=undefined) {callbk.call(_this);}
                         }
                         if (descend==true&&j==s){
                            if (s==0) _this.style.display ="none";
                            if (callbk!=undefined) {callbk.call(_this);}
                         }
                          },delay);
                })(i);
            }
    }
};

$.bounce= function(settings,bounce,callbk) {
    var left = getstyle(this,"left");
    var top =  getstyle(this,"top");
    this.start.left = (left=="auto") ? 0 : parseInt(left);
    this.start.top = (top=="auto") ? 0 : parseInt(top);

    if (settings.to.top == this.start.top) {
       var pos = "left";
    }
    else if (settings.to.left == this.start.left) {
       var pos = "top";
    }
   var _this = this;

   (function(pos) {
   var target = settings.to[pos];var b = bounce.length;var n = bounce.no;
   if (parseInt(_this.style[pos])==target) return;

   _this.move(settings,function() {
       var fh = (_this.start[pos] - settings.to[pos])/Math.abs(_this.start[pos] - settings.to[pos]);
       settings.to[pos] = target+b*fh*fun(1,n);
       settings.delay = Math.abs((parseInt(_this.style[pos]) - settings.to[pos]))/_this.speed*1.2;
       if (n<2) return;
       _this.move(settings,function() {
            var fh = (_this.start[pos] - settings.to[pos])/Math.abs(_this.start[pos] - settings.to[pos]);
            settings.to[pos] = parseInt(_this.style[pos])+b*fh*0.5*fun(2,n);
            if (n<3) return;
            settings.delay = Math.abs(parseInt(_this.style[pos]) - settings.to[pos])/_this.speed*1.5;
            _this.move(settings,function(){
                 if (n<4) return;
                 settings.to[pos] = target;
                 settings.delay = Math.abs(parseInt(_this.style[pos]) - settings.to[pos])/_this.speed*2;
                 _this.move(settings);
            });
       });
   });

   })(pos)

};

$.move = function(settings,callbk) {
    var _this = this;
    var left = getstyle(_this,"left");
    var top =  getstyle(_this,"top");
    _this.start.left = (left=="auto") ? 0 : parseInt(left);
    _this.start.top = (top=="auto") ? 0 : parseInt(top);

    if (settings.to.top == _this.start.top) { // x
        var descend = (settings.to.left>_this.start.left) ? false : true;
        var s = Math.min(_this.start.left,settings.to.left);
        var d = Math.max(_this.start.left,settings.to.left);
        _this.speed = (d -s)/settings.delay;

            for (i = s; i <= d; i++) {
              (function(j) {

				    var delay = (descend==true) ? (d-j)*settings.delay/(d - s) : (j-s)*settings.delay/(d - s);
                    setTimeout(function() {
                         _this.style.left = j+"px";

                          if (descend==false&&j==d&&callbk!=undefined) {callbk.call(_this);}
                          else if (descend==true&&callbk!=undefined&&j==s) {callbk.call(_this);}

                          },delay);
                })(i);
            }

    }

    else if (settings.to.left == _this.start.left) {  // y
        var descend = (settings.to.top>_this.start.top) ? false : true;
        var s = Math.min(_this.start.top,settings.to.top);
        var d = Math.max(_this.start.top,settings.to.top);
         _this.speed = (d -s)/settings.delay;
        for (i = s; i <= d; i++) {
          (function(j) {
                var delay = (descend==true) ? (d-j)*settings.delay/(d - s) : (j-s)*settings.delay/(d - s);
                setTimeout(function() {

                      _this.style.top = j+"px";
                      if (descend==false&&j==d&&callbk!=undefined) {callbk.call(_this);}
                      else if (descend==true&&callbk!=undefined&&j==s) {callbk.call(_this);}
                      },delay);

            })(i);

        }

    }

    else {

        var descend = (settings.to.left>_this.start.left) ? false : true;
        var s = Math.min(_this.start.left,settings.to.left);
        var d = Math.max(_this.start.left,settings.to.left);
        var k = (settings.to.top - _this.start.top)/(settings.to.left - _this.start.left);
        var b = (descend==false) ? _this.start.top :settings.to.top;
            for (i = s; i <= d; i++) {
              (function(j) {
                    var delay = (descend==true) ? (d-j)*settings.delay/(d - s) : (j-s)*settings.delay/(d - s);
                    setTimeout(function() {
                         _this.style.left = j+"px";
                          _this.style.top = k*j+b+"px";
                          if (descend==false&&j==d&&callbk!=undefined) {callbk.call(_this);}
                          else if (descend==true&&callbk!=undefined&&j==s) {callbk.call(_this);}
                          },delay);

                })(i);

            }
    }

};

return $;
}

