﻿function crawler(id)
{
    var that = this;
    this.id = id;
    this.speed = 2;
    this.interval = null;
    this.position = 0;
    this.ele = $(that.id);
    this.animate = function(){
        that.interval = setInterval(
            function(){
                that.ele.style.top = that.position + "px";
                if(parseInt(that.ele.style.top)<-parseInt(that.ele.offsetHeight))
                {that.ele.style.top = "100px";}
                that.position = parseInt(that.ele.style.top)-that.speed;
            },100)
    };
    this.reset = function(){
        clearInterval(that.interval);
        that.ele.style.top = "0px";
    };
    this.init = function(){
        $(that.ele.parentNode);
        that.ele.parentNode.listenOnEvent("mouseover",that.reset);
        that.ele.parentNode.listenOnEvent("mouseout",that.animate);
        that.ele.style.top = parseInt(that.ele.offsetHeight) + "px";
        that.animate();
    }
}