var CDirectory = {

    inner_click: false,

    highlight: function(element,event) {
        element.className='';
    },

    suspend: function(element,event) {
        element.className = 'suspended';
    },

    movePopup: function(element) {
        element = $(element);
        var target = $('pos_' + element.id);
        target.appendChild(element.cloneNode(true));
        element.remove();
    },

    expand: function(element,event) {
        if (document._currentwnd)
            document._currentwnd.style.display = 'none';

        var po = $(element.getAttribute('popupid'));

        var boxheight = Element.getDimensions(po).height;
        var boxposition = Position.cumulativeOffset(element)[1];
        var ps = pageSize();
        var windowheight = ps.windowHeight;
        var windowscroll = PageScroll().yScroll;
        var diff = boxheight + boxposition - (windowheight + windowscroll);

        if (diff > 0)
            po.parentNode.style.top = "-"+diff+"px";
        else
            po.parentNode.style.top = "0px";

        var img = document.getElementsByClassName("type3-decorimage", po);

        if (img && img.length > 0 && !img[0].src)
            img[0].setAttribute("src", img[0].getAttribute("dsrc"));

        Effect.Grow(po,
                {direction: (element.getAttribute('place') || 'top-left'),
                duration: 0.5,
                afterFinish: function(){}});
        Event.stop(event);

        document.onclick = new Function("event","CDirectory.externalclick(event);");
        document._currentwnd = po;

        this.toggleShadow(po);
    },

    toggleShadow: function(element) {
        var shadow = document.getElementsByClassName('shadowimg', element);
        if (shadow) {
            shadow = shadow[0];
            if ($B('msie < 7') && !shadow.runtimeStyle.filter) {
                shadow.runtimeStyle.filter =
                        "progid:DXImageTransform.Microsoft."
                        + "AlphaImageLoader(src='"
                        + shadow.src + "',sizingMethod='scale')";
                shadow.src = $('nullimg').src;
            }
        }
    },

    close: function(element, event) {
        var po = $(element.getAttribute('popupid'));
        if (po)
            po.hide();

        if (document._currentwnd)
            document._currentwnd = null;
    },

    externalclick: function(event) {
        event = (event || window.event);
        if (Event.isRightClick(event))
            return;
        if (!this.inner_click) {
            if (document._currentwnd) {
                Event.stop(event);
                document._currentwnd.hide();
                document._currentwnd = null;
            }
        } else {
            this.inner_click = false;
        }
    },

    click: function(element,event) {
        this.inner_click = true;
    }
}

function PageScroll(){

    var yScroll;

    if (self.pageYOffset) {
        yScroll = self.pageYOffset;
    } else if (document.documentElement && document.documentElement.scrollTop){  // Explorer 6 Strict
        yScroll = document.documentElement.scrollTop;
    } else if (document.body) {// all other Explorers
        yScroll = document.body.scrollTop;
    }


    return {"yScroll":yScroll};
};


    //
    // getPageSize()
    // Returns array with page width, height and window width, height
    // Core code from - quirksmode.org
    // Edit for Firefox by pHaez
    //
function pageSize() {

    var xScroll, yScroll;

    if (window.innerHeight && window.scrollMaxY) {
        xScroll = document.body.scrollWidth;
        yScroll = window.innerHeight + window.scrollMaxY;
    } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
        xScroll = document.body.scrollWidth;
        yScroll = document.body.scrollHeight;
    } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
        xScroll = document.body.offsetWidth;
        yScroll = document.body.offsetHeight;
    }

    var windowWidth, windowHeight;
    if (self.innerHeight) { // all except Explorer
        windowWidth = self.innerWidth;
        windowHeight = self.innerHeight;
    } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
        windowWidth = document.documentElement.clientWidth;
        windowHeight = document.documentElement.clientHeight;
    } else if (document.body) { // other Explorers
        windowWidth = document.body.clientWidth;
        windowHeight = document.body.clientHeight;
    }

    // for small pages with total height less then height of the viewport
    if(yScroll < windowHeight){
        pageHeight = windowHeight;
    } else {
        pageHeight = yScroll;
    }

    // for small pages with total width less then width of the viewport
    if(xScroll < windowWidth){
        pageWidth = windowWidth;
    } else {
        pageWidth = xScroll;
    }

    return {"pageWidth": pageWidth,
            "pageHeight": pageHeight,
            "windowWidth": windowWidth,
            "windowHeight": windowHeight};
};


Event.isRightClick = function(event) {
    return (((event.which) && (event.which == 2)) ||
            ((event.button) && (event.button == 2)));
};
/*

  onclick="Position.absolutize(this); Effect.Grow(
              this,
              {direction: 'top-center', duration: 0.2})"

*/