var AcidCMS = {
    Version: '0.1',
    Singleton: { _singletonOf: {} }
};

AcidCMS.Menue           = Class.create()
AcidCMS.Menue.prototype = {
    initialize: function(id, subMenue) {
        if(subMenue) {
            Event.observe(id,       'mouseover', this.openMenue.bindAsEventListener(this),       true);
            Event.observe(id,       'mouseout',  this.checkCloseMenue.bindAsEventListener(this), true);
            this.subMenue   = subMenue;
            Object.extend(id, this);
        }
    },
    openMenue: function () {
        Element.show(this.subMenue);
    },
    checkCloseMenue: function (event) {
        var pointerX      = event.pointerX;
        var pointerY      = event.pointerY;
        if (    ! Position.within(this,          pointerX, pointerY)
             && ! Position.within(this.subMenue, pointerX, pointerY)) {
             this.closeMenue();
        }
    },
    closeMenue: function () {
        Element.hide(this.subMenue);
    }
};

AcidCMS.Singleton.iFrame = Class.create();
AcidCMS.Singleton.iFrame.prototype = {
    initialize: function() {
        this.iFrames = $A([]);
        AcidCMS.Singleton._singletonOf.iFrame = this;
    },
    singleton:  function() {
        return AcidCMS.Singleton._singletonOf.iFrame
            ? AcidCMS.Singleton._singletonOf.iFrame
            : new AcidCMS.Singleton.iFrame();
    },
    addIFrame: function(iFrame) {
        this.iFrames.push(iFrame);
    }
};

AcidCMS.iFrame = Class.create();
AcidCMS.iFrame.prototype = {
    initialize: function(id) {
        this.id = id;
        AcidCMS.Singleton.iFrame.prototype.singleton().addIFrame(this);
    },
    maximizeHeight: function() {
        var iFrame  = $(this.id);
        if (iFrame) {
            var iFrameDocument = iFrame.contentDocument
                ? iFrame.contentDocument             // W3C compliant (Mozilla)
                : document.frames[this.id].document; // Internet Explorer
             var iFrameHeight = iFrameDocument.body.scrollHeight > iFrameDocument.body.offsetHeight
                ? iFrameDocument.body.scrollHeight
                : iFrameDocument.body.offsetHeight;
            // magic 35px used as workaround for wrong browser data
            iFrame.setStyle({ height: iFrameHeight + 35 + 'px' });
        }
    }
};
AcidCMS._block = false;
function reCalculate() {
    if (AcidCMS._block) return;
    AcidCMS._block = true;
    if (AcidCMS.Singleton._singletonOf.iFrame && AcidCMS.Singleton._singletonOf.iFrame.iFrames) {
        AcidCMS.Singleton._singletonOf.iFrame.iFrames.each(
            function (iFrame) {
                iFrame.maximizeHeight();
            }
        );
    }
    var bodyHeight = document.body.scrollHeight > document.body.offsetHeight
         ? document.body.scrollHeight
         : document.body.offsetHeight;
    $('leftC').setStyle({ height: document.documentElement.scrollHeight - 105 + 'px' });
    AcidCMS._block = false;
}

Event.observe(window, 'load', reCalculate, false);
Event.observe(window, 'resize', reCalculate, false);
