
//Prototype
String.prototype.toInt = function(n) {
    return parseInt(this, n || (n = 10));
};
function $extend(a) {
    for (var c = 1; c < arguments.length; c++) {
        var d = arguments[c];
        for (var f in d) if (d.hasOwnProperty(f)) a[f] = d[f]
    }
    return a
}

if (typeof ($) == 'undefined') {
    var $ = function(fctId) { return document.getElementById(fctId); };
}
function $loadJs(d, f, g, i) {
    var j = arguments.callee;
    var k = j.queue || (j.queue = {});
    var m = null;
    if (!(d in k)) {
        k[d] = [];
        if (g) {
            m = n();
            k[d].push(g)
        }
    } else {
        if (g) {
            if (k[d]) {
                m = n();
                k[d].push(g)
            } else {
                g()
            }
        }
        return
    }
    var o = document.createElement('script');
    o.type = 'text/javascript';
    o.charset = f;
    o.onload = o.onreadystatechange = function() {
        if (o.readyState && o.readyState != 'loaded' && o.readyState != 'complete') return;
        if (m) clearTimeout(m);
        o.onreadystatechange = o.onload = null;
        while (k[d].length) k[d].shift()();
        k[d] = null
    };
    o.src = d;
    document.getElementsByTagName('head')[0].appendChild(o);
    function n() {
        var a = k[d];
        var c = a.length;
        if (g && i) {
            return setTimeout(function(){if(g(true) !== true)a.splice(c, 1)},i)
        }
    }
}


//Components
var MadCat = function(fn) {
    this.events = {};
    if (fn) fn.apply(this);
};
$extend(MadCat.prototype, {
    set: function() { },
    get: function() { return null },
    evt: function(key, fn) { this.events[key] = fn },
    init: function() { }
});


var EMap = new MadCat(function() {
    var me = this,
        map = {},
        markers = this.markers = [];


    this.getMap = function(callback) {
        if (me.isLoaded) return callback();
        $loadJs('http://ditu.google.cn/maps?file=googleapi&key='+MapKey+'&async=2&hl=zh_cn', 'utf-8', function() {
            var timer = setInterval(function() {
                if (typeof GMap2 == 'undefined') return;
                clearInterval(timer);
                if (GBrowserIsCompatible()) {
                    callback();
                    me.isLoaded = true;
                }
                else me.state = 'Failure!!!';
            }, 20);
        })
    };

    this.init = function(query, result) {
        this.state = 'init';
        this.getMap(function() {
            map = me.map = new GMap2($('htl_map'));
            map.addControl(new GLargeMapControl());
            me.state = 'ok';
        });

    };

});
/**/


