/*
 * AdvancedAJAX 1.1.2
 * (c) 2005-2006 Lukasz Lach
 *  mail: anakin@php5.pl
 *  www:  http://advajax.anakin.us/
 *        http://anakin.us/
 * http://creativecommons.org/licenses/LGPL/2.1/
 */
function advAJAX() {

    var obj = new Object();

    obj.url = window.location.href;
    obj.method = "GET";
    obj.parameters = new Object();
    obj.jsonParameters = new Object();
    obj.headers = new Object();
    obj.async = true;
    obj.mimeType = "text/xml";
    obj.username = null;
    obj.password = null;
    obj.form = null;
    obj.disableForm = true;

    obj.unique = true;
    obj.uniqueParameter = "_uniqid";

    obj.requestDone = false;
    obj.queryString = "";
    obj.responseText = null;
    obj.responseXML = null;
    obj.status = null;
    obj.statusText = null;
    obj.aborted = false;
    obj.timeout = 0;
    obj.retryCount = 0;
    obj.retryDelay = 1000;
    obj.tag = null;
    obj.group = null;
    obj.progressTimerInterval = 50;

    obj.xmlHttpRequest = null;

    obj.onInitialization = null;
    obj.onFinalization = null;
    obj.onReadyStateChange = null;
    obj.onLoading = null;
    obj.onLoaded = null;
    obj.onInteractive = null;
    obj.onComplete = null;
    obj.onProgress = null;
    obj.onSuccess = null;
    obj.onFatalError = null;
    obj.onError = null;
    obj.onTimeout = null;
    obj.onRetryDelay = null;
    obj.onRetry = null;
    obj.onGroupEnter = null;
    obj.onGroupLeave = null;

    obj.createXmlHttpRequest = function() {

        if (typeof XMLHttpRequest != "undefined")
            return new XMLHttpRequest();
        var xhrVersion = [ "MSXML2.XMLHttp.5.0", "MSXML2.XMLHttp.4.0","MSXML2.XMLHttp.3.0",
                "MSXML2.XMLHttp","Microsoft.XMLHttp" ];
        for (var i = 0; i < xhrVersion.length; i++) {
            try {
                var xhrObj = new ActiveXObject(xhrVersion[i]);
                return xhrObj;
            } catch (e) { }
        }
        obj.raiseEvent("FatalError");
        return null;
    };

    obj._oldResponseLength = null;
    obj._progressTimer = null;
    obj._progressStarted = navigator.userAgent.indexOf('Opera') == -1;
    obj._onProgress = function() {

        if (typeof obj.onProgress == "function" &&
            typeof obj.xmlHttpRequest.getResponseHeader == "function") {
            var contentLength = obj.xmlHttpRequest.getResponseHeader("Content-length");
            if (contentLength != null && contentLength != '') {
                var responseLength = obj.xmlHttpRequest.responseText.length;
                if (responseLength != obj._oldResponseLength) {
                    obj.raiseEvent("Progress", obj, responseLength, contentLength);
                    obj._oldResponseLength = obj.xmlHttpRequest.responseText.length;
                }
            }
        }
        if (obj._progressStarted) return;
        obj._progressStarted = true;
        var _obj = this;
        this.__onProgress = function() {
            obj._onProgress();
            obj._progressTimer = window.setTimeout(_obj.__onProgress, obj.progressTimerInterval);
        }
        _obj.__onProgress();
    }

    obj._onInitializationHandled = false;
    obj._initObject = function() {

        if (obj.xmlHttpRequest != null) {
            delete obj.xmlHttpRequest["onreadystatechange"];
            obj.xmlHttpRequest = null;
        }
        if ((obj.xmlHttpRequest = obj.createXmlHttpRequest()) == null)
            return null;
        if (typeof obj.xmlHttpRequest.overrideMimeType != "undefined")
            obj.xmlHttpRequest.overrideMimeType(obj.mimeType);
        obj.xmlHttpRequest.onreadystatechange = function() {

            if (obj == null || obj.xmlHttpRequest == null)
                return;
            obj.raiseEvent("ReadyStateChange", obj, obj.xmlHttpRequest.readyState);
            obj._onProgress();
            switch (obj.xmlHttpRequest.readyState) {
                case 1: obj._onLoading(); break;
                case 2: obj._onLoaded(); break;
                case 3: obj._onInteractive(); break;
                case 4: obj._onComplete(); break;
            }
        };
        obj._onLoadingHandled =
            obj._onLoadedHandled =
            obj._onInteractiveHandled =
            obj._onCompleteHandled = false;
    };

    obj._onLoading = function() {

        if (obj._onLoadingHandled)
            return;
        if (!obj._retry && obj.group != null) {
            if (typeof advAJAX._groupData[obj.group] == "undefined")
                advAJAX._groupData[obj.group] = 0;
            advAJAX._groupData[obj.group]++;
            if (typeof obj.onGroupEnter == "function" && advAJAX._groupData[obj.group] == 1)
                obj.onGroupEnter(obj);
        }
        obj.raiseEvent("Loading", obj);
        obj._onLoadingHandled = true;
    };
    obj._onLoaded = function() {

        if (obj._onLoadedHandled)
            return;
        obj.raiseEvent("Loaded", obj);
        obj._onLoadedHandled = true;
    };
    obj._onInteractive = function() {

        if (obj._onInteractiveHandled)
            return;
        obj.raiseEvent("Interactive", obj);
        obj._onInteractiveHandled = true;
        if (!obj._progressStarted)
            obj._onProgress();
    };
    obj._onComplete = function() {

        if (obj._onCompleteHandled || obj.aborted)
            return;
        if (obj._progressStarted) {
            window.clearInterval(obj._progressTimer);
            obj._progressStarted = false;
        }
        obj.requestDone = true;
        with (obj.xmlHttpRequest) {
            obj.responseText = responseText;
            obj.responseXML = responseXML;
            if (typeof status != "undefined")
                obj.status = status;
            if (typeof statusText != "undefined")
                obj.statusText = statusText;
        }
        obj.raiseEvent("Complete", obj);
        obj._onCompleteHandled = true;
        if (obj.status == 200)
            obj.raiseEvent("Success", obj); else
            obj.raiseEvent("Error", obj);
        delete obj.xmlHttpRequest['onreadystatechange'];
        obj.xmlHttpRequest = null;
        if (obj.disableForm)
            obj.switchForm(true);
        obj._groupLeave();
        obj.raiseEvent("Finalization", obj);
    };

    obj._groupLeave = function() {

        if (obj.group != null) {
            advAJAX._groupData[obj.group]--;
            if (advAJAX._groupData[obj.group] == 0)
                obj.raiseEvent("GroupLeave", obj);
        }
    };

    obj._retry = false;
    obj._retryNo = 0;
    obj._onTimeout = function() {

        if (obj == null || obj.xmlHttpRequest == null || obj._onCompleteHandled)
            return;
        obj.aborted = true;
        obj.xmlHttpRequest.abort();
        obj.raiseEvent("Timeout", obj);
        obj._retry = true;
        if (obj._retryNo != obj.retryCount) {
            obj._initObject();
            if (obj.retryDelay > 0) {
                obj.raiseEvent("RetryDelay", obj);
                startTime = new Date().getTime();
                while (new Date().getTime() - startTime < obj.retryDelay);
            }
            obj._retryNo++;
            obj.raiseEvent("Retry", obj, obj._retryNo);
            obj.run();
        } else {
            delete obj.xmlHttpRequest["onreadystatechange"];
            obj.xmlHttpRequest = null;
            if (obj.disableForm)
                obj.switchForm(true);
            obj._groupLeave();
            obj.raiseEvent("Finalization", obj);
        }
    };

    obj.run = function() {

        obj._initObject();
        if (obj.xmlHttpRequest == null)
            return false;
        obj.aborted = false;
        if (!obj._onInitializationHandled) {
            obj.raiseEvent("Initialization", obj);
            obj._onInitializationHandled = true;
        }
        if (obj.method == "GET" && obj.unique)
            obj.parameters[encodeURIComponent(obj.uniqueParameter)] =
            new Date().getTime().toString().substr(5) + Math.floor(Math.random() * 100).toString();
        if (!obj._retry) {
            for (var a in obj.parameters) {
                if (obj.queryString.length > 0)
                    obj.queryString += "&";
                if (typeof obj.parameters[a] != "object")
                    obj.queryString += encodeURIComponent(a) + "=" + encodeURIComponent(obj.parameters[a]); else {
                    for (var i = 0; i < obj.parameters[a].length; i++)
                        obj.queryString += encodeURIComponent(a) + "=" + encodeURIComponent(obj.parameters[a][i]) + "&";
                    obj.queryString = obj.queryString.slice(0, -1);
                }
            }
            for (var a in obj.jsonParameters) {
                var useJson = typeof [].toJSONString == 'function';
                if (obj.queryString.length > 0)
                    obj.queryString += "&";
                obj.queryString += encodeURIComponent(a) + "=";
                if (useJson)
                    obj.queryString += encodeURIComponent(obj.jsonParameters[a].toJSONString()); else
                    obj.queryString += encodeURIComponent(obj.jsonParameters[a]);
            }
            if (obj.method == "GET" && obj.queryString.length > 0)
                obj.url += (obj.url.indexOf("?") != -1 ? "&" : "?") + obj.queryString;
        }
        if (obj.disableForm)
            obj.switchForm(false);
        try {
            obj.xmlHttpRequest.open(obj.method, obj.url, obj.async, obj.username || '', obj.password || '');
        } catch (e) {
            obj.raiseEvent("FatalError", obj, e);
            return;
        }
        if (obj.timeout > 0)
            setTimeout(obj._onTimeout, obj.timeout);
        if (typeof obj.xmlHttpRequest.setRequestHeader != "undefined")
            for (var a in obj.headers)
                obj.xmlHttpRequest.setRequestHeader(encodeURIComponent(a), encodeURIComponent(obj.headers[a]));
        if (obj.method == "POST" && typeof obj.xmlHttpRequest.setRequestHeader != "undefined") {
            obj.xmlHttpRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
            obj.xmlHttpRequest.send(obj.queryString);
        } else if (obj.method == "GET")
            obj.xmlHttpRequest.send('');
    };

    obj.handleArguments = function(args) {

        if (typeof args.form == "object" && args.form != null) {
            obj.form = args.form;
            obj.appendForm();
        }
        for (a in args) {
            if (typeof obj[a] == "undefined")
                obj.parameters[a] = args[a]; else {
                if (a != "parameters" && a != "headers")
                    obj[a] = args[a]; else
                    for (b in args[a])
                        obj[a][b] = args[a][b];
            }
        }
        obj.method = obj.method.toUpperCase();
    };

    obj.switchForm = function(enable) {

        if (typeof obj.form != "object" || obj.form == null)
            return;
        with (obj.form)
            for (var nr = 0; nr < elements.length; nr++)
                if (!enable) {
                    if (elements[nr]["disabled"])
                        elements[nr]["_disabled"] = true; else
                        elements[nr]["disabled"] = "disabled";
                } else
                    if (typeof elements[nr]["_disabled"] == "undefined")
                        elements[nr].removeAttribute("disabled");
    };

    obj.appendForm = function() {

        with (obj.form) {
            obj.method = getAttribute("method").toUpperCase();
            obj.url = getAttribute("action");
            for (var nr = 0; nr < elements.length; nr++) {
                var e = elements[nr];
                if (e.disabled)
                    continue;
                switch (e.type) {
                    case "text":
                    case "password":
                    case "hidden":
                    case "textarea":
                        obj.addParameter(e.name, e.value);
                        break;
                    case "select-one":
                        if (e.selectedIndex >= 0)
                            obj.addParameter(e.name, e.options[e.selectedIndex].value);
                        break;
                    case "select-multiple":
                        for (var nr2 = 0; nr2 < e.options.length; nr2++)
                            if (e.options[nr2].selected)
                                obj.addParameter(e.name, e.options[nr2].value);
                        break;
                    case "checkbox":
                    case "radio":
                        if (e.checked)
                            obj.addParameter(e.name, e.value);
                        break;
                }
            }
        }
    };

    obj.addParameter = function(name, value) {
        if (typeof obj.parameters[name] == "undefined")
            obj.parameters[name] = value; else
        if (typeof obj.parameters[name] != "object")
            obj.parameters[name] = [ obj.parameters[name], value ]; else
        obj.parameters[name][obj.parameters[name].length] = value;
    };
    obj.delParameter = function(name) {

        delete obj.parameters[name];
    };
    obj.raiseEvent = function(name) {
        var args = [];
        for (var i = 1; i < arguments.length; i++)
            args.push(arguments[i]);
        if (typeof obj["on" + name] == "function")
            obj["on" + name].apply(null, args);
        if (name == "FatalError")
            obj.raiseEvent("Finalization", obj);
    }

    if (typeof advAJAX._defaultParameters != "undefined")
        obj.handleArguments(advAJAX._defaultParameters);
    return obj;
}
advAJAX.get = function(args) {

    return advAJAX.handleRequest("GET", args);
};
advAJAX.post = function(args) {

    return advAJAX.handleRequest("POST", args);
};
advAJAX.head = function(args) {

    return advAJAX.handleRequest("HEAD", args);
};
advAJAX.submit = function(form, args) {

    if (typeof args == "undefined" || args == null)
        return -1;
    if (typeof form != "object" || form == null)
        return -2;
    var request = new advAJAX();
    args["form"] = form;
    request.handleArguments(args);
    return request.run();
};
advAJAX.assign = function(form, args) {

    if (typeof args == "undefined" || args == null)
        return -1;
    if (typeof form != "object" || form == null)
        return -2;
    if (typeof form["onsubmit"] == "function")
        form["_onsubmit"] = form["onsubmit"];
    form["advajax_args"] = args;
    form["onsubmit"] = function() {
        if (typeof this["_onsubmit"] != "undefined" && this["_onsubmit"]() === false)
            return false;
        if (advAJAX.submit(this, this["advajax_args"]) == false)
            return true;
        return false;
    }
    return true;
};
advAJAX.download = function(targetObj, url) {

    if (typeof targetObj == "string")
        targetObj = document.getElementById(targetObj);
    if (!targetObj)
        return -1;
    advAJAX.get({
        url: url,
        onSuccess : function(obj) {
            targetObj.innerHTML = obj.responseText;
        }
    });
};
advAJAX.scan = function() {

    var obj = document.getElementsByTagName("a");
    for (var i = 0; i < obj.length;) {
        if (obj[i].getAttribute("rel") == "advancedajax" && obj[i].getAttribute("href") !== null) {
            var url = obj[i].getAttribute("href");
            var div = document.createElement("div");
            div.innerHTML = obj[i].innerHTML;
            div.className = obj[i].className;
            var parent = obj[i].parentNode;
            parent.insertBefore(div, obj[i]);
            parent.removeChild(obj[i]);
            advAJAX.download(div, url);
        } else i++;
    }
};
advAJAX.handleRequest = function(requestType, args) {

    if (typeof args == "undefined" || args == null)
        return -1;
    var request = new advAJAX();
    window.advajax_obj = request;
    request.method = requestType;
    request.handleArguments(args);
    return request.run();
};
advAJAX._defaultParameters = new Object();
advAJAX.setDefaultParameters = function(args) {

    advAJAX._defaultParameters = new Object();
    for (a in args)
        advAJAX._defaultParameters[a] = args[a];
};
advAJAX._groupData = new Object();

/*
 * Raphael 1.0 RC1.3 - JavaScript Vector Library
 *
 * Copyright (c) 2008 - 2009 Dmitry Baranovskiy (http://raphaeljs.com)
 * Licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) license.
 */
window.Raphael=(function(){var y=/[, ]+/,F=document,m=window,q={was:"Raphael" in window,is:window.Raphael},E=function(){return J.apply(E,arguments);},B={},O={"clip-rect":"0 0 10e9 10e9",cx:0,cy:0,fill:"#fff","fill-opacity":1,font:'10px "Arial"',"font-family":'"Arial"',"font-size":"10","font-style":"normal","font-weight":400,gradient:0,height:0,href:"http://raphaeljs.com/",opacity:1,path:"M0,0",r:0,rotation:0,rx:0,ry:0,scale:"1 1",src:"",stroke:"#000","stroke-dasharray":"","stroke-linecap":"butt","stroke-linejoin":"butt","stroke-miterlimit":0,"stroke-opacity":1,"stroke-width":1,target:"_blank","text-anchor":"middle",title:"Raphael",translation:"0 0",width:0,x:0,y:0},T={"clip-rect":"csv",cx:"number",cy:"number",fill:"colour","fill-opacity":"number","font-size":"number",height:"number",opacity:"number",path:"path",r:"number",rotation:"csv",rx:"number",ry:"number",scale:"csv",stroke:"colour","stroke-opacity":"number","stroke-width":"number",translation:"csv",width:"number",x:"number",y:"number"},U=["click","dblclick","mousedown","mousemove","mouseout","mouseover","mouseup"];E.version="1.0 RC1.3";E.type=(window.SVGAngle||document.implementation.hasFeature("http://www.w3.org/TR/SVG11/feature#BasicStructure","1.1")?"SVG":"VML");E.svg=!(E.vml=E.type=="VML");E.idGenerator=0;E.fn={};E.isArray=function(R){return Object.prototype.toString.call(R)=="[object Array]";};E.setWindow=function(R){m=R;F=m.document;};E.hsb2rgb=x(function(AF,AD,AJ){if(typeof AF=="object"&&"h" in AF&&"s" in AF&&"b" in AF){AJ=AF.b;AD=AF.s;AF=AF.h;}var AA,AB,AK;if(AJ==0){return{r:0,g:0,b:0,hex:"#000"};}if(AF>1||AD>1||AJ>1){AF/=255;AD/=255;AJ/=255;}var AC=Math.floor(AF*6),AG=(AF*6)-AC,z=AJ*(1-AD),e=AJ*(1-(AD*AG)),AL=AJ*(1-(AD*(1-AG)));AA=[AJ,e,z,z,AL,AJ,AJ][AC];AB=[AL,AJ,AJ,e,z,z,AL][AC];AK=[z,z,AL,AJ,AJ,e,z][AC];AA*=255;AB*=255;AK*=255;var AH={r:AA,g:AB,b:AK},R=Math.round(AA).toString(16),AE=Math.round(AB).toString(16),AI=Math.round(AK).toString(16);if(R.length==1){R="0"+R;}if(AE.length==1){AE="0"+AE;}if(AI.length==1){AI="0"+AI;}AH.hex="#"+R+AE+AI;return AH;},E);E.rgb2hsb=x(function(R,e,AD){if(typeof R=="object"&&"r" in R&&"g" in R&&"b" in R){AD=R.b;e=R.g;R=R.r;}if(typeof R=="string"){var AF=E.getRGB(R);R=AF.r;e=AF.g;AD=AF.b;}if(R>1||e>1||AD>1){R/=255;e/=255;AD/=255;}var AC=Math.max(R,e,AD),i=Math.min(R,e,AD),AA,z,AB=AC;if(i==AC){return{h:0,s:0,b:AC};}else{var AE=(AC-i);z=AE/AC;if(R==AC){AA=(e-AD)/AE;}else{if(e==AC){AA=2+((AD-R)/AE);}else{AA=4+((R-e)/AE);}}AA/=6;if(AA<0){AA+=1;}if(AA>1){AA-=1;}}return{h:AA,s:z,b:AB};},E);E._path2string=function(){var z="",AC;for(var e=0,AA=this.length;e<AA;e++){for(var R=0,AB=this[e].length;R<AB;R++){z+=this[e][R];R&&R!=AB-1&&(z+=",");}e!=AA-1&&(z+="\n");}return z.replace(/,(?=-)/g,"");};function x(z,e,R){function i(){var AA=Array.prototype.splice.call(arguments,0,arguments.length),AB=AA.join("\u25ba");i.cache=i.cache||{};i.count=i.count||[];if(AB in i.cache){return R?R(i.cache[AB]):i.cache[AB];}if(i.count.length>1000){delete i.cache[i.count.unshift()];}i.count.push(AB);i.cache[AB]=z.apply(e,AA);return R?R(i.cache[AB]):i.cache[AB];}return i;}E.getRGB=x(function(R){var AF={aliceblue:"#f0f8ff",amethyst:"#96c",antiquewhite:"#faebd7",aqua:"#0ff",aquamarine:"#7fffd4",azure:"#f0ffff",beige:"#f5f5dc",bisque:"#ffe4c4",black:"#000",blanchedalmond:"#ffebcd",blue:"#00f",blueviolet:"#8a2be2",brown:"#a52a2a",burlywood:"#deb887",cadetblue:"#5f9ea0",chartreuse:"#7fff00",chocolate:"#d2691e",coral:"#ff7f50",cornflowerblue:"#6495ed",cornsilk:"#fff8dc",crimson:"#dc143c",cyan:"#0ff",darkblue:"#00008b",darkcyan:"#008b8b",darkgoldenrod:"#b8860b",darkgray:"#a9a9a9",darkgreen:"#006400",darkkhaki:"#bdb76b",darkmagenta:"#8b008b",darkolivegreen:"#556b2f",darkorange:"#ff8c00",darkorchid:"#9932cc",darkred:"#8b0000",darksalmon:"#e9967a",darkseagreen:"#8fbc8f",darkslateblue:"#483d8b",darkslategray:"#2f4f4f",darkturquoise:"#00ced1",darkviolet:"#9400d3",deeppink:"#ff1493",deepskyblue:"#00bfff",dimgray:"#696969",dodgerblue:"#1e90ff",firebrick:"#b22222",floralwhite:"#fffaf0",forestgreen:"#228b22",fuchsia:"#f0f",gainsboro:"#dcdcdc",ghostwhite:"#f8f8ff",gold:"#ffd700",goldenrod:"#daa520",gray:"#808080",green:"#008000",greenyellow:"#adff2f",honeydew:"#f0fff0",hotpink:"#ff69b4",indianred:"#cd5c5c",indigo:"#4b0082",ivory:"#fffff0",khaki:"#f0e68c",lavender:"#e6e6fa",lavenderblush:"#fff0f5",lawngreen:"#7cfc00",lemonchiffon:"#fffacd",lightblue:"#add8e6",lightcoral:"#f08080",lightcyan:"#e0ffff",lightgoldenrodyellow:"#fafad2",lightgreen:"#90ee90",lightgrey:"#d3d3d3",lightpink:"#ffb6c1",lightsalmon:"#ffa07a",lightsalmon:"#ffa07a",lightseagreen:"#20b2aa",lightskyblue:"#87cefa",lightslategray:"#789",lightsteelblue:"#b0c4de",lightyellow:"#ffffe0",lime:"#0f0",limegreen:"#32cd32",linen:"#faf0e6",magenta:"#f0f",maroon:"#800000",mediumaquamarine:"#66cdaa",mediumblue:"#0000cd",mediumorchid:"#ba55d3",mediumpurple:"#9370db",mediumseagreen:"#3cb371",mediumslateblue:"#7b68ee",mediumslateblue:"#7b68ee",mediumspringgreen:"#00fa9a",mediumturquoise:"#48d1cc",mediumvioletred:"#c71585",midnightblue:"#191970",mintcream:"#f5fffa",mistyrose:"#ffe4e1",moccasin:"#ffe4b5",navajowhite:"#ffdead",navy:"#000080",oldlace:"#fdf5e6",olive:"#808000",olivedrab:"#6b8e23",orange:"#ffa500",orangered:"#ff4500",orchid:"#da70d6",palegoldenrod:"#eee8aa",palegreen:"#98fb98",paleturquoise:"#afeeee",palevioletred:"#db7093",papayawhip:"#ffefd5",peachpuff:"#ffdab9",peru:"#cd853f",pink:"#ffc0cb",plum:"#dda0dd",powderblue:"#b0e0e6",purple:"#800080",red:"#f00",rosybrown:"#bc8f8f",royalblue:"#4169e1",saddlebrown:"#8b4513",salmon:"#fa8072",sandybrown:"#f4a460",seagreen:"#2e8b57",seashell:"#fff5ee",sienna:"#a0522d",silver:"#c0c0c0",skyblue:"#87ceeb",slateblue:"#6a5acd",slategray:"#708090",snow:"#fffafa",springgreen:"#00ff7f",steelblue:"#4682b4",tan:"#d2b48c",teal:"#008080",thistle:"#d8bfd8",tomato:"#ff6347",turquoise:"#40e0d0",violet:"#ee82ee",wheat:"#f5deb3",white:"#fff",whitesmoke:"#f5f5f5",yellow:"#ff0",yellowgreen:"#9acd32"},AB;if((R+"").toLowerCase() in AF){R=AF[R.toString().toLowerCase()];}if(!R){return{r:0,g:0,b:0,hex:"#000"};}if(R=="none"){return{r:-1,g:-1,b:-1,hex:"none"};}var i,z,AE,AC=(R+"").match(/^\s*((#[a-f\d]{6})|(#[a-f\d]{3})|rgb\(\s*([\d\.]+\s*,\s*[\d\.]+\s*,\s*[\d\.]+)\s*\)|rgb\(\s*([\d\.]+%\s*,\s*[\d\.]+%\s*,\s*[\d\.]+%)\s*\)|hs[bl]\(\s*([\d\.]+\s*,\s*[\d\.]+\s*,\s*[\d\.]+)\s*\)|hs[bl]\(\s*([\d\.]+%\s*,\s*[\d\.]+%\s*,\s*[\d\.]+%)\s*\))\s*$/i);if(AC){if(AC[2]){AE=parseInt(AC[2].substring(5),16);z=parseInt(AC[2].substring(3,5),16);i=parseInt(AC[2].substring(1,3),16);}if(AC[3]){AE=parseInt(AC[3].substring(3)+AC[3].substring(3),16);z=parseInt(AC[3].substring(2,3)+AC[3].substring(2,3),16);i=parseInt(AC[3].substring(1,2)+AC[3].substring(1,2),16);}if(AC[4]){AC=AC[4].split(/\s*,\s*/);i=parseFloat(AC[0]);z=parseFloat(AC[1]);AE=parseFloat(AC[2]);}if(AC[5]){AC=AC[5].split(/\s*,\s*/);i=parseFloat(AC[0])*2.55;z=parseFloat(AC[1])*2.55;AE=parseFloat(AC[2])*2.55;}if(AC[6]){AC=AC[6].split(/\s*,\s*/);i=parseFloat(AC[0]);z=parseFloat(AC[1]);AE=parseFloat(AC[2]);return E.hsb2rgb(i,z,AE);}if(AC[7]){AC=AC[7].split(/\s*,\s*/);i=parseFloat(AC[0])*2.55;z=parseFloat(AC[1])*2.55;AE=parseFloat(AC[2])*2.55;return E.hsb2rgb(i,z,AE);}var AC={r:i,g:z,b:AE},e=Math.round(i).toString(16),AA=Math.round(z).toString(16),AD=Math.round(AE).toString(16);(e.length==1)&&(e="0"+e);(AA.length==1)&&(AA="0"+AA);(AD.length==1)&&(AD="0"+AD);AC.hex="#"+e+AA+AD;AB=AC;}else{AB={r:-1,g:-1,b:-1,hex:"none"};}return AB;},E);E.getColor=function(e){var i=this.getColor.start=this.getColor.start||{h:0,s:1,b:e||0.75},R=this.hsb2rgb(i.h,i.s,i.b);i.h+=0.075;if(i.h>1){i.h=0;i.s-=0.2;if(i.s<=0){this.getColor.start={h:0,s:1,b:i.b};}}return R.hex;};E.getColor.reset=function(){delete this.start;};E.parsePathString=x(function(R){if(!R){return null;}var i={a:7,c:6,h:1,l:2,m:2,q:4,s:4,t:2,v:1,z:0},e=[];if(E.isArray(R)&&E.isArray(R[0])){e=S(R);}if(!e.length){(R+"").replace(/([achlmqstvz])[\s,]*((-?\d*\.?\d*(?:e[-+]?\d+)?\s*,?\s*)+)/ig,function(AA,z,AD){var AC=[],AB=z.toLowerCase();AD.replace(/(-?\d*\.?\d*(?:e[-+]?\d+)?)\s*,?\s*/ig,function(AF,AE){AE&&AC.push(+AE);});while(AC.length>=i[AB]){e.push([z].concat(AC.splice(0,i[AB])));if(!i[AB]){break;}}});}e.toString=E._path2string;return e;});var b=x(function(AG){if(!AG){return{x:0,y:0,width:0,height:0};}AG=p(AG);var AD=0,AC=0,z=[],e=[];for(var AA=0,AF=AG.length;AA<AF;AA++){if(AG[AA][0]=="M"){AD=AG[AA][1];AC=AG[AA][2];z.push(AD);e.push(AC);}else{var AB=k(AD,AC,AG[AA][1],AG[AA][2],AG[AA][3],AG[AA][4],AG[AA][5],AG[AA][6]);z=z.concat(AB.min.x,AB.max.x);e=e.concat(AB.min.y,AB.max.y);}}var R=Math.min.apply(0,z),AE=Math.min.apply(0,e);return{x:R,y:AE,width:Math.max.apply(0,z)-R,height:Math.max.apply(0,e)-AE};}),S=function(AC){var z=[];if(!E.isArray(AC)||!E.isArray(AC&&AC[0])){AC=E.parsePathString(AC);}for(var e=0,AA=AC.length;e<AA;e++){z[e]=[];for(var R=0,AB=AC[e].length;R<AB;R++){z[e][R]=AC[e][R];}}z.toString=E._path2string;return z;},C=x(function(AA){if(!E.isArray(AA)||!E.isArray(AA&&AA[0])){AA=E.parsePathString(AA);}var AG=[],AI=0,AH=0,AL=0,AK=0,z=0;if(AA[0][0]=="M"){AI=AA[0][1];AH=AA[0][2];AL=AI;AK=AH;z++;AG.push(["M",AI,AH]);}for(var AD=z,AM=AA.length;AD<AM;AD++){var R=AG[AD]=[],AJ=AA[AD];if(AJ[0]!=AJ[0].toLowerCase()){R[0]=AJ[0].toLowerCase();switch(R[0]){case"a":R[1]=AJ[1];R[2]=AJ[2];R[3]=AJ[3];R[4]=AJ[4];R[5]=AJ[5];R[6]=+(AJ[6]-AI).toFixed(3);R[7]=+(AJ[7]-AH).toFixed(3);break;case"v":R[1]=+(AJ[1]-AH).toFixed(3);break;case"m":AL=AJ[1];AK=AJ[2];default:for(var AC=1,AE=AJ.length;AC<AE;AC++){R[AC]=+(AJ[AC]-((AC%2)?AI:AH)).toFixed(3);}}}else{R=AG[AD]=[];if(AJ[0]=="m"){AL=AJ[1]+AI;AK=AJ[2]+AH;}for(var AB=0,e=AJ.length;AB<e;AB++){AG[AD][AB]=AJ[AB];}}var AF=AG[AD].length;switch(AG[AD][0]){case"z":AI=AL;AH=AK;break;case"h":AI+=+AG[AD][AF-1];break;case"v":AH+=+AG[AD][AF-1];break;default:AI+=+AG[AD][AF-2];AH+=+AG[AD][AF-1];}}AG.toString=E._path2string;return AG;},0,S),V=x(function(AA){if(!E.isArray(AA)||!E.isArray(AA&&AA[0])){AA=E.parsePathString(AA);}var AF=[],AH=0,AG=0,AK=0,AJ=0,z=0;if(AA[0][0]=="M"){AH=+AA[0][1];AG=+AA[0][2];AK=AH;AJ=AG;z++;AF[0]=["M",AH,AG];}for(var AD=z,AL=AA.length;AD<AL;AD++){var R=AF[AD]=[],AI=AA[AD];if(AI[0]!=(AI[0]+"").toUpperCase()){R[0]=(AI[0]+"").toUpperCase();switch(R[0]){case"A":R[1]=AI[1];R[2]=AI[2];R[3]=AI[3];R[4]=AI[4];R[5]=AI[5];R[6]=+(AI[6]+AH);R[7]=+(AI[7]+AG);break;case"V":R[1]=+AI[1]+AG;break;case"H":R[1]=+AI[1]+AH;break;case"M":AK=+AI[1]+AH;AJ=+AI[2]+AG;default:for(var AC=1,AE=AI.length;AC<AE;AC++){R[AC]=+AI[AC]+((AC%2)?AH:AG);}}}else{for(var AB=0,e=AI.length;AB<e;AB++){AF[AD][AB]=AI[AB];}}switch(R[0]){case"Z":AH=AK;AG=AJ;break;case"H":AH=R[1];break;case"V":AG=R[1];break;default:AH=AF[AD][AF[AD].length-2];AG=AF[AD][AF[AD].length-1];}}AF.toString=E._path2string;return AF;},null,S),D=function(e,z,R,i){return[e,z,R,i,R,i];},W=function(e,z,AB,AA,R,i){return[2/3*e+1/3*AB,2/3*z+1/3*AA,2/3*e+1/3*R,2/3*z+1/3*i,R,i];},P=function(AK,Ao,AT,AR,AL,AF,AA,AJ,An,AM){var AQ=Math.PI*120/180,R=Math.PI/180*(+AL||0),AX=[],AU,Ak=x(function(Ap,As,i){var Ar=Ap*Math.cos(i)-As*Math.sin(i),Aq=Ap*Math.sin(i)+As*Math.cos(i);return{x:Ar,y:Aq};});if(!AM){AU=Ak(AK,Ao,-R);AK=AU.x;Ao=AU.y;AU=Ak(AJ,An,-R);AJ=AU.x;An=AU.y;var e=Math.cos(Math.PI/180*AL),AH=Math.sin(Math.PI/180*AL),AZ=(AK-AJ)/2,AY=(Ao-An)/2;AT=Math.max(AT,Math.abs(AZ));AR=Math.max(AR,Math.abs(AY));var z=AT*AT,Ac=AR*AR,Ae=(AF==AA?-1:1)*Math.sqrt(Math.abs((z*Ac-z*AY*AY-Ac*AZ*AZ)/(z*AY*AY+Ac*AZ*AZ))),AO=Ae*AT*AY/AR+(AK+AJ)/2,AN=Ae*-AR*AZ/AT+(Ao+An)/2,AE=Math.asin((Ao-AN)/AR),AD=Math.asin((An-AN)/AR);AE=AK<AO?Math.PI-AE:AE;AD=AJ<AO?Math.PI-AD:AD;AE<0&&(AE=Math.PI*2+AE);AD<0&&(AD=Math.PI*2+AD);if(AA&&AE>AD){AE=AE-Math.PI*2;}if(!AA&&AD>AE){AD=AD-Math.PI*2;}}else{AE=AM[0];AD=AM[1];AO=AM[2];AN=AM[3];}var AI=AD-AE;if(Math.abs(AI)>AQ){var AP=AD,AS=AJ,AG=An;AD=AE+AQ*(AA&&AD>AE?1:-1);AJ=AO+AT*Math.cos(AD);An=AN+AR*Math.sin(AD);AX=P(AJ,An,AT,AR,AL,0,AA,AS,AG,[AD,AP,AO,AN]);}var AC=Math.cos(AE),Am=Math.sin(AE),AB=Math.cos(AD),Al=Math.sin(AD),AI=AD-AE,Aa=Math.tan(AI/4),Ad=4/3*AT*Aa,Ab=4/3*AR*Aa,Aj=[AK,Ao],Ai=[AK+Ad*Am,Ao-Ab*AC],Ah=[AJ+Ad*Al,An-Ab*AB],Af=[AJ,An];Ai[0]=2*Aj[0]-Ai[0];Ai[1]=2*Aj[1]-Ai[1];if(AM){return[Ai,Ah,Af].concat(AX);}else{AX=[Ai,Ah,Af].concat(AX).join(",").split(",");var AV=[];for(var Ag=0,AW=AX.length;Ag<AW;Ag++){AV[Ag]=Ag%2?Ak(AX[Ag-1],AX[Ag],R).y:Ak(AX[Ag],AX[Ag+1],R).x;}return AV;}},Z=x(function(e,R,AO,AM,AB,AA,AD,AC,AI){var AG=Math.pow(1-AI,3)*e+Math.pow(1-AI,2)*3*AI*AO+(1-AI)*3*AI*AI*AB+Math.pow(AI,3)*AD,AE=Math.pow(1-AI,3)*R+Math.pow(1-AI,2)*3*AI*AM+(1-AI)*3*AI*AI*AA+Math.pow(AI,3)*AC,AK=e+2*AI*(AO-e)+AI*AI*(AB-2*AO+e),AJ=R+2*AI*(AM-R)+AI*AI*(AA-2*AM+R),AN=AO+2*AI*(AB-AO)+AI*AI*(AD-2*AB+AO),AL=AM+2*AI*(AA-AM)+AI*AI*(AC-2*AA+AM),AH=(1-AI)*e+AI*AO,AF=(1-AI)*R+AI*AM,z=(1-AI)*AB+AI*AD,i=(1-AI)*AA+AI*AC;return{x:AG,y:AE,m:{x:AK,y:AJ},n:{x:AN,y:AL},start:{x:AH,y:AF},end:{x:z,y:i}};}),k=x(function(e,R,z,i,AM,AL,AI,AF){var AK=(AM-2*z+e)-(AI-2*AM+z),AH=2*(z-e)-2*(AM-z),AE=e-z,AC=(-AH+Math.sqrt(AH*AH-4*AK*AE))/2/AK,AA=(-AH-Math.sqrt(AH*AH-4*AK*AE))/2/AK,AG=[R,AF],AJ=[e,AI],AD=Z(e,R,z,i,AM,AL,AI,AF,AC>0&&AC<1?AC:0),AB=Z(e,R,z,i,AM,AL,AI,AF,AA>0&&AA<1?AA:0);AJ=AJ.concat(AD.x,AB.x);AG=AG.concat(AD.y,AB.y);AK=(AL-2*i+R)-(AF-2*AL+i);AH=2*(i-R)-2*(AL-i);AE=R-i;AC=(-AH+Math.sqrt(AH*AH-4*AK*AE))/2/AK;AA=(-AH-Math.sqrt(AH*AH-4*AK*AE))/2/AK;AD=Z(e,R,z,i,AM,AL,AI,AF,AC>0&&AC<1?AC:0);AB=Z(e,R,z,i,AM,AL,AI,AF,AA>0&&AA<1?AA:0);AJ=AJ.concat(AD.x,AB.x);AG=AG.concat(AD.y,AB.y);return{min:{x:Math.min.apply(Math,AJ),y:Math.min.apply(Math,AG)},max:{x:Math.max.apply(Math,AJ),y:Math.max.apply(Math,AG)}};}),p=x(function(AL,AG){var AA=V(AL),AH=AG&&V(AG),AI={x:0,y:0,bx:0,by:0,X:0,Y:0},R={x:0,y:0,bx:0,by:0,X:0,Y:0},AC=function(AM,AN){if(!AM){return["C",AN.x,AN.y,AN.x,AN.y,AN.x,AN.y];}switch(AM[0]){case"M":AN.X=AM[1];AN.Y=AM[2];break;case"A":AM=["C"].concat(P(AN.x,AN.y,AM[1],AM[2],AM[3],AM[4],AM[5],AM[6],AM[7]));break;case"S":var i=AN.x+(AN.x-(AN.bx||AN.x)),AO=AN.y+(AN.y-(AN.by||AN.y));AM=["C",i,AO,AM[1],AM[2],AM[3],AM[4]];break;case"T":var i=AN.x+(AN.x-(AN.bx||AN.x)),AO=AN.y+(AN.y-(AN.by||AN.y));AM=["C"].concat(W(AN.x,AN.y,i,AO,AM[1],AM[2]));break;case"Q":AM=["C"].concat(W(AN.x,AN.y,AM[1],AM[2],AM[3],AM[4]));break;case"L":AM=["C"].concat(D(AN.x,AN.y,AM[1],AM[2]));break;case"H":AM=["C"].concat(D(AN.x,AN.y,AM[1],AN.y));break;case"V":AM=["C"].concat(D(AN.x,AN.y,AN.x,AM[1]));break;case"Z":AM=["C"].concat(D(AN.x,AN.y,AN.X,AN.Y));break;}return AM;},e=function(AM,AN){if(AM[AN].length>7){AM[AN].shift();var AO=AM[AN];while(AO.length){AM.splice(AN++,0,["C"].concat(AO.splice(0,6)));}AM.splice(AN,1);AJ=Math.max(AA.length,AH&&AH.length||0);}},z=function(AQ,AP,AN,AM,AO){if(AQ&&AP&&AQ[AO][0]=="M"&&AP[AO][0]!="M"){AP.splice(AO,0,["M",AM.x,AM.y]);AN.bx=0;AN.by=0;AN.x=AQ[AO][1];AN.y=AQ[AO][2];AJ=Math.max(AA.length,AH&&AH.length||0);}};for(var AE=0,AJ=Math.max(AA.length,AH&&AH.length||0);AE<AJ;AE++){AA[AE]=AC(AA[AE],AI);e(AA,AE);AH&&(AH[AE]=AC(AH[AE],R));AH&&e(AH,AE);z(AA,AH,AI,R,AE);z(AH,AA,R,AI,AE);var AD=AA[AE],AK=AH&&AH[AE],AB=AD.length,AF=AH&&AK.length;AI.bx=AD[AB-4]||0;AI.by=AD[AB-3]||0;AI.x=AD[AB-2];AI.y=AD[AB-1];R.bx=AH&&(AK[AF-4]||0);R.by=AH&&(AK[AF-3]||0);R.x=AH&&AK[AF-2];R.y=AH&&AK[AF-1];}return AH?[AA,AH]:AA;},null,S),L=x(function(AH){if(typeof AH=="string"){AH=AH.split(/\s*\-\s*/);var z=AH.shift();if(z.toLowerCase()=="v"){z=90;}else{if(z.toLowerCase()=="h"){z=0;}else{z=parseFloat(z);}}z=-z;var AF={angle:z,type:"linear",dots:[],vector:[0,0,Math.cos(z*Math.PI/180).toFixed(3),Math.sin(z*Math.PI/180).toFixed(3)]},AG=1/(Math.max(Math.abs(AF.vector[2]),Math.abs(AF.vector[3]))||1);AF.vector[2]*=AG;AF.vector[3]*=AG;if(AF.vector[2]<0){AF.vector[0]=-AF.vector[2];AF.vector[2]=0;}if(AF.vector[3]<0){AF.vector[1]=-AF.vector[3];AF.vector[3]=0;}AF.vector[0]=AF.vector[0];AF.vector[1]=AF.vector[1];AF.vector[2]=AF.vector[2];AF.vector[3]=AF.vector[3];for(var AC=0,AI=AH.length;AC<AI;AC++){var R={},AE=AH[AC].match(/^([^:]*):?([\d\.]*)/);R.color=E.getRGB(AE[1]).hex;AE[2]&&(R.offset=AE[2]+"%");AF.dots.push(R);}for(var AC=1,AI=AF.dots.length-1;AC<AI;AC++){if(!AF.dots[AC].offset){var e=parseFloat(AF.dots[AC-1].offset||0),AA=false;for(var AB=AC+1;AB<AI;AB++){if(AF.dots[AB].offset){AA=AF.dots[AB].offset;break;}}if(!AA){AA=100;AB=AI;}AA=parseFloat(AA);var AD=(AA-e)/(AB-AC+1);for(;AC<AB;AC++){e+=AD;AF.dots[AC].offset=e+"%";}}}return AF;}else{return AH;}}),g=function(){var i,e,AA,z,R;if(typeof arguments[0]=="string"||typeof arguments[0]=="object"){if(typeof arguments[0]=="string"){i=F.getElementById(arguments[0]);}else{i=arguments[0];}if(i.tagName){if(arguments[1]==null){return{container:i,width:i.style.pixelWidth||i.offsetWidth,height:i.style.pixelHeight||i.offsetHeight};}else{return{container:i,width:arguments[1],height:arguments[2]};}}}else{if(typeof arguments[0]=="number"&&arguments.length>3){return{container:1,x:arguments[0],y:arguments[1],width:arguments[2],height:arguments[3]};}}},A=function(R,i){var e=this;for(var z in i){if(i.hasOwnProperty(z)&&!(z in R)){switch(typeof i[z]){case"function":(function(AA){R[z]=R===e?AA:function(){return AA.apply(e,arguments);};})(i[z]);break;case"object":R[z]=R[z]||{};A.call(this,R[z],i[z]);break;default:R[z]=i[z];break;}}}};if(E.svg){var o=function(R){return +R+(Math.floor(R)==R)*0.5;};var Y=function(AB){for(var e=0,z=AB.length;e<z;e++){if(AB[e][0].toLowerCase()!="a"){for(var R=1,AA=AB[e].length;R<AA;R++){AB[e][R]=o(AB[e][R]);}}else{AB[e][6]=o(AB[e][6]);AB[e][7]=o(AB[e][7]);}}return AB;};var a=function(i,R){for(var e in R){if(R.hasOwnProperty(e)){i.setAttribute(e,R[e]);}}};E.toString=function(){return"Your browser supports SVG.\nYou are running Rapha\u00ebl "+this.version;};var w=function(R,z){var e=F.createElementNS(z.svgns,"path");z.canvas&&z.canvas.appendChild(e);var i=new K(e,z);i.type="path";f(i,{fill:"none",stroke:"#000",path:R});return i;};var n=function(AD,AB,AE){AB=L(AB);var AA=F.createElementNS(AE.svgns,(AB.type||"linear")+"Gradient");AA.id="r"+(E.idGenerator++).toString(36);if(AB.vector&&AB.vector.length){a(AA,{x1:AB.vector[0],y1:AB.vector[1],x2:AB.vector[2],y2:AB.vector[3]});}AE.defs.appendChild(AA);var AC=true;for(var e=0,z=AB.dots.length;e<z;e++){var R=F.createElementNS(AE.svgns,"stop");if(AB.dots[e].offset){AC=false;}a(R,{offset:AB.dots[e].offset?AB.dots[e].offset:(e==0)?"0%":"100%","stop-color":E.getRGB(AB.dots[e].color).hex||"#fff"});AA.appendChild(R);}if(AC&&AB.dots[z-1].opacity!=null){a(R,{"stop-opacity":AB.dots[z-1].opacity});}a(AD,{fill:"url(#"+AA.id+")",opacity:1,"fill-opacity":1});AD.style.fill="";AD.style.opacity=1;AD.style.fillOpacity=1;};var Q=function(e){var R=e.getBBox();a(e.pattern,{patternTransform:E.format("translate({0},{1})",R.x,R.y)});};var f=function(AH,AQ){var AK={"":[0],none:[0],"-":[3,1],".":[1,1],"-.":[3,1,1,1],"-..":[3,1,1,1,1,1],". ":[1,3],"- ":[4,3],"--":[8,3],"- .":[4,3,1,3],"--.":[8,3,1,3],"--..":[8,3,1,3,1,3]},AM=AH.node,AI=AH.attrs,AE=AH.attr("rotation"),AB=function(AX,AW){AW=AK[(AW+"").toLowerCase()];if(AW){var AU=AX.attrs["stroke-width"]||"1",AS={round:AU,square:AU,butt:0}[AX.attrs["stroke-linecap"]||AQ["stroke-linecap"]]||0,AV=[];var AT=AW.length;while(AT--){AV[AT]=AW[AT]*AU+((AT%2)?1:-1)*AS;}a(AM,{"stroke-dasharray":AV.join(",")});}};parseFloat(AE)&&AH.rotate(0,true);for(var AL in AQ){if(!(AL in O)){continue;}var AJ=AQ[AL];AI[AL]=AJ;switch(AL){case"href":case"title":case"target":var AO=AM.parentNode;if(AO.tagName.toLowerCase()!="a"){var z=F.createElementNS(AH.paper.svgns,"a");AO.insertBefore(z,AM);z.appendChild(AM);AO=z;}AO.setAttributeNS(AH.paper.xlink,AL,AJ);break;case"clip-rect":var e=(AJ+"").split(y);if(e.length==4){AH.clip&&AH.clip.parentNode.parentNode.removeChild(AH.clip.parentNode);var i=F.createElementNS(AH.paper.svgns,"clipPath"),AN=F.createElementNS(AH.paper.svgns,"rect");i.id="r"+(E.idGenerator++).toString(36);a(AN,{x:e[0],y:e[1],width:e[2],height:e[3]});i.appendChild(AN);AH.paper.defs.appendChild(i);a(AM,{"clip-path":"url(#"+i.id+")"});AH.clip=AN;}if(!AJ){var AP=F.getElementById(AM.getAttribute("clip-path").replace(/(^url\(#|\)$)/g,""));AP&&AP.parentNode.removeChild(AP);a(AM,{"clip-path":""});delete AH.clip;}break;case"path":if(AJ&&AH.type=="path"){AI.path=Y(V(AJ));a(AM,{d:AI.path});}case"width":AM.setAttribute(AL,AJ);if(AI.fx){AL="x";AJ=AI.x;}else{break;}case"x":if(AI.fx){AJ=-AI.x-(AI.width||0);}case"rx":case"cx":AM.setAttribute(AL,AJ);AH.pattern&&Q(AH);break;case"height":AM.setAttribute(AL,AJ);if(AI.fy){AL="y";AJ=AI.y;}else{break;}case"y":if(AI.fy){AJ=-AI.y-(AI.height||0);}case"ry":case"cy":AM.setAttribute(AL,AJ);AH.pattern&&Q(AH);break;case"r":if(AH.type=="rect"){a(AM,{rx:AJ,ry:AJ});}else{AM.setAttribute(AL,AJ);}break;case"src":if(AH.type=="image"){AM.setAttributeNS(AH.paper.xlink,"href",AJ);}break;case"stroke-width":AM.style.strokeWidth=AJ;AM.setAttribute(AL,AJ);if(AI["stroke-dasharray"]){AB(AH,AI["stroke-dasharray"]);}break;case"stroke-dasharray":AB(AH,AJ);break;case"rotation":AE=AJ;AH.rotate(AJ,true);break;case"translation":var AC=(AJ+"").split(y);AH.translate((+AC[0]+1||2)-1,(+AC[1]+1||2)-1);break;case"scale":var AC=(AJ+"").split(y);AH.scale(+AC[0]||1,+AC[1]||+AC[0]||1,+AC[2]||null,+AC[3]||null);break;case"fill":var AA=(AJ+"").match(/^url\(['"]?([^\)]+)['"]?\)$/i);if(AA){var i=F.createElementNS(AH.paper.svgns,"pattern"),AG=F.createElementNS(AH.paper.svgns,"image");i.id="r"+(E.idGenerator++).toString(36);a(i,{x:0,y:0,patternUnits:"userSpaceOnUse"});a(AG,{x:0,y:0});AG.setAttributeNS(AH.paper.xlink,"href",AA[1]);i.appendChild(AG);var AR=F.createElement("img");AR.style.position="absolute";AR.style.top="-9999em";AR.style.left="-9999em";AR.onload=function(){a(i,{width:this.offsetWidth,height:this.offsetHeight});a(AG,{width:this.offsetWidth,height:this.offsetHeight});F.body.removeChild(this);B.safari();};F.body.appendChild(AR);AR.src=AA[1];AH.paper.defs.appendChild(i);AM.style.fill="url(#"+i.id+")";a(AM,{fill:"url(#"+i.id+")"});AH.pattern=i;AH.pattern&&Q(AH);break;}delete AQ.gradient;delete AI.gradient;if(typeof AI.opacity!="undefined"&&typeof AQ.opacity=="undefined"){AM.style.opacity=AI.opacity;a(AM,{opacity:AI.opacity});}if(typeof AI["fill-opacity"]!="undefined"&&typeof AQ["fill-opacity"]=="undefined"){AM.style.fillOpacity=AI["fill-opacity"];a(AM,{"fill-opacity":AI["fill-opacity"]});}case"stroke":AM.style[AL]=E.getRGB(AJ).hex;AM.setAttribute(AL,E.getRGB(AJ).hex);break;case"gradient":n(AM,AJ,AH.paper);break;case"opacity":case"fill-opacity":if(AI.gradient){var R=F.getElementById(AM.getAttribute("fill").replace(/^url\(#|\)$/g,""));if(R){var AD=R.getElementsByTagName("stop");AD[AD.length-1].setAttribute("stop-opacity",AJ);}break;}default:AL=="font-size"&&(AJ=parseInt(AJ,10)+"px");var AF=AL.replace(/(\-.)/g,function(AS){return AS.substring(1).toUpperCase();});AM.style[AF]=AJ;AM.setAttribute(AL,AJ);break;}}t(AH,AQ);parseInt(AE,10)&&AH.rotate(AE,true);};var l=1.2;var t=function(R,AA){if(R.type!="text"||!("text" in AA||"font" in AA||"font-size" in AA||"x" in AA||"y" in AA)){return ;}var AF=R.attrs,e=R.node,AH=e.firstChild?parseInt(F.defaultView.getComputedStyle(e.firstChild,"").getPropertyValue("font-size"),10):10;if("text" in AA){while(e.firstChild){e.removeChild(e.firstChild);}var z=(AA.text+"").split("\n");for(var AB=0,AG=z.length;AB<AG;AB++){var AD=F.createElementNS(R.paper.svgns,"tspan");AB&&a(AD,{dy:AH*l,x:AF.x});AD.appendChild(F.createTextNode(z[AB]));e.appendChild(AD);}}else{var z=e.getElementsByTagName("tspan");for(var AB=0,AG=z.length;AB<AG;AB++){AB&&a(z[AB],{dy:AH*l,x:AF.x});}}a(e,{y:AF.y});var AC=R.getBBox(),AE=AF.y-(AC.y+AC.height/2);AE&&a(e,{y:AF.y+AE});};var K=function(e,R){var z=0,i=0;this[0]=e;this.node=e;this.paper=R;this.attrs=this.attrs||{};this.transformations=[];this._={tx:0,ty:0,rt:{deg:0,cx:0,cy:0},sx:1,sy:1};};K.prototype.rotate=function(e,R,z){if(e==null){if(this._.rt.cx){return[this._.rt.deg,this._.rt.cx,this._.rt.cy].join(" ");}return this._.rt.deg;}var i=this.getBBox();e=(e+"").split(y);if(e.length-1){R=parseFloat(e[1]);z=parseFloat(e[2]);}e=parseFloat(e[0]);if(R!=null){this._.rt.deg=e;}else{this._.rt.deg+=e;}(z==null)&&(R=null);this._.rt.cx=R;this._.rt.cy=z;R=R==null?i.x+i.width/2:R;z=z==null?i.y+i.height/2:z;if(this._.rt.deg){this.transformations[0]=E.format("rotate({0} {1} {2})",this._.rt.deg,R,z);this.clip&&a(this.clip,{transform:E.format("rotate({0} {1} {2})",-this._.rt.deg,R,z)});}else{this.transformations[0]="";this.clip&&a(this.clip,{transform:""});}a(this.node,{transform:this.transformations.join(" ")});return this;};K.prototype.hide=function(){this.node.style.display="none";return this;};K.prototype.show=function(){this.node.style.display="block";return this;};K.prototype.remove=function(){this.node.parentNode.removeChild(this.node);};K.prototype.getBBox=function(){if(this.type=="path"){return b(this.attrs.path);}if(this.node.style.display=="none"){this.show();var z=true;}var AD={};try{AD=this.node.getBBox();}catch(AB){}finally{AD=AD||{};}if(this.type=="text"){AD={x:AD.x,y:Infinity,width:AD.width,height:0};for(var R=0,AA=this.node.getNumberOfChars();R<AA;R++){var AC=this.node.getExtentOfChar(R);(AC.y<AD.y)&&(AD.y=AC.y);(AC.y+AC.height-AD.y>AD.height)&&(AD.height=AC.y+AC.height-AD.y);}}z&&this.hide();return AD;};K.prototype.attr=function(){if(arguments.length==1&&typeof arguments[0]=="string"){if(arguments[0]=="translation"){return this.translate();}if(arguments[0]=="rotation"){return this.rotate();}if(arguments[0]=="scale"){return this.scale();}return this.attrs[arguments[0]];}if(arguments.length==1&&E.isArray(arguments[0])){var R={};for(var e in arguments[0]){R[arguments[0][e]]=this.attrs[arguments[0][e]];}return R;}if(arguments.length==2){var i={};i[arguments[0]]=arguments[1];f(this,i);}else{if(arguments.length==1&&typeof arguments[0]=="object"){f(this,arguments[0]);}}return this;};K.prototype.toFront=function(){this.node.parentNode.appendChild(this.node);return this;};K.prototype.toBack=function(){if(this.node.parentNode.firstChild!=this.node){this.node.parentNode.insertBefore(this.node,this.node.parentNode.firstChild);}return this;};K.prototype.insertAfter=function(R){if(R.node.nextSibling){R.node.parentNode.insertBefore(this.node,R.node.nextSibling);}else{R.node.parentNode.appendChild(this.node);}return this;};K.prototype.insertBefore=function(R){var e=R.node;e.parentNode.insertBefore(this.node,e);return this;};var c=function(e,R,AB,AA){R=o(R);AB=o(AB);var z=F.createElementNS(e.svgns,"circle");e.canvas&&e.canvas.appendChild(z);var i=new K(z,e);i.attrs={cx:R,cy:AB,r:AA,fill:"none",stroke:"#000"};i.type="circle";a(z,i.attrs);return i;};var j=function(i,R,AD,e,AB,AC){R=o(R);AD=o(AD);var AA=F.createElementNS(i.svgns,"rect");i.canvas&&i.canvas.appendChild(AA);var z=new K(AA,i);z.attrs={x:R,y:AD,width:e,height:AB,r:AC||0,rx:AC||0,ry:AC||0,fill:"none",stroke:"#000"};z.type="rect";a(AA,z.attrs);return z;};var G=function(e,R,AC,AB,AA){R=o(R);AC=o(AC);var z=F.createElementNS(e.svgns,"ellipse");e.canvas&&e.canvas.appendChild(z);var i=new K(z,e);i.attrs={cx:R,cy:AC,rx:AB,ry:AA,fill:"none",stroke:"#000"};i.type="ellipse";a(z,i.attrs);return i;};var N=function(i,AC,R,AD,e,AB){var AA=F.createElementNS(i.svgns,"image");a(AA,{x:R,y:AD,width:e,height:AB,preserveAspectRatio:"none"});AA.setAttributeNS(i.xlink,"href",AC);i.canvas&&i.canvas.appendChild(AA);var z=new K(AA,i);z.attrs={x:R,y:AD,width:e,height:AB,src:AC};z.type="image";return z;};var h=function(e,R,AB,AA){var z=F.createElementNS(e.svgns,"text");a(z,{x:R,y:AB,"text-anchor":"middle"});e.canvas&&e.canvas.appendChild(z);var i=new K(z,e);i.attrs={x:R,y:AB,"text-anchor":"middle",text:AA,font:O.font,stroke:"none",fill:"#000"};i.type="text";f(i,i.attrs);return i;};var d=function(e,R){this.width=e||this.width;this.height=R||this.height;this.canvas.setAttribute("width",this.width);this.canvas.setAttribute("height",this.height);return this;};var J=function(){var AA=g.apply(null,arguments),i=AA.container,AC=AA.x,AB=AA.y,z=AA.width,AD=AA.height;if(!i){throw new Error("SVG container not found.");}B.canvas=F.createElementNS(B.svgns,"svg");var R=B.canvas,AE=R.style;R.setAttribute("width",z||512);B.width=z||512;R.setAttribute("height",AD||342);B.height=AD||342;if(i==1){F.body.appendChild(R);AE.position="absolute";AE.left=AC+"px";AE.top=AB+"px";}else{if(i.firstChild){i.insertBefore(R,i.firstChild);}else{i.appendChild(R);}}i={canvas:R,clear:function(){while(this.canvas.firstChild){this.canvas.removeChild(this.canvas.firstChild);}this.desc=F.createElementNS(B.svgns,"desc");this.defs=F.createElementNS(B.svgns,"defs");this.desc.appendChild(F.createTextNode("Created with Rapha\u00ebl"));this.canvas.appendChild(this.desc);this.canvas.appendChild(this.defs);}};for(var e in B){if(e!="create"){i[e]=B[e];}}A.call(i,i,E.fn);i.clear();i.raphael=E;return i;};B.remove=function(){this.canvas.parentNode&&this.canvas.parentNode.removeChild(this.canvas);};B.svgns="http://www.w3.org/2000/svg";B.xlink="http://www.w3.org/1999/xlink";B.safari=function(){if({"Apple Computer, Inc.":1,"Google Inc.":1}[navigator.vendor]){var R=this.rect(-99,-99,this.width+99,this.height+99);setTimeout(function(){R.remove();});}};}if(E.vml){var X=function(AC){var AA=p(AC);for(var e=0,z=AA.length;e<z;e++){AA[e][0]=(AA[e][0]+"").toLowerCase();AA[e][0]=="z"&&(AA[e][0]="x");for(var R=1,AB=AA[e].length;R<AB;R++){AA[e][R]=Math.round(AA[e][R]);}}return(AA+"");};E.toString=function(){return"Your browser doesn\u2019t support SVG. Assuming it is Internet Explorer and falling down to VML.\nYou are running Rapha\u00ebl "+this.version;};var w=function(R,AB){var z=v("group"),AC=z.style;AC.position="absolute";AC.left=0;AC.top=0;AC.width=AB.width+"px";AC.height=AB.height+"px";z.coordsize=AB.coordsize;z.coordorigin=AB.coordorigin;var i=v("shape"),e=i.style;e.width=AB.width+"px";e.height=AB.height+"px";i.path="";i.coordsize=this.coordsize;i.coordorigin=this.coordorigin;z.appendChild(i);var AA=new K(i,z,AB);AA.isAbsolute=true;AA.type="path";AA.path=[];AA.Path="";if(R){AA.attrs.path=E.parsePathString(R);AA.node.path=X(AA.attrs.path);}f(AA,{fill:"none",stroke:"#000"});AA.setBox();AB.canvas.appendChild(z);return AA;};var f=function(AF,AJ){AF.attrs=AF.attrs||{};var AH=AF.node,AK=AF.attrs,AC=AH.style,z,AO=AF;for(var AD in AJ){AK[AD]=AJ[AD];}AJ.href&&(AH.href=AJ.href);AJ.title&&(AH.title=AJ.title);AJ.target&&(AH.target=AJ.target);if(AJ.path&&AF.type=="path"){AK.path=E.parsePathString(AJ.path);AH.path=X(AK.path);}if(AJ.rotation!=null){AF.rotate(AJ.rotation,true);}if(AJ.translation){z=(AJ.translation+"").split(y);AF.translate(z[0],z[1]);}if(AJ.scale){z=(AJ.scale+"").split(y);AF.scale(+z[0]||1,+z[1]||+z[0]||1,+z[2]||null,+z[3]||null);}if("clip-rect" in AJ){var R=(AJ["clip-rect"]+"").split(y);if(R.length==4){R[2]=+R[2]+(+R[0]);R[3]=+R[3]+(+R[1]);var AE=AH.clipRect||F.createElement("div"),AN=AE.style,AB=AH.parentNode;AN.clip=E.format("rect({0}px {2}px {3}px {1}px)",R);if(!AH.clipRect){AN.position="absolute";AN.top=0;AN.left=0;AN.width=AF.paper.width+"px";AN.height=AF.paper.height+"px";AB.parentNode.insertBefore(AE,AB);AE.appendChild(AB);AH.clipRect=AE;}}if(!AJ["clip-rect"]){AH.clipRect&&(AH.clipRect.style.clip="");}}if(AF.type=="image"&&AJ.src){AH.src=AJ.src;}if(AF.type=="image"&&AJ.opacity){AH.filterOpacity=" progid:DXImageTransform.Microsoft.Alpha(opacity="+(AJ.opacity*100)+")";AC.filter=(AH.filterMatrix||"")+(AH.filterOpacity||"");}AJ.font&&(AC.font=AJ.font);AJ["font-family"]&&(AC.fontFamily='"'+AJ["font-family"].split(",")[0].replace(/^['"]+|['"]+$/g,"")+'"');AJ["font-size"]&&(AC.fontSize=AJ["font-size"]);AJ["font-weight"]&&(AC.fontWeight=AJ["font-weight"]);AJ["font-style"]&&(AC.fontStyle=AJ["font-style"]);if(AJ.opacity!=null||AJ["stroke-width"]!=null||AJ.fill!=null||AJ.stroke!=null||AJ["stroke-width"]!=null||AJ["stroke-opacity"]!=null||AJ["fill-opacity"]!=null||AJ["stroke-dasharray"]!=null||AJ["stroke-miterlimit"]!=null||AJ["stroke-linejoin"]!=null||AJ["stroke-linecap"]!=null){AH=AF.shape||AH;var AI=(AH.getElementsByTagName("fill")&&AH.getElementsByTagName("fill")[0]),AL=false;!AI&&(AL=AI=v("fill"));if("fill-opacity" in AJ||"opacity" in AJ){var e=((+AK["fill-opacity"]+1||2)-1)*((+AK.opacity+1||2)-1);e<0&&(e=0);e>1&&(e=1);AI.opacity=e;}AJ.fill&&(AI.on=true);if(AI.on==null||AJ.fill=="none"){AI.on=false;}if(AI.on&&AJ.fill){var i=AJ.fill.match(/^url\(([^\)]+)\)$/i);if(i){AI.src=i[1];AI.type="tile";}else{AI.color=E.getRGB(AJ.fill).hex;AI.src="";AI.type="solid";}}AL&&AH.appendChild(AI);var AA=(AH.getElementsByTagName("stroke")&&AH.getElementsByTagName("stroke")[0]),AM=false;!AA&&(AM=AA=v("stroke"));if((AJ.stroke&&AJ.stroke!="none")||AJ["stroke-width"]||AJ["stroke-opacity"]!=null||AJ["stroke-dasharray"]||AJ["stroke-miterlimit"]||AJ["stroke-linejoin"]||AJ["stroke-linecap"]){AA.on=true;}(AJ.stroke=="none"||AA.on==null||AJ.stroke==0||AJ["stroke-width"]==0)&&(AA.on=false);AA.on&&AJ.stroke&&(AA.color=E.getRGB(AJ.stroke).hex);var e=((+AK["stroke-opacity"]+1||2)-1)*((+AK.opacity+1||2)-1);e<0&&(e=0);e>1&&(e=1);AA.opacity=e;AJ["stroke-linejoin"]&&(AA.joinstyle=AJ["stroke-linejoin"]||"miter");AA.miterlimit=AJ["stroke-miterlimit"]||8;AJ["stroke-linecap"]&&(AA.endcap={butt:"flat",square:"square",round:"round"}[AJ["stroke-linecap"]]||"miter");AJ["stroke-width"]&&(AA.weight=(parseFloat(AJ["stroke-width"])||1)*12/16);if(AJ["stroke-dasharray"]){var AG={"-":"shortdash",".":"shortdot","-.":"shortdashdot","-..":"shortdashdotdot",". ":"dot","- ":"dash","--":"longdash","- .":"dashdot","--.":"longdashdot","--..":"longdashdotdot"};AA.dashstyle=AG[AJ["stroke-dasharray"]]||"";}AM&&AH.appendChild(AA);}if(AO.type=="text"){var AC=B.span.style;AK.font&&(AC.font=AK.font);AK["font-family"]&&(AC.fontFamily=AK["font-family"]);AK["font-size"]&&(AC.fontSize=AK["font-size"]);AK["font-weight"]&&(AC.fontWeight=AK["font-weight"]);AK["font-style"]&&(AC.fontStyle=AK["font-style"]);B.span.innerHTML=AO.node.string.replace(/</g,"&#60;").replace(/&/g,"&#38;").replace(/\n/g,"<br>");AO.W=AK.w=B.span.offsetWidth;AO.H=AK.h=B.span.offsetHeight;AO.X=AK.x;AO.Y=AK.y+Math.round(AO.H/2);switch(AK["text-anchor"]){case"start":AO.node.style["v-text-align"]="left";AO.bbx=Math.round(AO.W/2);break;case"end":AO.node.style["v-text-align"]="right";AO.bbx=-Math.round(AO.W/2);break;default:AO.node.style["v-text-align"]="center";break;}}};var M=function(e,R,AA,z){var i=Math.round(Math.atan((parseFloat(AA)-parseFloat(e))/(parseFloat(z)-parseFloat(R)))*57.29)||0;if(!i&&parseFloat(e)<parseFloat(R)){i=180;}i-=180;if(i<0){i+=360;}return i;};var n=function(AD,AC){AC=L(AC);AD.attrs=AD.attrs||{};var e=AD.attrs,AB=AD.node.getElementsByTagName("fill");AD.attrs.gradient=AC;AD=AD.shape||AD.node;if(AB.length){AB=AB[0];}else{AB=v("fill");}if(AC.dots.length){AB.on=true;AB.method="none";AB.type=((AC.type+"").toLowerCase()=="radial")?"gradientTitle":"gradient";if(typeof AC.dots[0].color!="undefined"){AB.color=E.getRGB(AC.dots[0].color).hex;}if(typeof AC.dots[AC.dots.length-1].color!="undefined"){AB.color2=E.getRGB(AC.dots[AC.dots.length-1].color).hex;}var AE=[];for(var z=0,AA=AC.dots.length;z<AA;z++){if(AC.dots[z].offset){AE.push(AC.dots[z].offset+" "+E.getRGB(AC.dots[z].color).hex);}}var R=typeof AC.dots[AC.dots.length-1].opacity=="undefined"?(typeof e.opacity=="undefined"?1:e.opacity):AC.dots[AC.dots.length-1].opacity;if(AE.length){AB.colors.value=AE.join(",");R=typeof e.opacity=="undefined"?1:e.opacity;}else{AB.colors&&(AB.colors.value="0% "+AB.color);}AB.opacity=R;if(typeof AC.angle!="undefined"){AB.angle=(-AC.angle+270)%360;}else{if(AC.vector){AB.angle=M.apply(null,AC.vector);}}if((AC.type+"").toLowerCase()=="radial"){AB.focus="100%";AB.focusposition="0.5 0.5";}}};var K=function(AA,AC,R){var AB=0,i=0,e=0,z=1;this[0]=AA;this.node=AA;this.X=0;this.Y=0;this.attrs={};this.Group=AC;this.paper=R;this._={tx:0,ty:0,rt:{deg:0},sx:1,sy:1};};K.prototype.rotate=function(e,R,i){if(e==null){if(this._.rt.cx){return[this._.rt.deg,this._.rt.cx,this._.rt.cy].join(" ");}return this._.rt.deg;}e=(e+"").split(y);if(e.length-1){R=parseFloat(e[1]);i=parseFloat(e[2]);}e=parseFloat(e[0]);if(R!=null){this._.rt.deg=e;}else{this._.rt.deg+=e;}(i==null)&&(R=null);this._.rt.cx=R;this._.rt.cy=i;this.setBox(this.attrs,R,i);this.Group.style.rotation=this._.rt.deg;return this;};K.prototype.setBox=function(AB,AC,AA){var e=this.Group.style,AD=(this.shape&&this.shape.style)||this.node.style;AB=AB||{};for(var AE in AB){this.attrs[AE]=AB[AE];}AC=AC||this._.rt.cx;AA=AA||this._.rt.cy;var AH=this.attrs,AK,AJ,AL,AG;switch(this.type){case"circle":AK=AH.cx-AH.r;AJ=AH.cy-AH.r;AL=AG=AH.r*2;break;case"ellipse":AK=AH.cx-AH.rx;AJ=AH.cy-AH.ry;AL=AH.rx*2;AG=AH.ry*2;break;case"rect":case"image":AK=AH.x;AJ=AH.y;AL=AH.width||0;AG=AH.height||0;break;case"text":this.textpath.v=["m",Math.round(AH.x),", ",Math.round(AH.y-2),"l",Math.round(AH.x)+1,", ",Math.round(AH.y-2)].join("");AK=AH.x-Math.round(this.W/2);AJ=AH.y-this.H/2;AL=this.W;AG=this.H;break;case"path":if(!this.attrs.path){AK=0;AJ=0;AL=this.paper.width;AG=this.paper.height;}else{var AF=b(this.attrs.path);AK=AF.x;AJ=AF.y;AL=AF.width;AG=AF.height;}break;default:AK=0;AJ=0;AL=this.paper.width;AG=this.paper.height;break;}AC=(AC==null)?AK+AL/2:AC;AA=(AA==null)?AJ+AG/2:AA;var z=AC-this.paper.width/2,AI=AA-this.paper.height/2;if(this.type=="path"||this.type=="text"){(e.left!=z+"px")&&(e.left=z+"px");(e.top!=AI+"px")&&(e.top=AI+"px");this.X=this.type=="text"?AK:-z;this.Y=this.type=="text"?AJ:-AI;this.W=AL;this.H=AG;(AD.left!=-z+"px")&&(AD.left=-z+"px");(AD.top!=-AI+"px")&&(AD.top=-AI+"px");}else{(e.left!=z+"px")&&(e.left=z+"px");(e.top!=AI+"px")&&(e.top=AI+"px");this.X=AK;this.Y=AJ;this.W=AL;this.H=AG;(e.width!=this.paper.width+"px")&&(e.width=this.paper.width+"px");(e.height!=this.paper.height+"px")&&(e.height=this.paper.height+"px");(AD.left!=AK-z+"px")&&(AD.left=AK-z+"px");(AD.top!=AJ-AI+"px")&&(AD.top=AJ-AI+"px");(AD.width!=AL+"px")&&(AD.width=AL+"px");(AD.height!=AG+"px")&&(AD.height=AG+"px");var AM=(+AB.r||0)/(Math.min(AL,AG));if(this.type=="rect"&&this.arcsize!=AM&&(AM||this.arcsize)){var R=v(AM?"roundrect":"rect");R.arcsize=AM;this.Group.appendChild(R);this.node.parentNode.removeChild(this.node);this.node=R;this.arcsize=AM;f(this,this.attrs);this.setBox(this.attrs);}}};K.prototype.hide=function(){this.Group.style.display="none";return this;};K.prototype.show=function(){this.Group.style.display="block";return this;};K.prototype.getBBox=function(){if(this.type=="path"){return b(this.attrs.path);}return{x:this.X+(this.bbx||0),y:this.Y,width:this.W,height:this.H};};K.prototype.remove=function(){this[0].parentNode.removeChild(this[0]);this.Group.parentNode.removeChild(this.Group);this.shape&&this.shape.parentNode.removeChild(this.shape);};K.prototype.attr=function(){if(arguments.length==1&&typeof arguments[0]=="string"){if(arguments[0]=="translation"){return this.translate();}if(arguments[0]=="rotation"){return this.rotate();}if(arguments[0]=="scale"){return this.scale();}return this.attrs[arguments[0]];}if(this.attrs&&arguments.length==1&&E.isArray(arguments[0])){var R={};for(var e=0,z=arguments[0].length;e<z;e++){R[arguments[0][e]]=this.attrs[arguments[0][e]];}return R;}var AA;if(arguments.length==2){AA={};AA[arguments[0]]=arguments[1];}if(arguments.length==1&&typeof arguments[0]=="object"){AA=arguments[0];}if(AA){if(AA.gradient){n(this,AA.gradient);}if(AA.text&&this.type=="text"){this.node.string=AA.text;}f(this,AA);this.setBox(this.attrs);}return this;};K.prototype.toFront=function(){this.Group.parentNode.appendChild(this.Group);return this;};K.prototype.toBack=function(){if(this.Group.parentNode.firstChild!=this.Group){this.Group.parentNode.insertBefore(this.Group,this.Group.parentNode.firstChild);}return this;};K.prototype.insertAfter=function(R){if(R.Group.nextSibling){R.Group.parentNode.insertBefore(this.Group,R.Group.nextSibling);}else{R.Group.parentNode.appendChild(this.Group);}return this;};K.prototype.insertBefore=function(R){R.Group.parentNode.insertBefore(this.Group,R.Group);return this;};var c=function(e,AE,AD,R){var AA=v("group"),z=AA.style,i=v("oval"),AC=i.style;z.position="absolute";z.left=0;z.top=0;z.width=e.width+"px";z.height=e.height+"px";AA.coordsize=e.coordsize;AA.coordorigin=e.coordorigin;AA.appendChild(i);var AB=new K(i,AA,e);AB.type="circle";f(AB,{stroke:"#000",fill:"none"});AB.attrs.cx=AE;AB.attrs.cy=AD;AB.attrs.r=R;AB.setBox({x:AE-R,y:AD-R,width:R*2,height:R*2});e.canvas.appendChild(AA);return AB;};var j=function(e,AE,AD,AF,AA,R){var AB=v("group"),z=AB.style,i=v(R?"roundrect":"rect"),AG=(+R||0)/(Math.min(AF,AA));i.arcsize=AG;z.position="absolute";z.left=0;z.top=0;z.width=e.width+"px";z.height=e.height+"px";AB.coordsize=e.coordsize;AB.coordorigin=e.coordorigin;AB.appendChild(i);var AC=new K(i,AB,e);AC.type="rect";f(AC,{stroke:"#000"});AC.arcsize=AG;AC.setBox({x:AE,y:AD,width:AF,height:AA,r:+R});e.canvas.appendChild(AB);return AC;};var G=function(R,AF,AE,i,e){var AB=v("group"),AA=AB.style,z=v("oval"),AD=z.style;AA.position="absolute";AA.left=0;AA.top=0;AA.width=R.width+"px";AA.height=R.height+"px";AB.coordsize=R.coordsize;AB.coordorigin=R.coordorigin;AB.appendChild(z);var AC=new K(z,AB,R);AC.type="ellipse";f(AC,{stroke:"#000"});AC.attrs.cx=AF;AC.attrs.cy=AE;AC.attrs.rx=i;AC.attrs.ry=e;AC.setBox({x:AF-i,y:AE-e,width:i*2,height:e*2});R.canvas.appendChild(AB);return AC;};var N=function(e,R,AF,AE,AG,AA){var AB=v("group"),z=AB.style,i=v("image"),AD=i.style;z.position="absolute";z.left=0;z.top=0;z.width=e.width+"px";z.height=e.height+"px";AB.coordsize=e.coordsize;AB.coordorigin=e.coordorigin;i.src=R;AB.appendChild(i);var AC=new K(i,AB,e);AC.type="image";AC.attrs.src=R;AC.attrs.x=AF;AC.attrs.y=AE;AC.attrs.w=AG;AC.attrs.h=AA;AC.setBox({x:AF,y:AE,width:AG,height:AA});e.canvas.appendChild(AB);return AC;};var h=function(e,AF,AE,AG){var AB=v("group"),AA=AB.style,z=v("shape"),AD=z.style,AH=v("path"),R=AH.style,i=v("textpath");AA.position="absolute";AA.left=0;AA.top=0;AA.width=e.width+"px";AA.height=e.height+"px";AB.coordsize=e.coordsize;AB.coordorigin=e.coordorigin;AH.v=["m",Math.round(AF),", ",Math.round(AE),"l",Math.round(AF)+1,", ",Math.round(AE)].join("");AH.textpathok=true;AD.width=e.width;AD.height=e.height;AA.position="absolute";AA.left=0;AA.top=0;AA.width=e.width;AA.height=e.height;i.string=AG;i.on=true;z.appendChild(i);z.appendChild(AH);AB.appendChild(z);var AC=new K(i,AB,e);AC.shape=z;AC.textpath=AH;AC.type="text";AC.attrs.text=AG;AC.attrs.x=AF;AC.attrs.y=AE;AC.attrs.w=1;AC.attrs.h=1;f(AC,{font:O.font,stroke:"none",fill:"#000"});AC.setBox();e.canvas.appendChild(AB);return AC;};var d=function(i,R){var e=this.canvas.style;this.width=i||this.width;this.height=R||this.height;e.width=this.width+"px";e.height=this.height+"px";e.clip="rect(0 "+this.width+"px "+this.height+"px 0)";this.canvas.coordsize=this.width+" "+this.height;return this;};F.createStyleSheet().addRule(".rvml","behavior:url(#default#VML)");try{!F.namespaces.rvml&&F.namespaces.add("rvml","urn:schemas-microsoft-com:vml");var v=function(R){return F.createElement("<rvml:"+R+' class="rvml">');};}catch(u){var v=function(R){return F.createElement("<"+R+' xmlns="urn:schemas-microsoft.com:vml" class="rvml">');};}var J=function(){var z=g.apply(null,arguments),e=z.container,AE=z.height,AF,i=z.width,AD=z.x,AC=z.y;if(!e){throw new Error("VML container not found.");}var AB=B.canvas=F.createElement("div"),AA=AB.style;i=parseFloat(i)||"512px";AE=parseFloat(AE)||"342px";B.width=i;B.height=AE;B.coordsize=i+" "+AE;B.coordorigin="0 0";B.span=F.createElement("span");AF=B.span.style;AB.appendChild(B.span);AF.position="absolute";AF.left="-99999px";AF.top="-99999px";AF.padding=0;AF.margin=0;AF.lineHeight=1;AF.display="inline";AA.width=i+"px";AA.height=AE+"px";AA.position="absolute";AA.clip="rect(0 "+i+"px "+AE+"px 0)";if(e==1){F.body.appendChild(AB);AA.left=AD+"px";AA.top=AC+"px";e={style:{width:i,height:AE}};}else{e.style.width=i;e.style.height=AE;if(e.firstChild){e.insertBefore(AB,e.firstChild);}else{e.appendChild(AB);}}for(var R in B){e[R]=B[R];}A.call(e,e,E.fn);e.clear=function(){while(AB.firstChild){AB.removeChild(AB.firstChild);}};e.raphael=E;return e;};B.remove=function(){this.canvas.parentNode.removeChild(this.canvas);};B.safari=function(){};}var H=(function(){if(F.addEventListener){return function(AA,i,e,R){var z=function(AB){return e.call(R,AB);};AA.addEventListener(i,z,false);return function(){AA.removeEventListener(i,z,false);return true;};};}else{if(F.attachEvent){return function(AB,z,i,e){var AA=function(AC){return i.call(e,AC||m.event);};AB.attachEvent("on"+z,AA);var R=function(){AB.detachEvent("on"+z,AA);return true;};if(z=="mouseover"){AB.attachEvent("onmouseenter",AA);return function(){AB.detachEvent("onmouseenter",AA);return R();};}else{if(z=="mouseout"){AB.attachEvent("onmouseleave",AA);return function(){AB.detachEvent("onmouseleave",AA);return R();};}}return R;};}}})();for(var r=U.length;r--;){(function(R){K.prototype[R]=function(e){if(typeof e=="function"){this.events=this.events||{};this.events[R]=this.events[R]||{};this.events[R][e]=this.events[R][e]||[];this.events[R][e].push(H(this.shape||this.node,R,e,this));}return this;};K.prototype["un"+R]=function(e){this.events&&this.events[R]&&this.events[R][e]&&this.events[R][e].length&&this.events[R][e].shift()()&&!this.events[R][e].length&&delete this.events[R][e];};})(U[r]);}B.circle=function(R,i,e){return c(this,R,i,e);};B.rect=function(R,AA,e,i,z){return j(this,R,AA,e,i,z);};B.ellipse=function(R,z,i,e){return G(this,R,z,i,e);};B.path=function(R){if(R&&typeof R!="string"&&!E.isArray(R[0])){throw new Error("First argument for path method should be a string.");}return w(E.format.apply(E,arguments),this);};B.image=function(z,R,AA,e,i){return N(this,z,R,AA,e,i);};B.text=function(R,i,e){return h(this,R,i,e);};B.set=function(R){arguments.length>1&&(R=Array.prototype.splice.call(arguments,0,arguments.length));return new I(R);};B.setSize=d;K.prototype.stop=function(){clearTimeout(this.animation_in_progress);return this;};K.prototype.scale=function(AJ,AI,z,e){if(AJ==null&&AI==null){return{x:this._.sx,y:this._.sy,toString:function(){return this.x+" "+this.y;}};}AI=AI||AJ;!+AI&&(AI=AJ);var AN,AL,AM,AK,AZ=this.attrs;if(AJ!=0){var AH=this.getBBox(),AE=AH.x+AH.width/2,AB=AH.y+AH.height/2,AY=AJ/this._.sx,AX=AI/this._.sy;z=(+z||z==0)?z:AE;e=(+e||e==0)?e:AB;var AG=Math.round(AJ/Math.abs(AJ)),AD=Math.round(AI/Math.abs(AI)),AQ=this.node.style,Ab=z+(AE-z)*AG*AY,Aa=e+(AB-e)*AD*AX;switch(this.type){case"rect":case"image":var AF=AZ.width*AG*AY,AP=AZ.height*AD*AX,AC=Ab-AF/2,AA=Aa-AP/2;this.attr({width:AF,height:AP,x:AC,y:AA});break;case"circle":case"ellipse":this.attr({rx:AZ.rx*AY,ry:AZ.ry*AX,r:AZ.r*AY,cx:Ab,cy:Aa});break;case"path":var AS=C(AZ.path),AT=true;for(var AV=0,AO=AS.length;AV<AO;AV++){var AR=AS[AV];if(AR[0].toUpperCase()=="M"&&AT){continue;}else{AT=false;}if(E.svg&&AR[0].toUpperCase()=="A"){AR[AS[AV].length-2]*=AY;AR[AS[AV].length-1]*=AX;AR[1]*=AY;AR[2]*=AX;AR[5]=+(AG+AD?!!+AR[5]:!+AR[5]);}else{for(var AU=1,AW=AR.length;AU<AW;AU++){AR[AU]*=(AU%2)?AY:AX;}}}var R=b(AS),AN=Ab-R.x-R.width/2,AL=Aa-R.y-R.height/2;AS=C(AS);AS[0][1]+=AN;AS[0][2]+=AL;this.attr({path:AS.join(" ")});break;}if(this.type in {text:1,image:1}&&(AG!=1||AD!=1)){if(this.transformations){this.transformations[2]="scale(".concat(AG,",",AD,")");this.node.setAttribute("transform",this.transformations.join(" "));AN=(AG==-1)?-AZ.x-(AF||0):AZ.x;AL=(AD==-1)?-AZ.y-(AP||0):AZ.y;this.attr({x:AN,y:AL});AZ.fx=AG-1;AZ.fy=AD-1;}else{this.node.filterMatrix=" progid:DXImageTransform.Microsoft.Matrix(M11=".concat(AG,", M12=0, M21=0, M22=",AD,", Dx=0, Dy=0, sizingmethod='auto expand', filtertype='bilinear')");AQ.filter=(this.node.filterMatrix||"")+(this.node.filterOpacity||"");}}else{if(this.transformations){this.transformations[2]="";this.node.setAttribute("transform",this.transformations.join(" "));AZ.fx=0;AZ.fy=0;}else{this.node.filterMatrix="";AQ.filter=(this.node.filterMatrix||"")+(this.node.filterOpacity||"");}}AZ.scale=[AJ,AI,z,e].join(" ");this._.sx=AJ;this._.sy=AI;}return this;};E.easing_formulas={linear:function(R){return R;},"<":function(R){return Math.pow(R,3);},">":function(R){return Math.pow(R-1,3)+1;},"<>":function(R){R=R*2;if(R<1){return Math.pow(R,3)/2;}R-=2;return(Math.pow(R,3)+2)/2;},backIn:function(e){var R=1.70158;return e*e*((R+1)*e-R);},backOut:function(e){e=e-1;var R=1.70158;return e*e*((R+1)*e+R)+1;},elastic:function(i){if(i==0||i==1){return i;}var e=0.3,R=e/4;return Math.pow(2,-10*i)*Math.sin((i-R)*(2*Math.PI)/e)+1;},bounce:function(z){var e=7.5625,i=2.75,R;if(z<(1/i)){R=e*z*z;}else{if(z<(2/i)){z-=(1.5/i);R=e*z*z+0.75;}else{if(z<(2.5/i)){z-=(2.25/i);R=e*z*z+0.9375;}else{z-=(2.625/i);R=e*z*z+0.984375;}}}return R;}};K.prototype.animate=function(AS,AJ,AI,AA){clearTimeout(this.animation_in_progress);if(typeof AI=="function"||!AI){AA=AI||null;}var AM={},e={},AG={},AF={x:0,y:0};for(var AK in AS){if(AK in T){AM[AK]=this.attr(AK);(AM[AK]==null)&&(AM[AK]=O[AK]);e[AK]=AS[AK];switch(T[AK]){case"number":AG[AK]=(e[AK]-AM[AK])/AJ;break;case"colour":AM[AK]=E.getRGB(AM[AK]);var AL=E.getRGB(e[AK]);AG[AK]={r:(AL.r-AM[AK].r)/AJ,g:(AL.g-AM[AK].g)/AJ,b:(AL.b-AM[AK].b)/AJ};break;case"path":var AB=p(AM[AK],e[AK]);AM[AK]=AB[0];e[AK]=AB[1];AG[AK]=[];for(var AO=0,AE=AM[AK].length;AO<AE;AO++){AG[AK][AO]=[0];for(var AN=1,AQ=AM[AK][AO].length;AN<AQ;AN++){AG[AK][AO][AN]=(e[AK][AO][AN]-AM[AK][AO][AN])/AJ;}}break;case"csv":var R=(AS[AK]+"").split(y),AD=(AM[AK]+"").split(y);switch(AK){case"translation":AM[AK]=[0,0];AG[AK]=[R[0]/AJ,R[1]/AJ];break;case"rotation":AM[AK]=(AD[1]==R[1]&&AD[2]==R[2])?AD:[0,R[1],R[2]];AG[AK]=[(R[0]-AM[AK][0])/AJ,0,0];break;case"scale":AS[AK]=R;AM[AK]=(AM[AK]+"").split(y);AG[AK]=[(R[0]-AM[AK][0])/AJ,(R[1]-AM[AK][1])/AJ,0,0];break;case"clip-rect":AM[AK]=(AM[AK]+"").split(y);AG[AK]=[];var AO=4;while(AO--){AG[AK][AO]=(R[AO]-AM[AK][AO])/AJ;}break;}e[AK]=R;}}}var z=+new Date,AH=0,AR=function(i){return +i>255?255:+i;},AC=this;(function AP(){var AU=new Date-z,Ac={},AT;if(AU<AJ){var Aa=E.easing_formulas[AI]?E.easing_formulas[AI](AU/AJ):AU/AJ;for(var AY in AM){switch(T[AY]){case"number":AT=+AM[AY]+Aa*AJ*AG[AY];break;case"colour":AT="rgb("+[AR(Math.round(AM[AY].r+Aa*AJ*AG[AY].r)),AR(Math.round(AM[AY].g+Aa*AJ*AG[AY].g)),AR(Math.round(AM[AY].b+Aa*AJ*AG[AY].b))].join(",")+")";break;case"path":AT=[];for(var AW=0,Ad=AM[AY].length;AW<Ad;AW++){AT[AW]=[AM[AY][AW][0]];for(var AV=1,AX=AM[AY][AW].length;AV<AX;AV++){AT[AW][AV]=+AM[AY][AW][AV]+Aa*AJ*AG[AY][AW][AV];}AT[AW]=AT[AW].join(" ");}AT=AT.join(" ");break;case"csv":switch(AY){case"translation":var Ab=AG[AY][0]*(AU-AH),AZ=AG[AY][1]*(AU-AH);AF.x+=Ab;AF.y+=AZ;AT=[Ab,AZ].join(" ");break;case"rotation":AT=+AM[AY][0]+Aa*AJ*AG[AY][0];AM[AY][1]&&(AT+=","+AM[AY][1]+","+AM[AY][2]);break;case"scale":AT=[+AM[AY][0]+Aa*AJ*AG[AY][0],+AM[AY][1]+Aa*AJ*AG[AY][1],(2 in AS[AY]?AS[AY][2]:""),(3 in AS[AY]?AS[AY][3]:"")].join(" ");break;case"clip-rect":AT=[];var AW=4;while(AW--){AT[AW]=+AM[AY][AW]+Aa*AJ*AG[AY][AW];}break;}break;}Ac[AY]=AT;}AC.attr(Ac);AC.animation_in_progress=setTimeout(AP);E.svg&&B.safari();}else{(AF.x||AF.y)&&AC.translate(-AF.x,-AF.y);AC.attr(AS);clearTimeout(AC.animation_in_progress);E.svg&&B.safari();(typeof AA=="function")&&AA.call(AC);}AH=AU;})();return this;};K.prototype.translate=function(R,i){if(R==null){return{x:this._.tx,y:this._.ty};}this._.tx+=+R;this._.ty+=+i;switch(this.type){case"circle":case"ellipse":this.attr({cx:+R+this.attrs.cx,cy:+i+this.attrs.cy});break;case"rect":case"image":case"text":this.attr({x:+R+this.attrs.x,y:+i+this.attrs.y});break;case"path":var e=C(this.attrs.path);e[0][1]+=+R;e[0][2]+=+i;this.attr({path:e});break;}return this;};var I=function(R){this.items=[];this.length=0;if(R){for(var e=0,z=R.length;e<z;e++){if(R[e]&&(R[e].constructor==K||R[e].constructor==I)){this[this.items.length]=this.items[this.items.length]=R[e];this.length++;}}}};I.prototype.push=function(){var AA,R;for(var e=0,z=arguments.length;e<z;e++){AA=arguments[e];if(AA&&(AA.constructor==K||AA.constructor==I)){R=this.items.length;this[R]=this.items[R]=AA;this.length++;}}return this;};I.prototype.pop=function(){delete this[this.length--];return this.items.pop();};for(var s in K.prototype){I.prototype[s]=(function(R){return function(){for(var e=0,z=this.items.length;e<z;e++){this.items[e][R].apply(this.items[e],arguments);}return this;};})(s);}I.prototype.attr=function(e,AC){if(e&&E.isArray(e)&&typeof e[0]=="object"){for(var R=0,AB=e.length;R<AB;R++){this.items[R].attr(e[R]);}}else{for(var z=0,AA=this.items.length;z<AA;z++){this.items[z].attr.apply(this.items[z],arguments);}}return this;};I.prototype.getBBox=function(){var R=[],AC=[],e=[],AA=[];for(var z=this.items.length;z--;){var AB=this.items[z].getBBox();R.push(AB.x);AC.push(AB.y);e.push(AB.x+AB.width);AA.push(AB.y+AB.height);}R=Math.min.apply(Math,R);AC=Math.min.apply(Math,AC);return{x:R,y:AC,width:Math.max.apply(Math,e)-R,height:Math.max.apply(Math,AA)-AC};};E.registerFont=function(e){if(!e.face){return e;}this.fonts=this.fonts||{};var z={w:e.w,face:{},glyphs:{}},i=e.face["font-family"];for(var AC in e.face){z.face[AC]=e.face[AC];}if(this.fonts[i]){this.fonts[i].push(z);}else{this.fonts[i]=[z];}if(!e.svg){z.face["units-per-em"]=parseInt(e.face["units-per-em"],10);for(var AA in e.glyphs){var AB=e.glyphs[AA];z.glyphs[AA]={w:AB.w,k:{},d:AB.d&&"M"+AB.d.replace(/[mlcxtrv]/g,function(AD){return{l:"L",c:"C",x:"z",t:"m",r:"l",v:"c"}[AD]||"M";})+"z"};if(AB.k){for(var R in AB.k){z.glyphs[AA].k[R]=AB.k[R];}}}}return e;};B.getFont=function(AE,AF,e,AA){AA=AA||"normal";e=e||"normal";AF=+AF||{normal:400,bold:700,lighter:300,bolder:800}[AF]||400;var AB=E.fonts[AE];if(!AB){var z=new RegExp("(^|\\s)"+AE.replace(/[^\w\d\s+!~.:_-]/g,"")+"(\\s|$)","i");for(var R in E.fonts){if(z.test(R)){AB=E.fonts[R];break;}}}var AC;if(AB){for(var AD=0,AG=AB.length;AD<AG;AD++){AC=AB[AD];if(AC.face["font-weight"]==AF&&(AC.face["font-style"]==e||!AC.face["font-style"])&&AC.face["font-stretch"]==AA){break;}}}return AC;};B.print=function(AG,AF,AD,e,AK){var AB=this.set(),AE=(AD+"").split(""),R=0,AJ="",AA;typeof e=="string"&&(e=this.getFont(e));if(e){AA=(AK||16)/e.face["units-per-em"];for(var AC=0,AH=AE.length;AC<AH;AC++){var z=AC&&e.glyphs[AE[AC-1]]||{},AI=e.glyphs[AE[AC]];R+=AC?(z.w||e.w)+(z.k&&z.k[AE[AC]]||0):0;AI&&AI.d&&AB.push(this.path(AI.d).attr({fill:"#000",stroke:"none",translation:[R,0]}));}AB.scale(AA,AA,0,AF).translate(AG,(AK||16)/2);}return AB;};E.format=function(e){var R=E.isArray(arguments[1])?[0].concat(arguments[1]):arguments;e&&typeof e=="string"&&R.length-1&&(e=e.replace(/\{(\d+)\}/g,function(AA,z){return R[++z]==null?"":R[z];}));return e;};E.ninja=function(){var R=window.Raphael;if(q.was){window.Raphael=q.is;}else{try{delete window.Raphael;}catch(i){window.Raphael=void (0);}}return R;};E.el=K.prototype;return E;})();

/*
 * BEngine 0.9 JavaScript Controls Library
 *
 * Copyright (c) 2009 Andrzej Bielasty
 */
var wielkiOdliczacz = 0;
 
System = {
	crtb:function(nrow,ncol){
		var table = document.createElement('table');
		table.style.borderCollapse = 'collapse';
		table.style.cellPadding = '0px';
		var tbody = document.createElement('tbody');
		table.appendChild(tbody);
		
		var cells = new Array();
		var trs = new Array();
		for (var i=0;i<nrow;i++){
			var row = new Array();
			var tr = document.createElement('tr');
			trs.push(tr);
			for (var j=0;j<ncol;j++){
				var td = document.createElement('td');
				tr.appendChild(td);
				row.push(td);
			}
			tbody.appendChild(tr);
			cells.push(row);
		}
		return [table,cells,trs];
	},
	strToBool:function(value){
		if (value!=null){
			value = value.toLowerCase();
			if ((value=='true')||(value=='t')||(value=='y')||(value=='1')) return true;
			if ((value=='false')||(value=='f')||(value=='n')||(value=='0')) return false;
		}
		return false;
	},
	Utils : {
		Ajax:{
			post:function(url,param,onload){
				advAJAX.post({
					url : url,
					parameters : param, 
					onSuccess : function(obj) {
						onload(obj);
					},
					onError : function(obj) { alert("blad: " + obj.status); },
					onTimeout : function() { alert("Connection timed out."); },
					onRetry : function() { alert("Retry connection..."); },
					onRetryDelay : function() { alert("Awaiting retry..."); },
					onError : function(obj) { alert("Error: " + obj.status); }
				});					
			},
			get:function(url,param,onload){
				advAJAX.get({
					url : url,
					parameters : param, 
					onSuccess : function(obj) {
						onload(obj);
					},
					timeout : 10000,
					onTimeout : function() { alert("Connection timed out."); },
					onRetry : function() { alert("Retry connection..."); },
					onRetryDelay : function() { alert("Awaiting retry..."); },
					onError : function(obj) { alert("Error: " + obj.status); }
				});					
			},
			getUrl:function(param,onload){
				this.post(System.folderPath+'geturl.php',param,function(obj){
					if (onload) onload(obj);
				});
			}
		}	
	}
}

 
BEngine = {
	frameSize:5,
	toolFrameSize:4,
	captionBarSize:22,
	toolCaptionBarSize:18,
	borderColor: '#6c7579',
	windowColor: '#a3a4a4',
	captionBarFontSize: 12,
	captionBarFontColor: '#fff',
	toolCaptionBarFontSize: 11,
	lightBorder:'#fff',
	darkBorder:'#999',
	backColor:'#eee',
	lightBackColor:'#fdfdfd',
	buttonFontSize: 11,	
	contextMenuColor:'#fff',
	contextMenuBorderColor:'#aaa',
	folderPath:'skrypty/bengine/images/',
	Utils : {
		strToBool:function(value){
			if (value!=null){
				value = value.toLowerCase();
				if ((value=='true')||(value=='t')||(value=='y')||(value=='1')) return true;
				if ((value=='false')||(value=='f')||(value=='n')||(value=='0')) return false;
			}
			return false;
		},
		round:function(value,prec){
			var mno = 1.0;
			for (var i=0;i<prec;i++) mno*=10.0;
			var w = Math.round(value*mno)/mno;
			var wt = w.toString();
			if (wt.indexOf('.')==-1) {
				wt+='.';
				for (var j=0;j<prec;j++) wt+='0';
			}
			return wt;
		},
		textToXml:function(text){
			try {
				xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
				xmlDoc.async="false";
				xmlDoc.loadXML(text);
				return xmlDoc;
			}
			catch(e){
				var parser=new DOMParser();
				var xmlDoc=parser.parseFromString(text,"text/xml");
				return xmlDoc;
			}
		},
		HexToRGB:function(h){
			h = h.replace('#','');
				
			
			if (h.length==3){
				h = h[0]+''+h[0]+''+h[1]+''+h[1]+''+h[2]+''+h[2]+'';
			}	
			
			return [parseInt(h.substring(0,2),16),parseInt(h.substring(2,4),16),parseInt(h.substring(4,6),16)];
		},
		isIE:function() {
			return /msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent);
		}
	},
	Math : {
		PointPolyRelation:{
			Vertex:1,
			Edge:2,
			Outside:3,
			Inside:4
		},
		length:function(x1,y1,x2,y2){
			var dx = x1 - x2;
			var dy = y1 - y2;
			return Math.sqrt(dx*dx+dy*dy);
		},
		distanceFromPointToLine:function(x1,y1,x2,y2,x,y){
            var A = x - x1;
            var B = y - y1;
            var C = x2 - x1;
            var D = y2 - y1;

            var dot = A * C + B * D;
            var len_sq = C * C + D * D;
            var param = dot / len_sq;

            var xx, yy;

            if (param < 0)
            {
                xx = x1;
                yy = y1;
            }
            else if (param > 1)
            {
                xx = x2;
                yy = y2;
            }
            else
            {
                xx = x1 + param * C;
                yy = y1 + param * D;
            }

            return this.length(x, y, xx, yy);	
		},
		isPointOnLine:function(a,b,x,y,buffor){
            var czy = false;
            var minX = a.x, minY = a.y, maxX = a.x, maxY = a.y;

            if (b.x < minX) minX = b.x;
            if (b.x > maxX) maxX = b.x;
            if (b.y < minY) minY = b.y;
            if (b.y > maxY) maxY = b.y;

            if ((x > minX - buffor) && (x < maxX + buffor) && (y > minY - buffor) && (y < maxY + buffor)) czy = true;
            if (czy == true)
            {
                if (this.distanceFromPointToLine(a.x, a.y, b.x, b.y, x, y) < buffor) czy = true; else czy = false;
            }
            return czy;	
		
		},
		isPointInPoly:function(poly,x,y,precision){
            var i, j, nCrossCnt, i1;
            var iXP, iYP, iX0, iX1, iY0, iY1, iXA, iYA = 0;
            var nNoVert = poly.length;
            nCrossCnt = 0;
            iXP = x;
            iYP = y;
            var iPrec = precision;

            for (i = 0; i < nNoVert; i++){
                /* indeksy kolejnych wierzchołków w tablicy */
                i1 = (i + 1) % nNoVert;
                iX0 = poly[i].x;
                iX1 = poly[i1].x;
                iY0 = poly[i].y;
                iY1 = poly[i1].y;
                Math.abs(iY0 - iYP);
                /* czy punkt pokrywa się z wierzchołkiem struktury */
                if (Math.abs(iX0 - iXP) < iPrec && Math.abs(iY0 - iYP) < iPrec)
                    return BEngine.Math.PointPolyRelation.Vertex;
                if (Math.abs(iX1 - iXP) < iPrec && Math.abs(iY1 - iYP) < iPrec)
                    return BEngine.Math.PointPolyRelation.Vertex;
                if (iY0 == iY1)
                {  /* czy punkt leży na boku */
                    if ((Math.abs(iY0 - iYP) < iPrec) &&
                        ((iX0 < iXP && iXP < iX1) || (iX1 < iXP && iXP < iX0)))
                        return BEngine.Math.PointPolyRelation.Edge;
                }
                else
                {
                    if ((iY0 < iYP && iYP < iY1) || (iY1 < iYP && iYP < iY0))
                    {
                        iXA = iX0 + ((iYP - iY0) * (iX1 - iX0) / (iY1 - iY0));
                        if (Math.abs(iXA - iXP) < iPrec)
                            return BEngine.Math.PointPolyRelation.Edge;
                        if (iXA > iXP)
                            nCrossCnt++;
                    }
                    else
                        if (iY1 == iYP && iX1 > iXP)
                        {             /* koniec odcinka na półprostej,
                    poczštek poza prostš */
                            for (j = 1; j < nNoVert; j++)
                            {
                                iYA = poly[(i1 + j) % nNoVert].y;
                                if (iYA != iYP)
                                    break;
                            }
                            if (j == nNoVert)
                                return BEngine.Math.PointPolyRelation.Outside;
                            if ((iYA < iYP && iYP < iY0) || (iYA > iYP && iYP > iY0))
                                nCrossCnt++;
                        }
                }
            }
            if ((nCrossCnt % 2) != 0)
                return BEngine.Math.PointPolyRelation.Inside; /* nieparzysta liczba przecięć
               - punkt leży wewnštrz */
            else
                return BEngine.Math.PointPolyRelation.Outside; /* parzysta - na zewnštrz */
        },
		azymuth:function(dx,dy){
			var kat = Math.atan2(dy,dx);
			if (kat<0) kat+=2*3.14159;
			return kat;
		},
		lineLength:function(points){
			var suma = 0;
			for (var i=0;i<points.length-1;i++){
				var s = points[i];
				var k = points[i+1];
				suma+=this.length(s.x,s.y,k.x,k.y);
				
				
			}
			
			return suma;
		},
		area:function(tab){
			var tab2 = new Array()
			for (var i=0;i<tab.length;i++) {
				tab2.push({x:tab[i].x,y:tab[i].y});
			}
			tab2.push({x:tab[0].x,y:tab[0].y});
			var pole=0;
		
			var s = '';
			for (var i=0;i<tab2.length-1;i++) {
				var a = tab2[i];
				var b = tab2[i+1];				
				pole+=0.5 * ( parseFloat(a.x) * parseFloat(b.y) - parseFloat(b.x) * parseFloat(a.y));       
				s+=a.x+','+a.y+'|';
			}
			
			return Math.abs(pole);
		}
	},
	Ajax:{
		post:function(url,param,onload){
			advAJAX.post({
				url : url,
				parameters : param, 
				onSuccess : function(obj) {
					onload(obj);
				},
				onError : function(obj) { alert("blad: " + obj.status); },
				onTimeout : function() { alert("Connection timed out."); },
				onRetry : function() { alert("Retry connection..."); },
				onRetryDelay : function() { alert("Awaiting retry..."); },
				onError : function(obj) { alert("Error: " + obj.status); }
			});					
		},
		get:function(url,param,onload){
			advAJAX.get({
				url : url,
				parameters : param, 
				onSuccess : function(obj) {
					onload(obj);
				},
				timeout : 10000,
				onTimeout : function() { alert("Connection timed out."); },
				onRetry : function() { alert("Retry connection..."); },
				onRetryDelay : function() { alert("Awaiting retry..."); },
				onError : function(obj) { alert("Error: " + obj.status); }
			});					
		}
	},
	iGML : {
		actualMap : null,
		WMS: {
			createGetFeatureInfoRequest:function(url,version,layers,box,width,height,projection,x,y){
				var adress = url;
				var num = url.lastIndexOf("?");
                var num2 = url.lastIndexOf("&");
				var znak='';
				if (num==url.length){}
				else if (num2==url.length){}
				else{
                 if ((num==-1) &&(num2==-1)) znak = '?';
                 if (num!=-1) znak='&';
				}

				adress+=znak;
				adress+="VERSION=1.1.1&SERVICE=WMS&REQUEST=GetFeatureInfo&INFO_FORMAT=text/html";
				adress+="&LAYERS="+layers;
				adress+="&QUERY_LAYERS="+layers;
				adress+="&SRS="+projection+"&FORMAT=image/png";

				adress+="&BBOX="+box.xmin+","+box.ymin+","+box.xmax+","+box.ymax;

				adress+="&WIDTH="+width;
				adress+="&HEIGHT="+height;
				adress+="&X="+x+"&Y="+y;
				var przecinkiLayers='';
				for (var i=0;i<layers.split(",").length-1;i++) przecinkiLayers+=',';
				adress+="&styles="+przecinkiLayers;

				return adress;
			}
		},
		Point:function(x,y){
			this.x = x;
			this.y = y;
			this.createFromXml = function(xml){
				this.x = parseFloat(xml.getAttribute('x'));
				this.y = parseFloat(xml.getAttribute('y'));			
			}	
			this.isPointOver = function(x,y){
				var dx=Math.abs(x-this.x);
				var dy=Math.abs(y-this.y);
				if ((dx<5)&&(dy<5)) return true;
				return false;
			}	
			
		},
		Box:function(xmin,ymin,xmax,ymax){
			this.xmin = xmin;
			this.ymin = ymin;
			this.xmax = xmax;
			this.ymax = ymax;
			this.createFromXml = function(xml){
				this.xmin = parseFloat(xml.getAttribute('xmin'));
				this.ymin = parseFloat(xml.getAttribute('ymin'));
				this.xmax = parseFloat(xml.getAttribute('xmax'));
				this.ymax = parseFloat(xml.getAttribute('ymax'));		
			}
			this.toString = function(){
				return this.xmin+' '+this.ymin+' '+this.xmax+' '+this.ymax;
			}
			this.isPointIn = function(point){
				if ((point.x>=this.xmin)&&(point.x<=this.xmax)&&(point.y>=this.ymin)&&(point.y<=this.ymax)) return true;
				return false;
			}
			this.isInside = function(box){
				if ((this.xmin>box.xmax)||(this.xmax<box.xmin)||(this.ymin>box.ymax)||(this.ymax<box.ymin)) return false;
				return true;
			}
		},
		Utils:{
			PointsFromEWKT:function(text){
				var index = text.indexOf('POLYGON');
				var points = new Array();
				if (index!=-1){
					var w = text.substring(index+9,text.length-2).split(',');
					for (var i=0;i<w.length;i++){
						var c = w[i].split(' ');
						points[i]={x:parseFloat(c[0]),y:parseFloat(c[1])};
					}
				}
				return points;
			}	
		},
		Overlays:{
			PointStyle:function(param){
				if (param!=null){
					//image - adres obrazka
					//width - szeroksc obrazka
					//height - wysokosc obrazka
					//xCenter - wspólrzedna x srodka
					//yCenter - wspólrzedna y srodka
					this.image = param.image;
					this.width = param.width;
					this.height = param.height;
					this.xCenter = param.xCenter;
					this.yCenter = param.yCenter;
					
				}
			},
			Point:function(x,y,style){
				this.type = 0;
				this.coord = new BEngine.iGML.Point(x,y);
				this.scCoord = new BEngine.iGML.Point(0,0);
				this.canRotate = false;
				this.visible = true;
				this.userVisible = true;
				this.style = style;
				this.map = null;
				this.marked = false;
				this.rObject = null;
				this.onclick = null;
				this.angle = 0;
				//funkcje//
				this.onchangeposition = null;
				////////
				this.rotate = function(angle){
					this.angle = angle;
					if ((this.map!=null)&&(this.canRotate==true)){					
						this.map.rotateOverlay(this,angle);
					}
				}
				this.setSymbolAngle = function(angle){
					this.rObject.attr("rotation",angle*57.29578);
				}
				this.setCanRotate = function(value){
					this.canRotate = value;
				}
				this.setVisibility = function(visible){
					this.userVisible = visible;
				}
				this.show = function(){
					this.visible = true;
					this.rObject.show();
				}
				this.hide = function(){
					this.visible = false;
					this.rObject.hide();
				}			
				this.isPointOver = function(x,y){
					var dx=Math.abs(x-this.scCoord.x);
					var dy=Math.abs(y-this.scCoord.y);
					if ((dx<5)&&(dy<5)) return true;
					return false;
				}
				this.mark = function(){
					this.rObject.attr("scale",1.2);
					this.marked = true;
				}
				this.unmark = function(){
					this.rObject.attr("scale",1.0);
					this.marked = false;
				}			
				this.asText = function(){
					return this.coord.x+' '+this.coord.y;
				}
			},
			Line:function(points,style){
				this.type = 1;
				this.points = null;
				this.scPoints  = new Array();
				this.visible = true;
				this.userVisible = true;
				this.boundingBox = new BEngine.iGML.Box(-999999999,-999999999,999999999,999999999);
				this.map = null;
				this.marked = false;
				this.rObject = null;
				this.onclick = null;	
				
				if (points!=null){
					this.points = points;
					if (style!=null)
						this.style = style;
					else
						this.style = {};
					
					if (!this.style.width) this.style.width = 1;
					if (!this.style.color) this.style.color = '#000';
					if (!this.style.opacity) this.style.opacity = 1;
				}
				this.insertPoint = function(x,y,index){
					var tab = new Array();
					for (var i=0;i<index;i++){
						tab[i] = this.points[i];
					}
					tab[index] = {x:x,y:y};
					for (var i=index;i<this.points.length;i++){
						tab[i+1] = this.points[i];
					}
					this.points = tab;
				}
				this.calculateBox = function(){
					var xmin = 0;
					var ymin = 0;
					var xmax = 0;
					var ymax = 0;				
					if (this.points.length>0){
						xmin = this.points[0].x;
						ymin = this.points[0].y;
						xmax = this.points[0].x;
						ymax = this.points[0].y;
					}
					
					for (var i=0;i<this.points.length;i++){
						var p = this.points[i];
						if (p.x<xmin) xmin = p.x;
						if (p.y<ymin) ymin = p.y;
						if (p.x>xmax) xmax = p.x;
						if (p.y>ymax) ymax = p.y;					
					}
					this.boundingBox.xmin = xmin;
					this.boundingBox.ymin = ymin;
					this.boundingBox.xmax = xmax;
					this.boundingBox.ymax = ymax;			
				}
				this.isPointOver = function(x,y){
					for (var j=0;j<this.scPoints.length-1;j++){
						if (BEngine.Math.isPointOnLine(this.scPoints[j],this.scPoints[j+1],x,y,3)==true) return true;
					}
					return false;
				}
				this.isPointOverSegment = function(x,y){
					for (var j=0;j<this.scPoints.length-1;j++){
						if (BEngine.Math.isPointOnLine(this.scPoints[j],this.scPoints[j+1],x,y,3)==true) return j;
					}
					return -1;
				}			
				this.isPointOverPoint = function(x,y){
					for (var i=0;i<this.scPoints.length;i++){
						var dx=Math.abs(x-this.scPoints[i].x);
						var dy=Math.abs(y-this.scPoints[i].y);
						if ((dx<5)&&(dy<5)) return i;
					}
					return -1;
				}
				this.mark = function(){
					this.rObject.attr("stroke-width",this.style.width*1.5);
					this.marked = true;
				}
				this.unmark = function(){
					this.rObject.attr("stroke-width",this.style.width);
					this.marked = false;
				}
				this.show = function(){
					this.visible = true;
					this.rObject.show();
				}
				this.hide = function(){
					this.visible = false;
					this.rObject.hide();
				}			
				this.asText = function(){
					var g = new Array();
					for (var i=0;i<this.points.length;i++)
					g.push(this.points[i].x+' '+this.points[i].y);
					
					return g.join(',');
				}
			},
			Polygon:function(points,style){
				this.type = 2;
				this.points = null;
				this.scPoints  = new Array();
				this.visible = true;
				this.userVisible = true;
				this.boundingBox = new BEngine.iGML.Box(-999999999,-999999999,999999999,999999999);
				this.map = null;
				this.marked = false;
				this.rObject = null;
				this.onclick = null;	
				this.closed = false;
				this.calculateBox = function(){
					var xmin = 0;
					var ymin = 0;
					var xmax = 0;
					var ymax = 0;				
					if (this.points.length>0){
						xmin = this.points[0].x;
						ymin = this.points[0].y;
						xmax = this.points[0].x;
						ymax = this.points[0].y;
					}
					
					for (var i=0;i<this.points.length;i++){
						var p = this.points[i];
						if (p.x<xmin) xmin = p.x;
						if (p.y<ymin) ymin = p.y;
						if (p.x>xmax) xmax = p.x;
						if (p.y>ymax) ymax = p.y;					
					}
					this.boundingBox.xmin = xmin;
					this.boundingBox.ymin = ymin;
					this.boundingBox.xmax = xmax;
					this.boundingBox.ymax = ymax;
					
					this.closed = false;
					if (this.points.length>3)
					if ((this.points[0].x==this.points[this.points.length-1].x)&&(this.points[0].y==this.points[this.points.length-1].y))
					this.closed = true;
					
									
				}
				this.insertPoint = function(x,y,index){
					var tab = new Array();
					for (var i=0;i<index;i++){
						tab[i] = this.points[i];
					}
					tab[index] = {x:x,y:y};
					for (var i=index;i<this.points.length;i++){
						tab[i+1] = this.points[i];
					}
					this.points = tab;
				}			
				this.isPointOver = function(x,y){
					if (BEngine.Math.isPointInPoly(this.scPoints,x,y,0.1)==4) return true;
					return false;
				}
				this.isPointOverSegment = function(x,y){
					for (var j=0;j<this.scPoints.length-1;j++){
						if (BEngine.Math.isPointOnLine(this.scPoints[j],this.scPoints[j+1],x,y,3)==true) return j;
					}
					return -1;
				}			
				this.isPointOverPoint = function(x,y){
					for (var i=0;i<this.scPoints.length;i++){
						var dx=Math.abs(x-this.scPoints[i].x);
						var dy=Math.abs(y-this.scPoints[i].y);
						if ((dx<5)&&(dy<5)) return i;
					}
					return -1;
				}			
				this.mark = function(){
					this.rObject.attr("fill-opacity",this.style.fillOpacity*0.7);
					this.marked = true;
				}
				this.unmark = function(){
					this.rObject.attr("fill-opacity",this.style.fillOpacity);
					this.marked = false;
				}
				this.show = function(){
					this.visible = true;
					this.rObject.show();
				}
				this.hide = function(){
					this.visible = false;
					this.rObject.hide();
				}				
				this.asText = function(){
					var g = new Array();
					for (var i=0;i<this.points.length;i++)
					g.push(this.points[i].x+' '+this.points[i].y);
					
					return g.join(',');
				}
				if (points!=null){
					this.points = points;
					if (style!=null)
						this.style = style;
					else
						this.style = {};
					
					if (!this.style.lineWidth) this.style.lineWidth = 0;
					if (!this.style.lineColor) this.style.lineColor = '#000';
					
					if (!this.style.lineOpacity) {
						if (this.style.lineWidth==0)
						this.style.lineOpacity = 0;
						else
						this.style.lineOpacity = 1;
					}	
					if (!this.style.fillColor) this.style.fillColor = '#f00';
					if (!this.style.fillOpacity) this.style.fillOpacity = 0.5;	
					this.calculateBox();		
				}
			}					
		},
		WMSLayer : function(param){
			this.className = 'WMSLayer';
			if (param!=null){
				param.name == null?this.name='':this.name = param.name;
				param.title == null?this.title='':this.title = param.title;
				param.queryable == null?this.queryable=false:this.queryable = param.queryable;
				param.checked == null?this.checked=true:this.checked = param.checked;
				param.visibleFrom == null?this.visibleFrom=0:this.visibleFrom = param.visibleFrom;
				param.visibleTo == null?this.visibleTo=99999:this.visibleTo = param.visibleTo;
				param.icon == null?this.icon=null:this.icon = param.icon;
				
			}
			this.createFromXml = function(xml){
				if (xml.getAttribute('name')) this.name = xml.getAttribute('name');
				if (xml.getAttribute('title')) this.title = xml.getAttribute('title');
				if (xml.getAttribute('queryable')) this.queryable = BEngine.Utils.strToBool(xml.getAttribute('queryable'));
				if (xml.getAttribute('checked')) this.checked = BEngine.Utils.strToBool(xml.getAttribute('checked'));
			}
		},	
		WMSService : function(param,layers){
			this.className = 'WMSService';
			if (param!=null){
				param.id == null?this.id=null:this.id = param.id;
				param.name == null?this.name='':this.name = param.name;
				param.icon == null?this.icon='':this.icon = param.icon;
				param.url == null?this.url='':this.url = param.url;
				param.urls == null?this.urls=new Array():this.urls = param.urls;
				param.version == null?this.version='1.1.1':this.version = param.version;	
				param.format == null?this.format='image/png':this.format = param.format;
				param.group == null?this.group=0:this.group = param.group;
				param.checked == null?this.checked=true:this.checked = param.checked;	
				param.expandable ==null?this.expandable=true:this.expandable = param.expandable;	
				param.expanded ==null?this.expanded=true:this.expanded = param.expanded;	
				param.boundingBox==null?this.boundingBox = new BEngine.iGML.Box(0,0,0,0):this.boundingBox = param.boundingBox;
				param.visibleFrom == null?this.visibleFrom=0:this.visibleFrom = param.visibleFrom;
				param.visibleTo == null?this.visibleTo=9999999:this.visibleTo = param.visibleTo;
				layers==null?this.layers = new Array():this.layers = layers;
				this.tile_url = null;
				this.serviceType = 'WMS';
			}
			this.createFromXml = function(xml){
			
				if (xml.getAttribute('name')) this.name = xml.getAttribute('name'); 
				if (xml.getAttribute('url')) this.url = xml.getAttribute('url');
				if (xml.getAttribute('version')) this.version = xml.getAttribute('version');
				if (xml.getAttribute('format')) this.format = xml.getAttribute('format');
				if (xml.getAttribute('id')) this.id = xml.getAttribute('id');
				
				if (xml.getAttribute('expandable')) this.expandable = BEngine.Utils.strToBool(xml.getAttribute('expandable'));
				if (xml.getAttribute('expanded')) this.expanded = BEngine.Utils.strToBool(xml.getAttribute('expanded'));			
				if (xml.getAttribute('checked')) this.checked = BEngine.Utils.strToBool(xml.getAttribute('checked'));
						
				if (xml.getAttribute('visibleFrom')) this.visibleFrom = parseFloat(xml.getAttribute('visibleFrom'));
				if (xml.getAttribute('visibleTo')) this.visibleTo = parseFloat(xml.getAttribute('visibleTo'));	

				var boxes = xml.getElementsByTagName('BoundingBox');
				if (boxes.length>0) this.boundingBox.createFromXml(boxes[0]);
				
				this.layers = new Array();
				var layers = xml.getElementsByTagName('Layer');
				for (var i=0;i<layers.length;i++) {
					var layer = new BEngine.iGML.WMSLayer({});
					layer.createFromXml(layers[i]);
					this.layers.push(layer);			
				}
			}	
			this.getCheckedLayersList = function(scale){
				if (!scale) scale = 1;
				
				var layers = new Array();
				for (var i=0;i<this.layers.length;i++){
					var l = this.layers[i];
					if (!l.visibleFrom) l.visibleFrom = 0;
					if (!l.visibleTo) l.visibleTo = 99999;
					if ((l.checked==true)&&(scale>=l.visibleFrom)&&(scale<=l.visibleTo)){
						layers.push(l.name);
						//alert(l.name+' '+l.visibleFrom+' '+l.visibleTo+' '+scale);
					}
				}
				return layers.join(',');
			}
			this.isVisible = function(box,scale,index){
				var is = true;
				if (this.checked == false) is = false;
				if ((this.groupObject.id !=0)&&(((this.groupObject.id !=0)&&(this.groupObject.checked == false)).visible == false)) is = false;
				
				if (is==true){
					if ((scale<this.visibleFrom) || (scale>this.visibleTo))	{ is = false; }
					if (is==true){
						if (index){
							if (this.boundingBoxes[index].isInside(box)==false) { is=false;  }
						} else 
						if (this.boundingBox.isInside(box)==false) { is=false;  }
						
						if (is==true){
							var layers = this.getCheckedLayersList(scale);
							if (layers=='') { is = false; }
						}
					}
				}
				return is;
			}
			this.getMapRequest = function(box,crs,width,height,scale,index){
				var layers = this.getCheckedLayersList(scale);	
				if (layers!=''){
					if (index){
						var adress = this.urls[index];
						
					} else {
						var adress = this.url;
					}
					var urlt = adress;
					
					var num = urlt.lastIndexOf("?");
                    var num2 = urlt.lastIndexOf("&");
					var znak='';
					if (num==urlt.length){}
					else if (num2==urlt.length){}
					else{
                     if ((num==-1) &&(num2==-1)) znak = '?';
                     if (num!=-1) znak='&';
					}
        
					adress+=znak;
					adress+="VERSION="+this.version+"&SERVICE=WMS&REQUEST=GetMap";
					adress+="&LAYERS="+layers;
        
					adress+="&SRS="+crs;
        
					adress+="&BBOX="+box.xmin+","+box.ymin+","+box.xmax+","+box.ymax;
        
					adress+="&WIDTH="+width;
					adress+="&HEIGHT="+height;
					if (this.format!='image/jpeg')
					adress+="&TRANSPARENT=TRUE";
					else
					adress+="&TRANSPARENT=FALSE";
					adress+="&FORMAT="+this.format;
					var przecinkiLayers='';
					for (var i=0;i<layers.split(",").length-1;i++) przecinkiLayers+=',';
					adress+="&styles="+przecinkiLayers+'&unique='+Math.round(Math.random()*10000);

					return adress;
				} else {
					return null;	
				}				
			}
			this.getTileRequest = function(l,x,y){
				var adress = this.tile_url;
				var num = this.tile_url.lastIndexOf("?");
                var num2 = this.tile_url.lastIndexOf("&");
				var znak='';
				if (num==this.tile_url.length){}
				else if (num2==this.tile_url.length){}
				else{
                 if ((num==-1) &&(num2==-1)) znak = '?';
                 if (num!=-1) znak='&';
				}
    
				adress+=znak;
				if (this.tile_type == 'gs'){
					adress+="L="+l+"&X="+x+"&Y="+y;						
				}
				if (this.tile_type == 'gp'){	
					if ((l-this.tile_level)<0) return null;
					adress+="fileIDX=L"+(l-this.tile_level)+"X"+x+"Y"+y+"."+this.tile_format;	
				}				
				return adress;	
			}
			this.getFeatureInfoRequest = function(x,y,box,crs,width,height){
				var layers = '';
				for (var i=0;i<this.layers.length;i++){
					if ((this.layers[i].queryable==true)&&(this.layers[i].checked==true)) layers+=this.layers[i].name+',';
				}
				if (layers!='') layers = layers.substring(0,layers.length-1);
				return BEngine.iGML.WMS.createGetFeatureInfoRequest(this.url,this.version,layers,box,width,height,crs,x,y);
			}	
			this.isQueryable = function(){
				for (var i=0;i<this.layers.length;i++){
					if ((this.layers[i].queryable==true)&&(this.layers[i].checked==true)) return true;
				}							
				return false;
			}
		},
		Map : function(panel,mapPanel,baseMapPrint,linkMZ){
			var obj = this;
			this.folderPath = BEngine.mainPath+'bengine/images/igml';
			this.initOverlays = function(){
				this.paper = Raphael(this.overlayPanel.getWorkspaceDiv(),1200, 900);
				this.overlayPanel.div.style.overflow = 'hidden';
				this.overlays = new Array();
			}
			this.refreshOverlay = function(overlay){
				if (overlay.userVisible==true){
					if (overlay.type==0){
						if (this.box.isPointIn(overlay.coord)==true){
							if (overlay.visible==false) {
								overlay.rObject.show();
								overlay.visible=true;
							}	
							overlay.scCoord.x = obj.pX(overlay.coord.x);
							overlay.scCoord.y = obj.pY(overlay.coord.y);
							overlay.rObject.attr("x",overlay.scCoord.x-overlay.style.xCenter);
							overlay.rObject.attr("y",overlay.scCoord.y-overlay.style.yCenter);
							overlay.rObject.show();
						} else {
							if (overlay.visible==true){
								overlay.rObject.hide();
								overlay.visible=false;
							}
					
						}
					}
					if ((overlay.type==1)||(overlay.type==2)){
						if (overlay.boundingBox.isInside(obj.box)==true){
							if (overlay.visible==false) {
								overlay.rObject.show();
								overlay.visible=true;
							}				
							var path = '';
							overlay.scPoints.length = 0;
							for (var i=0;i<overlay.points.length;i++){
								overlay.scPoints[i] = new BEngine.iGML.Point(obj.pX(overlay.points[i].x),obj.pY(overlay.points[i].y));				
								if (i==0) path+='M'; else path+='L';
								path+=overlay.scPoints[i].x+' '+overlay.scPoints[i].y;
							}
							overlay.rObject.attr("path",path);
							
							if (overlay.type==2){
								if (overlay.closed==true){
									overlay.rObject.attr("fill-opacity",overlay.style.fillOpacity);
								} else {
									overlay.rObject.attr("fill-opacity",0);
								}
							}
							overlay.rObject.show();
							this.drawedPolygonsCount++;
						} else {
							if (overlay.visible==true){
								overlay.rObject.hide();
								overlay.visible=false;
							}										
						}
					}				
					
					
				} else {
					if (overlay.visible==true){
						overlay.hide();
					}
				}
				
			}
			this.refreshEditingLine = function(){
				this.editLineLine.hide();
				if ((this.editedOverlay!=null)&&((this.editedOverlay.type==1)||((this.editedOverlay.type==2)))){
					if (this.action != 'edit_line_move_point'){
						if ((this.editedOverlay.points.length>0)&&(this.editLineSnap!=0)){
							var lp = {x:0,y:0};
							if (this.editLineSnap==1){		
								//lp = this.editedOverlay.scPoints[this.editedOverlay.points.length-1];
								lp = new BEngine.iGML.Point(obj.pX(this.editedOverlay.points[this.editedOverlay.points.length-1].x),obj.pY(this.editedOverlay.points[this.editedOverlay.points.length-1].y));	
							}
							if (this.editLineSnap==2){		
								//lp = this.editedOverlay.scPoints[0];				
								lp = new BEngine.iGML.Point(obj.pX(this.editedOverlay.points[0].x),obj.pY(this.editedOverlay.points[0].y));	
							}
							var path = 'M'+lp.x+' '+lp.y+'L';
							path+='L'+this.mouseCoordinates.x+' '+this.mouseCoordinates.y;  
							this.editLineLine.attr("path",path);		
							this.editLineLine.toFront();
							
							var show = true;
							if ((this.editedOverlay.type==2)&&(this.editedOverlay.closed==true)) show = false;	 	

							if (show==true)		
							this.editLineLine.show();
						}	
					} else {
						if ((obj.editLineSelectedPoint-1)>=0)
						var lp = this.editedOverlay.scPoints[obj.editLineSelectedPoint-1];
						else{
							var lp = this.mouseCoordinates;
							if ((this.editedOverlay.type==2)&&(this.editedOverlay.closed==true)){
								lp = this.editedOverlay.scPoints[this.editedOverlay.points.length-2];
							}
						}
						
						if ((obj.editLineSelectedPoint+1)<this.editedOverlay.scPoints.length)
						var lk = this.editedOverlay.scPoints[obj.editLineSelectedPoint+1];
						else {
							var lk = this.mouseCoordinates;
							if ((this.editedOverlay.type==2)&&(this.editedOverlay.closed==true)){
								lk = this.editedOverlay.scPoints[1];
							}
						}
						
						var path = 'M'+lp.x+' '+lp.y+'L';
						path+='L'+this.mouseCoordinates.x+' '+this.mouseCoordinates.y;  
						path += 'L'+lk.x+' '+lk.y+'';
						this.editLineLine.attr("path",path);		
						this.editLineLine.toFront();
						
						
						this.editLineLine.show();				

					}
				}			 
			}
			this.refreshEditingControls = function(){
				this.editPointLine.hide();	
				this.editPointCenter.hide();
				this.editPointRotate.hide();
				
				for (var i=0;i<this.editLinePoints.length;i++){
					this.editLinePoints[i].r.remove();
				}
				this.editLinePoints.length = 0;
				
				if (this.editedOverlay!=null){
					if (this.editedOverlay.type == 0){

						if (this.editedOverlay.visible==true){								
							if (this.editedOverlay.canRotate == true){
								var r = 50;
								var path = 'M'+this.editedOverlay.scCoord.x+' '+this.editedOverlay.scCoord.y+'L';
								var rx = this.editedOverlay.scCoord.x+Math.round(r*Math.cos(this.editedOverlay.angle));
								var ry = this.editedOverlay.scCoord.y+Math.round(r*Math.sin(this.editedOverlay.angle));
								this.editPointRotateCoord = new BEngine.iGML.Point(rx,ry);
								path+=rx+' '+ry;
								//alert(path);
								this.editPointLine.attr("path",path);		
								this.editPointLine.toFront();					
								this.editPointLine.show();		
								
								this.editPointRotate.attr("cx",rx);
								this.editPointRotate.attr("cy",ry);			
								this.editPointRotate.toFront();					
								this.editPointRotate.show();							
							}		
							this.editPointCenter.attr("cx",this.editedOverlay.scCoord.x);
							this.editPointCenter.attr("cy",this.editedOverlay.scCoord.y);			
							this.editPointCenter.toFront();					
							this.editPointCenter.show();						
						} 
					}				
				
					if (((this.editedOverlay.type == 1)||(this.editedOverlay.type == 2))&&(this.editedOverlay.visible==true)){

						
						for (var i=0;i<this.editedOverlay.points.length;i++){
							var p = this.editedOverlay.scPoints[i];
							var r = this.paper.circle(p.x,p.y,4);
							r.attr('stroke-opacity',0);
							r.attr('fill','#f00');					
							
							this.editLinePoints.push({r:r,big:false});
						
						}
					}
				}
			}
			this.refreshOverlays = function(){
				for (var i=0;i<this.overlays.length;i++){
					if (this.overlays[i].visible==true)
					this.overlays[i].rObject.hide();
				}
				this.drawedPolygonsCount = 0;
				for (var i=0;i<this.overlays.length;i++){
					this.refreshOverlay(this.overlays[i]);
				}
				this.refreshEditingControls();	
				this.refreshEditingLine();	
				this.refreshMeasureLine();				
			}
			this.rotateOverlay = function(overlay,angle){
				overlay.angle = angle;
				overlay.rObject.attr("rotation",overlay.angle*(57.2958));
			}
			this.setMaxScale = function(scale){
				this.maxScale = scale;
			}
			this.addOverlay = function(overlay){
				this.overlays.push(overlay);
				if (overlay.type==0){
					overlay.rObject = this.paper.image(overlay.style.image,0,0,overlay.style.width,overlay.style.height);
					overlay.map = this;				
					this.refreshOverlay(overlay);
				}
				if (overlay.type==1){
					overlay.rObject = this.paper.path("M0 0L0 0");
					overlay.rObject.attr("stroke",overlay.style.color);
					overlay.rObject.attr("stroke-width",overlay.style.width);
					overlay.rObject.attr("stroke-opacity",overlay.style.opacity);
					overlay.calculateBox();
					overlay.map = this;
					this.refreshOverlay(overlay);
				}				
				if (overlay.type==2){
					overlay.rObject = this.paper.path("M0 0L0 0");

					overlay.rObject.attr("stroke",overlay.style.lineColor);
					overlay.rObject.attr("stroke-width",overlay.style.lineWidth);
					overlay.rObject.attr("stroke-opacity",overlay.style.lineOpacity);
					
					overlay.rObject.attr("fill",overlay.style.fillColor);
					overlay.rObject.attr("fill-opacity",overlay.style.fillOpacity);
					overlay.calculateBox();
					overlay.map = this;
					this.refreshOverlay(overlay);
				}			
				return overlay;
			}
			this.removeOverlay = function(overlay){
				overlay.rObject.remove();
				this.overlays.removeItem(overlay);
			}
			this.removeOverlays = function(){
				if (this.overlays){
					for (var i=this.overlays.length-1;i>=0;i--){
						this.removeOverlay(this.overlays[i]);
					}
				}
			}
			this.setCRS = function(crs){
				this.crs = crs;
			}
			this.calculateBox = function(x,y,scale){
				var width = this.controlPanel.getSize()[0];
				var height = this.controlPanel.getSize()[1];
				this.box.xmin = x-(width*0.5/scale);
				this.box.ymin = y-(height*0.5/scale);
				this.box.xmax = x+(width*0.5/scale);
				this.box.ymax = y+(height*0.5/scale);			
			}
			this.setView = function(x,y,scale){
				this.viewPoint.x = x;
				this.viewPoint.y = y;
				this.scale = this.findNearScale(scale);
				
				this.clearLevels();
				this.refresh();
			}
			this.setViewFromBox= function(box){
				obj.setViewFromExtent(box);
				obj.clearLevels(); 
				obj.refresh();
			}
			this.drawLoadingLayerStatus = function(){
				if (this.loadingLayersCount>0){
					this.loadingPanelText.div.innerHTML = this.loadingLayersCount;
					this.loadingPanelLoading.show();

				} else {
					this.loadingPanelLoading.hide();
					if (this.downloadError == false){
						
					} else {
						this.loadingPanelError.show();
					}
				}
			}
			this.drawWmsLevel = function(level,request,code){
				level.serType = 'wms';
				var width = this.mapPanel.getWorkspaceWidth();
				var height = this.mapPanel.getWorkspaceHeight();	
				var img = new Image();
				var div = level.div;
				div.name = level.service.name;

				var src = request;
				img.onload = function(){
					if ((level.actCode == code)){
							
						level.left = 0;
						level.top = 0;
						level.width = width;
						level.height = height;
						div.style.left = '0px';
						div.style.top = '0px';
						div.style.width = width+'px';
						div.style.height =  height+'px';
							
						img.style.width = '100%';
						img.style.height = '100%';						
						div.innerHTML = '';
						div.appendChild(img);
						obj.loadingLayersCount--;
						obj.drawLoadingLayerStatus();
						if (level.tdLoading)
						level.tdLoading.innerHTML = '';
					}
				}	
				img.onerror = function(){
					if ((level.actCode == code)){
						obj.downloadError = true;
						obj.loadingLayersCount--;
						obj.drawLoadingLayerStatus();
						
						if (level.tdLoading){
							var img = new Image();
							img.style.cursor = 'pointer';
							img.src = BEngine.mainPath+'bengine/images/igml/error_icon.png';
							level.tdLoading.innerHTML = '<a target="blank" href="'+src+'"><img style="border:none" src="'+img.src+'"/></a>';
						}	
					}	
				}
				img.src = src;				
			}
			this.drawTileLevel = function(level,ser){
				level.serType = 'tile';
				var width = this.mapPanel.getWorkspaceWidth();
				var height = this.mapPanel.getWorkspaceHeight();	
				var div = level.div;
				level.left = 0;
				level.top = 0;
				level.width = width;
				level.height = height;
				div.style.left = '0px';
				div.style.top = '0px';
				div.style.width = width+'px';
				div.style.height =  height+'px';
				
				
				var level = this.getLevel();
				var prec = 256/this.scale;
				
				var xminR = Math.floor(this.box.xmin/prec);
				var yminR = Math.floor(this.box.ymin/prec);
				xmin = xminR*prec;
				ymin = yminR*prec;			
				var xmaxR = Math.floor(this.box.xmax/prec)+1;
				var ymaxR = Math.floor(this.box.ymax/prec)+1;
				xmax = xmaxR*prec;
				ymax = ymaxR*prec;	
    
				//alert(xminR+' '+yminR+' '+xmaxR+' '+ymaxR);
				
				div.innerHTML = '';
				var tab = new Array();
				var str = '';
				for (var i=xminR;i<xmaxR;i++){
					for (var j=yminR;j<ymaxR;j++){
						var x = this.pX(xmin+(i-xminR)*prec);
						var y = this.pY(ymin+(j-yminR)*prec)-256;
						tab.push({i:i,j:j,x:x,y:y});
					}
				}
				
				
				var src = '';
				for (var i=0;i<tab.length;i++){
					var req = ser.getTileRequest(level,tab[i].i,tab[i].j);
					
					if (req!=null)
					src += '<img style="position:absolute;left:'+tab[i].x+'px;top:'+tab[i].y+'px" src="'+req+'"/>';
				}

				div.innerHTML = src;
				
				/*
				obj.loadingLayersCount--;
				obj.drawLoadingLayerStatus();
				if (level.tdLoading)
				level.tdLoading.innerHTML = '';
				*/		
			}
			this.refresh = function(odrazu){
				
				this.linkBox.value = adresStrony+'?x='+Math.round(this.viewPoint.x)+'&y='+Math.round(this.viewPoint.y)+'&scale='+this.scale;
			
				if (odrazu==null) odrazu = false;
			
				if (odrazu==false) wielkiOdliczacz=1000;
			
				for (var i=0;i<this.levels.length;i++){
					var actCode = 'code'+Math.round(Math.random()*100000);
					this.levels[i].actCode = actCode;	
				}		
				
				if (odrazu==true){
					obj.overlayPanel.div.style.left = '0px';
					obj.overlayPanel.div.style.top = '0px';		
					this.loadingPanelError.hide();
					if (this.onbeforerefresh) this.onbeforerefresh();
					var width = this.mapPanel.getWorkspaceWidth();
					var height = this.mapPanel.getWorkspaceHeight();	
					
					this.refreshInfo = {images:new Array(),width:width,height:height};
					
					this.calculateBox(this.viewPoint.x,this.viewPoint.y,this.scale);
					this.loadingLayersCount = 0;	
					obj.downloadError = false;			
					for (var i=0;i<this.services.length;i++){
						var ser = this.services[i];
						var visible = false;
						
						var actCodes = new Array();
						for (var j=0;j<ser.levels.length;j++){
							actCodes[j] = 'code'+Math.round(Math.random()*100000);
						}
						var serType = 0;
						
												
						if ((ser.checked == true)&&(((ser.groupObject.id ==0)||(ser.groupObject.visible == true)))){
							if (ser.tile_url!=null){
								if ((this.scale>=ser.tile_vis_from)&&(this.scale<=ser.tile_vis_to)) serType = 2;		
								//alert(ser.tile_vis_from+'|'+ser.tile_vis_to);		
							}
							if (serType==0){
								if (ser.urls.length>0){
									serType = 3;									
								} else {
									if (ser.url!=""){										
										if (ser.isVisible(this.box,this.scale)==true){
											serType = 1;		
										}
									}
								}
							}
						}

						if (serType==0){
							for (var j=0;j<ser.levels.length;j++){
								ser.levels[j].div.innerHTML='';
								ser.levels[j].active = false;
								ser.levels[j].actCode = actCodes[j];
		
							}	
							if (ser.item){
							
								ser.item.setTextColor('#999');
								if (ser.levels[0].tdLoading!=null)
								ser.levels[0].tdLoading.innerHTML = '';
								
							}							
						}
						
						if (serType==1){ //WMS 
							ser.levels[0].active = true;
							ser.levels[0].actCode = actCodes[0];
							if (ser.item){
								ser.levels[0].tdLoading = ser.item.getElement(2);
								if (ser.levels[0].tdLoading!=null)
								ser.levels[0].tdLoading.innerHTML = '<img src="'+BEngine.mainPath+'bengine/images/loadingmini.gif"/>';
								ser.item.setTextColor('#000');
							}
							
							
							var req = ser.getMapRequest(this.box,this.crs,width,height,this.scale);
							this.refreshInfo.images.push(req);
							this.drawWmsLevel(ser.levels[0],req,actCodes[0]);
							this.loadingLayersCount++;													
						}
						
						if (serType==3){ //Multi WMS 
							
							for (var j=0;j<ser.levels.length;j++){
								if (ser.isVisible(this.box,this.scale,j)==true){
									
									ser.levels[j].active = true;
									ser.levels[j].actCode = actCodes[j];
									if (ser.item){
										ser.levels[j].tdLoading = ser.item.getElement(2);
										if (ser.levels[j].tdLoading!=null)
										ser.levels[j].tdLoading.innerHTML = '<img src="'+BEngine.mainPath+'bengine/images/loadingmini.gif"/>';
										ser.item.setTextColor('#000');
									}
							
							
									var req = ser.getMapRequest(this.box,this.crs,width,height,this.scale,j);
									this.refreshInfo.images.push(req);
									//alert(req);
									this.drawWmsLevel(ser.levels[j],req,actCodes[j]);
									this.loadingLayersCount++;	
								} else {
									ser.levels[j].div.innerHTML='';
									ser.levels[j].active = false;
									ser.levels[j].actCode = actCodes[j];
								}
								
							}
																			
						}						
						
						if (serType==2){ //TILE 							
							ser.levels[0].active = true;
							ser.levels[0].actCode = actCode;
							if (ser.item){
								/*
								ser.levels[0].tdLoading = ser.item.getElement(2);
								if (ser.levels[0].tdLoading!=null)
								ser.levels[0].tdLoading.innerHTML = '';
								*/
								ser.item.setTextColor('#000');
								
							}
							this.drawTileLevel(ser.levels[0],ser);
							//this.loadingLayersCount++;							
						}						
						
					}
        
					obj.drawLoadingLayerStatus();
					this.refreshOverlays();
					this.refreshPrintFrame(); 
				}
				
				
				if (this.zoomInit==false){
					var width = 1000;
					var height = 1000;
					var cp = 0;
					var box = this.getExtendFromLayers();
					var dx = box.xmax-box.xmin;
					var dy = box.ymax-box.ymin;
					var wsx =width/dx;
					var wsy =height/dy;
					var scale = wsx;
					if (wsy<wsx) scale = wsy;
					co =  this.findNearLevel(scale);
					
					co = 14;
					
					this.zoomBar.style.height = (15*(co+1))+'px';
					this.zoomBar.style.display = 'block';
					this.zoomInit = true;
					
					this.zoomMinus.style.disply = 'block';
					this.zoomMinus.style.top = (32+(15*(co+1)))+'px';
					this.maxLevelZoom = co+1;
				}
				
				for( var i=0;i<this.zoomDivs.length;i++){
					this.zoomDivs[i].style.backgroundColor = '#ccc';
				}
				
				this.zoomDivs[this.zoomDivs.length-this.findNearLevel(this.scale)-1].style.backgroundColor = '#37b9ef';
			}
			this.loadLayersFromXml = function(xmlText){
				var xml = BEngine.Utils.textToXml(xmlText);
				
				var list = xml.getElementsByTagName('WMSService');
				for (var i=0;i<list.length;i++){
					var wms = new BEngine.iGML.WMSService({},null);
					wms.createFromXml(list[i]);
					this.services.push(wms); 
				}
				this.createLevels();
				this.fillLayerTree();
			}		
			this.addService = function(layer,index,refresh){
				if (index==null){
					this.services.push(layer);
				} else {
					for (var i=this.services.length;i>index;i--){
						this.services[i] = this.services[i-1];
					}
					this.services[index] = layer;
				}
				if (refresh!=false)
				this.fillLayerTree();
			},
			this.getServiceById = function(id){
				for (var i=0;i<this.services.length;i++){
					if (this.services[i].id == id) return this.services[i];
				}	
				
				var box = this.getExtendFromLayers();
				var dx = box.xmax-box.xmin;
				var dy = box.ymax-box.ymin;
				var wsx =width/dx;
				var wsy =height/dy;
				var scale = wsx;
				if (wsy<wsx) scale = wsy;
				var s = this.findNearScale(scale);
				
				
				
				this.zoomBar
				
				return null;
			},
			this.createLevels = function(){
				this.levels = new Array();
				this.mapPanel.div.innerHTML = '';
				var count = 400;
				for (var i=0;i<this.services.length;i++){
					this.services[i].levels = new Array();
					if (this.services[i].urls.length>0){
						for (var j=0;j<this.services[i].urls.length;j++){
							var div = BEngine.Controls.createDiv(0,0,0,0,null,null);
							div.style.zIndex = count;
							div.id = 'level_'+this.services[i].name;
							this.mapPanel.div.appendChild(div);
							var level = {service:this.services[i],div:div,top:0,left:0,width:this.mapPanel.getWorkspaceWidth(),height:this.mapPanel.getWorkspaceHeight()};
							this.levels.push(level);
							this.services[i].levels.push(level);
							count--;
						}
					} else {
						var div = BEngine.Controls.createDiv(0,0,0,0,null,null);
						div.style.zIndex = count;
						div.id = 'level_'+this.services[i].name;
						this.mapPanel.div.appendChild(div);
						var level = {service:this.services[i],div:div,top:0,left:0,width:this.mapPanel.getWorkspaceWidth(),height:this.mapPanel.getWorkspaceHeight()};
						this.levels.push(level);
						this.services[i].levels.push(level);						
						count--;
					}
				}	
				
				for (var i=0;i<this.levels.length;i++){
					var l= this.levels[i];
					//alert(l.service.name+' '+l.div.style.zIndex);
				}
				
			}
			this.clearLevels = function(){
				for (var i=0;i<this.levels.length;i++){
					this.levels[i].div.innerHTML = '';
				}
			}
			this.setDivExtentPosition = function(div,xp,yp,x,y){
				if ((Math.abs(y-yp)>2)&&(Math.abs(x-xp)>2)){
					if ((y-yp)>=0) {
						div.style.top = yp+'px';
						div.style.height = (y-yp-2)+'px';
					} else {
						div.style.top= y+'px';
						div.style.height = (-(y-yp+2))+'px';							
					}
					if ((x-xp)>=0){							
						div.style.left = xp+'px';
						div.style.width = (x-xp-2)+'px';
					} else {
						div.style.left = x+'px';
						div.style.width = (-x+xp+2)+'px';							
					}
					div.style.display = 'block';		
				}		
			}
			this.getCorrectBox = function(px,py,kx,ky){		
				var realKX = kx;
				var realKY = ky;
				var realPX = px;
				var realPY = py;	
		
				if (realKX>realPX){
					var minX = realPX;
					var maxX = realKX;
				} else {
					var minX = realKX;
					var maxX = realPX;
				}
				if (realKY>realPY){
					var minY = realPY;
					var maxY = realKY;
				} else {
					var minY = realKY;
					var maxY = realPY;
				}	
				return new BEngine.iGML.Box(minX,minY,maxX,maxY);
			}
			this.getExtendFromLayers = function(){
				var box = new BEngine.iGML.Box(9999999999,9999999999,-9999999999,-9999999999);
				for (var i=0;i<obj.services.length;i++){
					if (obj.services[i].boundingBox.xmin<box.xmin) box.xmin = obj.services[i].boundingBox.xmin;
					if (obj.services[i].boundingBox.ymin<box.ymin) box.ymin = obj.services[i].boundingBox.ymin;
					if (obj.services[i].boundingBox.xmax>box.xmax) box.xmax = obj.services[i].boundingBox.xmax;
					if (obj.services[i].boundingBox.ymax>box.ymax) box.ymax = obj.services[i].boundingBox.ymax;
				}
				return box;			
			}			
			this.setViewFromExtent=function(box){
				if (box!=null){		
					var width = obj.mapPanel.getWorkspaceWidth();
					var height = obj.mapPanel.getWorkspaceHeight();
					this.viewPoint.x = (box.xmin+box.xmax)*0.5;
					this.viewPoint.y = (box.ymin+box.ymax)*0.5;			
				
					var dx = box.xmax-box.xmin;
					var dy = box.ymax-box.ymin;
					//alert(dx+' '+dy);
					var wsx =width/dx;
					var wsy =height/dy;

					var scale = wsx;
					if (wsy<wsx) scale = wsy;
					this.scale = this.findNearScale(scale);
				}				
			}
			this.endZoomByExtent = function(){
				this.zoomByExtent = false;
				this.zoomDiv.style.display = 'none';
				this.zoomDiv.style.left = '2000px';
				this.zoomInButton.setCheck(false);
				this.action = '';			
				this.setCursor();
			}
			this.setCursor = function(){

				if ((obj.action == 'listen')||(obj.action == '')){
					obj.controlPanel.setCursor('default');
				}	
				if ((obj.action == 'move_map')||(obj.isOverOverlay == true)||(obj.editLineSelectedPoint!=-1)){
					if (obj.controlPanel.getCursor()!='move')
					obj.controlPanel.setCursor('move');
				}
				if ((obj.action=='edit_line_move_point')||(obj.editLineSnap!=0)||(obj.pointOnLineSegment!=-1)||(obj.action == 'zoom_by_extent')||(obj.zoomByExtent == true)||(((obj.editedOverlay!=null)&&(obj.editedOverlay.type==0)&&(obj.editedOverlay.coord.x==null)))){
					obj.controlPanel.setCursor('crosshair');
				}	
				if ((this.tool == 'measure')&&(obj.action == '')){
					obj.controlPanel.setCursor('crosshair');
				}
			}
			this.startEditing = function(overlay){
				this.editedOverlay = overlay;
				this.editedOverlay.unmark();
				
				if ((overlay.type==1)||(overlay.type==2)){
					if (overlay.points.length==0)
					this.editLineSnap = 1;
					else
					this.editLineSnap = 0;
					this.pointOnLineSegment = -1;
					this.editLineSelectedPoint= -1;
					this.editPolygonSnapPoint= -1;
					this.potSnap = -1;
				}

				this.refreshEditingControls();
				obj.refreshEditingLine();
			}		
			this.startMeasure = function(){
				this.measurePoints = new Array();
				if (!this.measureLine) {
					this.measureLine = this.paper.path("M0 0L0 0");
					this.measureLine.attr("stroke",'#0000ff');
					this.measureLine.attr("stroke-width",1);
					this.measureLine.hide();
				}
				if (!this.lastMeasureLine) {
					this.lastMeasureLine = this.paper.path("M0 0L0 0");
					this.lastMeasureLine.attr("stroke",'#0000ff');
					this.lastMeasureLine.attr("stroke-width",2);
					this.lastMeasureLine.attr("stroke-dasharray",".");
					this.lastMeasureLine.hide();
				}				
			}
			this.refreshMeasureLine = function(){ 
				if (this.measureLine) this.measureLine.hide();
				if (this.lastMeasureLine) this.lastMeasureLine.hide();
				if ((this.tool == 'measure')&&(this.measurePoints)){ 
					if (this.measurePoints.length>1){					
							var path = '';
							var tab = new Array();
							for (var i=0;i<this.measurePoints.length;i++){
								tab.push( new BEngine.iGML.Point(obj.pX(this.measurePoints[i].x),obj.pY(this.measurePoints[i].y)));				
								if (i==0) path+='M'; else path+='L';
								path+=tab[i].x+' '+tab[i].y;
							}
							this.measureLine.attr("path",path);	
							this.measureLine.show();						
					}			 
				}

				
			}
			this.onMouseMoveMeasureLine = function(x,y){
				obj.editDiv.style.display = 'block';
				obj.editDiv.style.height = (14)+'px';
				
				
				if (obj.measurePoints){
					if (obj.measurePoints.length>=2){
						var dx =  obj.measurePoints[0].x-obj.measurePoints[1].x;
						var dy =  obj.measurePoints[0].y-obj.measurePoints[1].y;
						
						
						obj.editDiv.innerHTML = '<b>Długość odcinka: '+Math.round(BEngine.Math.lineLength(obj.measurePoints))+' m</b>';
						if (obj.measurePoints.length>2){
							obj.editDiv.innerHTML += '<br/><b>Powierzchnia: '+Math.round(BEngine.Math.area(obj.measurePoints))+' m<sup>2</sup></b>';
							obj.editDiv.style.height = (43)+'px';						
						} else {
							obj.editDiv.style.height = (28)+'px';
						}
						obj.editDiv.innerHTML += '<br/><b>Y</b> - czyść';
						
					} 
					if (obj.measurePoints.length==0){
						obj.editDiv.innerHTML = 'Aby rozpocząć pomiar kliknij na mapę lewym przyciskiem myszy.';
						obj.editDiv.style.height = (28)+'px';
					} 	
					if (obj.measurePoints.length==1){
						obj.editDiv.innerHTML = 'Kliknij lewym przyciskiem myszy na mapie, by wskazać drugi punkt linii pomiarowej.';
						obj.editDiv.style.height = (40)+'px';
						//rysowanie tymczasowej linii
						
						
					}
					if (obj.measurePoints.length>=1){
	
						obj.lastMeasureLine.hide();
						var li = obj.measurePoints.length-1;
						
						var path = "M"+obj.pX(this.measurePoints[li].x)+" "+obj.pY(this.measurePoints[li].y);
						path+= "L"+obj.pX(x)+" "+obj.pY(y);		
						
						this.lastMeasureLine.attr("path",path);	
						obj.lastMeasureLine.show();
					} 
				}
			
			}
			this.onMouseUpMeasureLine = function(x,y){
				if (obj.measurePoints.length==40) {
					obj.measurePoints.length = 0;
				} else {
					obj.measurePoints.push({x:x,y:y});
				}
				obj.refreshMeasureLine();
			}
			this.setTool = function(name,param1){
				// name - nazwa narzedzia, dostepne: pointer,get_info,edit,multiedit
				// param1 w zaleznosci od narzedzie  edit - overlay do edycji , multiedit  - obiekt{ overlays,editingOverlay
				
				this.action = '';
				this.endZoomByExtent();
				this.pointerButton.setCheck(false);			
					
				this.framePrint.style.display = 'none';	
				this.framePrint2.style.display = 'none';	
					
				this.editedOverlay = null;
				this.refreshEditingControls();
				obj.refreshEditingLine();
				
				this.editLineSnap = 0;
				this.pointOnLineSegment = -1;
				this.editLineSelectedPoint= -1;
				this.editPolygonSnapPoint= -1;
				this.potSnap = -1;
				this.editDiv.style.display = 'none';
	
				
				
				this.printMZDiv.style.display = 'none';
				this.linkDiv.style.display = 'none';
				

				
				obj.tool = name;
				this.refreshMeasureLine();
				if (name=='pointer'){
					this.pointerButton.setCheck(true);			
				}
				if (name=='get_info'){
					this.startGetFeatureInfo();	
						
				}		
				if (name == 'edit'){
					//this.editPanel.show();
					this.startEditing(param1);
				}		
				if (name=='measure'){
					this.startMeasure();	
				
				}	
				if (name == 'printMZ'){
					this.printMZDiv.style.display = 'block';
					this.printMZText.innerHTML = 'Wskaż na mapie obszar dla którego chcesz zamówić wydruk.';	
					this.printMZState = 1;	//można wskazć obszar
				}				
			}
			this.createEditTool = function(){

				
				this.editDiv = BEngine.Controls.createDiv(33,3,null,null,230,40);
				this.controlPanel.div.appendChild(this.editDiv);	
				this.editDiv.style.fontSize='10px';
				this.editDiv.style.color = '#fff';
				this.editDiv.style.backgroundImage = 'url('+BEngine.mainPath+'bengine/images/igml/black.png)';
				this.editDiv.style.padding='4px';
				this.editDiv.style.lineHeight = '14px';
				this.editDiv.style.display = 'none';
				
				//point edition control
				this.editPointCenter =  this.paper.circle(50, 50, 4);
				this.editPointCenter.attr('fill','#f00');
				this.editPointCenter.attr('stroke-opacity',0);
				this.editPointCenter.hide();
				
				this.editPointLine =  this.paper.path("M10 10L90 90");
				this.editPointLine.attr('stroke','#f00');
				this.editPointLine.attr('stroke-width',2);
				this.editPointLine.attr('stroke-dasharray','. ');
				this.editPointLine.hide();			
				
				this.editPointRotate = this.paper.circle(50, 50, 3);
				this.editPointRotate.attr('fill','#f00');
				this.editPointRotate.attr('stroke-opacity',0);
				this.editPointRotate.hide();
				
				this.editLineLine =  this.paper.path("M10 10L90 90");
				this.editLineLine.attr('stroke','#f00');
				this.editLineLine.attr('stroke-width',2);
				this.editLineLine.attr('stroke-dasharray','. ');
				this.editLineLine.hide();	
				
				this.editLinePoints = new Array();
				
				this.editLineSnap = 0;
				this.pointOnLineSegment = -1;
				this.editLineSelectedPoint= -1;
				this.potSnap = -1;
			}
			this.startGetFeatureInfo = function(){
				
				/*
				this.getInfoCombo.removeAll();
				
				for (var i=0;i<this.services.length;i++){
					var ser = this.services[i];
					if ((ser.checked==true)&&(ser.isQueryable()==true)&&((ser.groupObject.id==0)||(ser.groupObject.visible==true))){					
						this.getInfoCombo.addItem(ser.name,ser);
						if ((this.selectedGetFeatureLayer!=null)&&(this.selectedGetFeatureLayer==ser)) this.getInfoCombo.selectItemByValue(ser);
					}
				}
				if ((this.selectedGetFeatureLayer == null)&&(this.getInfoCombo.select.length>0)){
					this.selectedGetFeatureLayer =  this.getInfoCombo.getItemByIndex(0).data;
				}
				
				this.getInfoPanel.show();
				*/
			}
			this.zoomExtent = function(){
				var box = new BEngine.iGML.Box(9999999999,9999999999,-9999999999,-9999999999);
				for (var i=0;i<obj.services.length;i++){
					if (obj.services[i].boundingBox.xmin<box.xmin) box.xmin = obj.services[i].boundingBox.xmin;
					if (obj.services[i].boundingBox.ymin<box.ymin) box.ymin = obj.services[i].boundingBox.ymin;
					if (obj.services[i].boundingBox.xmax>box.xmax) box.xmax = obj.services[i].boundingBox.xmax;
					if (obj.services[i].boundingBox.ymax>box.ymax) box.ymax = obj.services[i].boundingBox.ymax;
				}
				obj.setViewFromExtent(box);		
				obj.clearLevels(); 
				obj.refresh();		
				if (obj.tool == 'get_info'){
					obj.refreshInfoWindowPosition();					
				}				
			}
			this.createToolbar = function(){
			
				this.toolbar = new BEngine.Controls.Toolbar({x:0,y:0,height:30},this.mainWindow);
				this.toolbar.div.style.zIndex = 3000;
				this.pointerButton = new BEngine.Controls.ToolbarCheckButton({tip:"",image:BEngine.mainPath+'bengine/images/igml/pointer.png',group:1787878},this.toolbar);
				

				this.zoomInButton = new BEngine.Controls.ToolbarCheckButton({tip:"Przybliż widok przez zakres",image:BEngine.mainPath+'bengine/images/igml/zoomin.png'},this.toolbar);
				this.zoomOutButton = new BEngine.Controls.ToolbarButton({tip:"Oddal widok",image:BEngine.mainPath+'bengine/images/igml/zoomout.png'},this.toolbar);
				this.zoomExtend = new BEngine.Controls.ToolbarButton({tip:"Pokaż całą mapę",image:BEngine.mainPath+'bengine/images/igml/zoom_zakres.png'},this.toolbar);

				this.getInfoButton = new BEngine.Controls.ToolbarCheckButton({tip:"Informacja o obiekcie",image:BEngine.mainPath+'bengine/images/igml/info.png',group:1787878},this.toolbar);
				this.printButton = new BEngine.Controls.ToolbarButton({tip:"Wydruk",image:BEngine.mainPath+'bengine/images/igml/print.png'},this.toolbar);

				
				this.measureButton = new BEngine.Controls.ToolbarCheckButton({tip:"Pomiar odległości i pola powierzchni",image:BEngine.mainPath+'bengine/images/igml/measure.png',group:1787878},this.toolbar);
				this.linkButton = new BEngine.Controls.ToolbarButton({tip:"Link do aktualnego widoku",image:BEngine.mainPath+'bengine/images/igml/link.png'},this.toolbar);

				if (this.baseMapPrint==true){
					this.printMZButton = new BEngine.Controls.ToolbarCheckButton({tip:"Zamówienie wydruku mapy zasadniczej",text:'Zamówienie wydruku mapy zasadniczej',group:1787878},this.toolbar);
			
				}
				
				this.printLoading = BEngine.Controls.createDiv(145,0,null,null,10,10);
				this.printLoading.style.backgroundColor ='#fff';
				this.printLoading.style.padding = '2px 4px 2px 4px';
				this.printLoading.style.border = '1px solid #999';
				this.printLoading.style.display = 'none';
				this.printLoading.style.zIndex = 600000;
				this.workPanel.getWorkspaceDiv().appendChild(this.printLoading);
				 
				this.linkDiv = BEngine.Controls.createDiv(202,0,null,null,384,40);
				this.linkDiv.style.backgroundColor ='#fff';
				this.linkDiv.style.padding = '2px 4px 2px 4px';
				this.linkDiv.style.border = '1px solid #999';
				this.linkDiv.style.display = 'none';
				this.linkDiv.style.zIndex = 600000;
				this.workPanel.getWorkspaceDiv().appendChild(this.linkDiv);
				this.linkBox = document.createElement('textarea');
				this.linkDiv.appendChild(this.linkBox);
				this.linkBox.style.position = 'absolute';
				this.linkBox.style.fontfamily = 'arial';
				this.linkBox.style.fontSize = '11px';
				this.linkBox.style.top = '3px';
				this.linkBox.style.left = '3px';
				this.linkBox.style.width = '370px';
				this.linkBox.style.height = '34px';
				var cd = BEngine.Controls.createDiv(null,3,3,null,12,12);
				cd.style.backgroundImage = 'url('+BEngine.mainPath+'bengine/images/igml/close.png)';
				cd.style.cursor = 'pointer';
				this.linkDiv.appendChild(cd);

				this.printMZDiv = BEngine.Controls.createDiv(232,0,null,null,250,77);
				this.printMZDiv.style.backgroundColor ='#fff';
				this.printMZDiv.style.padding = '2px 4px 2px 4px';
				this.printMZDiv.style.border = '1px solid #999';
				this.printMZDiv.style.display = 'none';
				this.printMZDiv.style.zIndex = 600000;
				this.workPanel.getWorkspaceDiv().appendChild(this.printMZDiv);
				var cdMZ = BEngine.Controls.createDiv(null,3,3,null,12,12);
				cdMZ.style.backgroundImage = 'url('+BEngine.mainPath+'bengine/images/igml/close.png)';
				cdMZ.style.cursor = 'pointer';
				this.printMZDiv.appendChild(cdMZ);
				
				this.printMZOptions= BEngine.Controls.createDiv(2,2,null,null,235,23);
				this.printMZDiv.appendChild(this.printMZOptions);
				var lab1 = BEngine.Controls.createDiv(2,2,null,null,45,23);
				lab1.innerHTML = 'Format:';
				this.printMZOptions.appendChild(lab1);
				
				if ((this.linkMZ)&&(this.linkMZ!='')){
					var linkHelp = BEngine.Controls.createDiv(172,3,null,null,65,19);
					this.printMZOptions.appendChild(linkHelp);
					linkHelp.innerHTML = '<a target="blank" href="'+this.linkMZ+'">pomoc</a>';
				}
				
				this.mzFormat = new BEngine.Controls.ComboBox({x:50,y:2,width:100},this.printMZOptions);
				this.mzFormat.addItem('A4 pionowo','0.19|0.277|A4');
				this.mzFormat.addItem('A4 poziomo','0.277|0.19|A4');
				this.mzFormat.addItem('A3 pionowo','0.277|0.40|A3');
				this.mzFormat.addItem('A3 poziomo','0.40|0.277|A3');
				this.mzFormat.addItem('A2 pionowo','0.40|0.574|A2');
				this.mzFormat.addItem('A2 poziomo','0.574|0.40|A2');				
				
				
				this.printMZText = BEngine.Controls.createDiv(4,27,null,null,235,30);
				this.printMZDiv.appendChild(this.printMZText);
				this.printMZText.innerHTML = 'Wskaż na mapie obszar dla którego chcesz zamówić wydruk.';
				
			
				this.zoomInButton.onclick = function(){
					obj.zoomByExtent = true;
					obj.setCursor();
				}
				this.zoomOutButton.onclick = function(){
					obj.zoom(-1,false);
				}		
				this.pointerButton.onclick = function(){
					obj.setTool('pointer');
				}	
				this.getInfoButton.onclick = function(){
					obj.setTool('get_info');
				}	
				this.measureButton.onclick = function(){
					obj.setTool('measure');
				}				
				this.zoomExtend.onclick = function(){
					obj.zoomExtent();
				}
				
				var map = this;
				cd.onclick = function(){
					map.linkDiv.style.display = 'none';
				}
				this.printButton.onclick = function(){
					map.setTool('pointer');
					var b = map.box;
					var dx = b.xmax - b.xmin;
					var dy = b.ymax - b.ymin;
					
					dd = dx;
					if (dy>dx) dd = dy;
					dd = Math.round(dd*0.5);
					var w = 1000;
					var h = 1000;
					
					var box = new BEngine.iGML.Box(map.viewPoint.x-dd,map.viewPoint.y-dd,map.viewPoint.x+dd,map.viewPoint.y+dd);
					var adr = new Array();
					for (var i=0;i<map.services.length;i++){
						var s = map.services[i];
						if ((s.checked==true)&&(s.isVisible(map.box,map.scale)==true)){
							var r = s.getMapRequest(box,'EPSG:2180',w,h,map.scale);
							if (r!=null){
								if (r.indexOf("http")==-1) r = window.location.toString()+r;
								adr.push(r);
							}
						}
					}
					//BEngine.Interface.LoadingPanel.show();
					map.printLoading.style.display = 'block';
					map.printLoading.style.width = '155px';
					map.printLoading.style.height = '18px';
					map.printLoading.innerHTML = '<table style="padding:0px;margin:0px;border-collapse:collpase"><tr><td style="padding:0px"><img src="'+BEngine.mainPath+'bengine/images/igml/ladowanie_mini.gif"/></td><td style="padding:0px"> generowanie wydruku</td></tr></table>';
					
					var serwis = window.location.toString();
					BEngine.Ajax.post(BEngine.mainPath+'bengine/wydruk.php',{width:w,height:h,servers:adr.join('@'),nazwa_serwisu:serwis,naglowek_serwisu:BEngine.naglowekSerwisu,wdrozenie_sciezka:BEngine.wdrozenieSciezka},function(obj){
						var obiekt =eval( "("+obj.responseText+")");
						map.printLoading.style.width = '84px';
						var link = document.createElement('a');
						link.href = BEngine.mainPath+'bengine/'+obiekt.sciezka;
						link.target = 'blank';					
						link.innerHTML = 'pobierz plik';
						map.printLoading.innerHTML = '';
						map.printLoading.appendChild(link);
						
						var cd = BEngine.Controls.createDiv(null,5,4,null,12,12);
						cd.style.backgroundImage = 'url('+BEngine.mainPath+'bengine/images/igml/close.png)';
						cd.style.cursor = 'pointer';
						map.printLoading.appendChild(cd);
						cd.onclick = function(){
							map.printLoading.style.display = 'none';
						}
						link.onclick = function(){
							map.printLoading.style.display = 'none';
						}
					});
				
				

				}	
				this.linkButton.onclick = function(){
					map.setTool('pointer');
					map.linkDiv.style.display = 'block';
					
				
				

				}							
				if (this.baseMapPrint==true){
					this.printMZButton.onclick = function(){					
						map.setTool('printMZ');
						
					}
					cdMZ.onclick = function(){						
						map.setTool('pointer');
						
					}
				
				}
			
			}
			this.createMenuPanel = function(){
				if (this.outMapPanel==null){
				this.menuPanelWidth = 240;
				this.menuPanelTop = 70;
				this.menuPanelHeight = this.workPanel.getWorkspaceHeight()-this.menuPanelTop;
				
			
				this.menuPanel = new BEngine.Controls.ExtPanel({x:0,y:this.menuPanelTop,width:this.menuPanelWidth,height:this.menuPanelHeight,aTop:true,aBottom:true},this.workPanel);
				this.menuPanel.div.style.zIndex = 2100;
	

				this.layerTree = new BEngine.Controls.TreeView({backColor:'#f8f8f8',x:0,y:0,width:this.menuPanel.getWorkspaceSize()[0],height:this.menuPanel.getWorkspaceSize()[1],canmove:false,aRight:true,aBottom:true},this.menuPanel);
				this.menuPanel.hide();		
				} else {	
					this.layerTree = new BEngine.Controls.TreeView({backColor:'#fff',x:0,y:0,width:this.outMapPanel.getWorkspaceSize()[0],height:this.outMapPanel.getWorkspaceSize()[1],canmove:false,aRight:true,aBottom:true},this.outMapPanel);			
				}
			}		
			this.showMenuPanel = function(){
				if (this.menuPanelHeight > (this.workPanel.getWorkspaceHeight()-70)){
					this.menuPanelHeight = this.workPanel.getWorkspaceHeight()-70;			
					this.menuPanelTop = 70;
				}
				
				/*
				this.menuPanel.y = this.menuPanelTop;
				this.menuPanel.height = this.menuPanelHeight;
				this.menuPanel.width = this.menuPanelWidth;
				this.menuPanel.setPositionFromActualParameters();
				*/
				this.menuPanel.show();

				this.fillLayerTree();
			}
			this.setMenuPanelWidth = function(value){
				this.menuPanelWidth = value;
			}
			this.setMenuPanelHeight = function(value){
				this.menuPanelHeight = value;
				this.menuPanelTop = this.workPanel.getWorkspaceHeight()-this.menuPanelHeight;
			}		
			this.fillLayerTree = function(){
				this.layerTree.removeAll();
				for (var k=0;k<this.groups.length;k++){
					var g = this.groups[k];
					var parentNode = this.layerTree;
					if (g.active == true){
						var icon = '';
						
								
						var cells=['',g.name];	
						if (g.icon!='') cells[0] = '<img src="'+(BEngine.wdrozenieSciezka+'legenda/'+g.icon)+'"/>';
						
						var textIndex = 1;
						//alert(g.name+' '+g.expanded);
						
						g.treeNode = new BEngine.Controls.TreeViewItem({cells:cells,textIndex:textIndex,widths:'1px,700px,13px',checked:g.visible,extended:g.expanded,oncheck:function(checked){
							this.group.visible = checked;
							obj.refresh();
							if (obj.tool == 'get_info'){
								obj.startGetFeatureInfo();	
							}
						}});	
						g.treeNode.group = g;
						this.layerTree.addItem(g.treeNode);
						parentNode = g.treeNode;						
					}
					
					
					for (var i = 0;i<this.services.length;i++){
						var s = this.services[i];
						//alert(s.group);
						if (s.group == g.id){
							s.groupObject = g;
											
							var cells=['',s.name,''];
							
							if (s.icon!='') cells[0] = '<img src="'+(BEngine.wdrozenieSciezka+'legenda/'+s.icon)+'"/>';
							
							var textIndex = 1;
							
							var item = new BEngine.Controls.TreeViewItem({cells:cells,textIndex:textIndex,widths:'1px,700px,13px',checked:s.checked,extended:s.expanded,oncheck:function(checked){
								this.service.checked = checked;
								obj.refresh();
								if (obj.tool == 'get_info'){
									obj.startGetFeatureInfo();	
								}
							}});
							if (this.layersMenu) item.menu = this.layersMenu;
							
							item.onextend = function(){
								this.service.expanded = this.extended;
							}
							item.service = s;
							item.data = s;
							s.item = item;
							parentNode.addItem(item);
							if (s.expandable==true){	
								for (var j=0;j<s.layers.length;j++){
									var l = s.layers[j];
									
									var icon = '';
									if ((l.icon!=null)&&(l.icon!='')&&(l.icon.indexOf('.')!=-1)) icon = '<img src="'+l.icon+'"/>';
									var cells=[icon,l.title];
									var textIndex = 1;
									var subitem = new BEngine.Controls.TreeViewItem({cells:cells,textIndex:textIndex,widths:'1px,700px',checked:l.checked,extended:false,oncheck:function(checked){
										this.layer.checked = checked;
										obj.refresh();
										if (obj.tool == 'get_info'){
											obj.startGetFeatureInfo();	
										}								
									}});				
									subitem.layer = l;
									subitem.data = l;
									l.treeItem = subitem;
									if ((l.menuEnabled)&&(l.menuEnabled==true))
									subitem.dane = l;
									
									item.addItem(subitem);
									if (this.layersMenu) subitem.menu = this.layersMenu;
								}
							}
						}
					}					
					
				
				} 
			}
			this.refreshPrintFrame = function(){
				if ((this.tool == 'printMZ')&&(this.printMZCoord)){
					var wsp = obj.printMZCoord;
					var wspE = new Array();
					wspE[0] = obj.pX(wsp[0]); //xmin
					wspE[1] = obj.pY(wsp[1]); //ymin
					wspE[2] = obj.pX(wsp[2]); //xmax
					wspE[3] = obj.pY(wsp[3]); //ymax
					
					var wys = wspE[1]-wspE[3];
					
					obj.framePrint.style.left = wspE[0]+'px';
					obj.framePrint.style.top = wspE[3]+'px';
					obj.framePrint.style.width = parseInt((wspE[2]-wspE[0]))+'px';
					obj.framePrint.style.height = wys+'px';		

					var cm = Math.round((0.01*500)*this.scale);	
					obj.framePrint2.style.left = (wspE[0]-cm)+'px';
					obj.framePrint2.style.top = (wspE[3]-cm)+'px';
					obj.framePrint2.style.width = (parseInt((wspE[2]-wspE[0]))+(2*cm))+'px';
					obj.framePrint2.style.height = (wys+(cm*2))+'px';	
					
				}
			}
			this.preparePrintMZ = function(){
				this.printMZText.innerHTML =  '<table style="padding:0px;margin:0px;border-collapse:collpase"><tr><td style="padding:0px"><img src="'+BEngine.mainPath+'bengine/images/igml/ladowanie_mini.gif"/></td><td style="padding:0px"> przygotowywanie parametrów wydruku</td></tr></table>';
					this.printMZState = 2;
					var p = this.printMZCoord;

					var g = p[0]+' '+p[1]+','+p[0]+' '+p[3]+','+p[2]+' '+p[3]+','+p[2]+' '+p[1]+','+p[0]+' '+p[1];
				
				
				
					var map = this;
					BEngine.Ajax.post(BEngine.mainPath+'bengine/wydrukmz.php',{"geom":g},function(obj){
						try{
							var obiekt =eval( "("+obj.responseText+")");
	
							map.printMZText.innerHTML =  '';
							var divPob = document.createElement('div');
							divPob.style.textAlign = 'center';
							map.printMZText.appendChild(divPob);
							
							if (obiekt.data.length>0){
								var wym = map.mzFormat.getSelectedItem().value.split('|');
								
								var adres = '';
								var teryt = obiekt.data[0].substr(0,4);
								if (teryt=='1432') adres='http://sppwz-platnosci.igeomap.pl';
								if (teryt=='1412') adres='http://spminsk-platnosci.igeomap.pl';
								if (teryt=='3021') adres='http://platnosci.geo-system.com.pl';
								if (adres==''){
									divPob.innerHTML = 'Dla danego obszaru usługa nie jest dostępna, przepraszamy.';	
								
								} else {
									adres+='?pos=5&akcja=getmap&teryt='+teryt;
									divPob.innerHTML = '';
									var form = document.createElement('form');
									form.name="formularz";
									form.action = adres;
									form.target = '_blank';
									form.method = 'post';
									divPob.appendChild(form);
									form.onsubmit = function(){
										map.setTool('pointer');
									}
									
									var i1 =  document.createElement('input');
									i1.name = 'zakres';
									i1.type = 'hidden';
									i1.value = g;
									form.appendChild(i1);
									
									var i2 = document.createElement('input');
									i2.name = 'teryt';
									i2.type = 'hidden';
									i2.value = obiekt.data.join(',');
									form.appendChild(i2);

									var i3 = document.createElement('input');
									i3.name = 'format';
									i3.type = 'hidden';
									i3.value = wym[2];
									form.appendChild(i3);

									var i4 = document.createElement('input');
									i4.style.fontSize = '11px';
									i4.type = 'submit';
									i4.value = 'Zamów wydruk mapy';						
									form.appendChild(i4);

									/*	
									var t = '<form name="formularz" action="'+adres+'" target="_blank" method="post">';
									t+= '<input name="zakres" type="hidden" value="'+g+'"/>';
									t+= '<input name="teryt" type="hidden" value="'+obiekt.data.join(',')+'"/>';
									t+= '<input name="format" type="hidden" value="'+wym[2]+'"/>';
									t+= '<input name="" style="font-size:11px" type="submit" value="Zamów wydruk mapy"/>';
									divPob.innerHTML = t;
									*/
								}
							} else {
								divPob.innerHTML = 'Dla danego obszaru usługa nie jest dostępna, przepraszamy.';;							
							}
							var divCzysc = document.createElement('div');
							divCzysc.style.fontSize='11px';
							divCzysc.style.textAlign = 'center';
							map.printMZText.appendChild(divCzysc);
							var linkCzysc =  document.createElement('a');
							divCzysc.appendChild(linkCzysc);
							linkCzysc.style.cursor = 'pointer';
							linkCzysc.innerHTML = 'Wskaż nowy obszar';
							linkCzysc.style.fontSize='11px';
							linkCzysc.onclick = function(){
								map.printMZState = 1;								
								map.printMZText.innerHTML = 'Wskaż na mapie obszar dla którego chcesz zamówić wydruk.';
									 
							}
														
														
							
						} catch(err){
							alert(err);
						}
						
					});
				
			
			},
			this.initControls =function(){
				this.createToolbar(); 
				var workspace = this.controlPanel;
				this.mouseInWorkspace = false;
				this.zoomByExtent = false;
				this.action = '';
				this.tool = 'pointer';
				this.pPosMouse = new BEngine.iGML.Point(0,0);
				this.pPosReal = new BEngine.iGML.Point(0,0);
				this.state = 0;
				//div zoom
				this.zoomDiv = BEngine.Controls.createDiv(0,0,null,null,3,3);
				this.zoomDiv.style.border = '2px solid #45a';
				this.zoomDiv.style.backgroundColor = '#60abff';
				this.zoomDiv.style.filter='alpha(opacity=40)';
				this.zoomDiv.style.opacity='0.4';
				
				this.zoomDiv.style.display = 'none';
				obj.controlPanel.div.appendChild(this.zoomDiv);
				////////////
				
				workspace.div.onmousemove = function(e){
					var pos = BEngine.Controls.mouseCoordinates(e,workspace.div);
					var x = pos[0];
					var y = pos[1];
					
				
					var d = new Date();
					var msec = d.getTime();
					obj.mouseInWorkspace = true;
					obj.mouseCoordinates.x = x;				
					obj.mouseCoordinates.y = y;		
					var wspX = obj.box.xmin+((obj.box.xmax-obj.box.xmin)*(x/workspace.getWorkspaceWidth()));
					var wspY = obj.box.ymin+((obj.box.ymax-obj.box.ymin)*((workspace.getWorkspaceHeight()-y)/workspace.getWorkspaceHeight()));
					obj.position.x = wspX;
					obj.position.y = wspY;									
					obj.coordinatesTextBox.div.innerHTML = '<div style="font-size:11px;padding:3px 10px 2px 10px">X : '+BEngine.Utils.round(wspY,1)+'  Y : '+BEngine.Utils.round(wspX,1)+'</div>';	
					
					if (obj.action=='edit_point_center_move'){
						obj.editedOverlay.coord.x = obj.position.x;
						obj.editedOverlay.coord.y = obj.position.y;
						obj.refreshOverlay(obj.editedOverlay);
						obj.refreshEditingControls();
					}
					if (obj.action=='edit_point_rotate_move'){

						var dx = x - obj.editedOverlay.scCoord.x;
						var dy = y - obj.editedOverlay.scCoord.y;
						obj.editedOverlay.angle = MyMath.azymuth(dx,dy);
						obj.editedOverlay.setSymbolAngle(obj.editedOverlay.angle);
						obj.refreshOverlay(obj.editedOverlay);
						obj.refreshEditingControls();
						if (obj.editedOverlay.onrotate) obj.editedOverlay.onrotate(obj.editedOverlay.angle);
					}				
					
					if (obj.action == 'zoom_by_extent'){
						obj.setDivExtentPosition(obj.zoomDiv,obj.pPosMouse.x,obj.pPosMouse.y,x,y);								
					}
					if (obj.action == 'listen'){
						if (obj.tool == 'get_info'){
				
							if (((msec-obj.msec)>500) ||(Math.abs(x-obj.pPosMouse.x)>2)||(Math.abs(y-obj.pPosMouse.y)>2)) {
								obj.action = 'move_map';	
			
							}
						}
						if ((obj.tool == 'edit')||(obj.tool == 'printMZ')){			
							if (((msec-obj.msec)>500) ||(Math.abs(x-obj.pPosMouse.x)>2)||(Math.abs(y-obj.pPosMouse.y)>2)) {
								obj.action = 'move_map';			
							}
													
						}					
						if (obj.tool == 'pointer'){
							obj.action = 'move_map';	
						}	
						if (obj.tool == 'measure'){
							if (((msec-obj.msec)>500) ||(Math.abs(x-obj.pPosMouse.x)>2)||(Math.abs(y-obj.pPosMouse.y)>2)) {
								obj.action = 'move_map';	
							}
						}						
					}
					if (obj.action == 'move_map'){
						var dx = x - obj.pPosMouse.x;
						var dy = y - obj.pPosMouse.y;
						
						for (var i= 0;i<obj.levels.length;i++){
							
							var level = obj.levels[i];
							level.div.style.left = (level.left+dx)+'px';
							level.div.style.top = (level.top+dy)+'px';
							level.actCode = 'code'+Math.round(Math.random()*100000);
							
						}		
						obj.overlayPanel.div.style.left = (dx)+'px';
						obj.overlayPanel.div.style.top = (dy)+'px';						
						if (obj.tool == 'get_info'){
							obj.refreshInfoWindowPosition(dx,dy);					
						}						
					}
					
					if (obj.tool == 'edit'){
						
						if (obj.editedOverlay!=null){
							if ((obj.editedOverlay.type==0)&&(obj.editedOverlay.coord.x!=null)){
								obj.isOverOverlay = false;
								obj.isOverType = 0;
								if (obj.editedOverlay.isPointOver(x,y)==true){
									obj.isOverOverlay = true;
									obj.isOverType = 1;
								} 
								if ((obj.editedOverlay.canRotate==true)&&(obj.editPointRotateCoord.isPointOver(x,y)==true)){
									obj.isOverOverlay = true;
									obj.isOverType = 2;
								} 
							}
							
						}	


						
						if ((obj.editedOverlay.type==1)||(obj.editedOverlay.type==2)){
							if (obj.action == 'edit_line_move_point'){
								obj.refreshEditingLine();						
							}
							if ((obj.editLineSnap==0)&&(obj.action != 'edit_line_move_point')){
								if ((obj.editedOverlay.type==2)&&(obj.editedOverlay.closed==true)){
									obj.blockSnap = true;							
								}
								for (var i=0;i<obj.editLinePoints.length;i++){
									if (obj.editLinePoints[i].big==true){
										obj.editLinePoints[i].big = false;
										obj.editLinePoints[i].r.animate({r: 4}, 100);
									}
								}
								obj.editLineSelectedPoint = -1;
								var ind = obj.editedOverlay.isPointOverPoint(x,y);
								
								if (obj.potSnap!=-1){
									var dx = Math.abs(x-obj.potSnapX);
									var dy = Math.abs(y-obj.potSnapY);
									if ((dx>10)||(dy>10)){
										obj.editLineSnap=obj.potSnap;	
										obj.potSnap	= -1;	
									}								
								}	
								
								if ((obj.potSnap==-1)&&(obj.blockSnap!=true)){
									if (ind == 0){
										obj.potSnap=2;
									}  
									if (ind == (obj.editedOverlay.points.length-1)){
										obj.potSnap=1;										
									} 								
									obj.potSnapX = x;
									obj.potSnapY = y;								
								}
								
								//document.getElementById('info').innerHTML = obj.potSnap;
								if (obj.blockSnap == true){
									var dx = Math.abs(x-obj.blockSnapX);
									var dy = Math.abs(y-obj.blockSnapY);								
									if ((dx>15)||(dy>15)){
										obj.blockSnap = false;
									}
								}
								
								if ((ind!=-1)&&(ind<obj.editedOverlay.points.length)){
									obj.editLinePoints[ind].r.animate({r: 6}, 100);
									obj.editLinePoints[ind].big = true;								
								}
								obj.editLineSelectedPoint = ind;
								
								var indSeg=-1;							
								if (ind==-1){
									indSeg = obj.editedOverlay.isPointOverSegment(x,y);
									if ((indSeg!=-1)&&(ind<obj.editedOverlay.points.length-1)){
										obj.editLinePoints[indSeg].r.animate({r: 6}, 100);
										obj.editLinePoints[indSeg+1].r.animate({r: 6}, 100);
										obj.editLinePoints[indSeg].big = true;
										obj.editLinePoints[indSeg+1].big = true;
									}
								}
								obj.pointOnLineSegment = indSeg; 
							}
							if ((obj.editLineSnap!=0)&&(obj.editedOverlay.type==2)&&(obj.editedOverlay.points.length>=3)){
								obj.editPolygonSnapPoint= -1;
								var ind = obj.editedOverlay.isPointOverPoint(x,y);
								for (var i=0;i<obj.editLinePoints.length;i++){
									if (obj.editLinePoints[i].big==true){
										obj.editLinePoints[i].big = false;
										obj.editLinePoints[i].r.animate({r: 4}, 100);
									}
								}
								if ((obj.editLineSnap==1)&&(ind==0)){
									obj.editLinePoints[ind].r.animate({r: 6}, 100);
									obj.editLinePoints[ind].big = true;		
									obj.editPolygonSnapPoint= ind;
								}
								if ((obj.editLineSnap==2)&&(ind==(obj.editedOverlay.points.length-1))){
									obj.editLinePoints[ind].r.animate({r: 6}, 100);
									obj.editLinePoints[ind].big = true;	
									obj.editPolygonSnapPoint= ind;								
								}
								
							}
							if (obj.action=='')
							obj.refreshEditingLine();
						}					

						//komunikaty
						obj.editDiv.style.display = 'none';
						obj.editDiv.style.width = '190px';
						obj.editDiv.style.height = '';
						obj.editDiv.innerHTML = '';
						var ilew = 0;
						if (obj.editedOverlay.type==0){
							if (obj.editedOverlay.coord.x==null) {
								obj.editDiv.innerHTML += '<span style="color:#eff7ff;font-weight:bold">Lewy klik</span> - wstawienie punktu<br/>';
								ilew++;
							} else {
								obj.editDiv.innerHTML += '';
								if (obj.isOverType == 1){
									obj.editDiv.innerHTML += '<span style="color:#eff7ff;font-weight:bold">Lewy przeciągnięcie</span> - zmienia położenie punktu<br/>';
									ilew++;
								}
								if (obj.isOverType == 2){
									obj.editDiv.innerHTML += '<span style="color:#eff7ff;font-weight:bold">Lewy przeciągnięcie</span> - obraca punkt<br/>';
									ilew++;
								}
							}
						}
						if (obj.editedOverlay.type==1){
							if (obj.editLineSnap!=0){
								if (obj.editedOverlay.points.length<2) {
									obj.editDiv.innerHTML += '<span style="color:#eff7ff;font-weight:bold">Lewy klik</span> - dodanie punktu<br/>';
									ilew++;
								} else {
									obj.editDiv.innerHTML += '<span style="color:#eff7ff;font-weight:bold">Lewy klik</span> - dodanie punktu<br/><span style="color:#eff7ff;font-weight:bold">Spacja</span> - zakończenie wstawiania<br/>';
									ilew+=2;
								}
							} else {
								if (obj.editLineSelectedPoint!=-1){
									if ((obj.potSnap==1)||(obj.potSnap==2)){
										obj.editDiv.innerHTML += '<span style="color:#eff7ff;font-weight:bold">Przeciągnięcie</span> - kontynuowanie tworzenia<br/>';
										ilew++;
									}

									obj.editDiv.innerHTML += '<span style="color:#eff7ff;font-weight:bold">Lewy przeciągnięcie</span> - zmienia położenie punkt<br/>';
									ilew++;

									if (obj.editedOverlay.points.length>2){
										obj.editDiv.innerHTML +='<span style="color:#eff7ff;font-weight:bold">Delete</span> - usunięcie punktu<br/>';
										ilew++;
									}
								}
								if (obj.pointOnLineSegment!=-1){
									obj.editDiv.innerHTML += '<span style="color:#eff7ff;font-weight:bold">Lewy klik</span> - wstawienie punktu<br/>';
									ilew++;
								}
							}
							if (obj.editedOverlay.points.length>1){
								obj.editDiv.innerHTML += '<span style="color:#eff7ff;font-weight:bold">Y</span> - usunięcie linii<br/>';
								ilew++;
							}
						}
						if (obj.editedOverlay.type==2){
							if (obj.editLineSnap!=0){
								if (obj.editedOverlay.points.length<4) {
									obj.editDiv.innerHTML += '<span style="color:#eff7ff;font-weight:bold">Lewy klik</span> - dodanie punktu<br/>';
									ilew++;
								} else {
									if (obj.editPolygonSnapPoint!=-1){
										obj.editDiv.innerHTML += '<span style="color:#eff7ff;font-weight:bold">Lewy klik</span> - zamkniecie poligonu<br/>';
									} else {
										obj.editDiv.innerHTML += '<span style="color:#eff7ff;font-weight:bold">Lewy klik</span> - dodanie punktu<br/>';
									}
									obj.editDiv.innerHTML += '<span style="color:#eff7ff;font-weight:bold">Spacja</span> - zakończenie wstawiania<br/>';
									ilew+=2;
								}



							} else {
								if (obj.editLineSelectedPoint!=-1){
									if ((obj.potSnap==1)||(obj.potSnap==2)){
										obj.editDiv.innerHTML += '<span style="color:#eff7ff;font-weight:bold">Przeciągnięcie</span> - kontynuowanie tworzenia<br/>';
										ilew++;
									}

									obj.editDiv.innerHTML += '<span style="color:#eff7ff;font-weight:bold">Lewy przeciągnięcie</span> - zmienia położenie punkt<br/>';
									ilew++;

									if (obj.editedOverlay.points.length>4){
										obj.editDiv.innerHTML +='<span style="color:#eff7ff;font-weight:bold">Delete</span> - usunięcie punktu<br/>';
										ilew++;
									}
								}
								if (obj.pointOnLineSegment!=-1){
									obj.editDiv.innerHTML += '<span style="color:#eff7ff;font-weight:bold">Lewy klik</span> - wstawienie punktu<br/>';
									ilew++;
								}
							}
						}
						obj.editDiv.innerHTML += '';
						if (ilew>0){
							//obj.editDiv.style.height = ((14*ilew))+'px';
							obj.editDiv.style.display = 'block';			
						}				
					}
					
					if (obj.tool == 'printMZ'){
						if (obj.printMZState == 1){
							obj.framePrint.style.display = 'block';
							obj.framePrint2.style.display = 'block';
							var wym = obj.mzFormat.getSelectedItem().value.split('|');
							wym[0] = parseFloat(wym[0])*500; //skala mapy
							wym[1] = parseFloat(wym[1])*500; //skala mapy
							
							var wymW = wym[0]*0.5;
							var wymH = wym[1]*0.5;
							
							
							
							var wsp = new Array();
							wsp[0] = obj.position.x-wymW;
							wsp[1] = obj.position.y-wymH;
							wsp[2] = obj.position.x+wymW;
							wsp[3] = obj.position.y+wymH;
							
							obj.printMZCoord = wsp;				
						} else {
							//obj.framePrint.style.display = 'none';
						}
						obj.refreshPrintFrame();
						
						
					}
					
					if (obj.tool == 'measure'){
						obj.onMouseMoveMeasureLine(wspX,wspY);
					}	
					//ustawianie kursora
					obj.setCursor();
					if (BEngine.Controls.keys[17]==true) obj.controlPanel.setCursor('crosshair');
					
					
					if (obj.tool == 'pointer'){
					for (var i=0;i<obj.overlays.length;i++){
						var ovr = obj.overlays[i];							
						if (ovr.visible == true){
							if (ovr.marked==true) ovr.unmark();																		
						}
					}				
					for (var i=(obj.overlays.length-1);i>=0;i--){
						var ovr = obj.overlays[i];							
						if (ovr.visible == true){
							if (ovr.isPointOver(x,y)==true) { ovr.mark(); break; }														
						}
					}
					}
				};				
				workspace.addEvent('mousedown',function(x,y,button){
					obj.pPosMouse.x = x;
					obj.pPosMouse.y = y;
					obj.pPosReal.x = obj.position.x;
					obj.pPosReal.y = obj.position.y;
					var d = new Date();
					obj.msec = d.getTime();
					
					var isZoomByExtent = false;
					if ((button==0)&&((BEngine.Controls.keys[17]==true)||(obj.zoomByExtent==true))) { //CTRL
						isZoomByExtent = true;
					}				
					if (isZoomByExtent==true){
						obj.action = 'zoom_by_extent';	
					} else {
						if (((obj.tool == 'edit'))&&(button==0)){
							if (obj.editedOverlay!=null){
								if ((obj.editedOverlay.type==0)&&(obj.editedOverlay.coord.x!=null)){														
									if (obj.editedOverlay.isPointOver(x,y)==true){
										obj.action='edit_point_center_move';
										obj.editedOverlay.unmark();
									} 
									if ((obj.editedOverlay.canRotate==true)&&(obj.editPointRotateCoord.isPointOver(x,y)==true)){
										obj.action='edit_point_rotate_move';								
									} 
								}
								
								if (((obj.editedOverlay.type==1)||(obj.editedOverlay.type==2))&&(obj.editLineSnap==0)&&(obj.editLineSelectedPoint!=-1)){
									obj.action = 'edit_line_move_point';
								}
							}		
						
						}
						if ((button==0)&&(obj.action=='')) obj.action = 'listen';
					}
					obj.setCursor();
					
				});
				workspace.addEvent('mouseup',function(x,y,button){
					var d = new Date();
					var msec = d.getTime();
					
					if (obj.action=='edit_point_center_move'){
						obj.editedOverlay.unmark();		
						obj.action = '';
						if (obj.editedOverlay.onchangeposition) obj.editedOverlay.onchangeposition(obj.editedOverlay.coord.x,obj.editedOverlay.coord.y);
					}
					if (obj.action=='edit_point_rotate_move'){
						obj.action = '';
					}				
					if (obj.action == 'zoom_by_extent'){
						if ((Math.abs(x-obj.pPosMouse.x)>2)||(Math.abs(y-obj.pPosMouse.y)>2)) {					
							var box = obj.getCorrectBox(obj.pPosReal.x,obj.pPosReal.y,obj.position.x,obj.position.y);
							obj.setViewFromExtent(box);
							obj.clearLevels(); 
							obj.refresh();
							obj.zoomDiv.style.display = 'none';
							obj.action = '';
						} else {
							obj.zoom(1,true);
							obj.action = '';
						}		
						obj.endZoomByExtent();	
						if (obj.tool == 'get_info'){
							obj.refreshInfoWindowPosition();					
						}					
					}
					if ((obj.action == 'move_map')&&(button==0)){
						var dx = x - obj.pPosMouse.x;
						var dy = y - obj.pPosMouse.y;
						for (var i= 0;i<obj.levels.length;i++){
							var level = obj.levels[i];
							level.left+=dx;
							level.top+=dy;
							level.div.style.left = (level.left)+'px';
							level.div.style.top = (level.top)+'px';
						}
						obj.viewPoint.x-=dx/obj.scale;
						obj.viewPoint.y+=dy/obj.scale;

						
						obj.refresh();
						obj.action = '';	
						if (obj.tool == 'get_info'){
							obj.refreshInfoWindowPosition();					
						}
					}
					if (obj.action == 'edit_line_move_point'){
						obj.action = '';					
						obj.editLineSnap=0;
						obj.potSnap	= -1;								
						obj.editedOverlay.points[obj.editLineSelectedPoint].x = obj.position.x;
						obj.editedOverlay.points[obj.editLineSelectedPoint].y = obj.position.y;
						if ((obj.editedOverlay.type==2)&&(obj.editedOverlay.closed==true)){
							if (obj.editLineSelectedPoint == 0){
								obj.editedOverlay.points[obj.editedOverlay.points.length-1].x = obj.position.x;
								obj.editedOverlay.points[obj.editedOverlay.points.length-1].y = obj.position.y;						
							}
							if (obj.editLineSelectedPoint == (obj.editedOverlay.points.length-1)){
								obj.editedOverlay.points[0].x = obj.position.x;
								obj.editedOverlay.points[0].y = obj.position.y;						
							}						
						}
						obj.blockSnap = true;
						obj.blockSnapX = x;
						obj.blockSnapY = y;
						obj.editLineSelectedPoint=-1;
						obj.editedOverlay.calculateBox();
						obj.refreshOverlay(obj.editedOverlay);
						obj.refreshEditingControls();											
						obj.refreshEditingLine();		
					}
					if (obj.action=='listen') {
						if (obj.tool == 'get_info'){
							if ((msec-obj.msec)<500) {								
								var width = obj.mapPanel.getWorkspaceWidth();
								var height = obj.mapPanel.getWorkspaceHeight();
								obj.showInfoWindow(x,y,width,height,obj.box,obj.crs);			
							}						
						}
						if (((obj.tool == 'edit'))&&(button==0)){
							if (obj.editedOverlay!=null){
								if ((obj.editedOverlay.type==0)&&(obj.editedOverlay.coord.x==null)){														
									obj.editedOverlay.coord.x = obj.position.x;	
									obj.editedOverlay.coord.y = obj.position.y;	
									obj.refreshOverlay(obj.editedOverlay);
									obj.refreshEditingControls();	
									if (obj.editedOverlay.onchangeposition) obj.editedOverlay.onchangeposition(obj.position.x,obj.position.y);
								}
								if ((obj.editedOverlay.type==1)||(obj.editedOverlay.type==2)){ 
																
									var indexInsert = -1;
									
									if (obj.editLineSnap==1)
									indexInsert = obj.editedOverlay.points.length;
									if (obj.editLineSnap==2)
									indexInsert = 0;
									if (obj.editLineSnap==0){
										if (obj.pointOnLineSegment!=-1)
										indexInsert = obj.pointOnLineSegment+1;
									}
									
									if (indexInsert!=-1){
										var x = obj.position.x;
										var y = obj.position.y;
										if (obj.editPolygonSnapPoint!=-1){
											x = obj.editedOverlay.points[obj.editPolygonSnapPoint].x;
											y = obj.editedOverlay.points[obj.editPolygonSnapPoint].y;
											obj.editLineSnap = 0;
											obj.editPolygonSnapPoint=-1;
										}
										obj.editedOverlay.insertPoint(x,y,indexInsert);
										obj.editedOverlay.calculateBox();
										obj.refreshOverlay(obj.editedOverlay);
										obj.refreshEditingControls();	
										
									}
									obj.refreshEditingLine();
														
									
								}
							}		
						
						}					
						if (obj.tool == 'pointer'){
							for (var i=0;i<obj.overlays.length;i++){
								var ovr = obj.overlays[i];
								if (ovr.onclick!=null){
									if (ovr.visible == true){
										if (ovr.isPointOver(x,y)==true) { ovr.onclick(); break;}														
									}
								}
							}
							
							//obsluga zdarezn mapy - click
							for (var i=0;i<obj.events.length;i++){
								var evt = obj.events[i];
								if (evt.name == 'click') evt.func(obj.position.x,obj.position.y,button);
							
							}
							if (obj.onclick) obj.onclick(obj.position.x,obj.position.y);
							
							//getFeature dla warstw tematycznych
							if (((msec-obj.msec)<500)&&(obj.loged!=true)) {
								var width = obj.mapPanel.getWorkspaceWidth();
								var height = obj.mapPanel.getWorkspaceHeight();								
								obj.showInfoWindow(x,y,width,height,obj.box,obj.crs,true);	
							}	
							
							
							
						}
						if (obj.tool == 'measure'){
							if ((msec-obj.msec)<500) {
								obj.onMouseUpMeasureLine(obj.pPosReal.x,obj.pPosReal.y);
							}						
						}						
						if (obj.tool == 'printMZ'){
							if ((msec-obj.msec)<500) {
								if (obj.printMZState==1) obj.preparePrintMZ(); 
							}						
						}						
					}
		
					obj.action = '';
					obj.setCursor();
				});	
				workspace.addEvent('mouseout',function(x,y){
					if ((obj.action == 'move_map')){
						var dx = x - obj.pPosMouse.x;
						var dy = y - obj.pPosMouse.y;
						for (var i= 0;i<obj.levels.length;i++){
							var level = obj.levels[i];
							level.left+=dx;
							level.top+=dy;
							level.div.style.left = (level.left)+'px';
							level.div.style.top = (level.top)+'px';
						}
						obj.viewPoint.x-=dx/obj.scale;
						obj.viewPoint.y+=dy/obj.scale;
						obj.refresh();
						obj.action = '';	
					}
					
					obj.mouseInWorkspace = false;
					obj.setCursor();	
				});	
				workspace.addEvent('mousewheel', function(delta){
					if (obj.mouseInWorkspace==true){
						if ((obj.scale<obj.maxScale)||(delta<0)){
						obj.zoom(delta,true);
						if (obj.tool == 'get_info'){
							obj.refreshInfoWindowPosition();					
						}
						}
						return false;
					}
					return true;
				});	
				workspace.addEvent('keyup', function(code){
					if (obj.mouseInWorkspace == true){

						obj.setCursor();
						if ((obj.action == 'zoom_by_extent')&&(code==32)){
							obj.endZoomByExtent();				
						}
						if ((obj.editLineSnap!=0)&&(code==32)&&(obj.editedOverlay.points.length>1)){
							obj.editLineSnap = 0;
							obj.potSnap	= -1;	
							obj.refreshEditingControls();
							obj.refreshEditingLine();					
						}
						if ((obj.editedOverlay!=null)&&(obj.editLineSnap==0)&&(obj.editedOverlay.type==1)&&(code==46)&&(obj.editedOverlay.points.length>2)&&(obj.editLineSelectedPoint!=-1)){
							obj.editedOverlay.points.remove(obj.editLineSelectedPoint,obj.editLineSelectedPoint);
							obj.editLineSelectedPoint=-1;
							obj.editLineSnap=0;
							obj.potSnap	= -1;	
							obj.refreshOverlay(obj.editedOverlay);
							obj.refreshEditingControls();
							obj.refreshEditingLine();					
						}	
						if ((obj.editedOverlay!=null)&&(obj.editLineSnap==0)&&(obj.editedOverlay.type==2)&&(code==46)&&(obj.editedOverlay.points.length>4)&&(obj.editLineSelectedPoint!=-1)){
							obj.editedOverlay.points.remove(obj.editLineSelectedPoint,obj.editLineSelectedPoint);
							obj.editLineSelectedPoint=-1;
							obj.editLineSnap=0;
							obj.potSnap	= -1;	
							obj.refreshOverlay(obj.editedOverlay);
							obj.refreshEditingControls();
							obj.refreshEditingLine();					
						}				
						if ((obj.editedOverlay!=null)&&(obj.editedOverlay.type==1)&&(code==89)&&(obj.editedOverlay.points.length>1)){
							if (confirm('Czy na pewno chcesz usunąć linie?')){
								obj.removeOverlay(obj.editedOverlay);
								obj.setTool('pointer');
							}	
						}						
					
						if ((obj.tool == 'measure')&&(code==89)){
							obj.measurePoints.length = 0;
							obj.refreshMeasureLine();
						}
					}
				});
				workspace.addEvent('keydown', function(code){			
					if (code==17){
						obj.controlPanel.setCursor('crosshair');
					}
				});			
				this.createEditTool();
				this.createMenuPanel();
				this.setTool('pointer');
			}
			this.zoom = function(delta,wheel){
				var width = obj.controlPanel.getWorkspaceWidth();
				var height = obj.controlPanel.getWorkspaceHeight();
				
				var wsp = 1;
				if (delta>0) wsp=2;
				if (delta<0) wsp=0.5;
				var nsc = obj.scale*wsp;
							
				obj.scale=nsc;

				
				
				
				obj.scale = this.findNearScale(obj.scale);
				
				if (obj.scale>this.findNearScale(999)) {obj.scale = this.findNearScale(999); wsp=1; }
				
				var maxScale = this.levelsScale[this.levelsScale.length-this.maxLevelZoom];

				if (obj.scale<maxScale) {obj.scale = maxScale; wsp=1; }
				
				
				
			
				var x = obj.mouseCoordinates.x;
				var y = obj.mouseCoordinates.y;
				if (wheel==false){
					x=(width*0.5);
					y=(height*0.5);			
				}					
					
				for (var i= 0;i<obj.levels.length;i++){					
					var level = obj.levels[i];
					if ( level.active==true){	
						if (level.serType == 'tile') level.div.innerHTML = '';
						var dx = x-level.left;
						var dy = y-level.top;
						dx = dx/level.width;
						dy = dy/level.height;
						
						var dl = Math.round(((level.width*wsp)-level.width)*dx);
						var dt = Math.round(((level.height*wsp)-level.height)*dy);
						level.left-=dl;
						level.top-=dt;
						level.width = Math.round(level.width*wsp);
						level.height =Math.round(level.height *wsp);		
    
						level.div.style.width = (level.width)+'px';
						level.div.style.height = (level.height)+'px';
						level.div.style.top = (level.top)+'px';
						level.div.style.left = (level.left)+'px';		
					}						
				}	
				var dx = 0.5-(x/width);
				var dy = 0.5-(y/height);					
				var dl = Math.round(((width*wsp)-width)*dx);
				var dt = Math.round(((height*wsp)-height)*dy);					
				obj.viewPoint.x-=dl/obj.scale;
				obj.viewPoint.y+=dt/obj.scale;
				
				obj.refresh();	
    
/*
					
				for (var i= 0;i<obj.levels.length;i++){					
					var level = obj.levels[i];
					if ( level.active==true){								
						var dx = x-level.left;
						var dy = y-level.top;
						dx = dx/level.width;
						dy = dy/level.height;
						
						var dl = Math.round(((level.width*wsp)-level.width)*dx);
						var dt = Math.round(((level.height*wsp)-level.height)*dy);
						level.left-=dl;
						level.top-=dt;
						level.width = Math.round(level.width*wsp);
						level.height =Math.round(level.height *wsp);		

						level.div.style.width = (level.width)+'px';
						level.div.style.height = (level.height)+'px';
						level.div.style.top = (level.top)+'px';
						level.div.style.left = (level.left)+'px';		
					}						
				}	
				var dx = 0.5-(x/width);
				var dy = 0.5-(y/height);					
				var dl = Math.round(((width*wsp)-width)*dx);
				var dt = Math.round(((height*wsp)-height)*dy);					
				obj.viewPoint.x-=dl/obj.scale;
				obj.viewPoint.y+=dt/obj.scale;
				
				obj.refresh();	
*/
				
			}
			this.pX = function(x){
				return Math.round(((x-this.box.xmin)/(this.box.xmax-this.box.xmin))*this.mapPanel.getWorkspaceWidth());
			}
			this.pY = function(y){
				return Math.round(this.mapPanel.getWorkspaceHeight()-(((y-this.box.ymin)/(this.box.ymax-this.box.ymin))*this.mapPanel.getWorkspaceHeight()));
			}		
			this.addEventListener = function(event,func){
				//click (x,y,button) - tylko gdy tool == pointer
				this.events.push({name:event,func:func});
			}
			this.createTabGetFeatureInfo = function(req,name){
				BEngine.Ajax.post('skrypty/bengine/ajax_pobierz_info.php',{adres:req},function(object){
					//obj.gfiTabs.innerHTML += name+' ';	
					if (object.responseText!='')
					obj.gfiPanel.innerHTML += '<div style="font-size:14px;font-weight:bold;background-color:#777;padding:2px 5px 2px 5px;color:#fff">'+name+'</div><div style="padding:3px 3px 7px 3px">'+object.responseText+'</div>';
					
				
				});	
			}
			this.showInfoWindow = function(x,y,width,height,box,crs,thematicOnly){

				var lista = new Array();
				for (var i=0;i<this.services.length;i++){
					var ser = this.services[i];
					if ((ser.isVisible(box,obj.scale)==true)&&(ser.isQueryable()==true)){	
						if (thematicOnly==true){
							if (ser.thematicService == true){
								lista.push([ser.getFeatureInfoRequest(x,y,box,crs,width,height),ser.name]);
							}
						} else
						lista.push([ser.getFeatureInfoRequest(x,y,box,crs,width,height),ser.name]);	
					}	
				}		

				if (!this.getFeatureInfoWindow){
					this.getFeatureInfoWindow = new BEngine.Controls.Window({text:'Informacja o obiektach w punkcie',isMaximizeButton:false,borderStyle:'FIXED',startPosition:'CENTER',width:270,height:350});
					this.getFeatureInfoWindow.onclose = function(){
						this.hide();
						obj.setTool('pointer');	
						return false;
					}
			
					var sizeDiv = BEngine.Controls.createDiv(0,null,0,0,null,20);
					this.getFeatureInfoWindow.getWorkspaceDiv().appendChild(sizeDiv);
					sizeDiv.style.backgroundColor = '#ffffff';
					sizeDiv.style.borderTop = '1px solid #aaa';
					
					this.workFetDiv = BEngine.Controls.createDiv(0,0,0,22,null,null);
					this.getFeatureInfoWindow.getWorkspaceDiv().appendChild(this.workFetDiv);
					this.workFetDiv.style.backgroundColor = '#ffffff';
					
										
					this.gfiTabs = document.createElement('div');
					this.workFetDiv.appendChild(this.gfiTabs);
					this.gfiTabs.style.position = 'absolute';
					this.gfiTabs.style.top = '0px';
					this.gfiTabs.style.left = '0px';
					this.gfiTabs.style.right = '0px';
					this.gfiTabs.style.height = '20px';
					this.gfiTabs.style.borderBottom = '1px solid #fff';
					
					this.gfiPanel = document.createElement('div');
					this.workFetDiv.appendChild(this.gfiPanel);		
					this.gfiPanel.style.position = 'absolute';
					this.gfiPanel.style.top = '0px';
					this.gfiPanel.style.left = '0px';
					this.gfiPanel.style.right = '0px';
					this.gfiPanel.style.bottom = '0px';
					this.gfiPanel.style.overflow = 'auto';
					
					var leb = BEngine.Controls.createDiv(3,2,null,null,90,14);
					leb.innerHTML = 'Rozmiar okna:';
					sizeDiv.appendChild(leb);

					var min = BEngine.Controls.createDiv(90,2,null,null,31,14);
					min.style.cursor = 'pointer';
					min.style.color = '#4287d5';
					min.style.backgroundColor = '#fff';
					min.innerHTML = 'małe';
					sizeDiv.appendChild(min);	
					
					min.onclick = function(){
						obj.getFeatureInfoWindow.width = 220;
						obj.getFeatureInfoWindow.height = 250;
						obj.getFeatureInfoWindow.setPositionFromActualParameters();
					}

					var sre = BEngine.Controls.createDiv(124,2,null,null,46,14);
					sre.style.cursor = 'pointer';
					sre.style.color = '#4287d5';
					sre.style.backgroundColor = '#fff';
					sre.innerHTML = 'średnie';
					sizeDiv.appendChild(sre);	
					
					sre.onclick = function(){
						obj.getFeatureInfoWindow.width = 270;
						obj.getFeatureInfoWindow.height = 350;
						obj.getFeatureInfoWindow.setPositionFromActualParameters();
					}
					
					var duz = BEngine.Controls.createDiv(173,2,null,null,32,14);
					duz.style.cursor = 'pointer';
					duz.style.color = '#4287d5';
					duz.style.backgroundColor = '#fff';
					duz.innerHTML = 'duże';
					sizeDiv.appendChild(duz);
					
					duz.onclick = function(){
						obj.getFeatureInfoWindow.width = 320;
						obj.getFeatureInfoWindow.height = 400;
						obj.getFeatureInfoWindow.setPositionFromActualParameters();
					}
					
				} else {
					this.getFeatureInfoWindow.show();
				}
			

				this.gfiTabs.innerHTML = '';
				this.gfiPanel.innerHTML = '';
							
				for (var i=0;i<lista.length;i++){
					this.createTabGetFeatureInfo(lista[i][0],lista[i][1]);			
				}
				
				
			}
			this.refreshInfoWindowPosition = function(mdx,mdy){
				/*
				this.infoPanel.mainDiv.style.width = this.infoWindowWidth+'px';
				this.infoPanel.mainDiv.style.height = this.infoWindowHeight+'px';
				
				if (document.getElementById('infoFrame'))
				document.getElementById('infoFrame').style.height = (this.infoWindowHeight-47)+'px';
				
				var xe = this.pX(this.infoPanelX);
				var ye = this.pY(this.infoPanelY);
		
				var dx = Math.round((this.infoWindowWidth-21)*0.5);
								
				xe-=(8+32+dx);
				ye-=(14+32+this.infoWindowHeight);
				
				if (mdx!=null) xe+=mdx;
				if (mdy!=null) ye+=mdy;

				this.infoPanel.mainDiv.style.left = xe+'px';
				this.infoPanel.mainDiv.style.top = ye+'px';
				
				this.infoPanelOgonek.style.left = dx+'px';
				this.infoPanelB1.style.width = (dx-16)+'px';
				this.infoPanelB2.style.left = (dx+21)+'px';		
				*/				
			}		
			this.getLayersTree = function(){
				return this.layerTree;
			}			
			this.findNearScale = function(scale){
				min = 99999999999999999;
				var res = this.levelsScale[0];
				for (var i=0;i<this.levelsScale.length;i++){
					var dx = Math.abs(this.levelsScale[i]-scale);
					if (dx<min){
						min = dx;
						res = this.levelsScale[i];
					}
				}
				return res;
			}	
			this.findNearLevel = function(scale){
				min = 99999999999999999;
				var res = this.levelsScale[0];
				for (var i=0;i<this.levelsScale.length;i++){
					var dx = Math.abs(this.levelsScale[i]-scale);
					if (dx<min){
						min = dx;
						res = i;
					}
				}
				return res;
			}			
			this.getLevel = function(){
				min = 99999999999999999;
				var res = 0;
				for (var i=0;i<this.levelsScale.length;i++){
					var dx = Math.abs(this.levelsScale[i]-this.scale);
					if (dx<min){
						min = dx;
						res = i;
					}
				}
				return res;		
			}
			this.setMenu = function(menu){
				this.layersMenu = menu;
			}
			if (panel!=null){
				BEngine.iGML.actualMap = this;
				var parentDiv = panel.getWorkspaceDiv();
				this.parentPanel = panel;
				this.linkMZ = linkMZ;
				
				this.baseMapPrint = false;
				if (baseMapPrint) this.baseMapPrint = baseMapPrint;		
				
				this.levelsScale = new Array();
				this.levelsScale[0] = 0.000625;
				this.levelsScale[1] = 0.00125;
				this.levelsScale[2] = 0.0025;
				this.levelsScale[3] = 0.005;
				this.levelsScale[4] = 0.01;
				this.levelsScale[5] = 0.02;
				this.levelsScale[6] = 0.04;
				this.levelsScale[7] = 0.08;
				this.levelsScale[8] = 0.16;
				this.levelsScale[9] = 0.32;
				this.levelsScale[10] = 0.64;
				this.levelsScale[11] = 1.28;
				this.levelsScale[12] = 2.56;
				this.levelsScale[13] = 5.12;
				this.levelsScale[14] = 10.24;	
				this.zoomInit = false;	
				this.outMapPanel = mapPanel;
					
				this.events = new Array();
				//silnik
				this.services = new Array();
				this.groups = new Array();
				this.groups.push({id:0,name:'',visible:false,expanded:true,icon:'',active:false});
				
				this.viewPoint = new BEngine.iGML.Point(0,0);
				this.scale = 1;
				this.position = new BEngine.iGML.Point(0,0);
				this.box = new BEngine.iGML.Box(0,0,0,0);
				this.crs = 'EPSG:2180';
				this.maxScale = 9;
				this.mouseCoordinates = new BEngine.iGML.Point(0,0);
			
				//kontrolki
				var parSize = panel.getWorkspaceSize();
				this.mainWindow = new BEngine.Controls.Panel({x:0,y:0,width:parSize[0],height:parSize[1],aRight:true,aBottom:true,backParam:new BEngine.Controls.BackParam('#999')},panel);
				this.mainWindow.div.style.overflow = 'hidden';
				
				var mainWinSize = this.mainWindow.getWorkspaceSize();
				this.workPanel= new BEngine.Controls.Panel({x:1,y:30,width:mainWinSize[0]-2,height:mainWinSize[1]-31-25,aRight:true,aBottom:true,backParam:new BEngine.Controls.BackParam('#fff')},this.mainWindow);
				this.workPanel.div.style.overflow = 'hidden';		
							
				var workPanSize = this.workPanel.getWorkspaceSize();
				this.mapPanel = new BEngine.Controls.Panel({x:0,y:0,width:workPanSize[0],height:workPanSize[1],aRight:true,aBottom:true,backParam:new BEngine.Controls.BackParam('#fafafa')},this.workPanel);	
				this.mapPanel.div.style.overflow = 'hidden';
				
				this.mapPanel.addEvent('resize',function(){
					obj.refresh();
				});				
					
				this.overlayPanel = new BEngine.Controls.Panel({x:0,y:0,width:workPanSize[0],height:workPanSize[1],aRight:true,aBottom:true},this.workPanel);		
								
				this.initOverlays();

				this.controlPanel = new BEngine.Controls.Panel({x:0,y:0,width:workPanSize[0],height:workPanSize[1],aRight:true,aBottom:true,backParam:new BEngine.Controls.BackParam('transparent',BEngine.mainPath+'bengine/images/igml/plik_ktory_nie_istnieje.png')},this.workPanel);											
				BEngine.Controls.disableSelection(this.controlPanel.div);
				
				this.framePrint = BEngine.Controls.createDiv(100,100,null,null,200,200);
				this.workPanel.getWorkspaceDiv().appendChild(this.framePrint);
				this.framePrint.style.zIndex = 600;
				this.framePrint.style.border = '2px solid #3f5';
				this.framePrint.style.display = 'none';
				this.framePrint2 = BEngine.Controls.createDiv(100,100,null,null,200,200);
				this.workPanel.getWorkspaceDiv().appendChild(this.framePrint2);
				this.framePrint2.style.zIndex = 600;
				this.framePrint2.style.border = '2px solid #3f5';
				this.framePrint2.style.display = 'none';
				
				this.zoomPlus = BEngine.Controls.createDiv(5,3,null,null,25,25);
				this.workPanel.getWorkspaceDiv().appendChild(this.zoomPlus);
				this.zoomPlus.style.backgroundImage= 'url('+BEngine.mainPath+'bengine/images/igml/plus_zoom.png)';
				this.zoomPlus.style.zIndex = 700000;
				this.zoomPlus.style.cursor = 'pointer';
	
				this.zoomMinus = BEngine.Controls.createDiv(5,3,null,null,25,25);
				this.zoomMinus.style.disply = 'none';
				this.workPanel.getWorkspaceDiv().appendChild(this.zoomMinus);
				this.zoomMinus.style.backgroundImage= 'url('+BEngine.mainPath+'bengine/images/igml/minus_zoom.png)';
				this.zoomMinus.style.zIndex = 700000;
				this.zoomMinus.style.cursor = 'pointer';				
	
				this.zoomPlus.onclick = function(){
					obj.zoom(1,false);
				}
				this.zoomMinus.onclick = function(){
					obj.zoom(-1,false);
				}	
				this.zoomBar = BEngine.Controls.createDiv(5,30,null,null,25,225);
				//this.zoomBar.style.backgroundColor = '#f00';
				this.zoomBar.style.overflow = 'hidden';
				this.zoomBar.style.display = 'none';
				this.zoomBar.style.zIndex = 710000;
				this.workPanel.getWorkspaceDiv().appendChild(this.zoomBar);
				
				this.zoomDivs = new Array();
				for (var i=0;i<this.levelsScale.length;i++){
					var szcz = BEngine.Controls.createDiv(0,6+(i*15),null,null,23,3);
					this.zoomDivs.push(szcz);
					szcz.style.backgroundColor = '#ddd';
					szcz.style.border = '1px solid #777';
					szcz.style.cursor = 'pointer';
					szcz.style.zIndex = 712000;
					this.zoomBar.appendChild(szcz);
					szcz.level = this.levelsScale[this.levelsScale.length-i-1];
					szcz.onclick = function(){
						obj.setView(obj.viewPoint.x,obj.viewPoint.y,this.level);
					}
				}
				
				
				this.infoPanel = new BEngine.Controls.ExtPanel({x:0,y:0,width:250,height:250,text:'Informacja o obiekcie',barImage:'green'},this.workPanel);
				this.infoPanel.hide();
				
				var stBackParam = new BEngine.Controls.BackParam('#fff',BEngine.mainPath+'bengine/images/toolbars/24.png');	
				this.statusPanel = new BEngine.Controls.Panel({x:1,y:mainWinSize[1]-25,width:mainWinSize[0]-2,height:24,aRight:true,aTop:false,aBottom:true,backParam:stBackParam},this.mainWindow);		
				
				this.logoPanel = new BEngine.Controls.Panel({x:this.statusPanel.getWorkspaceSize()[0]-145,y:0,width:140,height:24,aLeft:false,aRight:true,aTop:true,aBottom:false,backParam:new BEngine.Controls.BackParam('transparent',BEngine.mainPath+'bengine/images/podpis.png','no-repeat','right center')},this.statusPanel);		
				this.logoPanel.addEvent('click',function(){
					window.open("http://www.geo-system.com.pl");				
				});
				this.logoPanel.div.style.cursor='pointer';
				
				if (this.outMapPanel==null){		
					var coorBackParam = new BEngine.Controls.BackParam('transparent',BEngine.mainPath+'bengine/images/igml/coor_back.png');							
					this.coordinatesTextBox = new BEngine.Controls.Panel({x:90,y:2,width:195,height:20,backParam:coorBackParam},this.statusPanel);	
				} else {
					var coorBackParam = new BEngine.Controls.BackParam('transparent',BEngine.mainPath+'bengine/images/igml/coor_back2.png');	
					this.coordinatesTextBox = new BEngine.Controls.Panel({x:25,y:2,width:260,height:20,backParam:coorBackParam},this.statusPanel);
				}				
				this.coordinatesTextBox.div.onclick = function(){
					alert('aktualna skala widoku: '+BEngine.Utils.round(obj.scale,3));
				}				
				this.loadedPanel = new BEngine.Controls.Panel({x:2,y:0,width:22,height:24},this.statusPanel);	
							
				
				this.loadingPanel = new BEngine.Controls.Panel({x:2,y:0,
												width:22,
												height:24,
												backParam:new BEngine.Controls.BackParam('transparent',BEngine.mainPath+'bengine/images/igml/loaded.png')
												},this.statusPanel);	
												
				
				// podczas ladowania
				this.loadingPanelLoading = new BEngine.Controls.Panel({x:2,y:0,
												width:22,
												height:24,
												backParam:new BEngine.Controls.BackParam('transparent',BEngine.mainPath+'bengine/images/igml/loading.gif')
												},this.statusPanel);
					
				this.loadingPanelText = new BEngine.Controls.Panel({x:6,y:5,
												width:10,
												height:11},this.loadingPanelLoading);
				this.loadingPanelText.div.style.fontSize = '10px';
				this.loadingPanelText.div.style.textAlign='center';
				this.loadingPanelText.div.style.color='#555';
				this.loadingPanelText.div.innerHTML='1';											
				this.loadingPanelLoading.hide();
				
				// gdy wystapi blad
				this.loadingPanelError = new BEngine.Controls.Panel({x:2,y:0,
												width:22,
												height:24,
												backParam:new BEngine.Controls.BackParam('transparent',BEngine.mainPath+'bengine/images/igml/loaderror.png')
												},this.statusPanel);																
				this.loadingPanelError.hide();				
				this.loadingLayersCount = 0;	

				if (this.outMapPanel==null){
					this.layerButton = new BEngine.Controls.CheckButton({x:25,y:2,width:62,height:20,text:'Warstwy',borderColor:'#bbb'},this.statusPanel);
					this.layerButton.onclick = function(checked){
						if (checked==true){
							obj.showMenuPanel();	
						} else {
							obj.menuPanel.hide();
						}	
					}					
				}	
				
				this.mapPanel.div.style.zIndex = 0;
				this.overlayPanel.div.style.zIndex = 1000;
				this.controlPanel.div.style.zIndex = 2000;
				this.statusPanel.div.style.zIndex = 3000;
				this.infoPanel.div.style.zIndex = 2989;
					
				BEngine.Controls.disableContextMenu(this.controlPanel.div);	

				this.initControls();
				
			}
		}			
	},
	Controls : {
		init:function(){
			if (window.addEventListener)
			window.addEventListener('DOMMouseScroll', this.wheelEvent, false);
			window.onmousewheel = document.onmousewheel = this.wheelEvent;
			this.wheelDivs = new Array();
			this.initExtPanelStyles();
			this.checkGroupButtons = new Array();
			
			this.keys = new Array()
			this.keyUpFunctions = new Array();
			this.keyDownFunctions = new Array();
			document.onkeyup=function(e){
				var key = null;
				if(window.event){
					key = window.event.keyCode;
				} else
				key = e.which;
				BEngine.Controls.keys[key] = false;
				for (var i=0;i<BEngine.Controls.keyUpFunctions.length;i++){
					var o = BEngine.Controls.keyUpFunctions[i];
					if (o[0].mouseIn==true)
					o[1](key);
				}

			} 
			document.onkeydown=function(e){ 
				var key = null;
				if(window.event){
					key = window.event.keyCode;
				} else
				key = e.which;
				BEngine.Controls.keys[key] = true;
				for (var i=0;i<BEngine.Controls.keyDownFunctions.length;i++){
					var o = BEngine.Controls.keyDownFunctions[i];
					if (o[0].mouseIn==true)
					o[1](key);
				}
				
				if (key==27){
				if ((e)&&(e.cancelable)){
					e.preventDefault()
				} else {
					if (!e) var e = window.event
					e.cancelBubble = true;
					e.returnValue = false;

				}
				}
			} 
		
		},
		createDiv:function(left,top,right,bottom,width,height){
			var div = document.createElement('div');
			div.style.position = 'absolute';
			if (left!=null)
			div.style.left = left+'px';
			if (top!=null)
			div.style.top = top+'px';
			if (right!=null)
			div.style.right = right+'px';
			if (bottom!=null)
			div.style.bottom = bottom+'px';
			if (width!=null)
			div.style.width = width+'px';
			if (height!=null)
			div.style.height = height+'px';
			return div;
		},
		modifyDiv:function(div,left,top,right,bottom,width,height){
			if (left!=null)
			div.style.left = left+'px';
			if (top!=null)
			div.style.top = top+'px';
			if (right!=null)
			div.style.right = right+'px';
			if (bottom!=null)
			div.style.bottom = bottom+'px';
			if (width!=null)
			div.style.width = width+'px';
			if (height!=null)
			div.style.height = height+'px';
		},	
		calculateDivPosition:function(parentWidth,parentHeight,x,y,width,height,aLeft,aTop,aRight,aBottom){
			if ((aLeft == true)&&(aRight == false)){
				styleRight = null;
				styleLeft = x;
				styleWidth = width;
			}
			if ((aLeft == false)&&(aRight == true)){
				styleRight = parentWidth-x-width;
				styleWidth = width;
				styleLeft = null;
			}
			if ((aLeft == true)&&(aRight == true)){
				styleLeft = x;
				styleRight = parentWidth-x-width;			
				styleWidth = null;
			}
			
			if ((aTop == true)&&(aBottom == false)){
				styleTop = y;
				styleHeight = height;
				styleBottom = null;
			}		
			if ((aTop == false)&&(aBottom == true)){
				styleBottom = parentHeight-y-height;
				styleHeight = height;
				styleTop = null;
			}			
			if ((aTop == true)&&(aBottom == true)){
				styleTop = y;
				styleBottom = parentHeight-y-height;
				styleHeight = null;
			}	
			return [styleLeft,styleTop,styleRight,styleBottom,styleWidth,styleHeight];
		},
		setDivInCenter:function (div,parentDiv){
			if ((parentDiv)&&(div)){
				var left = Math.round((parentDiv.clientWidth - div.clientWidth)*0.5);
				var top = Math.round((parentDiv.clientHeight - div.clientHeight)*0.5);
				div.style.left = left+'px';
				div.style.top = top+'px';
			}
		},
		setDiv:function(div,left,top,right,bottom,width,height){
			if (left!=null)
			div.style.left = left+'px';
			if (top!=null)
			div.style.top = top+'px';
			if (right!=null)
			div.style.right = right+'px';
			if (bottom!=null)
			div.style.bottom = bottom+'px';
			if (width!=null)
			div.style.width = width+'px';
			if (height!=null)
			div.style.height = height+'px';
		},
		isRightButtonPressed:function (e) {
			var rightclick;
			if (!e) var e = window.event;
			if (e.which) rightclick = (e.which == 3);
			else if (e.button) rightclick = (e.button == 2);
			return rightclick;
		},
		addEvent:function(element,event,fun){
			if (element.addEventListener){
				element.addEventListener(event,fun,false);
			} else {
				element.attachEvent('on'+event,fun);
			}
		},	
		addGlobalEvent:function(event,fun){
			this.addEvent( BEngine.Interface.rootPanel.div,event,fun);
		},
		executeClickEvent:function(div,e,fun){
			if (fun){
				var coor = BEngine.Controls.mouseCoordinates(e,div);
				fun(coor[0],coor[1]);
			}	
		},
		executeMousedownupEvent:function(div,e,fun){
			if (fun){
				var but = 0;
				if (this.isRightButtonPressed(e)==true) but = 1;
				var coor = BEngine.Controls.mouseCoordinates(e,div);
				fun(coor[0],coor[1],but);
			}	
		},	
		executeMousemoveEvent:function(div,e,fun){
			if (fun){
				var coor = BEngine.Controls.mouseCoordinates(e,div);
				fun(coor[0],coor[1]);
			}	
		},		
		wheelEvent:function(e){
			var delta = 0;
			if (!e) 
				e = window.event;
			if (e.wheelDelta) { 
				delta = e.wheelDelta/120;
				if (window.opera)
                    delta = -delta;
			} else 
			if (e.detail) { 
				delta = -e.detail/3;
			}
			var dalej = true;
			if (delta){
				for (var i=0;i<BEngine.Controls.wheelDivs.length;i++){
					if (BEngine.Controls.wheelDivs[i].div.mouseIn==true){
						BEngine.Controls.wheelDivs[i].fun(delta);						
					}
				}
			}				
		},
		setServiceStandardEvent:function(div,event,fun){
			//click (x,y)
			//mousedown (x,y,button)
			//mouseup (x,y,button)
			//mouseover
			if (event=='click'){
				BEngine.Controls.addEvent(div,'click',function(e){
					BEngine.Controls.executeClickEvent(div,e,fun);
				});				
			}
			if (event=='mousedown'){
				BEngine.Controls.addEvent(div,'mousedown',function(e){
					BEngine.Controls.executeMousedownupEvent(div,e,fun);
				});					
			}	
			if (event=='mouseup'){
				BEngine.Controls.addEvent(div,'mouseup',function(e){
					BEngine.Controls.executeMousedownupEvent(div,e,fun);
				});					
			}	
			if (event=='mouseover'){
				BEngine.Controls.addEvent(div,'mouseover',function(e){
					div.mouseIn = true;
					var pos = BEngine.Controls.mouseCoordinates(e,div);
					fun(pos[0],pos[1]);
				});					
			}
			if (event=='mouseout'){
				BEngine.Controls.addEvent(div,'mouseout',function(e){
					var pos = BEngine.Controls.mouseCoordinates(e,div);
					fun(pos[0],pos[1]);
					div.mouseIn = false;
				});					
			}		
			if (event=='mousemove'){
				
				BEngine.Controls.addEvent(div,'mousemove',function(e){
					BEngine.Controls.executeMousemoveEvent(div,e,fun);
				});
										
			}		
			if (event=='mousewheel'){
				this.wheelDivs.push({div:div,fun:fun,cancel:true});		
				BEngine.Controls.addEvent(div,'mouseover',function(e){
					div.mouseIn = true;
				});
				BEngine.Controls.addEvent(div,'mouseout',function(e){
					div.mouseIn = false;
				});		
				BEngine.Controls.addEvent(div,'mousedown',function(e){				
					div.mouseIn = true;
				});					
			}				
		},
		cancelEvent:function(e){
			if (!e) var e = window.event
			e.cancelBubble = true;
			if (e.stopPropagation) e.stopPropagation();	
		},	
		mouseDown:function(e){
			e = e || window.event;
			if (e.preventDefault){
				e.preventDefault();
			}
		},
		cancelMouseUp:function(div){
			div.onmouseup = function(e){
				if (!e) var e = window.event
				e.cancelBubble = true;
				if (e.stopPropagation) e.stopPropagation();		
			}	
		},		
		cancelStandardEvents:function(div){
			BEngine.Controls.addEvent(div,'click',function(e){	
				BEngine.Controls.cancelEvent(e);
			});				
			BEngine.Controls.addEvent(div,'mousedown',function(e){	
				//BEngine.Controls.cancelEvent(e);
			});		
			BEngine.Controls.addEvent(div,'mouseup',function(e){	
				BEngine.Controls.cancelEvent(e);
			});		
			BEngine.Controls.addEvent(div,'mousemove',function(e){	
				BEngine.Controls.cancelEvent(e);
			});	
			BEngine.Controls.addEvent(div,'mouseover',function(e){	
				BEngine.Controls.cancelEvent(e);
			});	
			BEngine.Controls.addEvent(div,'mouseout',function(e){	
				BEngine.Controls.cancelEvent(e);
			});				
		},
		disableContextMenu:function(div){
			div.oncontextmenu = function(e){
				return false; 
			}	
		},
		cancelMouseOver:function(div){
			div.onmouseover = function(e){
				if (!e) var e = window.event
				e.cancelBubble = true;
				if (e.stopPropagation) e.stopPropagation();		
			}	
		},		
		getSize:function(control){
			var size=[0,0];
			if (control.nodeName=='DIV'){
				size[0] = control.clientWidth;
				size[1] = control.clientHeight;				
			} else {
				if (control.getWorkspaceSize){
					size = control.getWorkspaceSize();
				}
			}
			return size;
		},
		divPosition:function(div) {
			var left = 0;
			var top = 0;
			if (div.offsetParent) {
				do {
					left += div.offsetLeft-div.scrollLeft;
					top += div.offsetTop-div.scrollTop;
					div = div.offsetParent;
				} while (div!=this.systemDiv);
			}
			return [left,top];
		},
		divPositionInDiv:function(div,divParent){
			var pos = this.divPosition(div);
			var posParent = this.divPosition(divParent);
			return [pos[0]-posParent[0],pos[1]-posParent[1]];
		},
		mouseCoordinates:function (e,div){
			/*
			function isIE() {
				return /msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent);
			}
			*/
		
			var posx = 0;
			var posy = 0;
		
			if (!e) var e = window.event;
			if (e.pageX || e.pageY) 	{
				posx = e.pageX;
				posy = e.pageY;
			}
			else if (e.clientX || e.clientY) 	{
				posx = e.clientX + document.body.scrollLeft
				+ document.documentElement.scrollLeft;
				posy = e.clientY + document.body.scrollTop
				+ document.documentElement.scrollTop;
			}
			
			if (BEngine.Utils.isIE()==true) {
				posx-=2;
				posy-=2;
			}	
			
			if (div!=null){
				var pos = this.divPosition(div);
				posx-=pos[0];
				posy-=pos[1];
			}
			return [posx,posy];
		},	
		setDivOpacity:function(div,opacity){
			div.style.opacity = opacity;
			div.style.filter = 'alpha(opacity='+Math.round(opacity*100)+')';	
		},
		disableSelection:function(target){
			if (typeof target.onselectstart!="undefined") //IE route
				target.onselectstart=function(){return false}
			else if (typeof target.style.MozUserSelect!="undefined") //Firefox route
				target.style.MozUserSelect="none"
			else //All other route (ie: Opera)
				target.onmousedown=function(){return false}
			target.style.cursor = "default"
		},
		initExtPanelStyles:function(){
			this.extPanelStyles = new Array();
			this.extPanelStyles[this.extPanelStyles.length] = new this.ExtPanelStyle('r11',BEngine.mainPath+'bengine/images/r11/',11,'#d4d4d4',9,8);
			this.extPanelStyles[this.extPanelStyles.length] = new this.ExtPanelStyle('s11',BEngine.mainPath+'bengine/images/s11/',11,'#d4d4d4',7,7);
		},
		getExtPanelStyleByName:function(name){
			for (var i=0;i<BEngine.Controls.extPanelStyles.length;i++){
				if (BEngine.Controls.extPanelStyles[i].name == name) return BEngine.Controls.extPanelStyles[i];
			}
			return null;
		},
		createColoredFrame:function(size,color,borderColor){
			var div = this.createDiv(0,0,0,0,null,null);
			var top = this.createDiv(size,0,size,null,null,size-1);
			top.style.backgroundColor = color;
			top.style.borderTop = '1px solid '+borderColor;
			div.appendChild(top);
			var left = this.createDiv(0,size,null,size,size-1,null);
			left.style.backgroundColor = color;
			left.style.borderLeft = '1px solid '+borderColor;
			div.appendChild(left);
			var lefttop = this.createDiv(0,0,null,null,size-1,size-1);
			lefttop.style.backgroundColor = color;
			lefttop.style.borderLeft = '1px solid '+borderColor;
			lefttop.style.borderTop = '1px solid '+borderColor;
			div.appendChild(lefttop);		
			var righttop = this.createDiv(null,0,0,null,size-1,size-1);
			righttop.style.backgroundColor = color;
			righttop.style.borderRight = '1px solid '+borderColor;
			righttop.style.borderTop = '1px solid '+borderColor;
			div.appendChild(righttop);	
			var right = this.createDiv(null,size,0,size,size-1,null);
			right.style.backgroundColor = color;
			right.style.borderRight= '1px solid '+borderColor;
			div.appendChild(right);		
			var rightbottom = this.createDiv(null,null,0,0,size-1,size-1);
			rightbottom.style.backgroundColor = color;
			rightbottom.style.borderRight= '1px solid '+borderColor;
			rightbottom.style.borderBottom= '1px solid '+borderColor;
			div.appendChild(rightbottom);
			var leftbottom = this.createDiv(0,null,null,0,size-1,size-1);
			leftbottom.style.backgroundColor = color;
			leftbottom.style.borderLeft= '1px solid '+borderColor;
			leftbottom.style.borderBottom= '1px solid '+borderColor;
			div.appendChild(leftbottom);
			var bottom = this.createDiv(size,null,size,0,null,size-1);
			bottom.style.backgroundColor = color;
			bottom.style.borderBottom = '1px solid '+borderColor;
			div.appendChild(bottom);		
			return [div,top,righttop,right,rightbottom,bottom,leftbottom,left,lefttop];
		},
		//Klasy obiektów	
		BackParam:function(color,image,repeat,position){
			color == null?this.color = 'transparent':this.color = color;
			image == null?this.image = null:this.image = image;
			repeat == null?this.repeat = 'repeat':this.repeat = repeat;		
			position == null?this.position = 'top left':this.position = position;			
			this.applyTo = function(div){
				if ((this.color!=null)&&(this.color != 'transparent')) div.style.backgroundColor = this.color;
				if (this.repeat!=null) div.style.backgroundRepeat = this.repeat;
				if (this.image!=null) div.style.backgroundImage = 'url('+this.image+')';		
				if (this.position!=null) div.style.backgroundPosition = this.position;				
			}
		},
		ExtPanelStyle:function(name,folderPath,size,color,borderSize,insideSize){
			this.name = name;
			this.paths = new Array();
			this.paths.push(folderPath+'lt.png');
			this.paths.push(folderPath+'t.png');
			this.paths.push(folderPath+'rt.png');
			this.paths.push(folderPath+'r.png');
			this.paths.push(folderPath+'rb.png');
			this.paths.push(folderPath+'b.png');
			this.paths.push(folderPath+'lb.png');
			this.paths.push(folderPath+'l.png');
			
			this.paths.push(folderPath+'ilt.png');
			this.paths.push(folderPath+'irt.png');
			this.paths.push(folderPath+'irb.png');
			this.paths.push(folderPath+'ilb.png');
			
			this.size = size;	
			if (borderSize!=null) this.bSize = borderSize; else this.bSize = size;
			if (insideSize!=null) this.insideSize = insideSize; else this.insideSize = size;
			this.color = color;	
			this.applyTo = function(div,offset,image){		
				if (!offset) {
					offset = 0;
				} else {
					if (!image){
						image = BEngine.mainPath+'bengine/images/bars/gray.png';
					} else {
						if ((image=='gray')||(image=='blue')||(image=='green')) {
							image = BEngine.mainPath+'bengine/images/bars/'+image+'.png';
						}
					}
				}
				
				var lt = BEngine.Controls.createDiv(0,0,null,null,this.size,this.size);
				lt.style.backgroundImage = 'url('+this.paths[0]+')';
				div.appendChild(lt);
				var t = BEngine.Controls.createDiv(this.size,0,this.size,null,null,this.size);
				t.style.backgroundImage = 'url('+this.paths[1]+')';
				div.appendChild(t);				
				var rt = BEngine.Controls.createDiv(null,0,0,null,this.size,this.size);
				rt.style.backgroundImage = 'url('+this.paths[2]+')';
				div.appendChild(rt);	
				var r = BEngine.Controls.createDiv(null,this.size,0,this.size,this.size,null);
				r.style.backgroundImage = 'url('+this.paths[3]+')';
				div.appendChild(r);				
				var rb = BEngine.Controls.createDiv(null,null,0,0,this.size,this.size);
				rb.style.backgroundImage = 'url('+this.paths[4]+')';
				div.appendChild(rb);	
				var b = BEngine.Controls.createDiv(this.size,null,this.size,0,null,this.size);
				b.style.backgroundImage = 'url('+this.paths[5]+')';
				div.appendChild(b);
				var lb = BEngine.Controls.createDiv(0,null,null,0,this.size,this.size);
				lb.style.backgroundImage = 'url('+this.paths[6]+')';
				div.appendChild(lb);		
				var l = BEngine.Controls.createDiv(0,this.size,null,this.size,this.size,null);
				l.style.backgroundImage = 'url('+this.paths[7]+')';
				div.appendChild(l);	
				
				var divWorkspace = BEngine.Controls.createDiv(this.bSize,this.bSize+offset,this.bSize,this.bSize,null,null);
				if (this.color!='transparent')
				divWorkspace.style.backgroundColor = this.color;
				div.appendChild(divWorkspace);
				var divBar = null;
				if (offset>0){
					divBar = BEngine.Controls.createDiv(this.bSize,this.bSize,this.bSize,null,null,offset);
					divBar.style.backgroundColor = '#ddd';
					div.appendChild(divBar);	
					divBar.style.backgroundImage = 'url('+image+')';
					var n1 = BEngine.Controls.createDiv(this.bSize,this.bSize,this.bSize,null,null,offset);
					n1.style.backgroundImage = 'url('+this.paths[8]+')';
					n1.style.backgroundRepeat = 'no-repeat';
					n1.style.backgroundPosition = 'top left';
					div.appendChild(n1);
					var n2 = BEngine.Controls.createDiv(this.bSize,this.bSize,this.bSize,null,null,offset);
					n2.style.backgroundImage = 'url('+this.paths[9]+')';
					n2.style.backgroundRepeat = 'no-repeat';
					n2.style.backgroundPosition = 'top right';
					div.appendChild(n2);	
					var n3 = BEngine.Controls.createDiv(this.bSize,this.bSize,this.bSize,null,null,offset);
					n3.style.backgroundImage = 'url('+this.paths[10]+')';
					n3.style.backgroundRepeat = 'no-repeat';
					n3.style.backgroundPosition = 'bottom right';
					div.appendChild(n3);				
					var n4 = BEngine.Controls.createDiv(this.bSize,this.bSize,this.bSize,null,null,offset);
					n4.style.backgroundImage = 'url('+this.paths[11]+')';
					n4.style.backgroundRepeat = 'no-repeat';
					n4.style.backgroundPosition = 'bottom left';
					div.appendChild(n4);					
				}
				return [divWorkspace,lt,t,rt,r,rb,b,lb,l,divBar];
			}						
		},
		Panel:function(param,parent){
			// param:
			// x : integer
			// y : integer
			// width : integer
			// height : integer
			// aLeft : boolean, kotwica lewa 
			// aTop : boolean, kotwica górna
			// aRight : boolean, kotwica prawa
			// aBottom : bolean, kotwica dolna
			// backParam : BackParam, styl tla
			// visible : boolean czy panel widoczny
			this.setCursor = function(cursor){
				this.div.style.cursor = cursor;
			}
			this.getCursor = function(){
				return this.div.style.cursor;
			}			
			this.setPosition = function(x,y){
				this.div.style.left = x+'px';
				this.div.style.top = y+'px';
			},
			this.canAddControl = function(controlName){
				if (controlName == 'Panel') return true;
				if (controlName == 'ExtPanel') return true;
				if (controlName == 'SlidePanel') return true;			
				if (controlName == 'Toolbar') return true;	
				if (controlName == 'Button') return true;	
				if (controlName == 'ComboBox') return true;
				if (controlName == 'TreeView') return true;		
				if (controlName == 'Table') return true;	
				if (controlName == 'StaticButtonPanel') return true;				
				return false;
			}
			this.addControl = function(control){
				this.div.appendChild(control.div);
				this.childControls.push(control);
			}
			this.getWorkspaceSize = function(){		
				if (this.visible == true)
				return [this.div.clientWidth,this.div.clientHeight];
				else
				return [this.width,this.height];
			}
			this.getWorkspaceWidth = function(){
				return this.getWorkspaceSize()[0];
			},
			this.getWorkspaceHeight = function(){
				return this.getWorkspaceSize()[1];
			},			
			this.getWorkspaceDiv = function(){
				return this.div;
			}
			this.show = function(){
				this.div.style.display = 'block';
				this.visible = true;
			}
			this.hide = function(){
				this.div.style.display = 'none';
				this.visible = false;
			}			
			this.getSize = function(){
				if (this.visible == true)
				return [this.div.clientWidth,this.div.clientHeight];
				else
				return [this.width,this.height];
			}
			this.addEvent = function(event,fun){
				BEngine.Controls.setServiceStandardEvent(this.div,event,fun);	
				if (event=='resize'){
					this.onresize = fun;
				}
				if (event=='keydown'){
					BEngine.Controls.keyDownFunctions.push([this.div,fun]);
				}	
				if (event=='keyup'){
					BEngine.Controls.keyUpFunctions.push([this.div,fun]);
				}				
			}
			this.resizing = function(){
				if (((this.aLeft==true)&&(this.aRight==true))||((this.aTop==true)&&(this.aBottom==true))){	
					if (this.onresize) this.onresize();
					this.width = this.getWorkspaceSize()[0];
					this.height = this.getWorkspaceSize()[1];
					for (var i=0;i<this.childControls.length;i++){
						if (this.childControls[i].resizing) this.childControls[i].resizing();
					}
				}
			}
			this.showBarrier =  function(onclick){
				var obj = this;
				BEngine.Interface.Barrier.show(this.div,function(){
					if (onclick) onclick();
				});
			}
			this.hideBarrier =  function(){
				BEngine.Interface.Barrier.hide();
			}				
			this.setMinimalSize = function(width,height){
				this.div.style.minWidth = width+"px";
				this.div.style.minHeight = height+"px";
			}
			this.addImage = function(image,x,y,width,height){
				var div = BEngine.Controls.createDiv(x,y,null,null,width,height);
				div.style.backgroundImage = 'url('+image+')';
				this.div.appendChild(div);
			}
			this.setPositionFromActualParameters = function(){
				var parentSize = BEngine.Controls.getSize(this.parent);
				var style = BEngine.Controls.calculateDivPosition(parentSize[0],parentSize[1],this.x,this.y,this.width,this.height,this.aLeft,this.aTop,this.aRight,this.aBottom);
				BEngine.Controls.modifyDiv(this.div,style[0],style[1],style[2],style[3],style[4],style[5]);			
			}
			if (param!=null){
				if ((parent != null)&& ((parent.nodeName=='DIV')||((parent.canAddControl)&&(parent.canAddControl('Panel')==true)))){
					this.parent = parent;
					param.x == null?this.x = 0:this.x = param.x;
					param.y == null?this.y = 0:this.y = param.y;
					param.width == null?this.width = 100:this.width = param.width;
					param.height == null?this.height = 100:this.height = param.height;
					param.aLeft == null?this.aLeft = true:this.aLeft = param.aLeft;
					param.aTop == null?this.aTop = true:this.aTop = param.aTop;
					param.aRight == null?this.aRight = false:this.aRight = param.aRight;
					param.aBottom == null?this.aBottom = false:this.aBottom = param.aBottom;
					param.backParam == null?this.backParam = new BEngine.Controls.BackParam():this.backParam = param.backParam;
					
					this.visible = true;
					this.childControls = new Array();
					
					var parentSize = BEngine.Controls.getSize(parent);
					var style = BEngine.Controls.calculateDivPosition(parentSize[0],parentSize[1],this.x,this.y,this.width,this.height,this.aLeft,this.aTop,this.aRight,this.aBottom);
					this.div = BEngine.Controls.createDiv(style[0],style[1],style[2],style[3],style[4],style[5]);	
							
					if (parent.nodeName=='DIV') {
						parent.appendChild(this.div);
					} else {
						parent.addControl(this);
					}											
					this.backParam.applyTo(this.div);	
					BEngine.Controls.cancelStandardEvents(this.div);		

					
					
					if (param.visible!=null){
						if (param.visible == false) this.hide();
					}					
				}
			}			
		},
		ExtPanel:function(param,parent){
			// param:
			// x : integer
			// y : integer
			// width : integer
			// height : integer
			// aLeft : boolean, kotwica lewa 
			// aTop : boolean, kotwica górna
			// aRight : boolean, kotwica prawa
			// aBottom : bolean, kotwica dolna
			// style : ExtPanelStyle, stym ramki i wypelnienia panelu, domyslnie r11 
			// visible : boolean czy panel widoczny
			// text : string, jego obecnosc powoduje ze pojawia sie pasek naglowka
			// barImage : string, adres url obrazka lub predefiniowany (green/blue/gray) 
			this.setCursor = function(cursor){
				this.workspaceDiv.style.cursor = cursor;
			},
			this.getCursor = function(){
				return this.workspaceDiv.style.cursor;
			}
			this.canAddControl = function(controlName){
				if (controlName == 'Panel') return true;
				if (controlName == 'ExtPanel') return true;
				if (controlName == 'SlidePanel') return true;
				if (controlName == 'Toolbar') return true;		
				if (controlName == 'Button') return true;	
				if (controlName == 'ComboBox') return true;
				if (controlName == 'TreeView') return true;				
				if (controlName == 'Table') return true;	
				if (controlName == 'StaticButtonPanel') return true;				
				return false;
			}
			this.addControl = function(control){
				this.workspaceDiv.appendChild(control.div);
				this.childControls.push(control);
			}
			this.getWorkspaceSize = function(){
				return [this.workspaceDiv.clientWidth,this.workspaceDiv.clientHeight];
			}
			this.getWorkspaceDiv = function(){
				return this.workspaceDiv;
			}
			this.show = function(){
				this.div.style.display = 'block';
				this.visible = true;
			}
			this.hide = function(){
				this.div.style.display = 'none';
				this.visible = false;
			}			
			this.getSize = function(){
				return [this.div.clientWidth,this.div.clientHeight];
			}
			this.addEvent = function(event,fun){
				BEngine.Controls.setServiceStandardEvent(this.workspaceDiv,event,fun);	
				if (event=='resize'){
					this.onresize = fun;
				}			
				if (event=='keydown'){
					BEngine.Controls.keyDownFunctions.push([this.div,fun]);
				}	
				if (event=='keyup'){
					BEngine.Controls.keyUpFunctions.push([this.div,fun]);
				}				
			}
			this.getWorkspaceWidth = function(){
				return this.getWorkspaceSize()[0];
			},
			this.getWorkspaceHeight = function(){
				return this.getWorkspaceSize()[1];
			},	
			this.resizing = function(){
				if (((this.aLeft==true)&&(this.aRight==true))||((this.aTop==true)&&(this.aBottom==true))){	
					if (this.onresize) this.onresize();
					for (var i=0;i<this.childControls.length;i++){
						if (this.childControls[i].resizing) this.childControls[i].resizing();
					}
				}
			}	
			this.showBarrier =  function(onclick){
				var obj = this;
				BEngine.Interface.Barrier.show(this.div,function(){
					if (onclick) onclick();
				});
			}
			this.hideBarrier =  function(){
				BEngine.Interface.Barrier.hide();
			}	
			this.setMinimalSize = function(width,height){
				this.div.style.minWidth = width+"px";
				this.div.style.minHeight = height+"px";
			}
			this.setWorkspaceHeight = function(height){
				var dy = this.getSize()[1]-this.getWorkspaceSize()[1];
				this.div.style.height = (height+dy)+"px"; 
			}
			this.addImage = function(image,x,y,width,height){
				var div = BEngine.Controls.createDiv(x,y,null,null,width,height);
				div.style.backgroundImage = 'url('+image+')';
				this.workspaceDiv.appendChild(div);
			}
			this.setPositionFromActualParameters = function(){
				var parentSize = BEngine.Controls.getSize(this.parent);
				var style = BEngine.Controls.calculateDivPosition(parentSize[0],parentSize[1],this.x,this.y,this.width,this.height,this.aLeft,this.aTop,this.aRight,this.aBottom);
				BEngine.Controls.modifyDiv(this.div,style[0],style[1],style[2],style[3],style[4],style[5]);			
			}
			this.setText = function(text){
				this.text = text;
				this.barDiv.innerHTML = '<table style="font-size:12px;border-collapse:collapse;height:100%;width:100%;font-weight:bold;color:#fff"><tr><td style="padding-left:10px;text-align:center">'+this.text+'</td></tr></table>';
			}
			if (param!=null){
				if ((parent != null)&& ((parent.nodeName=='DIV')||((parent.canAddControl)&&(parent.canAddControl('ExtPanel')==true)))){
					this.parent = parent;
					param.x == null?this.x = 0:this.x = param.x;
					param.y == null?this.y = 0:this.y = param.y;
					param.width == null?this.width = 100:this.width = param.width;
					param.height == null?this.height = 100:this.height = param.height;
					param.aLeft == null?this.aLeft = true:this.aLeft = param.aLeft;
					param.aTop == null?this.aTop = true:this.aTop = param.aTop;
					param.aRight == null?this.aRight = false:this.aRight = param.aRight;
					param.aBottom == null?this.aBottom = false:this.aBottom = param.aBottom;
					param.style == null?this.style = new BEngine.Controls.getExtPanelStyleByName('r11'):this.style = param.style;
					param.text == null?this.text = null:this.text = param.text;
					this.barImage = param.barImage;
					var barOffset = 0;
					if (param.text!=null) barOffset = 20;
				
					this.childControls = new Array();
					
					var parentSize = BEngine.Controls.getSize(parent);
					var style = BEngine.Controls.calculateDivPosition(parentSize[0],parentSize[1],this.x,this.y,this.width,this.height,this.aLeft,this.aTop,this.aRight,this.aBottom);
					this.div = BEngine.Controls.createDiv(style[0],style[1],style[2],style[3],style[4],style[5]);						
					BEngine.Controls.disableContextMenu(this.div);
					if (parent.nodeName=='DIV') {
						parent.appendChild(this.div);
					} else {
						parent.addControl(this);
					}											
					if (this.style!=null){
						var divs = this.style.applyTo(this.div,barOffset,this.barImage);
						this.workspaceDiv = divs[0];	
						if (barOffset>0){
							var barDiv = divs[9];
							barDiv.innerHTML = '<table style="font-size:12px;border-collapse:collapse;height:100%;width:100%;font-weight:bold;color:#fff"><tr><td style="padding-left:10px;text-align:center">'+this.text+'</td></tr></table>';
							this.barDiv = barDiv;
						}
					} else {
						this.workspaceDiv = this.div;
					}	
					BEngine.Controls.cancelStandardEvents(this.div);
					if (param.visible!=null){
						if (param.visible == false) this.hide();
					}
				}
			}			
		},
		SlidePanel:function(param,parent){
			// param:
			// x : integer
			// y : integer
			// width : integer
			// height : integer
			// aLeft : boolean, kotwica lewa 
			// aTop : boolean, kotwica górna
			// aRight : boolean, kotwica prawa
			// aBottom : bolean, kotwica dolna
			// backParam : BackParam, styl tla
			// visible : boolean czy panel widoczny
			// leftWidth : integer, szerokosc lewego panelu
			// minLeftWidth : integer, minimalna szerokosc lewego panelu
			// minRightWidth : integer, minimalna szerokosc prawego panelu
			this.getWorkspaceSize = function(){
				return [this.div.clientWidth,this.div.clientHeight];
			}
			this.getWorkspaceDiv = function(){
				return this.div;
			}
			this.show = function(){
				this.div.style.display = 'block';
				this.visible = true;
			}
			this.hide = function(){
				this.div.style.display = 'none';
				this.visible = false;
			}			
			this.getSize = function(){
				return [this.div.clientWidth,this.div.clientHeight];
			}
			this.addEvent = function(event,fun){
				BEngine.Controls.setServiceStandardEvent(this.div,event,fun);	
				if (event=='resize'){
					this.onresize = fun;
				}				
			}
			this.resizing = function(){
				if (((this.aLeft==true)&&(this.aRight==true))||((this.aTop==true)&&(this.aBottom==true))){	
					if (this.onresize) this.onresize();
					this.leftPanel.resizing();
					this.rightPanel.resizing();
					for (var i=0;i<this.childControls.length;i++){
						if (this.childControls[i].resizing) this.childControls[i].resizing();
					}
				}
			}
			this.showBarrier =  function(onclick){
				var obj = this;
				BEngine.Interface.Barrier.show(this.div,function(){
					if (onclick) onclick();
				});
			}
			this.hideBarrier =  function(){
				BEngine.Interface.Barrier.hide();
			}				
			this.setSliderPosition = function(left){
				this.leftWidth = left;
				if (this.leftWidth<this.minLeftWidth) this.leftWidth = this.minLeftWidth;
				var width = this.getSize()[0];
				if ((width-this.leftWidth)<this.minRightWidth) this.leftWidth = width-this.minRightWidth;
				
				this.leftPanel.div.style.width = this.leftWidth+'px';
				this.rightPanel.div.style.left = (this.leftWidth+5)+'px';
			}
			this.getLeftPanel = function(){
				return this.leftPanel;
			}
			this.getRightPanel = function(){
				return this.rightPanel;
			}			
			this.setMinimalSize = function(width,height){
				this.div.style.minWidth = width+"px";
				this.div.style.minHeight = height+"px";
			}			
			if (param!=null){
				if ((parent != null)&& ((parent.nodeName=='DIV')||((parent.canAddControl)&&(parent.canAddControl('SlidePanel')==true)))){
					param.x == null?this.x = 0:this.x = param.x;
					param.y == null?this.y = 0:this.y = param.y;
					param.width == null?this.width = 100:this.width = param.width;
					param.height == null?this.height = 100:this.height = param.height;
					param.aLeft == null?this.aLeft = true:this.aLeft = param.aLeft;
					param.aTop == null?this.aTop = true:this.aTop = param.aTop;
					param.aRight == null?this.aRight = false:this.aRight = param.aRight;
					param.aBottom == null?this.aBottom = false:this.aBottom = param.aBottom;
					param.backParam == null?this.backParam = new BEngine.Controls.BackParam():this.backParam = param.backParam;
					param.leftWidth == null?this.leftWidth = 300:this.leftWidth = param.leftWidth;
					param.minLeftWidth == null?this.minLeftWidth = 100:this.minLeftWidth = param.minLeftWidth;
					param.minRightWidth == null?this.minRightWidth = 100:this.minRightWidth = param.minRightWidth;
					
					this.visible = true;
					this.childControls = new Array();
					
					var parentSize = BEngine.Controls.getSize(parent);
					var style = BEngine.Controls.calculateDivPosition(parentSize[0],parentSize[1],this.x,this.y,this.width,this.height,this.aLeft,this.aTop,this.aRight,this.aBottom);
					this.div = BEngine.Controls.createDiv(style[0],style[1],style[2],style[3],style[4],style[5]);						
					if (parent.nodeName=='DIV') {
						parent.appendChild(this.div);
					} else {
						parent.addControl(this);
					}											
					this.backParam.applyTo(this.div);	
					BEngine.Controls.cancelStandardEvents(this.div);		

					if (param.visible!=null){
						if (param.visible == false) this.hide();
					}		
					this.leftPanel = new BEngine.Controls.Panel({x:0,y:0,width:this.leftWidth,height:this.getSize()[1],aBottom:true},this.div);
					this.rightPanel = new BEngine.Controls.Panel({x:this.leftWidth+5,y:0,width:this.getSize()[0]-(this.leftWidth+5),height:this.getSize()[1],aRight:true,aBottom:true},this.div);	
					
					
					this.div.style.cursor = 'col-resize';
					this.leftPanel.setCursor('default');
					this.rightPanel.setCursor('default');
					
					var obj = this;
					this.addEvent('mousedown',function(x,y){						
						if ((x>=obj.leftWidth)&&(x<(obj.leftWidth+5))){
							BEngine.Interface.MovingPanel.moveHorizontal(obj.div,x,function(width){
								obj.setSliderPosition(width);
								obj.leftPanel.resizing();
								obj.rightPanel.resizing();
							});
							return false;	
						}
					})					
				}
			}			
		},
		VerticalSlidePanel:function(param,parent){
			// param:
			// x : integer
			// y : integer
			// width : integer
			// height : integer
			// aLeft : boolean, kotwica lewa 
			// aTop : boolean, kotwica górna
			// aRight : boolean, kotwica prawa
			// aBottom : bolean, kotwica dolna
			// backParam : BackParam, styl tla
			// visible : boolean czy panel widoczny
			// topHeight : integer, wysokosc gornego panelu
			// minTopHeight : integer, wysokosc gornego panelu
			// minBottomHeight : integer, wysokosc dolnego panelu
			// keepRatio : boolean, trzym aproporce suwaka
			this.getWorkspaceSize = function(){
				if (this.visible == true)
				return [this.div.clientWidth,this.div.clientHeight];
				else
				return [this.width,this.height];
			}
			this.getWorkspaceDiv = function(){
				return this.div;
			}
			this.show = function(){
				this.div.style.display = 'block';
				this.visible = true;
			}
			this.hide = function(){
				this.div.style.display = 'none';
				this.visible = false;
			}			
			this.getSize = function(){
				if (this.visible == true)
				return [this.div.clientWidth,this.div.clientHeight];
				else
				return [this.width,this.height];
			}
			this.addEvent = function(event,fun){
				BEngine.Controls.setServiceStandardEvent(this.div,event,fun);	
				if (event=='resize'){
					this.onresize = fun;
				}				
			}
			this.resizing = function(){
				var height = this.getSize()[1];
				if (((this.aLeft==true)&&(this.aRight==true))||((this.aTop==true)&&(this.aBottom==true))){	
					if ((this.topPanel.visible==true) && (this.bottomPanel.visible==true)){
						var ratio = this.topHeight/this.innerHeight;
					
						
						if (this.keepRatio==true)
						this.setSliderPosition(Math.round(ratio*height));
					}
					this.topPanel.resizing();
					this.bottomPanel.resizing();
					
					if (this.onresize) this.onresize();
					for (var i=0;i<this.childControls.length;i++){
						if (this.childControls[i].resizing) this.childControls[i].resizing();
					}
				}
				this.innerHeight = height;
			}
			this.showBarrier =  function(onclick){
				var obj = this;
				BEngine.Interface.Barrier.show(this.div,function(){
					if (onclick) onclick();
				});
			}
			this.hideBarrier =  function(){
				BEngine.Interface.Barrier.hide();
			}				
			this.setSliderPosition = function(top){
				this.topHeight = top;
				if (this.topHeight<this.minTopHeight) this.topHeight = this.minTopHeight;
				var height = this.getSize()[1];
				if ((height-this.topHeight)<this.minBottomHeight) this.topHeight = height-this.minBottomHeight;
				
				this.topPanel.div.style.height = this.topHeight+'px';
				this.bottomPanel.div.style.top = (this.topHeight+5)+'px';
				
				
			}
			this.getTopPanel = function(){
				return this.topPanel;
			}
			this.getBottomPanel = function(){
				return this.bottomPanel;
			}			
			this.setMinimalSize = function(width,height){
				this.div.style.minWidth = width+"px";
				this.div.style.minHeight = height+"px";
			}			
			this.showOnlyTop = function(){
				this.topPanel.show();					
				this.bottomPanel.hide();
				this.topPanel.div.style.height = '';
				this.topPanel.div.style.bottom = '0px';
				this.topPanel.resizing();
			}
			this.showOnlyBottom = function(){
				this.bottomPanel.show();					
				this.topPanel.hide();
				this.bottomPanel.div.style.height = '';
				this.bottomPanel.div.style.top = '0px';
				this.bottomPanel.resizing();
			}	
			this.showBoth = function(){
				this.bottomPanel.show();					
				this.topPanel.show();
				this.topPanel.div.style.bottom = '';
				this.bottomPanel.div.style.top = '';
				this.setSliderPosition(this.topHeight);
				this.topPanel.resizing();
				this.bottomPanel.resizing();
			}				
			if (param!=null){
				if ((parent != null)&& ((parent.nodeName=='DIV')||((parent.canAddControl)&&(parent.canAddControl('SlidePanel')==true)))){
					param.x == null?this.x = 0:this.x = param.x;
					param.y == null?this.y = 0:this.y = param.y;
					param.width == null?this.width = 100:this.width = param.width;
					param.height == null?this.height = 100:this.height = param.height;
					param.aLeft == null?this.aLeft = true:this.aLeft = param.aLeft;
					param.aTop == null?this.aTop = true:this.aTop = param.aTop;
					param.aRight == null?this.aRight = false:this.aRight = param.aRight;
					param.aBottom == null?this.aBottom = false:this.aBottom = param.aBottom;
					param.backParam == null?this.backParam = new BEngine.Controls.BackParam():this.backParam = param.backParam;
					param.topHeight == null?this.topHeight = 300:this.topHeight = param.topHeight;
					param.minTopHeight == null?this.minTopHeight = 100:this.minTopHeight = param.minTopHeight;
					param.minBottomHeight == null?this.minBottomHeight = 100:this.minBottomHeight = param.minBottomHeight;
					param.keepRatio == null?this.keepRatio = false:this.keepRatio = param.keepRatio;
					
					this.visible = true;
					this.childControls = new Array();
					
					var parentSize = BEngine.Controls.getSize(parent);
					var style = BEngine.Controls.calculateDivPosition(parentSize[0],parentSize[1],this.x,this.y,this.width,this.height,this.aLeft,this.aTop,this.aRight,this.aBottom);
					this.div = BEngine.Controls.createDiv(style[0],style[1],style[2],style[3],style[4],style[5]);						
					if (parent.nodeName=='DIV') {
						parent.appendChild(this.div);
					} else {
						parent.addControl(this);
					}											
					this.backParam.applyTo(this.div);	
					BEngine.Controls.cancelStandardEvents(this.div);		

					if (param.visible!=null){
						if (param.visible == false) this.hide();
					}		
					this.topPanel = new BEngine.Controls.Panel({x:0,y:0,height:this.topHeight,width:this.getSize()[0],aRight:true},this.div);
					this.bottomPanel = new BEngine.Controls.Panel({y:this.topHeight+5,x:0,height:this.getSize()[1]-(this.topHeight+5),width:this.getSize()[0],aRight:true,aBottom:true},this.div);	
					
					
					this.div.style.cursor = 'row-resize';
					this.topPanel.setCursor('default');
					this.bottomPanel.setCursor('default');
					
					this.innerHeight = this.getSize()[1];
					
					var obj = this;
					this.addEvent('mousedown',function(x,y){						
						if ((y>=obj.topHeight)&&(y<(obj.topHeight+5))){
							BEngine.Interface.MovingPanel.moveVertical(obj.div,y,function(height){
								obj.setSliderPosition(height);
								obj.topPanel.resizing();
								obj.bottomPanel.resizing();
							});
							return false;	
						}
					})					
				}
			}			
		},	
		Button:function(param,parent){	
			// text : string
			// image : string
			// x : integer
			// y : integer
			// width : integer
			// height : integer	
			// aLeft : boolean, kotwica lewa 
			// aTop : boolean, kotwica górna
			// aRight : boolean, kotwica prawa
			// aBottom : bolean, kotwica dolna	
			// fontSize : integer	
			// onclick : funkcja
			// borderColor : string
			this.setActivity = function(active){
				this.activity = active;
				if (active==true) this.div.style.color = '#000'; else this.div.style.color = '#888';
			}
			if ((parent != null)&& ((parent.nodeName=='DIV')||((parent.canAddControl)&&(parent.canAddControl('Button')==true)))){
				this.text = param.text;
				param.x==null?this.x=0:this.x = param.x;
				param.y==null?this.y=0:this.y = param.y;
				param.width==null?this.width=50:this.width = param.width;
				param.height==null?this.height=24:this.height = param.height;
				param.aLeft == null?this.aLeft = true:this.aLeft = param.aLeft;
				param.aTop == null?this.aTop = true:this.aTop = param.aTop;
				param.aRight == null?this.aRight = false:this.aRight = param.aRight;
				param.aBottom == null?this.aBottom = false:this.aBottom = param.aBottom;
				param.fontSize == null?this.fontSize = 11:this.fontSize = param.fontSize;	
				param.borderColor == null?this.borderColor = '#999':this.borderColor = param.borderColor;				
				this.image = param.image;
				this.onclick = param.onclick;
			
				var parentSize = BEngine.Controls.getSize(parent);
				var style = BEngine.Controls.calculateDivPosition(parentSize[0],parentSize[1],this.x,this.y,this.width,this.height,this.aLeft,this.aTop,this.aRight,this.aBottom);
				var div = BEngine.Controls.createDiv(style[0],style[1],style[2],style[3],style[4],style[5]);	
				div.align = 'center';
				div.style.backgroundColor = this.borderColor;
				this.div = div;
				var workspaceDiv = BEngine.Controls.createDiv(1,1,1,1,null,null);
				div.appendChild(workspaceDiv);
				
				if (this.image==null){
					workspaceDiv.innerHTML = '<table valign="middle" style="font-size:'+this.fontSize+'px;height:'+(this.height-2)+'px;border-collapse:collapse"><tr><td style="text-align:center">'+this.text+'</td></tr></table>';
				} else {
					if ((this.image!=null)&&(this.text!=null)){
						var inn = '<table valign="middle" style="font-size:'+this.fontSize+'px;height:'+(this.height-2)+'px;border-collapse:collapse"><tr>';
						inn+='<td style="width:'+(this.height-2)+'px;background-repeat:no-repeat;background-position:center center;background-image:url('+this.image+')"></td>';
						inn +='<td style="text-align:center">'+this.text+'</td></tr></table>';
						workspaceDiv.innerHTML = inn;
					} else {
						if (this.image!=null){
							var inn = '<table valign="middle" style="font-size:'+this.fontSize+'px;height:'+(this.height-2)+'px;border-collapse:collapse"><tr>';
							inn+='<td style="width:'+(this.height-2)+'px;background-repeat:no-repeat;background-position:center center;background-image:url('+this.image+')"></td>';
							inn +='</tr></table>';
							workspaceDiv.innerHTML = inn;
						}							
					}
				}
				
				
				
				workspaceDiv.style.backgroundImage = 'url('+BEngine.mainPath+'bengine/images/toolbars/'+(this.height-2)+'.png)';
				BEngine.Controls.disableSelection(workspaceDiv);
				
				if (parent.nodeName=='DIV') {
					parent.appendChild(this.div);
				} else {
					parent.addControl(this);	
				}	
				
								
				var state = 0;
				this.activity = true;
				var obj = this;
				div.onmouseover = function(){
					div.style.backgroundColor =  '#70c2f1';
				}
				div.onmouseout = function(){
					div.style.backgroundColor =  obj.borderColor;
					workspaceDiv.style.backgroundImage = 'url('+BEngine.mainPath+'bengine/images/toolbars/'+(obj.height-2)+'.png)';
					state = 0;
				}	
				div.onmousedown = function(){
					if (obj.activity==true){
						workspaceDiv.style.backgroundImage = 'url('+BEngine.mainPath+'bengine/images/toolbars/'+(obj.height-2)+'p.png)';					
						state = 1;
					}
				}		
				div.onmouseup = function(){
					workspaceDiv.style.backgroundImage = 'url('+BEngine.mainPath+'bengine/images/toolbars/'+(obj.height-2)+'.png)';
					if (state==1){
						if (obj.onclick) obj.onclick();
						state = 0;
					}
				}								
			}
		},		
		CheckButton:function(param,parent){	
			// text : string
			// image : string
			// x : integer
			// y : integer
			// width : integer
			// height : integer	
			// aLeft : boolean, kotwica lewa 
			// aTop : boolean, kotwica górna
			// aRight : boolean, kotwica prawa
			// aBottom : bolean, kotwica dolna	
			// fontSize : integer	
			// onclick : funkcja
			// borderColor : string
			
			this.setActivity = function(active){
				this.activity = active;
				if (active==true) this.div.style.color = '#000'; else this.div.style.color = '#888';
			}
			this.setCheck = function(checked){
				if ((this.group!=null)&&(checked==true)){
					for (var i=0;i<BEngine.Controls.checkGroupButtons.length;i++){
						if (BEngine.Controls.checkGroupButtons[i].group == this.group)
						BEngine.Controls.checkGroupButtons[i].setCheck(false);
					}
				}
			
				this.checked = checked;
				if (checked == true)
				this.workspaceDiv.style.backgroundImage = 'url('+BEngine.mainPath+'bengine/images/toolbars/'+(this.height-2)+'p.png)';
				else
				this.workspaceDiv.style.backgroundImage = 'url('+BEngine.mainPath+'bengine/images/toolbars/'+(this.height-2)+'.png)';
			}
			if ((parent != null)&& ((parent.nodeName=='DIV')||((parent.canAddControl)&&(parent.canAddControl('Button')==true)))){
				this.text = param.text;
				param.x==null?this.x=0:this.x = param.x;
				param.y==null?this.y=0:this.y = param.y;
				param.width==null?this.width=50:this.width = param.width;
				param.height==null?this.height=24:this.height = param.height;
				param.aLeft == null?this.aLeft = true:this.aLeft = param.aLeft;
				param.aTop == null?this.aTop = true:this.aTop = param.aTop;
				param.aRight == null?this.aRight = false:this.aRight = param.aRight;
				param.aBottom == null?this.aBottom = false:this.aBottom = param.aBottom;
				param.fontSize == null?this.fontSize = 11:this.fontSize = param.fontSize;	
				param.borderColor == null?this.borderColor = '#999':this.borderColor = param.borderColor;	
				this.group = param.group;	
				this.image = param.image;
				this.onclick = param.onclick;
			
				var parentSize = BEngine.Controls.getSize(parent);
				var style = BEngine.Controls.calculateDivPosition(parentSize[0],parentSize[1],this.x,this.y,this.width,this.height,this.aLeft,this.aTop,this.aRight,this.aBottom);
				var div = BEngine.Controls.createDiv(style[0],style[1],style[2],style[3],style[4],style[5]);	
				div.align = 'center';
				div.style.backgroundColor = this.borderColor;
				this.div = div;
				var workspaceDiv = BEngine.Controls.createDiv(1,1,1,1,null,null);
				this.workspaceDiv = workspaceDiv;
				div.appendChild(workspaceDiv);
				
				if (this.image==null){
					workspaceDiv.innerHTML = '<table valign="middle" style="font-size:'+this.fontSize+'px;height:'+(this.height-2)+'px;border-collapse:collapse"><tr><td style="text-align:center">'+this.text+'</td></tr></table>';
				} else {
					if ((this.image!=null)&&(this.text!=null)){
						var inn = '<table valign="middle" style="font-size:'+this.fontSize+'px;height:'+(this.height-2)+'px;border-collapse:collapse"><tr>';
						inn+='<td style="width:'+(this.height-2)+'px;background-repeat:no-repeat;background-position:center center;background-image:url('+this.image+')"></td>';
						inn +='<td style="text-align:center">'+this.text+'</td></tr></table>';
						workspaceDiv.innerHTML = inn;
					} else {
						if (this.image!=null){
							var inn = '<table valign="middle" style="font-size:'+this.fontSize+'px;height:'+(this.height-2)+'px;border-collapse:collapse"><tr>';
							inn+='<td style="width:'+(this.height-2)+'px;background-repeat:no-repeat;background-position:center center;background-image:url('+this.image+')"></td>';
							inn +='</tr></table>';
							workspaceDiv.innerHTML = inn;
						}							
					}
				}
				
				workspaceDiv.style.backgroundImage = 'url('+BEngine.mainPath+'bengine/images/toolbars/'+(this.height-2)+'.png)';
				BEngine.Controls.disableSelection(workspaceDiv);
				
				if (parent.nodeName=='DIV') {
					parent.appendChild(this.div);
				} else {
					parent.addControl(this);	
				}	
				
								
				var state = 0;
				this.activity = true;				
				this.checked = false;
				var obj = this;
				div.onmouseover = function(){
					div.style.backgroundColor =  '#70c2f1';
				}
				div.onmouseout = function(){
					div.style.backgroundColor =  obj.borderColor;
					if (obj.checked==false)
					workspaceDiv.style.backgroundImage = 'url('+BEngine.mainPath+'bengine/images/toolbars/'+(obj.height-2)+'.png)';
					state = 0;
				}	
				div.onmousedown = function(){
					if (obj.activity==true){
						workspaceDiv.style.backgroundImage = 'url('+BEngine.mainPath+'bengine/images/toolbars/'+(obj.height-2)+'p.png)';					
						state = 1;
					}
				}		
				div.onmouseup = function(){
					workspaceDiv.style.backgroundImage = 'url('+BEngine.mainPath+'bengine/images/toolbars/'+(obj.height-2)+'.png)';
					if (state==1){
						if (obj.checked==true) obj.setCheck(false); else obj.setCheck(true);
						if (obj.onclick) obj.onclick(obj.checked);
						state = 0;
					}
				}		
				
			}
		},		
		ToolbarButton:function(param,parent){	
			this.setActivity = function(active){
				this.activity = active;
				if (active==true) this.div.style.color = '#000'; else this.div.style.color = '#888';
			}
			if ((param!=null)&&(parent!=null)){
				this.text = param.text;
				this.width = param.width;
				this.image = param.image;
				this.onclick = param.onclick;
				param.tip == null?this.tip = "":this.tip = param.tip;	
			
				if (this.image==null){	
					if (this.width==null) this.width = 20+(this.text.length*7);
				} else {
					if ((this.image!=null)&&(this.text!=null)){
						if (this.width==null) this.width = (parent.height-2)+10+(this.text.length*7);
					} else {
						if (this.image!=null){
							if (this.width==null) this.width = (parent.height-2);
						}
					}
				}
				
				var div = BEngine.Controls.createDiv(parent.offset+1,1,null,1,this.width,null);
				div.align = 'center';
				this.div = div;
				
				if (this.image==null){
					div.innerHTML = '<table valign="middle" style="padding:0px;margin:0px;font-size:'+parent.fontSize+'px;height:'+(parent.height-2)+'px;border-collapse:collapse"><tr><td style="text-align:center" valign="middle">'+this.text+'</td></tr></table>';
				} else {
					if ((this.image!=null)&&(this.text!=null)){
						var inn = '<table valign="middle" style="padding:0px;margin:0px;font-size:'+parent.fontSize+'px;height:'+(parent.height-2)+'px;border-collapse:collapse"><tr>';
						inn+='<td valign="middle" style="width:'+(parent.height-2)+'px;background-repeat:no-repeat;background-position:center center;background-image:url('+this.image+')"></td>';
						inn +='<td valign="middle" style="text-align:center">'+this.text+'</td></tr></table>';
						div.innerHTML = inn;
					} else {
						if (this.image!=null){
							var inn = '<table style="padding:0px;margin:0px;font-size:'+parent.fontSize+'px;height:'+(parent.height-2)+'px;border-collapse:collapse"><tr>';
							inn+='<td valign="middle" style="width:'+(parent.height-2)+'px;background-repeat:no-repeat;background-position:center center;background-image:url('+this.image+')"></td>';
							inn +='</tr></table>';
							div.innerHTML = inn;
						}							
					}
				}
				
				div.offset = parent.offset;
				parent.childControls.push(this);					
				parent.offset+=this.width+1;
				parent.div.appendChild(div);					
				div.style.backgroundImage = 'url('+BEngine.mainPath+'bengine/images/toolbars/'+(parent.height-2)+'.png)';
				
				var buttonsWidth = 1;
				for (var i=0;i<parent.childControls.length;i++){
					buttonsWidth+=parent.childControls[i].width+1;
				}	
				
				if (parent.fullWeight==false){
					parent.width = buttonsWidth;
					var parentSize = BEngine.Controls.getSize(parent.parent);
					var style = BEngine.Controls.calculateDivPosition(parentSize[0],parentSize[1],parent.x,parent.y,parent.width,parent.height,parent.aLeft,parent.aTop,parent.aRight,parent.aBottom);
					BEngine.Controls.modifyDiv(parent.div,style[0],style[1],style[2],style[3],style[4],style[5]);						
				}
				
				parent.workspaceDiv.style.left = buttonsWidth+'px';
				
								
				var state = 0;
				this.activity = true;
				var obj = this;
				div.onmouseover = function(e){
					parent.lightDiv.style.display = 'block';
					parent.lightDiv.style.width = (this.clientWidth+2)+'px';
					parent.lightDiv.style.left = (this.offset)+'px';
					
					var pos = BEngine.Controls.mouseCoordinates(e);
					if ((obj.tip!=null)&&(obj.tip!='')) tooltip.show(obj.tip,pos[0]+4,pos[1]+4); 
				}
				div.onmouseout = function(e){
					parent.lightDiv.style.display = 'none';
					this.style.backgroundImage = 'url('+BEngine.mainPath+'bengine/images/toolbars/'+(parent.height-2)+'.png)';
					state = 0;
					if ((obj.tip!=null)&&(obj.tip!='')) tooltip.hide();
				}	
				div.onmousedown = function(){
					if (obj.activity==true){
						this.style.backgroundImage = 'url('+BEngine.mainPath+'bengine/images/toolbars/'+(parent.height-2)+'p.png)';					
						state = 1;
					}
				}		
				div.onmouseup = function(){
					this.style.backgroundImage = 'url('+BEngine.mainPath+'bengine/images/toolbars/'+(parent.height-2)+'.png)';
					if (state==1){
						if (obj.onclick) obj.onclick();
						state = 0;
					}
				}								
			}
		},	
		ToolbarCheckButton:function(param,parent){	
			this.setCheck = function(checked){
				if ((this.group!=null)&&(checked==true)){
					for (var i=0;i<BEngine.Controls.checkGroupButtons.length;i++){
						if (BEngine.Controls.checkGroupButtons[i].group == this.group)
						BEngine.Controls.checkGroupButtons[i].setCheck(false);
					}
				}
			
				this.checked = checked;
				if (checked == true)
				this.div.style.backgroundImage = 'url('+BEngine.mainPath+'bengine/images/toolbars/'+(this.height)+'p.png)';
				else
				this.div.style.backgroundImage = 'url('+BEngine.mainPath+'bengine/images/toolbars/'+(this.height)+'.png)';
			}
			this.setActivity = function(active){
				this.activity = active;
				if (active==true) this.div.style.color = '#000'; else this.div.style.color = '#888';
			}
			if ((param!=null)&&(parent!=null)){
				this.text = param.text;
				this.width = param.width;
				this.image = param.image;
				this.group = param.group;
				this.onclick = param.onclick;
				param.tip == null?this.tip = "":this.tip = param.tip;	
				
				this.height = parent.height-2;
				
							
				if (this.image==null){	
					if (this.width==null) this.width = 20+(this.text.length*7);
				} else {
					if ((this.image!=null)&&(this.text!=null)){
						if (this.width==null) this.width = (this.height)+10+(this.text.length*7);
					} else {
						if (this.image!=null){
							if (this.width==null) this.width = (this.height);
						}
					}
				}
				
				var div = BEngine.Controls.createDiv(parent.offset+1,1,null,1,this.width,null);
				div.align = 'center';
				this.div = div;
				if (this.group!=null) BEngine.Controls.checkGroupButtons.push(this);
				
				if (this.image==null){
					div.innerHTML = '<table valign="middle" style="padding:0px;margin:0px;font-size:'+parent.fontSize+'px;height:'+(parent.height-2)+'px;border-collapse:collapse"><tr><td style="text-align:center" valign="middle">'+this.text+'</td></tr></table>';
				} else {
					if ((this.image!=null)&&(this.text!=null)){
						var inn = '<table valign="middle" style="padding:0px;margin:0px;font-size:'+parent.fontSize+'px;height:'+(parent.height-2)+'px;border-collapse:collapse"><tr>';
						inn+='<td valign="middle" style="width:'+(parent.height-2)+'px;background-repeat:no-repeat;background-position:center center;background-image:url('+this.image+')"></td>';
						inn +='<td valign="middle" style="text-align:center">'+this.text+'</td></tr></table>';
						div.innerHTML = inn;
					} else {
						if (this.image!=null){
							var inn = '<table style="padding:0px;margin:0px;font-size:'+parent.fontSize+'px;height:'+(parent.height-2)+'px;border-collapse:collapse"><tr>';
							inn+='<td valign="middle" style="width:'+(parent.height-2)+'px;background-repeat:no-repeat;background-position:center center;background-image:url('+this.image+')"></td>';
							inn +='</tr></table>';
							div.innerHTML = inn;
						}							
					}
				}
				
				div.offset = parent.offset;
				parent.childControls.push(this);					
				parent.offset+=this.width+1;
				parent.div.appendChild(div);					
				div.style.backgroundImage = 'url('+BEngine.mainPath+'bengine/images/toolbars/'+(this.height)+'.png)';
				div.style.backgroundRepeat = 'repeat-x';
				
				var buttonsWidth = 1;
				for (var i=0;i<parent.childControls.length;i++){
					buttonsWidth+=parent.childControls[i].width+1;
				}	
				
				if (parent.fullWeight==false){
					parent.width = buttonsWidth;
					var parentSize = BEngine.Controls.getSize(parent.parent);
					var style = BEngine.Controls.calculateDivPosition(parentSize[0],parentSize[1],parent.x,parent.y,parent.width,parent.height,parent.aLeft,parent.aTop,parent.aRight,parent.aBottom);
					BEngine.Controls.modifyDiv(parent.div,style[0],style[1],style[2],style[3],style[4],style[5]);						
				}
				
				parent.workspaceDiv.style.left = buttonsWidth+'px';
				
								
				var state = 0;
				this.checked = false;
				this.activity = true;
				var obj = this;
				div.onmouseover = function(e){
					parent.lightDiv.style.display = 'block';
					parent.lightDiv.style.width = (this.clientWidth+2)+'px';
					parent.lightDiv.style.left = (this.offset)+'px';
					
					var pos = BEngine.Controls.mouseCoordinates(e);
					if ((obj.tip!=null)&&(obj.tip!='')) tooltip.show(obj.tip,pos[0]+4,pos[1]+4); 
				}	
				div.onmouseout = function(e){
					parent.lightDiv.style.display = 'none';
					if (obj.checked==false)
					this.style.backgroundImage = 'url('+BEngine.mainPath+'bengine/images/toolbars/'+(parent.height-2)+'.png)';
					state = 0;
					if ((obj.tip!=null)&&(obj.tip!='')) tooltip.hide();
				}	
				div.onmousedown = function(){
					if (obj.activity==true){
						this.style.backgroundImage = 'url('+BEngine.mainPath+'bengine/images/toolbars/'+(parent.height-2)+'p.png)';
						state = 1;
					}
				}		
				div.onmouseup = function(){
					this.style.backgroundImage = 'url('+BEngine.mainPath+'bengine/images/toolbars/'+(parent.height-2)+'.png)';
					if (state==1){
						if (obj.checked==true) obj.setCheck(false); else obj.setCheck(true);
						if (obj.onclick) obj.onclick(obj.checked);
						state = 0;
					}
				}								
			}
		},		
		Toolbar:function(param,parent){
			// param:
			// x : integer
			// y : integer
			// fullWeight : bool, czy toolbar zajmuej cala szerokosc czy sie dostosowuje podlog przyciskow
			// height : integer, dostepne 32, 30, 28, 26, 24, 22, 20
			// aLeft : boolean, kotwica lewa 
			// aTop : boolean, kotwica górna
			// aRight : boolean, kotwica prawa
			// aBottom : bolean, kotwica dolna
			// visible : boolean czy toolbar widoczny
			// fontSize : integer, wielkosc czcionki
			this.setPosition = function(x,y){
				this.div.style.left = x+'px';
				this.div.style.top = y+'px';
			},
			this.getWorkspaceSize = function(){
				return [this.div.clientWidth,this.div.clientHeight];
			}
			this.getWorkspaceDiv = function(){
				return this.div;
			}
			this.show = function(){
				this.div.style.display = 'block';
				this.visible = true;
			}
			this.hide = function(){
				this.div.style.display = 'none';
				this.visible = false;
			}			
			this.getSize = function(){
				return [this.div.clientWidth,this.div.clientHeight];
			}
			this.showBarrier =  function(onclick){
				var obj = this;
				BEngine.Interface.Barrier.show(this.div,function(){
					if (onclick) onclick();
				});
			}
			this.hideBarrier =  function(){
				BEngine.Interface.Barrier.hide();
			}				
			if (param!=null){
				if ((parent != null)&& ((parent.nodeName=='DIV')||((parent.canAddControl)&&(parent.canAddControl('Toolbar')==true)))){
					param.x == null?this.x = 0:this.x = param.x;
					param.y == null?this.y = 0:this.y = param.y;
					param.fullWeight == null?this.fullWeight = true:this.fullWeight = param.fullWeight;
					
					this.width = 2;
					if (this.fullWeight == true){
						var parentWidth = 0;
						if (parent.nodeName=='DIV') parentWidth = parent.clientWidth-this.x; else parentWidth = parent.getWorkspaceSize()[0]-this.x;					
						this.width = parentWidth;
						param.aRight = true;
					}
					
					param.height == null?this.height = 26:this.height = param.height;
					param.aLeft == null?this.aLeft = true:this.aLeft = param.aLeft;
					param.aTop == null?this.aTop = true:this.aTop = param.aTop;
					param.aRight == null?this.aRight = false:this.aRight = param.aRight;
					param.aBottom == null?this.aBottom = false:this.aBottom = param.aBottom;
					param.fontSize == null?this.fontSize = 11:this.fontSize = param.fontSize;
					
					this.parent = parent;
					
					this.visible = true;
					this.childControls = new Array();
					
					
					var parentSize = BEngine.Controls.getSize(parent);
					var style = BEngine.Controls.calculateDivPosition(parentSize[0],parentSize[1],this.x,this.y,this.width,this.height,this.aLeft,this.aTop,this.aRight,this.aBottom);
					this.div = BEngine.Controls.createDiv(style[0],style[1],style[2],style[3],style[4],style[5]);	

					this.div.style.backgroundColor = '#999';	
					BEngine.Controls.disableSelection(this.div);
					
					if (parent.nodeName=='DIV') {
						parent.appendChild(this.div);
					} else {
						parent.addControl(this);
					}																
					BEngine.Controls.cancelStandardEvents(this.div);		

					if (param.visible!=null){
						if (param.visible == false) this.hide();
					}		

					this.workspaceDiv = BEngine.Controls.createDiv(1,1,1,1,null,null);
					this.workspaceDiv.style.backgroundImage = 'url('+BEngine.mainPath+'bengine/images/toolbars/'+(this.height-2)+'.png)';
					this.div.appendChild(this.workspaceDiv);
					this.lightDiv = BEngine.Controls.createDiv(0,0,null,null,10,this.height);
					this.div.appendChild(this.lightDiv);
					this.lightDiv.style.backgroundColor = '#70c2f1';
					this.lightDiv.style.display = 'none';
					this.offset = 0;

				}
			}			
		},
		ComboBox:function(param,parent){
			// param:
			// x : integer
			// y : integer
			// width : integer
			// height : integer
			// aLeft : boolean, kotwica lewa 
			// aTop : boolean, kotwica górna
			// aRight : boolean, kotwica prawa
			// aBottom : bolean, kotwica dolna
			// visible : boolean czy kontrolka jest widoczna
			// fontSize : integer
			this.removeAll = function(){
				this.select.length = 0;
			}	
			this.addItem = function(name,value){
				this.select.options[this.select.options.length] = new Option(name,value);
				this.select.options[this.select.options.length-1].data = value;
				return this.select.options[this.select.options.length-1];
			}
			this.getSelectedItem = function(){
				if (this.selectedItem)
				return this.selectedItem;
				else
				return this.select[this.select.selectedIndex];
			}		
			this.selectItem = function(name){
				for (var i=0;i<this.select.length;i++){
					if (this.select.options[i].text == name) {
						this.select.options[i].selected = true;
						this.selectedItem =this.select.options[i];
						return;
					} 	
				}
			}
			this.selectItemByValue = function(value){
				for (var i=0;i<this.select.length;i++){
					if (this.select.options[i].data == value) {
						this.select.options[i].selected = true;
						this.selectedItem =this.select.options[i];
						return;
					} 	
				}
			}		
			this.selectItemByName = function(name){
				for (var i=0;i<this.select.length;i++){
					if (this.select.options[i].text== name) {
						this.select.options[i].selected = true;
						this.selectedItem =this.select.options[i];
						return;
					} 	
				}
			}			
			this.selectItemByIndex = function(index){
				this.select.selectedIndex = index;
				this.selectedItem =this.select.options[index];

			}	
			this.getLength = function(){
				return this.select.options.length;
			}
			this.getItemByIndex = function(index){
				return this.select.options[index];
			}				
			this.setPosition = function(x,y){
				this.div.style.left = x+'px';
				this.div.style.top = y+'px';
			},
			this.getWorkspaceSize = function(){
				return [this.div.clientWidth,this.div.clientHeight];
			}
			this.getWorkspaceWidth = function(){
				return this.getWorkspaceSize()[0];
			},
			this.getWorkspaceHeight = function(){
				return this.getWorkspaceSize()[1];
			},			
			this.getWorkspaceDiv = function(){
				return this.div;
			}
			this.show = function(){
				this.div.style.display = 'block';
				this.visible = true;
			}
			this.hide = function(){
				this.div.style.display = 'none';
				this.visible = false;
			}			
			this.getSize = function(){
				return [this.div.clientWidth,this.div.clientHeight];
			}
			this.addEvent = function(event,fun){
				if (event == 'click') this.onclick = fun;
				if (event == 'change') this.onchange = fun;
			}			
			this.setMinimalSize = function(width,height){
				this.div.style.minWidth = width+"px";
				this.div.style.minHeight = height+"px";
			}
			if (param!=null){
				if ((parent != null)&& ((parent.nodeName=='DIV')||((parent.canAddControl)&&(parent.canAddControl('ComboBox')==true)))){
					param.x == null?this.x = 0:this.x = param.x;
					param.y == null?this.y = 0:this.y = param.y;
					param.width == null?this.width = 100:this.width = param.width;
					param.height == null?this.height = 20:this.height = param.height;
					param.aLeft == null?this.aLeft = true:this.aLeft = param.aLeft;
					param.aTop == null?this.aTop = true:this.aTop = param.aTop;
					param.aRight == null?this.aRight = false:this.aRight = param.aRight;
					param.aBottom == null?this.aBottom = false:this.aBottom = param.aBottom;
					param.fontSize == null?this.fontSize = 11:this.fontSize = param.fontSize;
					
					this.visible = true;
					
					var parentSize = BEngine.Controls.getSize(parent);

					var style = BEngine.Controls.calculateDivPosition(parentSize[0],parentSize[1],this.x,this.y,this.width,this.height,this.aLeft,this.aTop,this.aRight,this.aBottom);
					this.div = BEngine.Controls.createDiv(style[0],style[1],style[2],style[3],style[4],style[5]);	
							
					if (parent.nodeName=='DIV') {
						parent.appendChild(this.div);
					} else {
						parent.addControl(this);
					}											
				
					if (param.visible!=null){
						if (param.visible == false) this.hide();
					}		

					this.select = document.createElement('select');
					this.select.style.fontSize = this.fontSize+'px';
					this.select.style.height = this.height+'px';
					//this.select.style.margin = '0px';
					this.select.style.margin = '0px';
					this.select.style.padding = '1px';
					this.select.style.width = '100%';
					var obj = this;
					this.select.onchange = function(){ 
						obj.selectedItem = obj.select.options[obj.select.selectedIndex];
						if (obj.onchange) obj.onchange();
					}
					this.select.onclick = function(){ 
						if (obj.onclick) obj.onclick();
					}			
					this.div.appendChild(this.select);		
				}
			}
		},
		SimpleComboBox:function(items,parent){
			this.removeAll = function(){
				this.select.options.length = 0;
			}
			this.addItem = function(value,text){
				var option = new Option(text,value);
				this.select.options[this.select.options.length] = option;
				return option;
			}
			this.getValue = function(){
				return this.select.value;
			}
			this.getItem = function(){
				return this.select.options[this.select.selectedIndex];
			}
			if (parent!=null){
				this.select = document.createElement('select');
				parent.appendChild(this.select);
				this.select.style.fontSize = '11px';
				for (var i=0;i<items.length;i++){
					this.addItem(items[i][0],items[i][1]);
				}
				var obj = this;
				this.select.onchange = function(){
					if (obj.onchange) obj.onchange(this.value);
				}
			}
		},
		TableFrame:function(numCol,numRow,parent){
			this.cell = function(col,row){
				return this.cells[row][col];
			}
			if ((parent!=null)&&(numCol>0)&&(numRow>0)){
				this.table = document.createElement('table');
				this.table.style.padding = '0px';				
				this.table.style.margin = '0px';
				this.table.style.borderCollapse = 'collapse';
				
				this.cells = new Array();
								
				parent.appendChild(this.table);
				var tbody = document.createElement('tbody');
				this.table.appendChild(tbody);
				
				for (var i=0;i<numRow;i++){
					var tr = document.createElement('tr');
					tbody.appendChild(tr);
					var row = new Array();
					for (var j=0;j<numCol;j++){
						var td = document.createElement('td');
						td.style.padding = "1px 2px 1px 2px";
						tr.appendChild(td);		
						row.push(td);	
					}
					this.cells.push(row);
				}
			}
		},
		SimpleButton:function(text,parent){
			this.button = document.createElement('input');
			this.button.type = 'button';
			this.button.value = text;
			this.button.style.fontSize = '11px';
			parent.appendChild(this.button);
			var obj = this;
			this.button.onclick = function(){
				if (obj.onclick) obj.onclick();
			}
		},
		TreeView:function(param,parent){
			// param:
			// x : integer
			// y : integer
			// width : integer
			// height : integer
			// aLeft : boolean, kotwica lewa 
			// aTop : boolean, kotwica górna
			// aRight : boolean, kotwica prawa
			// aBottom : bolean, kotwica dolna
			// backColor : string, kolor tla
			// borderColor : string, kolor tla
			// visible : boolean czy panel widoczny
			// check : boolean
			this.unselectItems = function(){
				this.selectedItem = null;
				for (var i=0;i<this.items.length;i++){
					this.items[i].mainTextDiv.style.backgroundColor = '#fff';
					this.items[i].unselectItems();
				}
			}
			this.addItem = function(item,position){
				var tree = this;
				this.hasChildren = true;
				item.parent = this;
				item.tree = this;
				item.level = 0;
				this.items.push(item);
				item.mainDiv = document.createElement('div');
				item.mainDiv.style.position = 'relative';			
				this.workspaceDiv.appendChild(item.mainDiv);
				
				var textDiv = document.createElement('div');
				//textDiv.style.backgroundColor = '#f00';
				
				item.mainDiv.appendChild(textDiv); 

				item.contentDiv = document.createElement('div');
				item.contentDiv.style.position = 'relative';
				
				item.mainDiv.appendChild(item.contentDiv); 
				
				var table = document.createElement('table');
				table.style.padding = '1px';
				table.style.fontSize = '11px';
				table.style.borderCollapse= 'collapse';
				textDiv.appendChild(table);
				item.table = table;		
				
				var tBody = document.createElement('tbody');
				table.appendChild(tBody);
					
				var tr = document.createElement('tr');
				tBody.appendChild(tr);
					
		
				var td = document.createElement('td');
				td.style.width = '0px';
				item.plusTd = td;
				tr.appendChild(td);
				td.onclick = function(){
					if (item.hasChildren == true){
						if (item.extended == true) item.collapse(); else item.extend();
						if (item.onextend) item.onextend( item.extended);
					}
				}	
				if (item.check == true){
					var td = document.createElement('td');
					td.style.width = '10px';
					tr.appendChild(td);	
					item.checkbox = document.createElement('input');
					item.checkbox.type = 'checkbox';	
					td.appendChild(item.checkbox);
					item.checkbox.checked = item.checked;
					item.checkbox.onclick = function(){
						item.checked = item.checkbox.checked;
						if (item.oncheck) item.oncheck(item.checked);
					}	
				}
				
				var w=null;
				if (item.widths!=null){
					w = item.widths.split(',');			
				}	
				var a=null;
				if (item.aligns!=null){
					a = item.aligns.split(',');			
				}	
				
				BEngine.Controls.cancelMouseUp(item.mainDiv);
				function setSelection(div,item){
					
					div.onmousedown = function(){
						obj.downSelectedItem = item;			
					}			
					div.onmouseout = function(){
						if (obj.downSelectedItem == item){
							//item.mainDiv.style.display = 'none';
							obj.unselectItems(); 
							div.style.backgroundColor = '#9eceff';	
							obj.selectedItem = item;
							if (obj.canmove==true){
								obj.dragged = item;
								if (obj.onstartchangeposition) {
									obj.onstartchangeposition();
								}
							}	
						}
						item.mainDiv.style.borderTop = 'none';
					}
					div.onmouseup = function(e){
						var but = 0;
						if (BEngine.Controls.isRightButtonPressed(e)==true) but = 1;
					
						if (obj.downSelectedItem == item){
							obj.unselectItems(); 
							div.style.backgroundColor = '#9eceff';	
							if (tree.onselect) tree.onselect(item,but);
							obj.selectedItem = item;
							obj.dragged = null;
						} else
						if (obj.dragged!=null){
							if (obj.onendchangeposition) {
								var drg = obj.dragged;
								obj.dragged = null;		
								
								obj.onendchangeposition(function(ok){	
									if (ok==true){
										obj.workspaceDiv.insertBefore(drg.mainDiv,item.mainDiv);
										if (obj.onchangeposition) obj.onchangeposition(drg,item);					
									} 	
								});
							} else {
								var drg = obj.dragged;
								obj.dragged = null;								
								obj.workspaceDiv.insertBefore(drg.mainDiv,item.mainDiv);
								if (obj.onchangeposition) obj.onchangeposition(drg,item);
							}
						}
						obj.downSelectedItem = 	null;	
						
						var pos = BEngine.Controls.mouseCoordinates(e,obj.workspaceDiv);	
						if (obj.onmouseup) obj.onmouseup(but,pos[0],pos[1]);	
					}		
					div.onmousemove = function(){
						if (obj.dragged!=null){
							item.mainDiv.style.borderTop = '2px solid #bcf';
						}		
					}					
				}
				
				for (var i = 0;	i<item.cells.length;i++){			
					var td = document.createElement('td');
					td.style.padding = '1px';
					if ((w!=null)&&(w[i])) td.style.width = w[i];
					if ((a!=null)&&(a[i])) td.style.textAlign = a[i]; else td.style.textAlign = 'left';
					tr.appendChild(td);
					if (i==item.textIndex){
						var div = document.createElement("div");
						div.style.display = 'inline';
						div.style.padding = '1px 2px 1px 2px';
						div.innerHTML = item.cells[i];
						td.appendChild(div);
						item.mainTextDiv = div;
						setSelection(div,item);
					} else td.innerHTML = item.cells[i];
					item.tds.push(td);
				}
				
				if ((item.extended == false)){
					item.contentDiv.style.display = 'none';					
				}	
				item.checkParentItems();
				return item;
			}
			this.removeAll = function(){
				this.items.length = 0;
				this.workspaceDiv.innerHTML = '';
				this.selectedItem = null;
			}
			this.getCheckedItems = function(){
				var tab = new Array();
				for (var i=0;i<this.items.length;i++){
					if (this.items[i].checked) tab.push(this.items[i]);
				}
				return tab;		
			}
			this.setPosition = function(x,y){
				this.div.style.left = x+'px';
				this.div.style.top = y+'px';
			},
			this.getWorkspaceSize = function(){
				return [this.workspaceDiv.clientWidth,this.workspaceDiv.clientHeight];
			}
			this.getWorkspaceWidth = function(){
				return this.getWorkspaceSize()[0];
			},
			this.getWorkspaceHeight = function(){
				return this.getWorkspaceSize()[1];
			},			
			this.getWorkspaceDiv = function(){
				return this.workspaceDiv;
			}
			this.show = function(){
				this.div.style.display = 'block';
				this.visible = true;
			}
			this.hide = function(){
				this.div.style.display = 'none';
				this.visible = false;
			}			
			this.getSize = function(){
				return [this.div.clientWidth,this.div.clientHeight];
			}				
			this.setMinimalSize = function(width,height){
				this.div.style.minWidth = width+"px";
				this.div.style.minHeight = height+"px";
			}
			if (param!=null){
				if ((parent != null)&& ((parent.nodeName=='DIV')||((parent.canAddControl)&&(parent.canAddControl('TreeView')==true)))){
					this.items = new Array();
					this.dragged = null;
					this.selectdItem = null;
					this.parent = parent;
					
					param.x == null?this.x = 0:this.x = param.x;
					param.y == null?this.y = 0:this.y = param.y;
					param.width == null?this.width = 100:this.width = param.width;
					param.height == null?this.height = 100:this.height = param.height;
					param.aLeft == null?this.aLeft = true:this.aLeft = param.aLeft;
					param.aTop == null?this.aTop = true:this.aTop = param.aTop;
					param.aRight == null?this.aRight = false:this.aRight = param.aRight;
					param.aBottom == null?this.aBottom = false:this.aBottom = param.aBottom;
					param.backColor == null?this.backColor = '#fff':this.backColor = param.backColor;
					param.borderColor == null?this.borderColor = '#999':this.borderColor = param.borderColor;
					
					if (param.check!=null) this.check = param.check; else this.check = true;	
					if (param.canmove!=null) this.canmove = param.canmove; else this.canmove = false;	
					
					this.visible = true;
					
					var parentSize = BEngine.Controls.getSize(parent);
					var style = BEngine.Controls.calculateDivPosition(parentSize[0],parentSize[1],this.x,this.y,this.width,this.height,this.aLeft,this.aTop,this.aRight,this.aBottom);
					this.div = BEngine.Controls.createDiv(style[0],style[1],style[2],style[3],style[4],style[5]);	
						
					this.div.style.backgroundColor = this.borderColor;	
					
					if (parent.nodeName=='DIV') {
						parent.appendChild(this.div);
					} else {
						parent.addControl(this);
					}																	
					BEngine.Controls.cancelStandardEvents(this.div);		
					
					this.workspaceDiv = BEngine.Controls.createDiv(1,1,1,1,null,null);
					this.div.appendChild(this.workspaceDiv);
					this.workspaceDiv.style.backgroundColor = this.backColor;	
					this.workspaceDiv.style.overflow = 'auto';
					
					var obj = this;
					this.workspaceDiv.onmouseup = function(e){
						obj.unselectItems();
						var but = 0;
						if (BEngine.Controls.isRightButtonPressed(e)==true) but = 1;
						var pos = BEngine.Controls.mouseCoordinates(e,obj.workspaceDiv);	
						if (obj.onmouseup) obj.onmouseup(but,pos[0],pos[1]);	
					};
					BEngine.Controls.disableContextMenu(this.div);
					BEngine.Controls.disableContextMenu(this.workspaceDiv);
				
					if (param.visible!=null){
						if (param.visible == false) this.hide();
					}					
				}
			}			
		},		
		TreeViewItem:function(param){
			//cells ['adas','asdad']
			//widths  '10px,23px' lub '10%,90%'
			//aligns 'left,right',..
			//check
			//oncheck
			//extended (true/false)
			//textIndex	
			//optionsEnable
			var obj = this;
			this.checked = param.checked;
			this.cells = param.cells;
			this.aligns = param.aligns;
			this.oncheck = param.oncheck;
			this.parent = null;
			this.tds = new Array();
			this.mainDiv = null;
			this.level = null;
			this.tree = null;
			this.items = new Array();
			this.hasChildren = false;
			this.widths = param.widths;
			this.aligns = param.aligns;
			this.data = null;
			this.optionsEnable = false;

			if (param.optionsEnable !=null)
				this.optionsEnable = param.optionsEnable;
			else	
				this.optionsEnable = false;
			
			if (param.check !=null)
				this.check = param.check;
			else	
				this.check = true;
				
			if (param.checked !=null)
				this.checkd = param.checked;
			else	
				this.checked = false;
				
			if (param.extended !=null)
				this.extended = param.extended;
			else	
				this.extended = true;
				
			if (param.showChildrenItem !=null)
				this.showChildrenItem = param.showChildrenItem;
			else	
				this.showChildrenItem = true;	
					
			if (param.textIndex != null)
				this.textIndex = param.textIndex;
			else
				this.textIndex = 0;
				
			this.unselectItems = function(){
				if (this.items.length>0){
					for (var i=0;i<this.items.length;i++){
						this.items[i].mainTextDiv.style.backgroundColor = '#fff';
						this.items[i].unselectItems();
					}
				}
			}	
			this.addItem = function(item,position){
				var tree =  this.tree;
				if (this.parent!=null){
					this.hasChildren = true;
					item.parent = this;
					item.tree = this.tree;
					item.level = this.level+1;
					this.items.push(item);
					
					item.mainDiv = document.createElement('div');
					item.mainDiv.style.paddingLeft = '16px';
				
					this.contentDiv.appendChild(item.mainDiv);
				
					var textDiv = document.createElement('div');
					textDiv.style.position = 'relative';
					item.mainDiv.appendChild(textDiv); 


					var opcDiv = BEngine.Controls.createDiv(null,2,0,null,16,16);
					opcDiv.style.backgroundImage = 'url(skrypty/bengine/images/more.png)';
					opcDiv.style.display = 'none';
					opcDiv.style.cursor = 'pointer';
					textDiv.appendChild(opcDiv);
					
				
					textDiv.opcDiv = opcDiv;
					textDiv.onmouseover = function(){
						if (item.dane)
						this.opcDiv.style.display = 'block';
						this.style.backgroundColor = '#fafafa';
					}					
					textDiv.onmouseout = function(){
						this.opcDiv.style.display = 'none';
						this.style.backgroundColor = 'transparent';
					}					
					opcDiv.onclick = function(){
						if (item.menu) {
							item.menu.dane = item.dane;
								var off = 0;
							if (BEngine.Utils.isIE()==true) off = -16;	
							item.menu.show(this,off,0);							
						}	
					}
					
					item.contentDiv = document.createElement('div');
					item.mainDiv.appendChild(item.contentDiv); 
				
					var table = document.createElement('table');	
					table.style.padding = '0px';
					table.style.fontSize = '11px';
					table.style.borderCollapse= 'collapse';
					textDiv.appendChild(table);
					item.table = table;
						
					var tBody = document.createElement('tbody');
					table.appendChild(tBody);
					var tr = document.createElement('tr');
					tBody.appendChild(tr);
					
					
					var td = document.createElement('td');
					td.style.width = '0px';
					tr.appendChild(td);
					item.plusTd = td;
					
					td.onclick = function(){
						if (item.hasChildren == true){
							if (item.extended == true) item.collapse(); else item.extend();
							if (item.onextend) item.onextend(item.extended);			
						}
					}
					
					if (item.check == true){
						var td = document.createElement('td');
						td.style.width = '10px';
						tr.appendChild(td);	
						item.checkbox = document.createElement('input');
						item.checkbox.type = 'checkbox';						
						td.appendChild(item.checkbox);
						item.checkbox.checked = item.checked;
						item.checkbox.onclick = function(){
							item.checked = item.checkbox.checked;
							if (item.oncheck) item.oncheck(item.checked);
						}	
					}
					
					var w=null;
					if (item.widths!=null){
						w = item.widths.split(',');			
					}	
					var a=null;
					if (item.aligns!=null){
						a = item.aligns.split(',');			
					}	
				
					BEngine.Controls.cancelMouseUp(item.mainDiv);
					function setSelection(div,item){
						div.onmousedown = function(){
							obj.tree.downSelectedItem = item;			
						}			
						div.onmouseup = function(e){
							var but = 0;
							if (BEngine.Controls.isRightButtonPressed(e)==true) but = 1;
							
							if (obj.tree.downSelectedItem == item){
								obj.tree.unselectItems(); 
								div.style.backgroundColor = '#9eceff';	
								if (tree.onselect) tree.onselect(item,but);
								obj.tree.selectedItem = item;
							}	
							var but = 0;
							if (BEngine.Controls.isRightButtonPressed(e)==true) but = 1;
							var pos = BEngine.Controls.mouseCoordinates(e,obj.tree.workspaceDiv);	
							if (obj.tree.onmouseup) obj.tree.onmouseup(but,pos[0],pos[1]);		
						}				
					}
					
					for (var i = 0;	i<item.cells.length;i++){			
						var td = document.createElement('td');
						td.style.padding = '1px';
						if ((w!=null)&&(w[i])) td.style.width = w[i];
						if ((a!=null)&&(a[i])) td.style.textAlign = a[i]; else td.style.textAlign = 'left';
						tr.appendChild(td);
						if (i==item.textIndex){
							var div = document.createElement("div");
							div.style.display = 'inline';
							div.style.padding = '1px 2px 1px 2px';
							div.innerHTML = item.cells[i];
							td.appendChild(div);
							item.mainTextDiv = div;
							setSelection(div,item);
						} else td.innerHTML = item.cells[i];
						item.tds.push(td);
					}
					
					if ((item.extended == false)){
						item.contentDiv.style.display = 'none';					
					}	
					
					if (this.extended==true)
						this.setPlusState(2);
					else
						this.setPlusState(1);
					
					item.checkParentItems();
					this.checkParentItems();
					
					return item;				
				} else alert('Najpierw dodaj dany wezel.');
				return null;
			}
			this.getCheckedItems = function(){
				var tab = new Array();
				for (var i=0;i<this.items.length;i++){
					if (this.items[i].checked) tab.push(this.items[i]);
				}
				return tab;		
			}
			this.extend = function(){
				this.extended = true;
				this.contentDiv.style.display = 'block';		
				this.setPlusState(2);
			}
			this.collapse = function(){
				this.extended = false;
				this.contentDiv.style.display = 'none';		
				this.setPlusState(1);			
			}		
			this.setPlusState = function(state){
				if (state == 0){
					this.plusTd.innerHTML ='';			
				} else {
					if (state == 1){					
						this.plusTd.innerHTML = '<img src="'+BEngine.mainPath+'bengine/images/plusik1.png"/>';	
					} else {
						this.plusTd.innerHTML = '<img src="'+BEngine.mainPath+'bengine/images/plusikr1.png"/>';		
					}				
					this.plusTd.backgroundRepeat = 'no-repeat';
					this.plusTd.backgroundPosition ='center center';	
				}	
			}
			this.getElement = function(index){
				if (this.tds[index])
				return this.tds[index];
				else
				return null;
			}
			this.setTextColor = function(color){
				this.table.style.color = color;
			}
			this.checkParentItems = function(){
				var list = this.parent.items;	
				//alert(this.cells[0]+' '+list.length);	
				var has = false;
				for (var i=0;i<list.length;i++)
					if (list[i].hasChildren == true) has = true;
				if (has==true){
					for (var i=0;i<list.length;i++)
						list[i].plusTd.style.width ='10px';	
				}else {
					for (var i=0;i<list.length;i++)
						list[i].plusTd.style.width ='1px';	
				}			
			}
			this.setCheck = function(state){
				this.checkbox.checked = state;
				this.checked = state;
			}
		},
		StaticButtonPanel:function(param,parent){
			// param:
			// x : integer
			// y : integer
			// width : integer
			// height : integer
			// aLeft : boolean, kotwica lewa 
			// aTop : boolean, kotwica górna
			// aRight : boolean, kotwica prawa
			// aBottom : bolean, kotwica dolna
			// backParam : BackParam, styl tla
			// borderColor : string
			// visible : boolean czy panel widoczny	
			// onselect : function(selectedid)
			this.addButton = function(text,id,backColor,textColor,fontSize){
				if (backColor==null) backColor = '#9a9a9a';
				if (textColor==null) textColor = '#fff';
				if (fontSize==null) fontSize = 11;
				
				var div = document.createElement('div');
				div.style.display = 'inline-block';
				div.style.padding = '2px 7px 2px 7px';
				div.style.margin = '2px';
				div.style.color = textColor;
				div.textColor = textColor;
				div.style.backgroundColor = backColor;
				div.backColor = backColor;
				div.style.fontSize = fontSize+'px';

				if (navigator.userAgent.indexOf('MSIE')!=-1){
					div.style.zoom = 1;
					div.style.display = 'inline';
					div.style._height = (fontSize+8)+"px";
				}
				
				div.innerHTML = text;
				BEngine.Controls.disableSelection(div);
				
				div.ide = id;
				div.selected = false;
				this.childControls.push(div); 
				var obj = this;
				div.onmouseover = function(){
					if (this.selected == false){
						var rgb = BEngine.Utils.HexToRGB(this.backColor);
						rgb[0] = Math.round((rgb[0]/255)*100);
						rgb[1] = Math.round((rgb[1]/255)*100);
						rgb[2] = Math.round((rgb[2]/255)*100);
					
						rgb[0]*=1.3; if (rgb[0]>100) rgb[0] = 100;
						rgb[1]*=1.3; if (rgb[1]>100) rgb[1] = 100;					
						rgb[2]*=1.3; if (rgb[2]>100) rgb[2] = 100;					
						this.style.backgroundColor = 'rgb('+rgb[0]+'%,'+rgb[1]+'%,'+rgb[2]+'%)'; 
					}
				}	
				div.onmouseout = function(){
					if (this.selected == false){
						this.style.backgroundColor = this.backColor;
					}					
				}		
				div.onclick = function(){
					if (this.selected == false){
						if (obj.onselect){
							if (obj.onselect(this.ide)==false) return 0;					
						}
						
						for (var i=0;i<obj.childControls.length;i++){
							obj.childControls[i].style.backgroundColor = obj.childControls[i].backColor;
							obj.childControls[i].style.color = obj.childControls[i].textColor;
							obj.childControls[i].selected = false;
						}
						this.style.backgroundColor = '#fff'; 
						this.style.color = '#000'; 
						this.selected = true;
					}
				}
				
				this.workspaceDiv.appendChild(div);
			}			
			this.addNewLine = function(){
				var nl = document.createElement('br');
				this.workspaceDiv.appendChild(nl);
			}
			this.setPosition = function(x,y){
				this.div.style.left = x+'px';
				this.div.style.top = y+'px';
			},
			this.getWorkspaceSize = function(){
				return [this.workspaceDiv.clientWidth,this.workspaceDiv.clientHeight];
			}
			this.getWorkspaceWidth = function(){
				return this.getWorkspaceSize()[0];
			},
			this.getWorkspaceHeight = function(){
				return this.getWorkspaceSize()[1];
			},			
			this.getWorkspaceDiv = function(){
				return this.workspaceDiv;
			}
			this.show = function(){
				this.div.style.display = 'block';
				this.visible = true;
			}
			this.hide = function(){
				this.div.style.display = 'none';
				this.visible = false;
			}			
			this.getSize = function(){
				return [this.div.clientWidth,this.div.clientHeight];
			}
			this.showBarrier =  function(onclick){
				var obj = this;
				BEngine.Interface.Barrier.show(this.div,function(){
					if (onclick) onclick();
				});
			}
			this.hideBarrier =  function(){
				BEngine.Interface.Barrier.hide();
			}				
			this.setMinimalSize = function(width,height){
				this.div.style.minWidth = width+"px";
				this.div.style.minHeight = height+"px";
			}
			if (param!=null){
				if ((parent != null)&& ((parent.nodeName=='DIV')||((parent.canAddControl)&&(parent.canAddControl('StaticButtonPanel')==true)))){
					this.parent = parent;
					param.x == null?this.x = 0:this.x = param.x;
					param.y == null?this.y = 0:this.y = param.y;
					param.width == null?this.width = 100:this.width = param.width;
					param.height == null?this.height = 100:this.height = param.height;
					param.aLeft == null?this.aLeft = true:this.aLeft = param.aLeft;
					param.aTop == null?this.aTop = true:this.aTop = param.aTop;
					param.aRight == null?this.aRight = false:this.aRight = param.aRight;
					param.aBottom == null?this.aBottom = false:this.aBottom = param.aBottom;
					param.backParam == null?this.backParam = new BEngine.Controls.BackParam():this.backParam = param.backParam;
					param.borderColor == null?this.borderColor = null:this.borderColor = param.borderColor;
					this.onselect = param.onselect;
					
					this.visible = true;
					this.childControls = new Array();
					
					var parentSize = BEngine.Controls.getSize(parent);
					var style = BEngine.Controls.calculateDivPosition(parentSize[0],parentSize[1],this.x,this.y,this.width,this.height,this.aLeft,this.aTop,this.aRight,this.aBottom);
					this.div = BEngine.Controls.createDiv(style[0],style[1],style[2],style[3],style[4],style[5]);	
							
					if (parent.nodeName=='DIV') {
						parent.appendChild(this.div);
					} else {
						parent.addControl(this);
					}		
					if (param.borderColor!=null) {
						this.div.style.backgroundColor = this.borderColor;
						this.workspaceDiv = BEngine.Controls.createDiv(1,1,1,1,null,null);	
					}else {
						this.workspaceDiv = BEngine.Controls.createDiv(0,0,0,0,null,null);	
					}					
					this.div.appendChild(this.workspaceDiv);
					this.backParam.applyTo(this.workspaceDiv);	
					BEngine.Controls.cancelStandardEvents(this.workspaceDiv);		
					this.workspaceDiv.style.overflow = 'auto';
					this.workspaceDiv.style.textAlign = 'left';
					
					if (param.visible!=null){
						if (param.visible == false) this.hide();
					}					
				}
			}			
		},
		Table:function(param,parent){
			// param:
			// x : integer
			// y : integer
			// width : integer
			// height : integer
			// aLeft : boolean, kotwica lewa 
			// aTop : boolean, kotwica górna
			// aRight : boolean, kotwica prawa
			// aBottom : bolean, kotwica dolna
			// borderColor : string
			// visible : boolean czy panel widoczny	
			// horizontalPadding : integer
			this.setPosition = function(x,y){
				this.div.style.left = x+'px';
				this.div.style.top = y+'px';
			},
			this.getWorkspaceSize = function(){
				return [this.workspaceDiv.clientWidth,this.workspaceDiv.clientHeight];
			}
			this.getWorkspaceWidth = function(){
				return this.getWorkspaceSize()[0];
			},
			this.getWorkspaceHeight = function(){
				return this.getWorkspaceSize()[1];
			},			
			this.getWorkspaceDiv = function(){
				return this.workspaceDiv;
			}
			this.show = function(){
				this.div.style.display = 'block';
				this.visible = true;
			}
			this.hide = function(){
				this.div.style.display = 'none';
				this.visible = false;
			}			
			this.getSize = function(){
				return [this.div.clientWidth,this.div.clientHeight];
			}
			this.showBarrier =  function(onclick){
				var obj = this;
				BEngine.Interface.Barrier.show(this.div,function(){
					if (onclick) onclick();
				});
			}
			this.hideBarrier =  function(){
				BEngine.Interface.Barrier.hide();
			}				
			this.setMinimalSize = function(width,height){
				this.div.style.minWidth = width+"px";
				this.div.style.minHeight = height+"px";
			}
			this.setHeaders  = function(headers,fontSize){
				if (fontSize==null) fontSize = 11;
				this.headerTable.style.fontSize = fontSize+"px";		
				
				this.headers = headers;
				for (var i=0;this.headerTr.cells.length;i++){
					this.headerTr.deleteCell(0);
				}
				for (var i=0;i<headers.length;i++){
					var td = document.createElement('td');
					td.style.paddingLeft = this.horizontalPadding+"px";		
					td.style.paddingRight = this.horizontalPadding+"px";	
					td.style.paddingTop = '3px';
					td.style.paddingBottom = '3px';
					td.style.width = (headers[i].width-(2*this.horizontalPadding))+"px";
					td.style.minWidth = (headers[i].width-(2*this.horizontalPadding))+"px";
					td.style.textAlign = 'center';
					td.innerHTML = headers[i].text;			
					this.headerTr.appendChild(td);
					headers[i].td = td;
					
					td.style.borderRight = '1px solid #ccc';
					td.style.color = '#444';
					//td.style.fontWeight = 'bold';
				}
				var height = this.headerDiv.clientHeight;
				this.tableDiv.style.top = (height+1)+'px';
				height = (Math.round((height/2))*2);
				this.headerDiv.style.backgroundImage = 'url('+BEngine.mainPath+'bengine/images/toolbars/'+(height)+'.png)';

				for (var i=0;i<headers.length;i++){
					headers[i].width = headers[i].td.clientWidth;
					headers[i].minWidth = headers[i].td.clientWidth;
				}
			}
			this.setData = function(data,fontSize,callback){
				//if (data.length>500) data.length = 500;
			
				while (this.tbody.rows.length > 0) {
					this.tbody.deleteRow(0);
				}
				if (fontSize==null) fontSize = 11;
				this.dataTable.style.fontSize = fontSize+"px";	
				var obj = this;
				var trs = new Array();
				this.trs = trs;
				var tds = new Array();
				for (var i = 0;i<data.length;i++){
					var tr = document.createElement('tr');
					trs.push(tr);
					tr.style.backgroundColor = '#eee';
					if (this.cursor!=null) tr.style.cursor = this.cursor;
					if (i%2==0) tr.style.backgroundColor = '#fff';
					tr.backColor = tr.style.backgroundColor;
					
					
					
					if (this.ids) tr.ids = i;
										
					tr.onclick = function(){
						for (var j=0;j<trs.length;j++) trs[j].style.backgroundColor = trs[j].backColor;
						this.style.backgroundColor = '#d1eaf8';
						if (obj.onclickfun) obj.onclickfun(obj.ids[this.ids]);
					}
					
					this.tbody.appendChild(tr);
					for (var j=0;j<this.headers.length;j++){
						var td = document.createElement('td');
						td.style.paddingLeft = this.horizontalPadding+"px";		
						td.style.paddingRight = this.horizontalPadding+"px";	
						td.style.paddingTop = '3px';
						td.style.paddingBottom = '3px';
						td.style.width = (this.headers[j].width-(2*this.horizontalPadding))+"px";
						td.style.minWidth = (this.headers[j].width-(2*this.horizontalPadding))+"px";
						td.style.textAlign = 'center';
						if (this.headers[j].align!='') td.style.textAlign = this.headers[j].align;
						td.innerHTML = data[i][j];			
						tr.appendChild(td);
					
						if (i%2==0) td.style.borderRight = '1px solid #e4e4e4'; else td.style.borderRight = '1px solid #d4d4d4';
						if (i==data.length-1) td.style.borderBottom = '1px solid #d4d4d4';
						
						td.style.color = '#000';
						if (i==(data.length-1)){
							tds.push(td);
						}
					}			
				}
				
				if (data.length>0){
					for (var i=0;i<this.headers.length;i++){
						this.headers[i].td.style.width = (tds[i].clientWidth-(2*this.horizontalPadding))+"px";
						this.headers[i].td.style.minWidth = (tds[i].clientWidth-(2*this.horizontalPadding))+"px";
					}
				}
				if (callback) callback();
			}
			this.setOnClick = function(fun,ids,callback){
				this.onclickfun = fun;
				this.ids = ids;			
				if (callback) callback();				
			}
			this.clearSelection = function(){
				for (var j=0;j<this.trs.length;j++) this.trs[j].style.backgroundColor = this.trs[j].backColor;
			}
			if (param!=null){
				if ((parent != null)&& ((parent.nodeName=='DIV')||((parent.canAddControl)&&(parent.canAddControl('Table')==true)))){
					this.parent = parent;
					param.x == null?this.x = 0:this.x = param.x;
					param.y == null?this.y = 0:this.y = param.y;
					param.width == null?this.width = 100:this.width = param.width;
					param.height == null?this.height = 100:this.height = param.height;
					param.aLeft == null?this.aLeft = true:this.aLeft = param.aLeft;
					param.aTop == null?this.aTop = true:this.aTop = param.aTop;
					param.aRight == null?this.aRight = false:this.aRight = param.aRight;
					param.aBottom == null?this.aBottom = false:this.aBottom = param.aBottom;					
					param.borderColor == null?this.borderColor = null:this.borderColor = param.borderColor;
					param.horizontalPadding == null?this.horizontalPadding = 8:this.horizontalPadding = param.horizontalPadding;
					param.cursor == null?this.cursor = null:this.cursor = param.cursor;
					
					this.backParam = new BEngine.Controls.BackParam(param.borderColor);
					this.headers = new Array();
					this.visible = true;
					this.childControls = new Array();
					this.ids = new Array();
					this.trs = new Array();
					
					var parentSize = BEngine.Controls.getSize(parent);
					var style = BEngine.Controls.calculateDivPosition(parentSize[0],parentSize[1],this.x,this.y,this.width,this.height,this.aLeft,this.aTop,this.aRight,this.aBottom);
					this.div = BEngine.Controls.createDiv(style[0],style[1],style[2],style[3],style[4],style[5]);	
							
					if (parent.nodeName=='DIV') {
						parent.appendChild(this.div);
					} else {
						parent.addControl(this);
					}		
					if (param.borderColor!=null) {
						this.div.style.backgroundColor = this.borderColor;
						this.workspaceDiv = BEngine.Controls.createDiv(1,1,1,1,null,null);	
					}else {
						this.workspaceDiv = BEngine.Controls.createDiv(0,0,0,0,null,null);	
					}					
					this.div.appendChild(this.workspaceDiv);
					this.backParam.applyTo(this.workspaceDiv);
					this.workspaceDiv.style.overflow = 'hidden';
					BEngine.Controls.cancelStandardEvents(this.workspaceDiv);		

					
					if (param.visible!=null){
						if (param.visible == false) this.hide();
					}			
					var obj = this;
					
					this.headerDiv = document.createElement('div');
					this.workspaceDiv.appendChild(this.headerDiv);
					
					this.headerDiv.style.backgroundColor = '#ccc';
					this.headerDiv.style.position = 'relative';
					this.headerDiv.style.width = '100%';
					
					this.headerTable = document.createElement('table');
					this.headerDiv.appendChild(this.headerTable);
					this.headerTable.style.position = 'relative';
					this.headerTable.style.borderCollapse = 'collapse';
					this.headerTable.style.padding = '0px';
					
					var tbody = document.createElement('tbody');
					this.headerTable.appendChild(tbody); 
					
					this.headerTr = document.createElement('tr');
					tbody.appendChild(this.headerTr);
					
										
					this.tableDiv = document.createElement('div');
					this.workspaceDiv.appendChild(this.tableDiv);
					this.tableDiv.style.position = 'absolute';
					this.tableDiv.style.overflow = 'auto';
					this.tableDiv.style.backgroundColor = '#eee';
					this.tableDiv.style.width = '100%';
					this.tableDiv.style.top = '48px';
					this.tableDiv.style.bottom = '0px';

					this.tableDiv.onscroll = function(){
						obj.headerTable.style.left = '-'+this.scrollLeft+'px';
					}
					
					
					this.dataTable = document.createElement('table');
					this.tableDiv.appendChild(this.dataTable);
					//this.dataTable.style.position = 'relative';
					this.dataTable.style.borderCollapse = 'collapse';
					this.dataTable.style.padding = '0px';
					
					this.tbody = document.createElement('tbody');
					this.dataTable.appendChild(this.tbody); 
					
				}
			}			
		},
		//text - pozycja menu
		//enable - czy pozycja aktywna
		//onclick - funkcja na klikniecie, przyjmuje obiekt rodzica
		MenuItem:function(text,enable,onclick,submenu){
			var obj = this;
			this.addSubMenu = function(submenu){
				this.submenu = submenu;
				var div = System.createDiv(null,4,3,0,6,9);
				div.style.backgroundImage = 'url(forms/strzalka.png)';
				this.mainDiv.appendChild(div);
				submenu.setParent(this.parent);
				System.addEvent(this.mainDiv,'mouseover',function(e){		
					var x,y;
					x = obj.mainDiv.clientWidth;
					y = 0;
					submenu.show(obj.mainDiv,x,y);
				});
			}
			this.getSubMenu = function(){
				return this.submenu;
			}
			this.setEnable = function(enable){
				this.enable = enable;
				if (this.enable==false) 
					this.mainDiv.style.color = '#bbb'; 
				else
					this.mainDiv.style.color = '#000'; 
			}
			this.getParentMenu = function(){
				return this.parentMenu;
			}
			this.setParent = function(parent){
				this.parent = parent;
				if (this.menu!=null) this.menu.setParent(parent);	
			}
			if (text!=null){
				this.text = text;
				if (enable!=null)  
					this.enable = enable;
				else
					this.enable = true;
				
				this.onclick = onclick;
				
				if (this.text!="-"){
					this.mainDiv = BEngine.Controls.createDiv(0,0,null,null,100,17);
					this.mainDiv.style.margin = '1px';
					this.mainDiv.style.paddingTop = '1px';
					this.mainDiv.style.paddingLeft = '8px';
					this.height = 20;	
								
					if (this.enable==false) this.mainDiv.style.color = '#bbb'; 			
					this.mainDiv.innerHTML = this.text;
					
				
								
					BEngine.Controls.addEvent(this.mainDiv,'mouseover',function(e){
						obj.getParentMenu().hideSubMenus(obj.getSubMenu());
						obj.mainDiv.style.backgroundColor = '#b0d0e5';
					});
					BEngine.Controls.addEvent(this.mainDiv,'mouseout',function(e){
						obj.mainDiv.style.backgroundColor = '#fff';
					});		
				
					if (this.onclick!=null){
						BEngine.Controls.addEvent(this.mainDiv,'mousedown',function(e){
							if (obj.enable == true){
								obj.onclick(obj.parentMenu.dane);
								obj.parentMenu.hide();
							}
						});	
					}	
					
				
					if (submenu!=null){
						this.addSubMenu(submenu);
					}	
					
				} else {
					this.mainDiv = BEngine.Controls.createDiv(0,0,0,null,null,5);	
					this.height=5;			
				
					var div2 = BEngine.Controls.createDiv(4,2,4,null,null,1);
					div2.style.backgroundColor = '#aaa';
					this.mainDiv.appendChild(div2);
				}
			}

		},		
		//width
		//items - tablica MenuItem
		//onclick
		Menu:function(param,items){
			var obj = this;
			this.addItem = function(item){
				this.items.push(item);
				item.mainDiv.style.top = this.height+'px';
				this.mainDiv.appendChild(item.mainDiv);
				item.mainDiv.style.width = (this.width-10)+'px';
				item.parent = this.parent;
				this.height+=item.height;
				this.mainDiv.style.height = this.height+'px';
				item.parentMenu = this;
			}
			this.hideSubMenus = function(actmenu){
				var i;
				for (i=0;i<this.items.length;i++)
				if ((this.items[i].submenu!=null)&&(this.items[i].submenu.opened==true)&&(this.items[i].submenu!=actmenu)) this.items[i].submenu.hide();
			}
			this.show = function(parentDiv,x,y){
				if (this.items.length>0){
					this.opened = true;
					if (parentDiv == BEngine.Interface.bodyDiv)
						parentDiv.appendChild(this.mainDiv);
					else {
						BEngine.Interface.bodyDiv.appendChild(this.mainDiv);
						var pos = BEngine.Controls.divPosition(parentDiv);
						x+=pos[0];
						y+=pos[1];
					}
					this.mainDiv.style.display = 'block';
					this.mainDiv.style.zIndex = 999999999;
					BEngine.Interface.zIndex+=1000;
					this.mainDiv.style.left = x+'px';
					this.mainDiv.style.top = y+'px';
				}	
			}
			this.setAutoHidding = function(){
				BEngine.Controls.addGlobalEvent('mousedown',function(e){	
					if(obj.opened == true){			
						
						obj.hide();
					}
				});
			}		
			this.hide = function(){
				this.opened = false;
				this.mainDiv.style.display = 'none';
				var i;
				for (i=0;i<this.items.length;i++)
				if ((this.items[i].submenu!=null)) this.items[i].submenu.hide();
			}	
			this.setParent = function(parent){
				this.parent = parent;
				var i;
				for (i=0;i<this.items.length;i++){
					this.items[i].setParent(parent); 	
				}
			}		
			if (param!=null){
				this.formType = 'MENU';
				if (param.width!=null)
					this.width = param.width;
				else
					this.width = 150;

				this.height = 0;	
				this.opened = false;
				
				this.mainDiv = BEngine.Controls.createDiv(0,0,null,null,this.width,this.height);
				this.mainDiv.style.backgroundColor = '#eee';
				this.mainDiv.style.border = '1px solid #aaa';
				this.mainDiv.style.display = 'none';
				this.mainDiv.style.fontFamily = 'tahoma';
				this.mainDiv.style.fontSize = '11px';
				BEngine.Controls.disableSelection(this.mainDiv);
				BEngine.Controls.disableContextMenu(this.mainDiv);
				BEngine.Controls.cancelMouseOver(this.mainDiv);
				
				BEngine.Controls.addEvent(this.mainDiv,'mousedown',function(){
					if (obj.onclick) obj.onclick();
				})
				
				var i;
				this.items = new Array();	
				for (i=0;i<items.length;i++){
					this.addItem(items[i]); 	
				}
			}	
		},
		ButtonWindow:function (param,parent){
			var obj = this;
			this.hide = function(){
				this.mainDiv.style.display = 'none';
			}
			this.show = function(){
				this.mainDiv.style.display = 'block';
			}		
			this.setText =  function(text){
				var div = document.getElementById(this.idText);
				div.innerHTML = text;
			}
			this.setEnabled = function(enabled){
				this.enabled = enabled;
				var div = document.getElementById(this.idText);
				if (enabled==true) 
					div.style.color = '#000';
				else
					div.style.color = '#666';
				
			}
			this.setWidth = function(width){
				this.mainDiv.style.width = width+'px';
			}
			this.setImage = function(url){
				var td = document.getElementById(obj.imageDivId);		
				if (td!=null) td.style.backgroundImage = 'url('+url+')';
			}
			this.calculatePositionParameters = function(){
				var parentWidth = 0;
				var parentHeight = 0;
				
				parentWidth = this.parentDiv.clientWidth;
				parentHeight = this.parentDiv.clientHeight;
					
				if ((this.anchorLeft == true)&&(this.anchorRight == false)){
					this.styleRight = null;
					this.styleLeft = this.x;
					this.styleWidth = this.width;
				}
				if ((this.anchorLeft == false)&&(this.anchorRight == true)){
					this.styleRight = parentWidth-this.x-this.width;
					this.styleWidth = this.width;
					this.styleLeft = null;
				}
				if ((this.anchorLeft == true)&&(this.anchorRight == true)){
					this.styleLeft = this.x;
					this.styleRight = parentWidth-this.x-this.width;			
					this.styleWidth = null;
				}
				
				if ((this.anchorTop == true)&&(this.anchorBottom == false)){
					this.styleTop = this.y;
					this.styleHeight = this.height;
					this.styleBottom = null;
				}		
				if ((this.anchorTop == false)&&(this.anchorBottom == true)){
					this.styleBottom = parentHeight-this.y-this.height;
					this.styleHeight = this.height;
					this.styleTop = null;
				}			
				if ((this.anchorTop == true)&&(this.anchorBottom == true)){
					this.styleTop = this.y;
					this.styleBottom = parentHeight-this.y-this.height;
					this.styleHeight = null;
				}		
			}
			this.setPositionFromActualParameters = function(){
				obj.calculatePositionParameters(); 
				if (obj.styleWidth!=null) obj.styleWidth-=2;
				if (obj.styleHeight!=null) obj.styleHeight-=2;
			
				System.setDiv(obj.mainDiv,obj.styleLeft,obj.styleTop,obj.styleRight,obj.styleBottom,obj.styleWidth,obj.styleHeight);
			}
			this.setPosition = function(x,y){
				obj.x = x;
				obj.y = y;
				obj.setPositionFromActualParameters();
			}
			if ((param!=null)&&(parent!=null)){
				this.formType = 'BUTTON';
				this.enabled = true;
				this.parentDiv = null;
				if (parent.nodeName=='DIV')
				this.parentDiv = parent;
				else {
					if (parent.formType!=undefined){
						if (parent.formType == 'WINDOW') this.parentDiv = parent.getWorkspaceDiv();
						if (parent.formType == 'PANEL') this.parentDiv = parent.mainDiv;
					}
				}
				
				if (this.parentDiv!=null){	
					this.onclick = null;
					if (param.x!=null)
						this.x = param.x;
					else
						this.x = 0;
				
					if (param.y!=null)
						this.y = param.y;
					else
						this.y = 0;
				
					if (param.width!=null)
						this.width = param.width;
					else
						this.width = 24;		
        
					if (param.height!=null)
						this.height = param.height;
					else
						this.height = 24;
				
					if (param.anchorLeft!=null)
						this.anchorLeft = param.anchorLeft;
					else
						this.anchorLeft = true;
				
					if (param.anchorTop!=null)
						this.anchorTop = param.anchorTop;
					else
						this.anchorTop = true;
					
					if (param.anchorRight!=null)
						this.anchorRight = param.anchorRight;
					else
						this.anchorRight = false;	
        
					if (param.anchorBottom!=null)
						this.anchorBottom = param.anchorBottom;
					else
						this.anchorBottom = false;	
					
					if ((this.anchorBottom == false)&&(this.anchorTop == false)) this.anchorTop = true;	
					if ((this.anchorLeft == false)&&(this.anchorRight == false)) this.anchorLeft = true;	
				
					if (param.lightBorder!=null)
						this.lightBorder = param.lightBorder;
					else
						this.lightBorder = System.lightBorder;
						
					if (param.darkBorder!=null)
						this.darkBorder = param.darkBorder;
					else
						this.darkBorder = System.darkBorder;	
						
					if (param.backColor!=null)
						this.backColor = param.backColor;
					else
						this.backColor = '';	
						
					this.image = param.image; 	
					if (param.lightBackColor!=null)
						this.lightBackColor = param.lightBackColor;
					else
						this.lightBackColor = System.lightBackColor;
					
					this.text = param.text;
				
					this.calculatePositionParameters();
					if (this.styleWidth!=null) this.styleWidth-=2;
					if (this.styleHeight!=null) this.styleHeight-=2;
					this.mainDiv = BEngine.Controls.createDiv(this.styleLeft,this.styleTop,this.styleRight,this.styleBottom,this.styleWidth,this.styleHeight);
					this.mainDiv.style.borderTop = '1px solid '+this.lightBorder;
					this.mainDiv.style.borderLeft = '1px solid '+this.lightBorder;
					this.mainDiv.style.borderRight = '1px solid '+this.darkBorder;
					this.mainDiv.style.borderBottom = '1px solid '+this.darkBorder;
					this.mainDiv.style.fontSize = BEngine.buttonFontSize+'px';
					this.mainDiv.style.fontFamily = 'tahoma';
					BEngine.Controls.disableSelection(this.mainDiv);
					
					/*
					if(this.mainDiv.addEventListener){
					this.mainDiv.addEventListener('mousedown', System.mouseDown, true);
					}
					*/
					
					this.idText = 'buttonText'+Math.round(Math.random()*10000);
					
					if ((this.image!=null)&&(this.text==null)){					
						var img = new Image();
						obj.imageDivId = 'img'+Math.round(Math.random()*100000);
						img.onload = function(){
							obj.mainDiv.innerHTML='<table cellspacing=0 cellpadding=0 style="height:100%;margin: 0 auto"><tr><td id="'+obj.imageDivId+'" style="width:'+img.width+'px;background-image:url('+img.src+');background-position:center center;background-repeat:no-repeat"></td></tr></table>';
						}
						img.src = this.image;
					}
					
					if ((this.image==null)&&(this.text!=null))	
					this.mainDiv.innerHTML='<table cellspacing=0 cellpadding=0 style="width:100%;height:100%"><tr><td id="'+this.idText+'" align="center" valign="middle">'+this.text+'</td></tr></table>';			
					
					if ((this.image!=null)&&(this.text!=null)){	
						var img = new Image();
						obj.imageDivId = 'img'+Math.round(Math.random()*100000);
						img.onload = function(){
							obj.mainDiv.innerHTML='<table cellspacing=0 cellpadding=0 style="height:100%;margin: 0 auto"><tr><td id="'+obj.imageDivId+'" style="width:'+img.width+'px;background-image:url('+img.src+');background-position:center center;background-repeat:no-repeat"></td><td id="'+this.idText+'" align="center" valign="middle">'+obj.text+'</td></tr></table>';
						}
						img.src = this.image;
					}
					
					if (this.backColor!=null)
					this.mainDiv.style.backgroundColor = this.backColor;
					
					this.mainDiv.onmouseover = function(e){
						if (obj.enabled==true) obj.mainDiv.style.backgroundColor = obj.lightBackColor;
					}
					this.mainDiv.onmouseout= function(e){
						obj.mainDiv.style.backgroundColor = obj.backColor;
						obj.mainDiv.style.marginTop = '0px';
					}	
					this.down = false;
					var idText = this.idText;
					this.mainDiv.onmousedown= function(e){
						if ((obj.enabled==true)&&(obj.down==false)&&(BEngine.Controls.isRightButtonPressed(e)==false)){	
							obj.mainDiv.style.marginTop = '1px';	
							//document.getElementById(idText).style.marginTop = '1px';	
							if (!e) var e = window.event 
							e.cancelBubble = true;
							if (e.stopPropagation) e.stopPropagation();
							obj.down = true;
						}
					}
					this.mainDiv.onmouseup= function(e){
						if ((obj.down==true)&&(BEngine.Controls.isRightButtonPressed(e)==false)){	
							obj.mainDiv.style.marginTop = '0px';
							//document.getElementById(idText).style.marginTop = '0px';
							obj.down = false;
							if (obj.onclick!=null) obj.onclick(e);		
						}
					}			
					this.parentDiv.appendChild(this.mainDiv);
				}
			}	
		},
		Window:function(param,parent){
			var obj = this;
			this.parent = parent;
			this.parentSize = function(){
				var parentWidth = 0;
				var parentHeight = 0;
				
				if (this.parent==null){
					parentWidth = BEngine.getWidth();
					parentHeight = BEngine.getHeight();			
				} else {
					parentWidth = this.parent.getWidth();
					parentHeight = this.parent.getHeight();					
				}
				return [parentWidth,parentHeight];
			}
			this.calculatePositionParameters = function(){
				var parentWidth = 0;
				var parentHeight = 0;
				
				if (this.parent==null){
					parentWidth = BEngine.Interface.rootPanel.getWorkspaceWidth();
					parentHeight = BEngine.Interface.rootPanel.getWorkspaceHeight();			
				} else {
					parentWidth = this.parent.getWidth();
					parentHeight = this.parent.getHeight();					
				}

				if ((this.anchorLeft == true)&&(this.anchorRight == false)){
					this.styleRight = null;
					this.styleLeft = this.x;
					this.styleWidth = this.width;
				}
				if ((this.anchorLeft == false)&&(this.anchorRight == true)){
					this.styleRight = parentWidth-this.x-this.width;
					this.styleWidth = this.width;
					this.styleLeft = null;
				}
				if ((this.anchorLeft == true)&&(this.anchorRight == true)){
					this.styleLeft = this.x;
					this.styleRight = parentWidth-this.x-this.width;
					this.styleWidth = null;
				}
				
				if ((this.anchorTop == true)&&(this.anchorBottom == false)){
					this.styleTop = this.y;
					this.styleHeight = this.height;
					this.styleBottom = null;
				}		
				if ((this.anchorTop == false)&&(this.anchorBottom == true)){
					this.styleBottom = parentHeight-this.y-this.height;
					this.styleHeight = this.height;
					this.styleTop = null;
				}			
				if ((this.anchorTop == true)&&(this.anchorBottom == true)){
					this.styleTop = this.y;
					this.styleBottom = parentHeight-this.y-this.height;
					this.styleHeight = null;
				}		
			}
			this.addWindow = function(window){
				this.mainDiv.appendChild(window.mainDiv);
				this.mainDiv.style.zIndex =  BEngine.zIndex;
				BEngine.zIndex+=1000;
				if (!this.windows){
					this.windows = new Array();
				}
				this.windows.push(window);
			}
			this.getWidth = function(){
				return this.mainDiv.clientWidth;
			},
			this.getHeight = function(){
				return this.mainDiv.clientHeight;
			}
			this.getWorkspaceWidth = function(){
				return this.workspaceDiv.clientWidth;
			},
			this.getWorkspaceHeight = function(){
				return this.workspaceDiv.clientHeight;
			}
			this.getWorkspaceDiv = function(){
				return this.workspaceDiv;
			}
			this.show = function(){
				this.mainDiv.style.display = 'block';
			}
			this.close = function(){
				this.hide();
				obj = null;
			}
			this.hide = function(){
				this.mainDiv.style.display = 'none';
			}	
			this.setPositionFromActualParameters = function(){
				this.calculatePositionParameters(); 
				BEngine.Controls.setDiv(this.mainDiv,this.styleLeft,this.styleTop,this.styleRight,this.styleBottom,this.styleWidth,this.styleHeight);
			}
			this.innerOnResize = function(){
				var width = this.width;
				var height = this.height;
				this.width = this.mainDiv.clientWidth; 
				this.height = this.mainDiv.clientHeight; 		
				this.x = this.mainDiv.offsetLeft;
				this.y = this.mainDiv.offsetTop;
				this.calculatePositionParameters();
				
				if (((width != this.mainDiv.clientWidth)||(height != this.mainDiv.clientHeight))&&(this.onresize!=null)) this.onresize();	

				if (this.windows)
				for (i45645=0;i45645<this.windows.length;i45645++) 
				if (this.windows[i45645]!=null) this.windows[i45645].innerOnResize();	
			}
			this.maximize = function(){
				this.maximized = true;

				if (this.maximizeButton!=null)
				this.maximizeButton.setImage(BEngine.folderPath+'max2.png');
				
				this.beforeMaxX = this.x;
				this.beforeMaxY = this.y;
				this.beforeMaxWidth = this.width;
				this.beforeMaxHeight = this.height;
				if (this.borderStyle != 'NONE'){
					this.mainDiv.style.left = (-BEngine.frameSize)+'px';
					this.mainDiv.style.top = '0px';
					this.mainDiv.style.right = (-BEngine.frameSize)+'px';
					this.mainDiv.style.bottom = (-BEngine.frameSize)+'px';
				} else {
					this.mainDiv.style.left = '0px';
					this.mainDiv.style.top = '0px';
					this.mainDiv.style.right = '0px';
					this.mainDiv.style.bottom = '0px';
				}
				
				this.mainDiv.style.width = '';
				this.mainDiv.style.height = '';	
				if (this.onresize) this.onresize();	
				
			}
			this.restore = function(){
				this.maximized = false;
				
				if (this.maximizeButton!=null)
				this.maximizeButton.setImage(BEngine.folderPath+'max.png');
				this.x = this.beforeMaxX;
				this.y = this.beforeMaxY;
				this.width = this.beforeMaxWidth;
				this.height = this.beforeMaxHeight;
				this.setPositionFromActualParameters();
			}
			this.setText = function(text){
				if (this.captionDiv!=null)
				this.captionDiv.innerHTML = '<table><tr><td>'+text+'</td></tr></table>';
			}
			this.fullScreen = function(){
				this.mainDiv.style.width = '';
				this.mainDiv.style.height = '';	
				
				this.mainDiv.style.left = (-this.workLeft-1)+'px';
				this.mainDiv.style.top = (-this.workTop-1)+'px';
				this.mainDiv.style.right = (-this.workRight-1)+'px';
				this.mainDiv.style.bottom = (-this.workBottom-1)+'px';			
				if (this.resize)
				this.onresize();
			}
			this.sendOnTop = function(){
				var obj = this;
				if ((obj.sendOnTop==true)&&(obj.mainDiv.style.zIndex<BEngine.zIndex)){	
					obj.mainDiv.style.zIndex = BEngine.zIndex;
					BEngine.zIndex+=1000;
				}
			}
			if ((param!=null)&&((parent==null)||(parent.formType == 'WINDOW')||(parent.formType == 'PANEL'))){
				this.formType = 'WINDOW';
				this.onclose = null;
				this.onresize = null;
				this.onmousemove = null;
				
				this.offsetTop = 0;
				this.offsetBottom = 0;
				
				this.parent = parent;
				if (param.text!=null)
					this.text = param.text; 
				else
					this.text = '';		
				
				if (param.x!=null)
					this.x = param.x;
				else
					this.x = 0;
				
				if (param.y!=null)
					this.y = param.y;
				else
					this.y = 0;
				
				if (param.width!=null)
					this.width = param.width;
				else
					this.width = 200;		

				if (param.minWidth!=null)
					this.minWidth = param.minWidth;
				else
					this.minWidth = 150;					
												
				if (param.height!=null)
					this.height = param.height;
				else
					this.height = 200;
					
				if (param.minHeight!=null)
					this.minHeight = param.minHeight;
				else
					this.minHeight = 120;		
				
				if (param.anchorLeft!=null)
					this.anchorLeft = param.anchorLeft;
				else
					this.anchorLeft = true;
				
				if (param.anchorTop!=null)
					this.anchorTop = param.anchorTop;
				else
					this.anchorTop = true;
					
				if (param.anchorRight!=null)
					this.anchorRight = param.anchorRight;
				else
					this.anchorRight = false;	

				if (param.anchorBottom!=null)
					this.anchorBottom = param.anchorBottom;
				else
					this.anchorBottom = false;	
					
				if ((this.anchorBottom == false)&&(this.anchorTop == false)) this.anchorTop = true;	
				if ((this.anchorLeft == false)&&(this.anchorRight == false)) this.anchorLeft = true;	
				
				if (param.startPosition!=null)
					this.startPosition = param.startPosition;
				else
					this.startPosition = 'MANUAL';
					
				if (param.backColor!=null)
					this.backColor = param.backColor;
				else
					this.backColor = BEngine.backColor;
					
				if (param.sendOnTop!=null)
					this.sendOnTop  = param.sendOnTop;
				else
					this.sendOnTop = true;
					
				if (param.dialog !=null)
					this.dialog = param.dialog;
				else
					this.dialog = false;
			
				var parentWidth = 0;
				var parentHeight = 0;
				
			
				if (parent==null){
					parentWidth = BEngine.Interface.rootPanel.getWorkspaceWidth();
					parentHeight = BEngine.Interface.rootPanel.getWorkspaceHeight();			
				} else {
					parentWidth = parent.getWidth();
					parentHeight = parent.getHeight();					
				}
				
				if (this.startPosition == 'CENTER'){
					this.x = Math.round((parentWidth-this.width)*0.5);
					this.y = Math.round((parentHeight-this.height)*0.5);
				}
				
				if (param.clipChildren!=null)
					this.clipChildren = param.clipChildren;
				else
					this.clipChildren = true;	
					
				if (param.borderStyle!=null)
					this.borderStyle = param.borderStyle;
				else
					this.borderStyle = 'SIZABLE';
			
				if (param.isCloseButton!=null)
					this.isCloseButton = param.isCloseButton;
				else
					this.isCloseButton = true;
				if (param.isMaximizeButton!=null)
					this.isMaximizeButton = param.isMaximizeButton;
				else
					this.isMaximizeButton = true;
			
				this.maximized = false;
			
				this.calculatePositionParameters();
			
		
			
				this.mainDiv = BEngine.Controls.createDiv(this.styleLeft,this.styleTop,this.styleRight,this.styleBottom,this.styleWidth,this.styleHeight);
				this.conDiv = BEngine.Controls.createDiv(0,0,0,0,null,null);
				this.mainDiv.appendChild(this.conDiv);
				if (parent==null){
					BEngine.Interface.addWindow(this);
				} else {
					parent.addWindow(this);		
				}
				
				if ((this.sendOnTop==true)){	
					obj.mainDiv.style.zIndex = BEngine.zIndex;
					BEngine.zIndex+=1000;
				}
					
				if (this.dialog == true){
					this.dialogDiv = BEngine.Controls.createDiv(-1000,-1000,null,null,3000,3000);
					this.dialogDiv.style.backgroundImage = 'url('+BEngine.folderPath+'blank.png)';				
					this.mainDiv.appendChild(this.dialogDiv);
					this.dialogDiv.onclick = function(){
						
					}
				}
				
				//this.mainDiv.style.backgroundColor = '#ccc';
			
				var workLeft = 0;
				var workTop = 0;
				var workRight = 0;
				var workBottom = 0;
				
				if (this.borderStyle != 'NONE'){
				
					if ((this.borderStyle == 'SIZABLE')||(this.borderStyle == 'FIXED')){
						workLeft = BEngine.frameSize;
						workTop = BEngine.captionBarSize+1;
						workRight = BEngine.frameSize;
						workBottom = BEngine.frameSize;	
						this.workLeft = workLeft;
						this.workTop = workTop;
						this.workRight = workRight;
						this.workBottom = workBottom;
						
						var ramki = BEngine.Controls.createColoredFrame(BEngine.frameSize,BEngine.windowColor,BEngine.borderColor);	
						this.frameDiv = ramki[0];
						this.mainDiv.appendChild(this.frameDiv);
						this.captionDiv = BEngine.Controls.createDiv(BEngine.frameSize,1,BEngine.frameSize,null,null,BEngine.captionBarSize);
						this.captionDiv.style.backgroundColor = BEngine.windowColor;
						this.captionDiv.innerHTML = '<table><tr><td>'+this.text+'</td></tr></table>';
						this.captionDiv.style.fontSize = BEngine.captionBarFontSize+'px';
						this.captionDiv.style.fontFamily = 'tahoma';
						this.captionDiv.style.fontWeight = 'bold';
						this.captionDiv.style.overflow = 'hidden';
						BEngine.Controls.disableSelection(this.captionDiv);
						this.captionDiv.style.color = BEngine.captionBarFontColor;
						this.mainDiv.appendChild(this.captionDiv);
						if (this.isCloseButton==true){
							this.closeButton = new BEngine.Controls.ButtonWindow({x:(this.width-35),y:3,width:22,height:16,anchorRight:true,anchorLeft:false,lightBorder:'#eee',darkBorder:'#eee',backColor:'#e56748',image:BEngine.folderPath+'close.png',lightBackColor:'#e3bfbf'},this.captionDiv);
							this.closeButton.onclick = function(e){
								if (obj.onclose !=null){
									if (obj.onclose()!=false){
										obj.mainDiv.style.display = 'none';
										obj = null;
									}
								} else {
									obj.mainDiv.style.display = 'none';
									obj = null;
								}
							}
						}
						if (this.isMaximizeButton==true){
							this.maximizeButton = new BEngine.Controls.ButtonWindow({x:(this.width-60),y:3,width:22,height:16,anchorRight:true,anchorLeft:false,lightBorder:'#eee',darkBorder:'#eee',backColor:'#61b8ef',image:BEngine.folderPath+'max.png',lightBackColor:'#bedaec'},this.captionDiv);
							this.maximizeButton.onclick = function(e){
								if (obj.maximized==false) obj.maximize(); else obj.restore();
							}
						}
					}
					if ((this.borderStyle == 'TOOL')||(this.borderStyle == 'TOOL_FIXED')){
						workLeft = BEngine.toolFrameSize;
						workTop = 1+BEngine.toolCaptionBarSize;
						workRight = BEngine.toolFrameSize;
						workBottom = BEngine.toolFrameSize;
						this.workLeft = workLeft;
						this.workTop = workTop;
						this.workRight = workRight;
						this.workBottom = workBottom;					
						var ramki = BEngine.createColoredFrame(BEngine.frameSize,BEngine.windowColor,BEngine.borderColor);	
						this.frameDiv = ramki[0];
						this.mainDiv.appendChild(this.frameDiv);	
						this.captionDiv = BEngine.Controls.createDiv(BEngine.toolFrameSize,1,BEngine.toolFrameSize,null,null,BEngine.toolCaptionBarSize);
						this.captionDiv.style.backgroundColor = BEngine.windowColor;
						this.captionDiv.innerHTML = '<table><tr><td>'+this.text+'</td></tr></table>';
						this.captionDiv.style.fontSize = BEngine.toolCaptionBarFontSize+'px';
						this.captionDiv.style.fontFamily = 'tahoma';
						this.captionDiv.style.fontWeight = 'bold';	
						this.captionDiv.style.overflow = 'hidden';
						this.captionDiv.style.color = BEngine.captionBarFontColor;
						BEngine.disableSelection(this.captionDiv);			
						this.mainDiv.appendChild(this.captionDiv);		
						if (this.isCloseButton==true){
							this.closeButton = new BEngine.Button({x:(this.width-23),y:2,width:14,height:14,anchorRight:true,anchorLeft:false,lightBorder:'#eee',darkBorder:'#eee',backColor:'#e56748',image:BEngine.folderPath+'close.png',lightBackColor:'#e3bfbf'},this.captionDiv);
							this.closeButton.onclick = function(e){
								if (obj.onclose !=null){
									if (obj.onclose()!=false)
									obj.mainDiv.style.display = 'none';
								} else {
									obj.mainDiv.style.display = 'none';
								}
							}	
						}		
					}
					var obj = this;
					BEngine.Controls.addEvent(window,'resize',function(e){  
						if (obj!=null) obj.innerOnResize();			 
					});	
					BEngine.Controls.addEvent(this.captionDiv,'mousedown',function(e){  
						if ((obj.maximized==false)&&(BEngine.Controls.isRightButtonPressed(e)==false)){
							var pos = BEngine.Controls.mouseCoordinates(e);
							obj.moveState = 1;			 
							obj.tempX = pos[0];
							obj.tempY = pos[1];
							BEngine.Interface.MovingPanelForWindow.show(
								function(x,y){
									if ((obj!=null)&&(obj.moveState == 1)){
	
										var dx = x - obj.tempX;
										var dy = y - obj.tempY;
																						
										if (obj.anchorLeft==true){
											obj.mainDiv.style.left = (obj.styleLeft+dx)+'px';
										}
										
										if (obj.anchorTop==true) {
											obj.mainDiv.style.top = (obj.styleTop+dy)+'px';
										}
										
										if (obj.anchorRight==true){
											obj.mainDiv.style.right = (obj.styleRight-dx)+'px';
										}
										if (obj.anchorBottom==true){
											obj.mainDiv.style.bottom = (obj.styleBottom-dy)+'px';
										}					
									}
								},
								function(x,y){
									BEngine.Interface.MovingPanelForWindow.hide();
									if ((obj!=null)&&(obj.moveState == 1)){
										obj.moveState = 0;
										var dx = x - obj.tempX;
										var dy = y - obj.tempY;
										
										if (obj.anchorLeft==true){
										obj.mainDiv.style.left = (obj.styleLeft+dx)+'px';
										}
										if (obj.anchorTop==true) {
											obj.mainDiv.style.top = (obj.styleTop+dy)+'px';
										}
										
										if (obj.anchorRight==true){
											obj.mainDiv.style.right = (obj.styleRight-dx)+'px';
										}
										if (obj.anchorBottom==true){
											obj.mainDiv.style.bottom= (obj.styleBottom-dy)+'px';
										}	
										
										obj.innerOnResize();
									}																
								},
								function(x,y){
									BEngine.Interface.MovingPanelForWindow.hide();
									if ((obj!=null)&&(obj.moveState == 1)){
										obj.moveState = 0;
										var dx = x - obj.tempX;
										var dy = y - obj.tempY;
										
										if (obj.anchorLeft==true){
										obj.mainDiv.style.left = (obj.styleLeft+dx)+'px';
										}
										if (obj.anchorTop==true) {
											obj.mainDiv.style.top = (obj.styleTop+dy)+'px';
										}
										
										if (obj.anchorRight==true){
											obj.mainDiv.style.right = (obj.styleRight-dx)+'px';
										}
										if (obj.anchorBottom==true){
											obj.mainDiv.style.bottom= (obj.styleBottom-dy)+'px';
										}	
										
										obj.innerOnResize();
									}								
								}
							);
						}
					});			


				} else {
					this.workLeft = 0
					this.workTop = 0;
					this.workRight = 0;
					this.workBottom = 0;
				}
				
				
				
				this.workspaceDiv = BEngine.Controls.createDiv(workLeft,workTop,workRight,workBottom,null,null);
				this.workspaceDiv.style.backgroundColor = this.backColor;
				

				
				if (this.borderStyle != 'NONE'){
					this.backDiv = BEngine.Controls.createDiv(workLeft,workTop,workRight,workBottom,null,null);
					this.backDiv.style.backgroundColor = BEngine.borderColor;

					this.workspaceDiv = BEngine.Controls.createDiv(1,1,1,1,null,null);				
					this.workspaceDiv.style.backgroundColor = this.backColor;
					this.backDiv.appendChild(this.workspaceDiv);
				
				
					if (this.clipChildren==true) this.workspaceDiv.style.overflow = 'hidden';
					this.mainDiv.appendChild(this.backDiv);
				} else {
					this.workspaceDiv = BEngine.Controls.createDiv(workLeft,workTop,workRight,workBottom,null,null);
					this.workspaceDiv.style.backgroundColor = this.backColor;
					if (this.clipChildren==true) this.workspaceDiv.style.overflow = 'hidden';
					this.mainDiv.appendChild(this.workspaceDiv);			
				}
				
	
				BEngine.Controls.addEvent(this.workspaceDiv,'mousemove',function(e){
					if (obj.onmousemove!=null){
						var pos = BEngine.mouseCoordinates(e);
						var dpos = BEngine.divPosition(obj.workspaceDiv);
						obj.onmousemove(pos[0]-dpos[0],pos[1]-dpos[1]);			
					}
				});
					
					
					
		
				
				BEngine.Controls.addEvent(this.mainDiv,'mousedown',function(e){
				
					if ((obj.sendOnTop==true)&&(obj.mainDiv.style.zIndex<BEngine.Interface.zIndex)){	
						obj.mainDiv.style.zIndex = BEngine.Interface.zIndex;
						BEngine.Interface.zIndex+=1000;
					}
				});	
								
						
				if ((this.borderStyle == 'SIZABLE')||(this.borderStyle == 'TOOL')){
					ramki[4].style.cursor = 'se-resize';
					
					if(ramki[4].addEventListener){
					ramki[4].addEventListener('mousedown', BEngine.Controls.mouseDown, true);
					}
					
					
					BEngine.Controls.addEvent(ramki[4],'mousedown',function(e){  
						if ((obj.maximized==false)&&(BEngine.Controls.isRightButtonPressed(e)==false)){
						
							var pos = BEngine.Controls.mouseCoordinates(e);
							obj.resizeState = 1;	
							obj.resizeIndex = 4;					
							obj.tempX = pos[0];
							obj.tempY = pos[1];
							obj.tmpWidth = obj.width;
							obj.tmpHeight = obj.height;
							
						}
					});
					BEngine.Controls.addGlobalEvent('mousemove',function(e){
						if ((obj!=null)&&(obj.resizeIndex == 4)&&(obj.resizeState == 1)){
							var pos = BEngine.Controls.mouseCoordinates(e);
							var dx = pos[0] - obj.tempX;
							var dy = pos[1] - obj.tempY;
							
							if ((obj.anchorRight==false)&&(obj.anchorLeft==true)&&((obj.tmpWidth+dx)>obj.minWidth)){
								obj.width = obj.tmpWidth+dx;
								obj.mainDiv.style.width = obj.width+'px';
							}
							if ((obj.anchorRight==true)&&(obj.anchorLeft==false)&&((obj.tmpWidth+dx)>obj.minWidth)){
								obj.width = obj.tmpWidth+dx;
								var par = obj.parentSize();
								obj.mainDiv.style.width = obj.width+'px';
								obj.mainDiv.style.right = (par[0]-obj.width-obj.x)+'px';
							}				
							if ((obj.anchorRight==true)&&(obj.anchorLeft==true)&&((obj.tmpWidth+dx)>obj.minWidth)){
								obj.width = obj.tmpWidth+dx;
								var par = obj.parentSize();
								obj.mainDiv.style.right = (par[0]-obj.width-obj.x)+'px';
							}					
							if ((obj.anchorBottom==false)&&(obj.anchorTop==true)&&((obj.tmpHeight+dy)>obj.minHeight)){
								obj.height = obj.tmpHeight+dy;
								obj.mainDiv.style.height = obj.height+'px';
							}
							if ((obj.anchorBottom==true)&&(obj.anchorTop==false)&&((obj.tmpHeight+dy)>obj.minHeight)){
								obj.height = obj.tmpHeight+dy;
								var par = obj.parentSize();
								obj.mainDiv.style.height = obj.height+'px';
								obj.mainDiv.style.bottom = (par[1]-obj.height-obj.y)+'px';
							}
							if ((obj.anchorBottom==true)&&(obj.anchorTop==true)&&((obj.tmpHeight+dy)>obj.minHeight)){
								obj.height = obj.tmpHeight+dy;
								var par = obj.parentSize();
								obj.mainDiv.style.bottom = (par[1]-obj.height-obj.y)+'px';
							}					
							
								
						}
					});			
					BEngine.Controls.addGlobalEvent('mouseup',function(e){
						if ((obj!=null)&&(obj.resizeState == 1)){
							obj.resizeState = 0;
							obj.innerOnResize();
							if (obj.onresize!=null) obj.onresize();	
						}
					});	
					
					ramki[3].style.cursor = 'e-resize';
					if(ramki[3].addEventListener){
					ramki[3].addEventListener('mousedown', BEngine.Controls.mouseDown, true);
					}
					
					BEngine.Controls.addEvent(ramki[3],'mousedown',function(e){  
						if ((obj.maximized==false)&&(BEngine.Controls.isRightButtonPressed(e)==false)){
							var pos = BEngine.Controls.mouseCoordinates(e);
							obj.resizeState = 1;	
							obj.resizeIndex = 3;	
							obj.tempX = pos[0];
							obj.tempY = pos[1];
							obj.tmpWidth = obj.width;
							obj.tmpHeight = obj.height;
						}
					});
					BEngine.Controls.addGlobalEvent('mousemove',function(e){
						if ((obj!=null)&&(obj.resizeIndex == 3)&&(obj.resizeState == 1)){
							var pos = BEngine.Controls.mouseCoordinates(e);
							var dx = pos[0] - obj.tempX;
							var dy = pos[1] - obj.tempY;
							
							if ((obj.anchorRight==false)&&(obj.anchorLeft==true)&&((obj.tmpWidth+dx)>obj.minWidth)){
								obj.width = obj.tmpWidth+dx;
								obj.mainDiv.style.width = obj.width+'px';
							}
							if ((obj.anchorRight==true)&&(obj.anchorLeft==false)&&((obj.tmpWidth+dx)>obj.minWidth)){
								obj.width = obj.tmpWidth+dx;
								var par = obj.parentSize();
								obj.mainDiv.style.width = obj.width+'px';
								obj.mainDiv.style.right = (par[0]-obj.width-obj.x)+'px';
							}				
							if ((obj.anchorRight==true)&&(obj.anchorLeft==true)&&((obj.tmpWidth+dx)>obj.minWidth)){
								obj.width = obj.tmpWidth+dx;
								var par = obj.parentSize();
								obj.mainDiv.style.right = (par[0]-obj.width-obj.x)+'px';
							}																							
						}
					});		
					
					ramki[5].style.cursor = 'n-resize';
					if(ramki[5].addEventListener){
					ramki[5].addEventListener('mousedown', BEngine.Controls.mouseDown, true);
					}
					
					BEngine.Controls.addEvent(ramki[5],'mousedown',function(e){  
						if ((obj.maximized==false)&&(BEngine.Controls.isRightButtonPressed(e)==false)){
							var pos = BEngine.Controls.mouseCoordinates(e);
							obj.resizeState = 1;	
							obj.resizeIndex = 5;					
							obj.tempX = pos[0];
							obj.tempY = pos[1];
							obj.tmpWidth = obj.width;
							obj.tmpHeight = obj.height;
						}
					});
					BEngine.Controls.addGlobalEvent('mousemove',function(e){
						if ((obj!=null)&&(obj.resizeIndex == 5)&&(obj.resizeState == 1)){
							var pos = BEngine.Controls.mouseCoordinates(e);
							var dx = pos[0] - obj.tempX;
							var dy = pos[1] - obj.tempY;
										
							if ((obj.anchorBottom==false)&&(obj.anchorTop==true)&&((obj.tmpHeight+dy)>obj.minHeight)){
								obj.height = obj.tmpHeight+dy;
								obj.mainDiv.style.height = obj.height+'px';
							}
							if ((obj.anchorBottom==true)&&(obj.anchorTop==false)&&((obj.tmpHeight+dy)>obj.minHeight)){
								obj.height = obj.tmpHeight+dy;
								var par = obj.parentSize();
								obj.mainDiv.style.height = obj.height+'px';
								obj.mainDiv.style.bottom = (par[1]-obj.height-obj.y)+'px';
							}
							if ((obj.anchorBottom==true)&&(obj.anchorTop==true)&&((obj.tmpHeight+dy)>obj.minHeight)){
								obj.height = obj.tmpHeight+dy;
								var par = obj.parentSize();
								obj.mainDiv.style.bottom = (par[1]-obj.height-obj.y)+'px';
							}							
						}
					});			

				}
			}
			this.addContextMenuToWorkspace = function(menu){
				BEngine.Controls.disableContextMenu(this.workspaceDiv);
				BEngine.Controls.cancelMouseUp(this.workspaceDiv);
				BEngine.Controls.addEvent(this.workspaceDiv,'mouseup',function(e){
					if(BEngine.Controls.isRightButtonPressed(e)==true){
						var pos = BEngine.Controls.mouseCoordinates(e);
						menu.setParent(obj);	
						menu.show(BEngine.systemDiv,pos[0],pos[1]);
					}
				});
				BEngine.Controls.addGlobalEvent('mousedown',function(e){
					if(menu.opened == true){			
						menu.hide();
					}
				});

			}	
		}
	
	
	},
	Interface:{
		init:function(interfaceParm,callback){
			// IntefacParam:
			// width : integer, szerokosc strony, jesli null to wypelnia calosc
			// backParam : BackParam, styl tla
			this.windows = new Array();
			if (interfaceParm!=null){
				interfaceParm.backParam == null?this.backParam = new BEngine.Controls.BackParam():this.backParam = interfaceParm.backParam;
				interfaceParm.width == null?this.width = null:this.width = interfaceParm.width;
				
				//ustawianie parametrow tla
				this.backParam.applyTo(document.body);
				
				this.bodyDiv = BEngine.Controls.createDiv(0,0,0,0,null,null);
				document.body.appendChild(this.bodyDiv);
				this.bodyDiv.style.overflow = 'hidden';
				
				//tworzenie div-a korzenia
				if (this.width==null){
					this.rootDiv = BEngine.Controls.createDiv(0,0,0,0,null,null);
				} else {
					this.rootDiv = BEngine.Controls.createDiv(0,0,null,0,this.width,null);
					
					BEngine.Controls.addEvent(window,'resize',function(){
						BEngine.Controls.setDivInCenter(BEngine.Interface.rootDiv,BEngine.Interface.bodyDiv);
					});
				}
				this.bodyDiv.appendChild(this.rootDiv);			
				BEngine.Controls.setDivInCenter(BEngine.Interface.rootDiv,BEngine.Interface.bodyDiv);
				
				this.rootPanel = new BEngine.Controls.Panel({x:0,y:0,width:this.rootDiv.clientWidth,height:this.rootDiv.clientHeight,aLeft:true,aTop:true,aRight:true,aBottom:true},this.rootDiv);
				BEngine.Controls.addEvent(window,'resize',function(){
					BEngine.Interface.rootPanel.resizing();
				});

				this.Barrier.init(this.bodyDiv);		
				this.MovingPanel.init(this.bodyDiv);	
				this.LoadingPanel.init(this.bodyDiv);
				this.MovingPanelForWindow.init(this.bodyDiv);
				this.zIndex = 4000;
				
				if (callback) callback(this.rootPanel);
			}
		},
		addWindow:function(window){
			this.windows.push(window);
			this.rootPanel.getWorkspaceDiv().appendChild(window.mainDiv);
			window.mainDiv.style.zIndex =  9000000;
			this.zIndex+=1000;
		},		
		Barrier:{
			init:function(parentDiv){
				this.barrierDiv1 = BEngine.Controls.createDiv(0,0,0,0,null,null);	
				this.barrierDiv2 = BEngine.Controls.createDiv(0,0,0,0,null,null);
				this.barrierDiv3 = BEngine.Controls.createDiv(0,0,0,0,null,null);
				this.barrierDiv4 = BEngine.Controls.createDiv(0,0,0,0,null,null);
				
				this.barrierDiv1.style.zIndex = 40000000;
				this.barrierDiv2.style.zIndex = 40000000;
				this.barrierDiv3.style.zIndex = 40000000;
				this.barrierDiv4.style.zIndex = 40000000;
				
				BEngine.Controls.cancelStandardEvents(this.barrierDiv1);
				BEngine.Controls.cancelStandardEvents(this.barrierDiv2);
				BEngine.Controls.cancelStandardEvents(this.barrierDiv3);
				BEngine.Controls.cancelStandardEvents(this.barrierDiv4);
				
				parentDiv.appendChild(this.barrierDiv1);
				parentDiv.appendChild(this.barrierDiv2);
				parentDiv.appendChild(this.barrierDiv3);
				parentDiv.appendChild(this.barrierDiv4);
				
				this.barrierDiv1.style.display = 'none';
				this.barrierDiv2.style.display = 'none';
				this.barrierDiv3.style.display = 'none';
				this.barrierDiv4.style.display = 'none';
				
				this.barrierDiv1.style.backgroundColor = '#eee';
				this.barrierDiv2.style.backgroundColor = '#eee';
				this.barrierDiv3.style.backgroundColor = '#eee';
				this.barrierDiv4.style.backgroundColor = '#eee';
				
				BEngine.Controls.setDivOpacity(this.barrierDiv1,0.1);
				BEngine.Controls.setDivOpacity(this.barrierDiv2,0.1);
				BEngine.Controls.setDivOpacity(this.barrierDiv3,0.1);
				BEngine.Controls.setDivOpacity(this.barrierDiv4,0.1);		
			},
			show:function(div,onclick){
				var pos = BEngine.Controls.divPosition(div);
				var w = div.clientWidth;
				var h = div.clientHeight;
				
				BEngine.Controls.modifyDiv(this.barrierDiv1,0,0,null,0,pos[0],null);
				this.barrierDiv1.style.display = 'block';
				BEngine.Controls.modifyDiv(this.barrierDiv2,pos[0]+w,0,0,0,null,null);
				this.barrierDiv2.style.display = 'block';		
				BEngine.Controls.modifyDiv(this.barrierDiv3,pos[0],0,null,null,w,pos[1]);
				this.barrierDiv3.style.display = 'block';		
				BEngine.Controls.modifyDiv(this.barrierDiv4,pos[0],pos[1]+h,null,0,w,null);
				this.barrierDiv4.style.display = 'block';	
				
    
				this.barrierDiv1.onmousedown = function(e){	
					if (onclick) onclick();	
					BEngine.Controls.cancelEvent(e);			
					BEngine.Interface.Barrier.hide();
				};	
				this.barrierDiv2.onmousedown = function(e){	
					if (onclick) onclick();	
					BEngine.Controls.cancelEvent(e);			
					BEngine.Interface.Barrier.hide();
				};	
				this.barrierDiv3.onmousedown = function(e){	
					if (onclick) onclick();	
					BEngine.Controls.cancelEvent(e);			
					BEngine.Interface.Barrier.hide();
				};	
				this.barrierDiv4.onmousedown = function(e){	
					if (onclick) onclick();	
					BEngine.Controls.cancelEvent(e);			
					BEngine.Interface.Barrier.hide();
				};				
			},
			hide:function(){
				this.barrierDiv1.style.display = 'none';
				this.barrierDiv2.style.display = 'none';
				this.barrierDiv3.style.display = 'none';
				this.barrierDiv4.style.display = 'none';			
			}
		},		
		LoadingPanel:{
			init:function(div){
				var backParam = new BEngine.Controls.BackParam('#fff',BEngine.mainPath+'bengine/images/loading.gif','no-repeat','center center');
				this.loadingPanel = new BEngine.Controls.Panel({visible:false,x:0,y:0,width:div.clientWidth,height:div.clientHeight,backParam:backParam,aRight:true,aBottom:true},div);	
				this.loadingPanel.div.style.zIndex = 10000000;
				BEngine.Controls.setDivOpacity(this.loadingPanel.div,0.3);
				this.visible = false;
			},
			show:function(){
				this.loadingPanel.show();
				this.visible = true;
			},
			hide:function(){
				this.loadingPanel.hide();
				this.visible = false;
			}			
		},
		MovingPanel:{
			init:function(div){
				this.movingType = null;
				var backParam = new BEngine.Controls.BackParam('transparent');
				this.panel = new BEngine.Controls.Panel({visible:false,clip:false,x:0,y:0,width:div.clientWidth,height:div.clientHeight,backParam:backParam,aRight:true,aBottom:true},div);	
				this.panel.div.style.zIndex = 4000;
				
				//BEngine.Controls.setDivOpacity(this.panel.div,0.1);		
				this.slideDiv = BEngine.Controls.createDiv(100,0,null,10,4,null);

				this.panel.div.appendChild(this.slideDiv);
				this.panel.setCursor('default');
				BEngine.Controls.disableSelection(this.panel.div);
				var obj = this;
				this.panel.addEvent('mousemove',function(x,y){
					if (obj.movingType == 'horizontal'){
						var pos = BEngine.Controls.divPosition(obj.movingDiv);
						BEngine.Controls.modifyDiv(obj.slideDiv,x-2,pos[1],null,null,4,obj.movingDiv.clientHeight);
					}
					if (obj.movingType == 'vertical'){
						var pos = BEngine.Controls.divPosition(obj.movingDiv);
						BEngine.Controls.modifyDiv(obj.slideDiv,pos[0],y-2,null,null,obj.movingDiv.clientWidth,4);
					}
							
				});
				this.panel.addEvent('mouseup',function(x,y){
					if (obj.movingType == 'horizontal'){
						var pos = BEngine.Controls.divPosition(obj.movingDiv);
						if (obj.callback){
							obj.panel.hide();
							obj.callback(x-pos[0]);
						}
					}
					if (obj.movingType == 'vertical'){
						var pos = BEngine.Controls.divPosition(obj.movingDiv);
						if (obj.callback){
							obj.panel.hide();
							obj.callback(y-pos[1]);
						}
					}					
				});				
			},
			moveHorizontal:function(div,x,callback){
				var pos = BEngine.Controls.divPosition(div);
				BEngine.Controls.modifyDiv(this.slideDiv,pos[0]+x-2,pos[1],null,null,4,div.clientHeight);				
				this.panel.show();
				this.movingType = 'horizontal'
				this.movingDiv = div;
				this.callback = callback;
				this.slideDiv.style.backgroundImage = 'url('+BEngine.mainPath+'bengine/images/dashed.png)';
				this.slideDiv.style.cursor = 'col-resize';
			},
			moveVertical:function(div,y,callback){
				var pos = BEngine.Controls.divPosition(div);
				BEngine.Controls.modifyDiv(this.slideDiv,pos[0],pos[1]+y-2,null,null,div.clientWidth,4);				
				this.panel.show();
				this.movingType = 'vertical'
				this.movingDiv = div;
				this.callback = callback;
				this.slideDiv.style.backgroundImage = 'url('+BEngine.mainPath+'bengine/images/dashedver.png)';
				this.slideDiv.style.cursor = 'row-resize';				
			}
		},
		MovingPanelForWindow:{
			init:function(div){
				this.movingType = null;
				var backParam = new BEngine.Controls.BackParam('transparent');
				this.panel = new BEngine.Controls.Panel({visible:false,clip:false,x:0,y:0,width:div.clientWidth,height:div.clientHeight,backParam:backParam,aRight:true,aBottom:true},div);	
				this.panel.div.style.zIndex = 10000000;
				this.panel.getWorkspaceDiv().style.backgroundImage = 'url(plik_ktory_nie_istniej.png)';
				
				BEngine.Controls.disableSelection(this.panel.div);							
			},
			show:function(movefun,upfun,outfun){
				this.panel.show();
				this.panel.getWorkspaceDiv().onmousemove = function(e){
					var pos = BEngine.Controls.mouseCoordinates(e);
					movefun(pos[0],pos[1]);
				}
				this.panel.getWorkspaceDiv().onmouseup = function(e){
					var pos = BEngine.Controls.mouseCoordinates(e);
					upfun(pos[0],pos[1]);
				}
				this.panel.getWorkspaceDiv().onmouseout = function(e){
					var pos = BEngine.Controls.mouseCoordinates(e);
					outfun(pos[0],pos[1]);
				}				
			},
			hide:function(){
				this.panel.hide();
			}			
		}
	},
	start:function(mainPath){
		mainPath == null?this.mainPath = '':this.mainPath = mainPath;
		this.expandCapabilityPrototype();
		this.Controls.init();

	},
	expandCapabilityPrototype:function(){
		Array.prototype.remove = function(from, to) {
			var rest = this.slice((to || from) + 1 || this.length);
			this.length = from < 0 ? this.length + from : from;
			return this.push.apply(this, rest);
		};
		Array.prototype.removeItem = function(item) {
			for (var i=0;i<this.length;i++){
				if (this[i]==item) {
					this.remove(i);
					break;	
				}	
			}
		};	
		Array.prototype.isItem = function(item) {
			for (var i=0;i<this.length;i++){
				if (this[i]==item) {
					return true;	
				}	
			}
			return false;
		};
		String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ''); }
	}


}


window.setInterval(function () {
	if (wielkiOdliczacz != 0){
		wielkiOdliczacz-=100;
		if (wielkiOdliczacz==0) {
			BEngine.iGML.actualMap.refresh(true);	
		}	
	}
},100);