var _pane;
var introRun = true;

function _init() {
    _pane = new Pane(document.getElementById("pane"));
    _pane._mapw = 700*4;
    _pane._maph = 250*3;
    _pane._winw = 700;
    _pane._winh = 250;
    // no more animation
    return;
    _pane.setTimeout("intro('logo1')",5000);
    _pane.setTimeout("intro('logo2')",10000);
}

function showMenu() {
    document.getElementById("loading").style.visibility="hidden";
    document.getElementById("bottom").style.visibility="visible";
}

function intro(id) {
    if (introRun) {
        _pane.moveToIntro(id);
    }
}

function Pane(obj) {
    this.obj = obj;
    this._mapw;
    this._maph;
    this._winw;
    this._winh;
    this.softX;
    this.softY;
}

Pane.prototype.moveTo = function(id) {
    introRun = false;
    x = parseInt(document.getElementById(id).style.left);
    y = parseInt(document.getElementById(id).style.top);
    this.moveSoftXY(-x,-y);
}

Pane.prototype.moveToIntro = function(id) {
    x = parseInt(document.getElementById(id).style.left);
    y = parseInt(document.getElementById(id).style.top);
    this.moveSoftXY(-x,-y);
}

Pane.prototype.moveXY = function(x,y) {
    this.moveX(x);
    this.moveY(y);
}

Pane.prototype.moveSoftXY = function(x,y) {
    this.softX = new Accel(parseInt(this.obj.style.left),x);
    this.softY = new Accel(parseInt(this.obj.style.top), y);
    this.moveSoft(x,y);
}

Pane.prototype.moveSoft = function(x,y) {
    if (this.softX.more()) {
        this.moveX(this.softX.next());
    }
    if (this.softY.more()) {
        this.moveY(this.softY.next());
    }
    if (this.softY.more() || this.softX.more()) {
        this.moveTimeout = this.setTimeout("this.moveSoft("+x+","+y+")", 10);
    } else {
        this.moveTimeout = null;
    }
}

Pane.prototype.moveY = function(x) {
    this.obj.style.top = x + "px";
    return;
}

Pane.prototype.moveX = function(x) {
    this.obj.style.left = x + "px";
    return;
}

function Ss(x) {
    this.x = x;
    this.t = 0;
}
Ss.prototype.reset = function () {
    this.t = 0;
}
Ss.prototype.next = function () {
    this.t++;
    var r = Math.PI * (this.t / this.x - 0.5);
    return (Math.sin(r) + 1)/2;
}
Ss.prototype.more=function() {
    return this.t<this.x;
}
Ss.prototype.stop=function() {
    this.t = this.x;
}

function Accel(from,to) {
    this.from = from;
    this.to = to;
    this.cur = from;
}
Accel.prototype.reset = function () {
    this.cur = 0;
}
Accel.prototype.more=function() {
    return (this.cur!=this.to);
}
Accel.prototype.stop=function() {
    this.cur = this.to;
}
Accel.prototype.next = function () {
    if (this.from<this.to) {
        if (Math.abs(this.cur-this.to) < 100) {
            this.cur+=1+Math.abs(this.cur-this.to)/10;
        } else {
            this.cur+=20;
        }
        if (this.cur>this.to)
        this.cur = this.to;
    } else {
        if (Math.abs(this.cur-this.to) < 100) {
            this.cur-=1+Math.abs(this.cur-this.to)/10;
        } else {
            this.cur-=20;
        }
        if (this.cur<this.to)
        this.cur = this.to;
    }
    return this.cur;
}


var _tc = 0;
Object.prototype.setTimeout = function (ex, ti) {
    var un = "_t" + _tc++;
    eval(un + " = this;");
    return window.setTimeout(un + '._eval("' + ex.jsEsc() + '");' + un + " = null;", ti);
}

Object.prototype._eval = function (input) {
    eval(input);
}

String.prototype.xmlEsc = function () {
    return this.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
}

String.prototype.jsEsc = function () {
    return this.replace(/\\/g, "\\\\").replace(/\'/g, '\\"').xmlEsc();
}
