var vvcalendar = {
        c: document.createElement("DIV"),
        canvas: null,
        options: {
                vvcalid: "vvcid",
                content: "vvcal-html",
                max_width: ""
                },

        init: function() {
                vvcalendar.canvas = document.getElementsByTagName(document.compatMode && document.compatMode == "CSS1Compat" ? "HTML" : "BODY")[0];
                vvcalendar.c.setAttribute("id", "vvcalendar");
                document.body.appendChild(vvcalendar.c);
                vvcalendar.h();
                if (document.getElementById(vvcalendar.options.vvcalid)){
                        vvcalendar.l(document.getElementById(vvcalendar.options.vvcalid), "click", vvcalendar.d);
                     }
                },

         a: function(x, y){
                var w_width = vvcalendar.canvas.clientWidth ? vvcalendar.canvas.clientWidth + vvcalendar.canvas.scrollLeft : window.innerWidth + window.pageXOffset;
                var w_height = window.innerHeight ? window.innerHeight + window.pageYOffset : vvcalendar.canvas.clientHeight + vvcalendar.canvas.scrollTop;

                if (document.all && document.all.item && !window.opera) vvcalendar.c.style.width = vvcalendar.options.max_width && vvcalendar.c.offsetWidth > vvcalendar.options.max_width ? vvcalendar.options.max_width + "px" : "auto";

                var t_width = vvcalendar.c.offsetWidth;
                var t_height = vvcalendar.c.offsetHeight;

                vvcalendar.c.style.left = x + "px";
                vvcalendar.c.style.top = y + "px";

                if (x + t_width > w_width) vvcalendar.c.style.left = w_width - t_width + "px";
                if (y + t_height > w_height) vvcalendar.c.style.top = w_height - t_height + "px";
        },
        l: function(o, e, a){
                if (o.addEventListener) o.addEventListener(e, a, false);
                else if (o.attachEvent) o.attachEvent("on" + e, a);
                        else return null;
        },
        h: function(e){
                if (typeof vvcalendar == "undefined") return;
                vvcalendar.c.innerHTML = "";
                document.getElementById(vvcalendar.options.vvcalid).innerHTML = "календаря";
                vvcalendar.c.style.visibility = "hidden";
                vvcalendar.a(-99, -99);

        },
        d: function(e){
                if (vvcalendar.c.style.visibility == "visible") vvcalendar.h(e);
                else vvcalendar.s(e);

        },
        s: function(e){
                if (typeof vvcalendar == "undefined") return;
                var d = window.event ? window.event.srcElement : e.target;
                if (!d) return;

                vvcalendar.c.innerHTML = document.getElementById(vvcalendar.options.content).innerHTML;
                document.getElementById(vvcalendar.options.vvcalid).innerHTML = "календаря&nbsp;(скрыть)&gt;";
                vvcalendar.c.style.visibility = "visible";
                var x = d.offsetLeft;
                var y = d.offsetTop + d.offsetHeight;
                vvcalendar.a(x+250, y-70);

        }
        }

var root = window.addEventListener || window.attachEvent ? window : document.addEventListener ? document : null;
if (root){
        if (root.addEventListener) root.addEventListener("load", vvcalendar.init, false);
        else if (root.attachEvent) root.attachEvent("onload", vvcalendar.init);
}