ika-core.org Ikariam Tools

Next generation Ikariam search and addons script

目前为 2015-01-11 提交的版本,查看 最新版本

// ==UserScript==
// @name	ika-core.org Ikariam Tools
// @namespace	ika-core
// @description	Next generation Ikariam search and addons script
// @license     Creative Commons Attribution License
// $icon	http://www.ika-core.org/git/icon48.png
// @include	http://s*.ikariam.gameforge.com/*
// @include	http://m*.ikariam.gameforge.com/*
// @exclude http://support.*.ikariam.gameforge.com/*
// @run-at	document-start
// @require	https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js
// @resource	css http://www.ika-core.org/git/ika-core.css
// @resource	lic http://www.ika-core.org/git/licencemsg.txt
// @version	1.8
// @grant	GM_addStyle
// @grant	GM_getValue
// @grant	GM_setValue
// @grant	GM_getResourceText
// @grant	GM_openInTab
// @grant	GM_xmlhttpRequest
// ==/UserScript==
this.$ = this.jQuery = jQuery.noConflict(true);
var nlang = (navigator.language) ? navigator.language : navigator.userLanguage;
var ufo = unsafeWindow, game, log, ikariam, screen, server,player,ally,selectedcity,island,islandx,islandy,realHour,nmb,resman,worlddraw,worldmap,transload=false,dbg=localStorage.getItem('debug'),lang,hours=36e5,minutes=60000,seconds=1000,COMPRESS=true;
var goods={0:'<img src="skin/resources/icon_wood.png"/>',1:'<img src="skin/resources/icon_wine.png"/>',2:'<img src="skin/resources/icon_marble.png"/>',3:'<img src="skin/resources/icon_glass.png"/>',4:'<img src="skin/resources/icon_sulfur.png"/>'};
var buildings=["townHall","shipyard","port","glassblowing","branchOffice","barracks","academy","warehouse","palace","palaceColony","tavern","museum","workshop","wall","dump","vineyard","pirateFortress","safehouse","embassy","stonemason","carpentering","forester","winegrower","alchemist","optician","fireworker","architect","temple","blackMarket","marineChartArchive"];
String.prototype.strip=function(){
	return this.replace(/<.*?[^>]>/g,'');
};
String.prototype.digits = function(){
	var d=this.replace(/\D/g, '');
	if (d=='') return 0;
	return d;
};
String.prototype.toJSON = function(){
	try {
        return JSON.parse(str);
    } catch (e) {		
        return false;
    }
};
if (dbg=='y'){
	var deb=ufo.console.log.bind(console);
}else { deb=function(){};}
exportFunction(parser, unsafeWindow.console, {defineAs: "log"});
document.addEventListener('beforescriptexecute', function(e) {
	if (e.target.innerHTML.search(/console\s=/) != -1 ) {
		e.stopPropagation();
		e.preventDefault();		
		window.removeEventListener(e.type, arguments.callee, true);
	}}, true);
