﻿// Author: AlexeyS magen-ta@yandex.ru
// Client file for the SocialShare user control.

document.sharingPopup = {
    id: "",
    closed: true,
    top: null,
    arr: null,
    menu_bd: null,
    menu_hlp: null,
    menu_shadow: null,
    eid: function(id) { return document.getElementById(id); },
    init: function() {
        this.top = this.eid(this.id + "_top");
        this.arr = this.eid(this.id + "_arr");
        this.menu_bd = this.eid(this.id + "_menu_bd");
        this.menu_hlp = this.eid(this.id + "_menu_hlp");
        this.menu_shadow = this.eid(this.id + "_menu_shadow");
    },
    invalidate: function() {
        this.menu_bd.style.top = this.top.offsetHeight - 1 + "px";
        this.menu_bd.style.left = this.top.offsetWidth - this.menu_bd.offsetWidth - 1 + "px";
        this.menu_hlp.style.width = this.top.offsetWidth - 2 + "px";
        this.menu_hlp.style.top = this.top.offsetHeight - 2 + "px";
        this.menu_shadow.style.left = this.menu_bd.style.pixelLeft + 2 + "px";
        this.menu_shadow.style.width = this.menu_bd.style.width;
        this.menu_shadow.style.height = this.menu_bd.style.pixelTop + this.menu_bd.offsetHeight + "px";
    },
    open: function() {
        this.top.className = "link_text horz_li share_top_opened";
        this.arr.className = "up_arrow";
        this.menu_bd.className = "menu-bd-opened";
        this.menu_hlp.className = "menu-hlp-opened";
        this.menu_shadow.className = "menu-shadow-opened";
        this.invalidate();
        this.closed = false;
    },
    close: function() {
        this.eid(this.id + "_top").className = "link_text horz_li share_top_closed";
        this.eid(this.id + "_arr").className = "down_arrow";
        this.eid(this.id + "_menu_bd").className = "menu-bd-closed";
        this.eid(this.id + "_menu_hlp").className = "menu-hlp-closed";
        this.eid(this.id + "_menu_shadow").className = "menu-shadow-closed";
        this.closed = true;
    },
    sw: function() { if (this.closed) this.open(); },
    mouseup: function() { if (!document.sharingPopup.closed) window.setTimeout("document.sharingPopup.close();", 100); return true; },
    attach: function(item, h, eventname) {
        if (item && item.attachEvent)
            item.attachEvent("on" + eventname, h);
        else if (item && item.addEventListener)
            item.addEventListener(eventname, h, false);
    },
    run: function(id) { this.id = id; this.init(); this.attach(document, this.mouseup, "mouseup"); }

}