document.onreadystatechange = function() {
	if (document.readyState == "complete") {		
		main();
		GM_addStyle( GM_getResourceText('css'));
	}
};
function toJSON(str) {    
	try {
        return JSON.parse(str);
    } catch (e) {		
        return false;
    }
}
var LZString = {
    // private property
    _keyStr: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
    _f: String.fromCharCode,
    compressToBase64: function(input) {
        if (input == null) return "";
        var output = "";
        var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
        var i = 0;
        input = LZString.compress(input);
        while (i < input.length * 2) {
            if (i % 2 == 0) {
                chr1 = input.charCodeAt(i / 2) >> 8;
                chr2 = input.charCodeAt(i / 2) & 255;
                if (i / 2 + 1 < input.length)
                    chr3 = input.charCodeAt(i / 2 + 1) >> 8;
                else
                    chr3 = NaN;
            } else {
                chr1 = input.charCodeAt((i - 1) / 2) & 255;
                if ((i + 1) / 2 < input.length) {
                    chr2 = input.charCodeAt((i + 1) / 2) >> 8;
                    chr3 = input.charCodeAt((i + 1) / 2) & 255;
                } else
                    chr2 = chr3 = NaN;
            }
            i += 3;
            enc1 = chr1 >> 2;
            enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
            enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
            enc4 = chr3 & 63;
            if (isNaN(chr2)) {
                enc3 = enc4 = 64;
            } else if (isNaN(chr3)) {
                enc4 = 64;
            }
            output = output +
                LZString._keyStr.charAt(enc1) + LZString._keyStr.charAt(enc2) +
                LZString._keyStr.charAt(enc3) + LZString._keyStr.charAt(enc4);
        }
        return output;
    },
    decompressFromBase64: function(input) {
        if (input == null) return "";
        var output = "",
            ol = 0,
            output_,
            chr1, chr2, chr3,
            enc1, enc2, enc3, enc4,
            i = 0,
            f = LZString._f;
        input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
        while (i < input.length) {
            enc1 = LZString._keyStr.indexOf(input.charAt(i++));
            enc2 = LZString._keyStr.indexOf(input.charAt(i++));
            enc3 = LZString._keyStr.indexOf(input.charAt(i++));
            enc4 = LZString._keyStr.indexOf(input.charAt(i++));
            chr1 = (enc1 << 2) | (enc2 >> 4);
            chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
            chr3 = ((enc3 & 3) << 6) | enc4;
            if (ol % 2 == 0) {
                output_ = chr1 << 8;
                if (enc3 != 64) {
                    output += f(output_ | chr2);
                }
                if (enc4 != 64) {
                    output_ = chr3 << 8;
                }
            } else {
                output = output + f(output_ | chr1);
                if (enc3 != 64) {
                    output_ = chr2 << 8;
                }
                if (enc4 != 64) {
                    output += f(output_ | chr3);
                }
            }
            ol += 3;
        }
        return LZString.decompress(output);
    },
    compressToUTF16: function(input) {
        if (input == null) return "";
        var output = "",
            i, c,
            current,
            status = 0,
            f = LZString._f;
        input = LZString.compress(input);
        for (i = 0; i < input.length; i++) {
            c = input.charCodeAt(i);
            switch (status++) {
                case 0:
                    output += f((c >> 1) + 32);
                    current = (c & 1) << 14;
                    break;
                case 1:
                    output += f((current + (c >> 2)) + 32);
                    current = (c & 3) << 13;
                    break;
                case 2:
                    output += f((current + (c >> 3)) + 32);
                    current = (c & 7) << 12;
                    break;
                case 3:
                    output += f((current + (c >> 4)) + 32);
                    current = (c & 15) << 11;
                    break;
                case 4:
                    output += f((current + (c >> 5)) + 32);
                    current = (c & 31) << 10;
                    break;
                case 5:
                    output += f((current + (c >> 6)) + 32);
                    current = (c & 63) << 9;
                    break;
                case 6:
                    output += f((current + (c >> 7)) + 32);
                    current = (c & 127) << 8;
                    break;
                case 7:
                    output += f((current + (c >> 8)) + 32);
                    current = (c & 255) << 7;
                    break;
                case 8:
                    output += f((current + (c >> 9)) + 32);
                    current = (c & 511) << 6;
                    break;
                case 9:
                    output += f((current + (c >> 10)) + 32);
                    current = (c & 1023) << 5;
                    break;
                case 10:
                    output += f((current + (c >> 11)) + 32);
                    current = (c & 2047) << 4;
                    break;
                case 11:
                    output += f((current + (c >> 12)) + 32);
                    current = (c & 4095) << 3;
                    break;
                case 12:
                    output += f((current + (c >> 13)) + 32);
                    current = (c & 8191) << 2;
                    break;
                case 13:
                    output += f((current + (c >> 14)) + 32);
                    current = (c & 16383) << 1;
                    break;
                case 14:
                    output += f((current + (c >> 15)) + 32, (c & 32767) + 32);
                    status = 0;
                    break;
            }
        }
        return output + f(current + 32);
    },
    decompressFromUTF16: function(input) {
        if (input == null) return "";
        var output = "",
            current, c,
            status = 0,
            i = 0,
            f = LZString._f;
        while (i < input.length) {
            c = input.charCodeAt(i) - 32;
            switch (status++) {
                case 0:
                    current = c << 1;
                    break;
                case 1:
                    output += f(current | (c >> 14));
                    current = (c & 16383) << 2;
                    break;
                case 2:
                    output += f(current | (c >> 13));
                    current = (c & 8191) << 3;
                    break;
                case 3:
                    output += f(current | (c >> 12));
                    current = (c & 4095) << 4;
                    break;
                case 4:
                    output += f(current | (c >> 11));
                    current = (c & 2047) << 5;
                    break;
                case 5:
                    output += f(current | (c >> 10));
                    current = (c & 1023) << 6;
                    break;
                case 6:
                    output += f(current | (c >> 9));
                    current = (c & 511) << 7;
                    break;
                case 7:
                    output += f(current | (c >> 8));
                    current = (c & 255) << 8;
                    break;
                case 8:
                    output += f(current | (c >> 7));
                    current = (c & 127) << 9;
                    break;
                case 9:
                    output += f(current | (c >> 6));
                    current = (c & 63) << 10;
                    break;
                case 10:
                    output += f(current | (c >> 5));
                    current = (c & 31) << 11;
                    break;
                case 11:
                    output += f(current | (c >> 4));
                    current = (c & 15) << 12;
                    break;
                case 12:
                    output += f(current | (c >> 3));
                    current = (c & 7) << 13;
                    break;
                case 13:
                    output += f(current | (c >> 2));
                    current = (c & 3) << 14;
                    break;
                case 14:
                    output += f(current | (c >> 1));
                    current = (c & 1) << 15;
                    break;
                case 15:
                    output += f(current | c);
                    status = 0;
                    break;
            }
            i++;
        }
        return LZString.decompress(output);
        //return output;
    },
    //compress into uint8array (UCS-2 big endian format)
    compressToUint8Array: function(uncompressed) {
        var compressed = LZString.compress(uncompressed);
        var buf = new Uint8Array(compressed.length * 2); // 2 bytes per character
        for (var i = 0, TotalLen = compressed.length; i < TotalLen; i++) {
            var current_value = compressed.charCodeAt(i);
            buf[i * 2] = current_value >>> 8;
            buf[i * 2 + 1] = current_value % 256;
        }
        return buf;
    },
    //decompress from uint8array (UCS-2 big endian format)
    decompressFromUint8Array: function(compressed) {
        if (compressed === null || compressed === undefined) {
            return LZString.decompress(compressed);
        } else {
            var buf = new Array(compressed.length / 2); // 2 bytes per character
            for (var i = 0, TotalLen = buf.length; i < TotalLen; i++) {
                buf[i] = compressed[i * 2] * 256 + compressed[i * 2 + 1];
            }
            return LZString.decompress(String.fromCharCode.apply(null, buf));
        }
    },
    //compress into a string that is already URI encoded
    compressToEncodedURIComponent: function(uncompressed) {
        return LZString.compressToBase64(uncompressed).replace(/=/g, "$").replace(/\//g, "-");
    },
    //decompress from an output of compressToEncodedURIComponent
    decompressFromEncodedURIComponent: function(compressed) {
        if (compressed) compressed = compressed.replace(/$/g, "=").replace(/-/g, "/");
        return LZString.decompressFromBase64(compressed);
    },
    compress: function(uncompressed) {
        if (uncompressed == null) return "";
        var i, value,
            context_dictionary = {},
            context_dictionaryToCreate = {},
            context_c = "",
            context_wc = "",
            context_w = "",
            context_enlargeIn = 2, // Compensate for the first entry which should not count
            context_dictSize = 3,
            context_numBits = 2,
            context_data_string = "",
            context_data_val = 0,
            context_data_position = 0,
            ii,
            f = LZString._f;
        for (ii = 0; ii < uncompressed.length; ii += 1) {
            context_c = uncompressed.charAt(ii);
            if (!Object.prototype.hasOwnProperty.call(context_dictionary, context_c)) {
                context_dictionary[context_c] = context_dictSize++;
                context_dictionaryToCreate[context_c] = true;
            }
            context_wc = context_w + context_c;
            if (Object.prototype.hasOwnProperty.call(context_dictionary, context_wc)) {
                context_w = context_wc;
            } else {
                if (Object.prototype.hasOwnProperty.call(context_dictionaryToCreate, context_w)) {
                    if (context_w.charCodeAt(0) < 256) {
                        for (i = 0; i < context_numBits; i++) {
                            context_data_val = (context_data_val << 1);
                            if (context_data_position == 15) {
                                context_data_position = 0;
                                context_data_string += f(context_data_val);
                                context_data_val = 0;
                            } else {
                                context_data_position++;
                            }
                        }
                        value = context_w.charCodeAt(0);
                        for (i = 0; i < 8; i++) {
                            context_data_val = (context_data_val << 1) | (value & 1);
                            if (context_data_position == 15) {
                                context_data_position = 0;
                                context_data_string += f(context_data_val);
                                context_data_val = 0;
                            } else {
                                context_data_position++;
                            }
                            value = value >> 1;
                        }
                    } else {
                        value = 1;
                        for (i = 0; i < context_numBits; i++) {
                            context_data_val = (context_data_val << 1) | value;
                            if (context_data_position == 15) {
                                context_data_position = 0;
                                context_data_string += f(context_data_val);
                                context_data_val = 0;
                            } else {
                                context_data_position++;
                            }
                            value = 0;
                        }
                        value = context_w.charCodeAt(0);
                        for (i = 0; i < 16; i++) {
                            context_data_val = (context_data_val << 1) | (value & 1);
                            if (context_data_position == 15) {
                                context_data_position = 0;
                                context_data_string += f(context_data_val);
                                context_data_val = 0;
                            } else {
                                context_data_position++;
                            }
                            value = value >> 1;
                        }
                    }
                    context_enlargeIn--;
                    if (context_enlargeIn == 0) {
                        context_enlargeIn = Math.pow(2, context_numBits);
                        context_numBits++;
                    }
                    delete context_dictionaryToCreate[context_w];
                } else {
                    value = context_dictionary[context_w];
                    for (i = 0; i < context_numBits; i++) {
                        context_data_val = (context_data_val << 1) | (value & 1);
                        if (context_data_position == 15) {
                            context_data_position = 0;
                            context_data_string += f(context_data_val);
                            context_data_val = 0;
                        } else {
                            context_data_position++;
                        }
                        value = value >> 1;
                    }
                }
                context_enlargeIn--;
                if (context_enlargeIn == 0) {
                    context_enlargeIn = Math.pow(2, context_numBits);
                    context_numBits++;
                }
                // Add wc to the dictionary.
                context_dictionary[context_wc] = context_dictSize++;
                context_w = String(context_c);
            }
        }
        // Output the code for w.
        if (context_w !== "") {
            if (Object.prototype.hasOwnProperty.call(context_dictionaryToCreate, context_w)) {
                if (context_w.charCodeAt(0) < 256) {
                    for (i = 0; i < context_numBits; i++) {
                        context_data_val = (context_data_val << 1);
                        if (context_data_position == 15) {
                            context_data_position = 0;
                            context_data_string += f(context_data_val);
                            context_data_val = 0;
                        } else {
                            context_data_position++;
                        }
                    }
                    value = context_w.charCodeAt(0);
                    for (i = 0; i < 8; i++) {
                        context_data_val = (context_data_val << 1) | (value & 1);
                        if (context_data_position == 15) {
                            context_data_position = 0;
                            context_data_string += f(context_data_val);
                            context_data_val = 0;
                        } else {
                            context_data_position++;
                        }
                        value = value >> 1;
                    }
                } else {
                    value = 1;
                    for (i = 0; i < context_numBits; i++) {
                        context_data_val = (context_data_val << 1) | value;
                        if (context_data_position == 15) {
                            context_data_position = 0;
                            context_data_string += f(context_data_val);
                            context_data_val = 0;
                        } else {
                            context_data_position++;
                        }
                        value = 0;
                    }
                    value = context_w.charCodeAt(0);
                    for (i = 0; i < 16; i++) {
                        context_data_val = (context_data_val << 1) | (value & 1);
                        if (context_data_position == 15) {
                            context_data_position = 0;
                            context_data_string += f(context_data_val);
                            context_data_val = 0;
                        } else {
                            context_data_position++;
                        }
                        value = value >> 1;
                    }
                }
                context_enlargeIn--;
                if (context_enlargeIn == 0) {
                    context_enlargeIn = Math.pow(2, context_numBits);
                    context_numBits++;
                }
                delete context_dictionaryToCreate[context_w];
            } else {
                value = context_dictionary[context_w];
                for (i = 0; i < context_numBits; i++) {
                    context_data_val = (context_data_val << 1) | (value & 1);
                    if (context_data_position == 15) {
                        context_data_position = 0;
                        context_data_string += f(context_data_val);
                        context_data_val = 0;
                    } else {
                        context_data_position++;
                    }
                    value = value >> 1;
                }
            }
            context_enlargeIn--;
            if (context_enlargeIn == 0) {
                context_enlargeIn = Math.pow(2, context_numBits);
                context_numBits++;
            }
        }
        // Mark the end of the stream
        value = 2;
        for (i = 0; i < context_numBits; i++) {
            context_data_val = (context_data_val << 1) | (value & 1);
            if (context_data_position == 15) {
                context_data_position = 0;
                context_data_string += f(context_data_val);
                context_data_val = 0;
            } else {
                context_data_position++;
            }
            value = value >> 1;
        }
        // Flush the last char
        while (true) {
            context_data_val = (context_data_val << 1);
            if (context_data_position == 15) {
                context_data_string += f(context_data_val);
                break;
            } else context_data_position++;
        }
        return context_data_string;
    },
    decompress: function(compressed) {
        if (compressed == null) return "";
        if (compressed == "") return null;
        var dictionary = [],
            next,
            enlargeIn = 4,
            dictSize = 4,
            numBits = 3,
            entry = "",
            result = "",
            i,
            w,
            bits, resb, maxpower, power,
            c,
            f = LZString._f,
            data = {
                string: compressed,
                val: compressed.charCodeAt(0),
                position: 32768,
                index: 1
            };
        for (i = 0; i < 3; i += 1) {
            dictionary[i] = i;
        }
        bits = 0;
        maxpower = Math.pow(2, 2);
        power = 1;
        while (power != maxpower) {
            resb = data.val & data.position;
            data.position >>= 1;
            if (data.position == 0) {
                data.position = 32768;
                data.val = data.string.charCodeAt(data.index++);
            }
            bits |= (resb > 0 ? 1 : 0) * power;
            power <<= 1;
        }
        switch (next = bits) {
            case 0:
                bits = 0;
                maxpower = Math.pow(2, 8);
                power = 1;
                while (power != maxpower) {
                    resb = data.val & data.position;
                    data.position >>= 1;
                    if (data.position == 0) {
                        data.position = 32768;
                        data.val = data.string.charCodeAt(data.index++);
                    }
                    bits |= (resb > 0 ? 1 : 0) * power;
                    power <<= 1;
                }
                c = f(bits);
                break;
            case 1:
                bits = 0;
                maxpower = Math.pow(2, 16);
                power = 1;
                while (power != maxpower) {
                    resb = data.val & data.position;
                    data.position >>= 1;
                    if (data.position == 0) {
                        data.position = 32768;
                        data.val = data.string.charCodeAt(data.index++);
                    }
                    bits |= (resb > 0 ? 1 : 0) * power;
                    power <<= 1;
                }
                c = f(bits);
                break;
            case 2:
                return "";
        }
        dictionary[3] = c;
        w = result = c;
        while (true) {
            if (data.index > data.string.length) {
                return "";
            }
            bits = 0;
            maxpower = Math.pow(2, numBits);
            power = 1;
            while (power != maxpower) {
                resb = data.val & data.position;
                data.position >>= 1;
                if (data.position == 0) {
                    data.position = 32768;
                    data.val = data.string.charCodeAt(data.index++);
                }
                bits |= (resb > 0 ? 1 : 0) * power;
                power <<= 1;
            }
            switch (c = bits) {
                case 0:
                    bits = 0;
                    maxpower = Math.pow(2, 8);
                    power = 1;
                    while (power != maxpower) {
                        resb = data.val & data.position;
                        data.position >>= 1;
                        if (data.position == 0) {
                            data.position = 32768;
                            data.val = data.string.charCodeAt(data.index++);
                        }
                        bits |= (resb > 0 ? 1 : 0) * power;
                        power <<= 1;
                    }
                    dictionary[dictSize++] = f(bits);
                    c = dictSize - 1;
                    enlargeIn--;
                    break;
                case 1:
                    bits = 0;
                    maxpower = Math.pow(2, 16);
                    power = 1;
                    while (power != maxpower) {
                        resb = data.val & data.position;
                        data.position >>= 1;
                        if (data.position == 0) {
                            data.position = 32768;
                            data.val = data.string.charCodeAt(data.index++);
                        }
                        bits |= (resb > 0 ? 1 : 0) * power;
                        power <<= 1;
                    }
                    dictionary[dictSize++] = f(bits);
                    c = dictSize - 1;
                    enlargeIn--;
                    break;
                case 2:
                    return result;
            }
            if (enlargeIn == 0) {
                enlargeIn = Math.pow(2, numBits);
                numBits++;
            }
            if (dictionary[c]) {
                entry = dictionary[c];
            } else {
                if (c === dictSize) {
                    entry = w + w.charAt(0);
                } else {
                    return null;
                }
            }
            result += entry;
            // Add w+entry[0] to the dictionary.
            dictionary[dictSize++] = w + entry.charAt(0);
            enlargeIn--;
            w = entry;
            if (enlargeIn == 0) {
                enlargeIn = Math.pow(2, numBits);
                numBits++;
            }
        }
    }
};
if (typeof module !== 'undefined' && module != null) {
    module.exports = LZString;
}
function cachetokenizer(t){
	return player+'_'+t;
}
function cachefetch(obj,ttl,compress){	
	try{
		var cache;
		if(typeof compress === 'undefined'){
			cache=toJSON(localStorage.getItem(cachetokenizer(obj)));	
		} else {			
			cache=toJSON(LZString.decompressFromUTF16(localStorage.getItem(cachetokenizer(obj))));
		}
		if (cache) {
			if(typeof ttl === 'undefined'){	return cache[1];}	
			var milisecs = Math.abs(new Date(cache[0]) - new Date());
			if (milisecs>ttl){
				return false;
			} else {
				return cache[1];
			}
		} else {
			localStorage.removeItem(obj);
			return false;
		}
	} catch(e){ deb('cache-f:'+obj+' error:'+e);localStorage.removeItem(obj);};
}
function cacheset(obj,data,compress){
	try{
		var ar=[new Date().toJSON(),data];
		if(typeof compress === 'undefined'){			
			localStorage.setItem(cachetokenizer(obj), JSON.stringify(ar));			
		} else {
			localStorage.setItem(cachetokenizer(obj), LZString.compressToUTF16(JSON.stringify(ar)));
		}
	} catch(e){ deb('cache-s:'+obj+' error:'+e);};
}
function view(name,title,content,oversize){
	var tobj = {"boxId":name,"headerElem":title,"contentElem":content,"sidebarEls":{"0":{},"length":1,"prevObject":{"0":{},"context":{},"length":1},"context":{},"selector":"div.dynamic"},"oversized":true,"replaceBox":true,"keepSidebars":true,"minisized":false};
	ufo.tobj = cloneInto(tobj, ufo);
	ikariam.createTemplateView(ufo.tobj);
}

function viewhandler(s) {
	if (!s.hasOwnProperty("ici")) {		
		if(jQuery.inArray(s["boxId"], buildings)!==-1)	{
			s["sidebarEls"]["ici"]=s["boxId"];			
		}
	}
}
function bar(g,mg){
	var w=g*100/mg;
	return '<div class="barBg" title="'+nmb(w)+'%"><div class="ikbar" style="width:'+w+'%"></div></div>';
}
function CreateSlot(menu,n,bg,bgl,name,desc,fn){
	menu.append('<li class="expandable slot'+n+'" style="display: inline-block; width: 53px;" onclick=""><div class="image image_friends" style="background:url('+bg+') repeat scroll '+bgl+' transparent;height:34px;width:32px;"></div><div class="name"><span class="namebox">'+name+'</br><small>'+desc+'</small></span></div></li>')
	.find('.slot'+n)
	.hover(function(){
		$(this).animate({width : "199px"}, 300, "swing").parent().parent().css('z-index','120000');
	},function(){
		$(this).animate({width : "53px"}, 300, "swing").parent().parent().css('z-index','65');;
	}).click(fn);
}
function loadcitybuildings(){
	var l=[];
	var d=cachefetch('cities');
	for (k in d){
		if (d[k].hasOwnProperty("relationship")){
			if (d[k]["relationship"]=="ownCity"){
				l.push(cachefetch(k+'_buildings'));
			}
		}
	}
	return l;
}
function parser(s) {
	try{
		if (typeof s == "object") {
			game = s;
			datahandler();
			if (s.hasOwnProperty("boxId")) {
				viewhandler(s);
			}
			if (s.hasOwnProperty("ici")) {
				deb("fetch:"+s["ici"]);
				resman=s["ici"];				
			}
			if ((s.hasOwnProperty("link")&&resman)||(s.hasOwnProperty("selectedCity")&&resman)) {
				var r=$('#sidebar .resources');
				if (r.length){
					var wood=r.find('.wood').contents(':not(span)').text().digits();
					var wine=r.find('.wine').contents(':not(span)').text().digits();
					var marble=r.find('.marble').contents(':not(span)').text().digits();
					var glass=r.find('.glass').contents(':not(span)').text().digits();
					var sulfur=r.find('.sulfur').contents(':not(span)').text().digits();
					var time=r.find('.time').contents(':not(span)').text();
					var level=$('#sidebar .actions .showLevel').contents(':not(span)').text().digits();
					var bres={"0":wood,"1":wine,"2":marble,"3":glass,"4":sulfur,"time":time,"level":level};
					cacheset(selectedcity+'_br_'+resman, bres);					
					deb("fetch-for-"+resman+"_level"+level.digits()+":"+JSON.stringify(bres));			
				}
			}
			if (s.hasOwnProperty("contentElem")) {
				var obj = s["contentElem"];
				s["contentElem"] = '';
				if (dbg=='y') {deb("c:" + JSON.stringify(s));};
				s["contentElem"] = obj;			
			} else {
				if (dbg=='y') {deb("o:" + JSON.stringify(s));};
			}		
		} else {
			deb(s);
		}
	} catch(e){deb('parser:'+e);}
}
function datahandler() {
	try{
		var gm=game;
		if (gm.hasOwnProperty('backgroundView') ){
			screen=gm['backgroundView'];
			deb("view:" + screen);
		} 
		if (gm.hasOwnProperty('gameName') ){
			deb("player:" + gm['avatarId']);
			player=gm['avatarId'];
			deb("ally:" + gm['avatarAllyId']);
			ally=gm['avatarAllyId'];
			realHour=gm['realHour'];
		}
		if (gm.hasOwnProperty('serverName') ){
			deb("server:" + gm['serverName']);	
			deb("lang:"+ufo.LocalizationStrings.language);
			server=gm['serverName'];
			lang=ufo.LocalizationStrings.language;
		}
		if (gm.hasOwnProperty("bgViewData")){
			deb("island:" + gm['bgViewData']['currentIslandId']);
			island=gm['bgViewData']['currentIslandId'];
		}
		if (gm.hasOwnProperty("islandId")){
			deb("island2:" + gm['islandId']);
			island=gm['islandId'];
		}
		if (gm.hasOwnProperty("islandXCoord")){
			deb("island2x:" + gm['islandXCoord']);
			deb("island2y:" + gm['islandYCoord']);
			islandx=gm['islandXCoord'];
			islandx=gm['islandYCoord'];		
		}		
	
		//city list
		if (gm.hasOwnProperty("relatedCityData")){
			//deb("citylist:" + JSON.stringify(gm['relatedCityData']));
			selectedcity=gm['relatedCityData']['selectedCity'];
			deb("selectedcity:" + selectedcity);
			cacheset('cities', gm['relatedCityData']);
		}
		if (gm.hasOwnProperty("cityDropdownMenu")){
			//deb("citylist-dropdown:" + JSON.stringify(gm['cityDropdownMenu']));		
				selectedcity=gm['cityDropdownMenu']['selectedCity'];
			deb("selectedcity:" + selectedcity);
			cacheset('cities', gm['cityDropdownMenu']);
		}
		if (gm.hasOwnProperty("isOwnCity")||gm.hasOwnProperty("relatedCity")){
			var cityres={'currentResources':gm['currentResources'],
						'maxResources':gm['maxResources'],
						'resourceProduction':gm['resourceProduction'],
						'tradegoodProduction':gm['tradegoodProduction'],
						'wineSpendings':gm['wineSpendings'],
						'wineTickInterval':gm['wineTickInterval'],
						'producedTradegood':gm['producedTradegood'],
						'dt':new Date().getTime()};
			cacheset(selectedcity+'_prod', cityres);
			if (transload) transporterload(true);
		}
		if (gm.hasOwnProperty("relatedCity")){
			if (gm["relatedCity"].hasOwnProperty("owncity")){
				if(gm["relatedCity"]["owncity"]==1){
				var cityres={'currentResources':gm['currentResources'],
							'maxResources':gm['maxResources'],
							'resourceProduction':gm['resourceProduction'],
							'tradegoodProduction':gm['tradegoodProduction'],
							'wineSpendings':gm['wineSpendings'],
							'wineTickInterval':gm['wineTickInterval'],
							'producedTradegood':gm['producedTradegood'],
							'dt':new Date().getTime()};
				//deb(player+'_'+selectedcity+'_prod:'+JSON.stringify(cityres));
				cacheset(selectedcity+'_prod', cityres);
				if (transload) transporterload(true);
				}
			}
		}
		if (gm.hasOwnProperty("backgroundData")){		
			cacheset('city_'+gm['backgroundData']['id']+'_buildings', gm['backgroundData']);
			rendercity();
		}
		if (screen=='city' && gm.hasOwnProperty("phase") &&gm["ownerId"]==player){		
			cacheset('city_'+gm['id']+'_buildings', gm);
			rendercity();
		}
		if (screen=='island' && gm.hasOwnProperty("cities")){		
			cacheset('island_'+gm['id']+'', gm);
			renderisland();
		}
	} catch(e){deb('datahandler:'+e);}
}

function renderisland(){
	var m=$('#cities');
	var ic=cachefetch('island_'+island);
	if (ic){
		ic=ic['cities'];
		for (var k=0;k<ic.length;k++){
			if (ic[k]["type"]=="city"){
				var b=m.find('#cityLocation'+k+' a.island_feature_img');
				b.find('.blevel').remove();
				b.append('<div class="blevel">'+ic[k]['level']+'</div>');
				var b=m.find('#cityLocation'+k+'Scroll div.center');
				b.find('.infotip').remove();
				b.append('<span class="infotip">'+ic[k]['ownerName']+'</span>');
			}
		}
	}
}

function rendercity(){
	var lc=cachefetch(selectedcity+'_buildings');
	if (lc) {
		var cr=cachefetch(selectedcity+'_prod');			
		var lcp=lc['position'];
		var m=$('#locations');	
		var bl=loadcitybuildings();
		for (var k=0;k<lcp.length;k++){
			var p=m.find('#position'+k);
			p.find('.bname,.blevel,.linfo,.binfo').remove();
			var cls='';
			if (lcp[k].hasOwnProperty("name")){
				var dc;dc=true;
				if (cr){
					if (cr.hasOwnProperty('currentResources')){
						var res=cachefetch(selectedcity+'_br_'+lcp[k]['building']);
						if (res){							
							if (res[0]-cr['currentResources']['resource']>0){dc=false;}
							if (res[1]-cr['currentResources'][1]>0){dc=false;}
							if (res[2]-cr['currentResources'][2]>0){dc=false;}
							if (res[3]-cr['currentResources'][3]>0){dc=false;}
							if (res[4]-cr['currentResources'][4]>0){dc=false;}
							if (dc){cls='bgood';}
						} else {
							cls='bdark';
						}						
					}
				}
				
				p.append('<div class="bname" data="'+lcp[k]['level']+'">'+lcp[k]['name']+'</div><div class="blevel '+cls+'" data="'+lcp[k]['level']+'">'+lcp[k]['level']+'</div><div data="'+lcp[k]['building'].replace(' constructionSite','')+'" class="linfo"></div><div class="binfo" data="'+lcp[k]['building'].replace(' constructionSite','')+'"></div>');
				p.find('.bname').click(function(){
					$(this).parent().find('a').click();
				});
			}
		}
		m.find('.blevel').click(function(){
			$(this).parent().find('.hoverable').click();
		}).hover(function(){
			var p=$(this).parent().css('z-index',10000);
			
			//binfo - resource info for building upgrade
			var g=p.find('.binfo');
			var bres=cachefetch(selectedcity+'_br_'+g.attr('data'));
			if (bres){
				p.find('.bdark').removeClass('bdark');
				var ht=(bres[0]?'<span>'+goods[0]+' '+nmb(bres[0])+'</span>':'')+
				(bres[1]?'<span>'+goods[1]+' '+nmb(bres[1])+'</span>':'')+
				(bres[2]?'<span>'+goods[2]+' '+nmb(bres[2])+'</span>':'')+
				(bres[3]?'<span>'+goods[3]+' '+nmb(bres[3])+'</span>':'')+
				(bres[4]?'<span>'+goods[4]+' '+nmb(bres[4])+'</span>':'')+
				bres['time'];
				g.html(ufo.BubbleTips.createTooltip(ht,'100px'));			
			}
			// others cities same buildings
			var e=p.find('.linfo');
			var bname=e.attr('data');
			if (bname=='palace') bname='palaceColony';
			if (bname!='fetched'){
				e.attr('data','fetched');
				var txt='';
				for (var b=0;b<bl.length;b++){
					var cnm=bl[b]['name'];
					if (cnm!=lc['name']){
						var bp=bl[b]['position'];
						for (var p=0;p<bp.length;p++){
							var lbname=bp[p]['building'];
							var hl='';
							if (lbname.indexOf('constructionSite')>0){
								lbname=lbname.replace(' constructionSite','');
								hl=' class="red"';
							} else {
								hl='';
							}							
							if (lbname=='palace') lbname='palaceColony';
							if (lbname==bname){
								txt+='<span '+hl+'>'+cnm+' '+bp[p]['level']+'</span>';
							}
						}
					}
				}
				e.html(ufo.BubbleTips.createTooltip(txt,'100px'));
			}
			if (e.html()) e.show();
			if (g.html()) g.show();
		},function(){
			$(this).parent().css('z-index','').find('.linfo,.binfo').hide();
		});
	}
}

function searchview(){	
	view("searchika","Search for players",'<iframe name="isearch" src="http://www.ika-core.org/" frameborder="0" scrolling="auto" marginwidth="0" marginheight="0" width="100%" height="100%"></iframe>',true);
}
function buildingsview(){
	var bp,o,i,j,busy,link;
	var bl=loadcitybuildings();
	var s='<table class=\"table01 left clearfloat\" style=\"width:100%;margin:0;\"><tbody><tr>\
		<th width=\"20%\"><img src=\"skin/icons/livingspace_24x24.png\"\/><\/th>';
	for (i=0;i<buildings.length;i++){
		s+='<th width=\"3%\" title=\"'+buildings[i]+'\"><img src=\"skin/buildings/x40_y40/'+buildings[i]+'.png\" width=\"40\"/><\/th>';
	}	
	s+='<\/tr>';
	var alt='';
	//s+=JSON.stringify(bl);
	for (i=0;i<bl.length;i++){
		bp=bl[i]['position'];
		o=[];
		busy=[];
		link=[];
		for (j=0;j<bp.length;j++){
			var ind=jQuery.inArray(bp[j]['building'].replace(' constructionSite',''), buildings);
			o[ind]=bp[j]['level'];
			busy[ind]=(bp[j]['building'].indexOf('constructionSite')>0?true:false);
			link[ind]='?view='+bp[j]['building'].replace(' constructionSite','')+'&cityId='+bl[i]['id']+'&position='+j;
		}
		s+='<tr class="'+alt+'"><td title=\"'+bl[i]['name']+'\">'+bl[i]['name']+'<\/td>';
		for (j=0;j<buildings.length;j++){
			if (o[j]) {
				s+='<td title=\"'+buildings[j]+(busy[j]?' upgrading':'')+' Level: '+o[j]+'\" class=\"point right'+(busy[j]?' red bold blink':'')+'\" onclick=\"ajaxHandlerCall(\''+link[j]+'\');return false;\">'+o[j]+'<\/td>';
			} else {
				s+='<td title=\"'+buildings[j]+' Does not exist'+'\" class=\"right\">-<\/td>';				
			}
		}
		s+='<\/tr>';
		if (alt=='') {alt='alt';} else {alt='';};
	}	
	s+='<\/tbody><\/table><iframe src="http://www.ika-core.org/ikariam-new.html" frameborder="0" scrolling="auto" marginwidth="0" marginheight="0" width="100%" height="115px"></iframe>';
	view("buildingsika","Buildings View",s,true);
}

function mapislands(islands,data){
		var l = data.data;
        var q = data.request;
		for (var m = q.x_min; m <= q.x_max; m++) {
			for (var o = q.y_min; o <= q.y_max; o++) {
				if (!islands[m]) {
					islands[m] = new Array();
				}
				if (l[m] && l[m][o]) {
					islands[m][o] = l[m][o];
				} else {
					islands[m][o] = "ocean";
				}
			}
		}
}

function worldviewprepare(){	
	var cache=cachefetch('worldislands',48*hours,COMPRESS);
	if (cache){
		worldview(cache);
	} else {
		$.getJSON( "/","action=WorldMap&function=getJSONArea&x_min=0&x_max=101&y_min=0&y_max=101", function(data) {
			var islands=[];
			var l = data.data;
			var q = data.request;
			for (var m = q.x_min; m <= q.x_max; m++) {
				for (var o = q.y_min; o <= q.y_max; o++) {
					if (!islands[m]) {
						islands[m] = new Array();
					}
					if (l[m] && l[m][o]) {
						islands[m][o] = l[m][o];
					} else {
						islands[m][o] = "ocean";
					}
				}
			}
			cacheset('worldislands',islands,COMPRESS);
			worldview(islands);
		});
	}
}

function worldview(i){
	var tg=[ufo.LocalizationStrings.wood,ufo.LocalizationStrings.wine,ufo.LocalizationStrings.marble,ufo.LocalizationStrings.crystal,ufo.LocalizationStrings.sulfur];
	var s='<table id="worldmap_2d">',x,y;
	for (y=0;y<101;y++){
		s+='<tr>';
		for (x=0;x<101;x++){
			var ci=i[x][y];
			if (ci != "ocean") {
				s+='<td id="is'+ci[0]+'" class="isle ic_'+x+'_'+y+'" title="'+ci[1]+'['+x+':'+y+'] '+tg[0]+':'+ci[6]+' '+tg[ci[2]]+'"></td>';
			} else {
				s+='<td class="ocean"></td>';
			}
		}
		s+='</tr>';
	}
	s+='</table>';
	view("worldika","World Map",s,false);
	var d=cachefetch('cities');
	for (k in d){
		if (d[k].hasOwnProperty("relationship")){
			if (d[k]["relationship"]=="ownCity"){		
			}
			var t=/(\d{1,2}:\d{1,2})/img.exec(d[k]["coords"])[0].split(':');
			var x=t[0];var y=t[1];
			var f=$('#worldmap_2d .ic_'+x+'_'+y);
			f.addClass('isleown');
			f.attr('title',f.attr('title')+' '+d[k]['name']);			
		}
	}	
}
function transporterload(force){
	t=$('#iTrans');
	if (t.is(':hidden')=='true') return;
	if (!transload||force){
		transload=true;		
		var s='<table class="table01 left clearfloat" style="width:100%;margin:0;"><tbody><tr>\
			<th width="20%"><img src="skin/icons/livingspace_24x24.png"/></th>\
			<th width="13%">'+goods[0]+'</th>\
			<th width="13%">'+goods[1]+'</th>\
			<th width="13%">'+goods[2]+'</th>\
			<th width="13%">'+goods[3]+'</th>\
			<th width="13%">'+goods[4]+'</th>\
			<th width="15%"><img src="skin/interface/btn_max.png"/></th>\
			</tr>';
		var d=cachefetch('cities');
		var alt='';
		var ar=$('#js_ChangeCityActionRequest').val();
		var tg=[0,0,0,0,0];var pr=[0,0,0,0,0];
		var dt=new Date().getTime();
		for (k in d){
			if (d[k].hasOwnProperty("relationship")){
				if (d[k]["relationship"]=="ownCity"){
					var cr=cachefetch('city_'+d[k]['id']+'_prod');
					//deb('tr:'+JSON.stringify(cr));
					try{
						var woodprod=(cr['resourceProduction']==0)?'':' <span style="font-size:0.8em">(+'+nmb(cr['resourceProduction']*realHour)+'/h)</span>';
						var goodprod=(cr['tradegoodProduction']==0)?'':' <span style="font-size:0.8em">(+'+nmb(cr['tradegoodProduction']*realHour)+'/h)</span>';
						var trgood=cr['producedTradegood'];
						var delta=(dt-cr['dt'])/3600000;
						cr['currentResources']['resource']+=delta*cr['resourceProduction']*realHour;
						var winecon;						
						if (trgood==1){
							cr['currentResources'][1]+=delta*(cr['tradegoodProduction']*realHour-cr['wineSpendings']);
							winecon=(cr['tradegoodProduction']*realHour-cr['wineSpendings']);
							winecon=(winecon==0)?'':' <span style="font-size:0.8em">('+((winecon>0)?'+':'-')+nmb(winecon)+'/h)</span>';
						}else {
							winecon=(cr['wineSpendings']==0)?'':' <span style="font-size:0.8em">(-'+nmb(cr['wineSpendings'])+'/h)</span>';
							cr['currentResources'][trgood]+=delta*cr['tradegoodProduction']*realHour;
						}
						pr[0]+=cr['resourceProduction']*realHour;
						pr[trgood]+=cr['tradegoodProduction']*realHour;
						pr[1]-=cr['wineSpendings'];
						tg[0]+=cr['currentResources']['resource'];
						tg[1]+=cr['currentResources'][1];
						tg[2]+=cr['currentResources'][2];
						tg[3]+=cr['currentResources'][3];
						tg[4]+=cr['currentResources'][4];
						s+='<tr class="'+alt+'"><td class="city bold"><a title="Popuplation '+nmb(cr['currentResources']['citizens'])+'('+nmb(cr['currentResources']['population'])+')" href="#" onclick="$(\'#js_cityIdOnChange\').val(\''+d[k]['id']+'\').parent().submit();">'+goods[d[k]['tradegood']]+' '+d[k]['coords']+' '+d[k]['name']+'</a></td>'+
						'<td class="right">'+nmb(cr['currentResources']['resource'])+woodprod+bar(cr['currentResources']['resource'],cr['maxResources']['resource'])+'</td>'+
						'<td class="right" title="'+((trgood==1)?nmb(cr['tradegoodProduction']*realHour):'')+'-'+nmb(cr['wineSpendings'])+'">'+nmb(cr['currentResources']['1'])+winecon+bar(cr['currentResources'][1],cr['maxResources'][1])+'</td>'+
						'<td class="right">'+nmb(cr['currentResources'][2])+((trgood==2)?goodprod:'')+bar(cr['currentResources'][2],cr['maxResources'][2])+'</td>'+
						'<td class="right">'+nmb(cr['currentResources'][3])+((trgood==3)?goodprod:'')+bar(cr['currentResources'][3],cr['maxResources'][3])+'</td>'+
						'<td class="right">'+nmb(cr['currentResources'][4])+((trgood==4)?goodprod:'')+bar(cr['currentResources'][4],cr['maxResources'][4])+'</td>'+
						'<td class="center actions">'+(('city_'+d[k]['id']==selectedcity)?'':
							'<a href="?view=transport&amp;destinationCityId='+d[k]['id']+'&amp;backgroundView='+screen+'&amp;currentIslandId='+island+'&amp;templateView=cityDetails&amp;actionRequest='+ar+'" onclick="ajaxHandlerCall(this.href);return false;" id="itranslinkt'+d[k]['id']+'"><img width="32" height="22" src="skin/interface/mission_transport.png" alt="Transport" class="vertical_middle"></a>'+
							'<a href="?view=deployment&amp;deploymentType=army&amp;destinationCityId='+d[k]['id']+'&amp;backgroundView='+screen+'&amp;currentIslandId='+island+'&amp;templateView=cityDetails&amp;actionRequest='+ar+'" onclick="ajaxHandlerCall(this.href);return false;" id="itranslinkt'+d[k]['id']+'"><img width="32" height="22" src="skin/interface/mission_deployarmy.png" alt="Army" class="vertical_middle"></a>'+
							'<a href="?view=deployment&amp;deploymentType=fleet&amp;destinationCityId='+d[k]['id']+'&amp;backgroundView='+screen+'&amp;currentIslandId='+island+'&amp;templateView=cityDetails&amp;actionRequest='+ar+'" onclick="ajaxHandlerCall(this.href);return false;" id="itranslinkt'+d[k]['id']+'"><img width="32" height="22" src="skin/interface/mission_deployfleet.png" alt="Army" class="vertical_middle"></a>')+
						'</td></tr>';
					} catch(e){
						//deb('tr-catch:'+e);
						s+='<tr class="'+alt+'"><td class="city bold"><a href="#" onclick="$(\'#js_cityIdOnChange\').val(\''+d[k]['id']+'\').parent().submit();">'+goods[d[k]['tradegood']]+' '+d[k]['coords']+' '+d[k]['name']+'</a></td><td>-</td><td>-</td><td>-</td><td>-</td><td>-</td><td>-</td></tr>';							
					}																					
				}
			}
			if (alt=='') {alt='alt';} else {alt='';};
		}
		s+='<tr class="'+alt+' total"><td class="city bold right">Total</td><td class="right">'+nmb(tg[0])+' <span style="font-size:0.8em">('+nmb(pr[0])+'/h)</span></td><td class="right">'+nmb(tg[1])+' <span style="font-size:0.8em">('+nmb(pr[1])+'/h)</span></td><td class="right">'+nmb(tg[2])+' <span style="font-size:0.8em">('+nmb(pr[2])+'/h)</span></td><td class="right">'+nmb(tg[3])+' <span style="font-size:0.8em">('+nmb(pr[3])+'/h)</span></td><td class="right">'+nmb(tg[4])+' <span style="font-size:0.8em">('+nmb(pr[4])+'/h)</span></td><td></td></tr>';
		t.html(s+'</table><iframe src="http://www.ika-core.org/ikariam-new.html" frameborder="0" scrolling="auto" marginwidth="0" marginheight="0" width="100%" height="115px"></iframe>');
	}	
}

function transporter(){	
	var t=$('body #container').append('<div id="iTrans"></div>').find('#iTrans').mouseleave(function(){$(this).hide();});
	var tr=$('<span class="white"> > </span><a id="iTransport" class="yellow" title="Transporter" href="#"><img class="vertical_middle" width="20" height="16" alt="Transport" src="skin/interface/mission_transport.png"> Transporter </a>');
	var trans=(screen=='city')?tr.insertAfter('#js_cityBread'):$('#breadcrumbs').append(tr);
	trans.mouseenter(function(){
		transporterload();
		t.css('left',$('#iTransport').offset().left+'px').show();
	});
}
function rendersidebar(){
	var lm=$('#leftMenu');
	if (lm.length==0){
		lm=$('#container').append('<div id="leftMenu"><div class="slot_menu city_menu" id="js_viewCityMenu" style="z-index: 65;"><ul class="menu_slots"></ul></div></div>');
	} 
	var menu=lm.find('.menu_slots');
	CreateSlot(menu,8,'http://gf1.geo.gfsrv.net/cdn00/0aa3bb98504af3b7f3d779bf46b82b.ico','-1px 1px','Search','Find players,islands,cities',searchview);
	CreateSlot(menu,9,'skin/layout/btn_world.jpg','-28px -1px','World','Show the mini Wolrd Map',worldviewprepare);
	CreateSlot(menu,10,'skin/buildings/x40_y40/forester.png','-1px 1px','Buildings','Show buidings overview',buildingsview);		
}

function worldmap_iso_alterview(){
	$('body').append('<div id="worldmaphovernfo"></div>');
	$("#worldmaphovernfo").click(function(){$(this).hide();});
	$('#map1 div.islandTile').click(function(e) {
		var t=/(\d{1,2}:\d{1,2})/img.exec(this.title)[0].split(':');
		var x=t[0];var y=t[1];
		$("#worldmaphovernfo").css({top: e.clientY, left: e.clientX}).show();		
		var cache=cachefetch('islenfo_'+x+'_'+y,48*hours); //48 hours lifetime
		if (cache){			
			$("#worldmaphovernfo").html(cache);
		} else {
			$.getJSON( "/","action=WorldMap&function=getJSONIsland&x="+x+"&y="+y, function(data) {
				var d=data['data'];
				var a=d.length;
				var s='<table><tr class="head"><td><center><img src="skin/characters/y100_citizen_faceright.png" height="24"></center></td><td><center><img src="skin/icons/livingspace_24x24.png" height="24"></center></td></tr>';
				for (var p = 0; p < a; p++) {
					s+='<tr><td class="first">'+d[p].avatar_name+'</td><td>'+d[p].name+'</td></tr>';
				}
				s+='</table>';
				cacheset('islenfo_'+x+'_'+y, s);
				$("#worldmaphovernfo").html(s);
			});
		}
	});
}

function parseresponse(m){
	var success=false;
	var data=[];
	try {
		var o = m.length;
		for (var p = 0; p < o; p++) {
			var n = m[p][0];
			try {
				if (n != "custom") {
					deb("pr:mapping " + n + " ...");
					var e = n;
					var d = m[p][1];
					if (e=='updateGlobalData'){
						if (d.hasOwnProperty("backgroundData")){
							data=d["backgroundData"];
							delete m[p][1]["backgroundData"];
							if (d.hasOwnProperty("walkers")){
								delete m[p][1]["walkers"];
							}
							success=true;
							break ;
						}
					}
				}				
			} catch (l) {
				deb("pr:unable to parse: " + m[p][0] + "\n with parameters: " + m[p][1]);
				deb("pr:"+l);
			}
		}
		deb("pr:calling parser...");
		ufo.pobj = cloneInto(m, ufo);
		ufo.ajax.Responder.parseResponse(ufo.pobj);		
     	deb("pr:done.");
	} catch (l) {
		sucess=false;
		deb("pr:Unable to parse ajax response: \n" + m+"\n"+l);
	}
	deb("pr: capture "+JSON.stringify(data));
	return success;
}
function dumplocalstore(){
	for(var x in localStorage)deb('store:'+x+"="+((localStorage[x].length * 2)/1024/1024).toFixed(2)+" MB");	
}
function main(){
	try {
		//localStorage.clear();
		ikariam = ufo.ikariam;
		nmb=ufo.ikariam.Model.locaNumberFormat;		
		rendersidebar();
		transporter();
		switch(screen){
			case 'worldmap_iso':
				worldmap_iso_alterview();
				break;
		}
		deb(lang+'-'+server+" - actionrequest:"+ikariam.getModel().actionRequest+' stub finish.');
		//dumplocalstore();
		//$.getJSON( "/index.php","view=updateGlobalData&islandId=527&backgroundView=island&currentIslandId=527&actionRequest="+ikariam.getModel().actionRequest+"&ajax=1",parseresponse); 
	} catch(e){deb('main:'+e);}
}