Array.prototype.in_array = function (element) {
    for (var values in this) {
        if (this[values] == element)
            return true;
    }
    return false;
};


var toLoadJsObjects = [];
$$('script').findAll( function(s) {
  return (s.src && s.src.match(/default\.js(\?.*)?$/))
}).each( function(s) {
    var loadItems = s.src.match(/\?.*load=([a-z,]*)/i);
    if ((loadItems) && loadItems[1]) {
        loadItems[1].split(',').each(function(element) {
            toLoadJsObjects.push(element);
        });
    }
});


var ErdeeLayout = Class.create();

ErdeeLayout.prototype = {
    
    wideContentFrame        : null,
    
    // constructor
    initialize              : function(wideContentFrame)
    {
        this.wideContentFrame = wideContentFrame;
        this.correctMultiColLayout();
    },
    
    correctMultiColLayout   : function()
    {
        try {
            var $contentFrameDiv = $(this.wideContentFrame);
            if ($('left_frame_div').getHeight() > $('main_frame_div').getHeight())
                $('main_frame_div').setStyle({'height' : $('left_frame_div').getHeight() + 'px'});
            if ($contentFrameDiv.getHeight() > $('main_frame_div').getHeight())
                $('main_frame_div').setStyle({'height' : $($contentFrameDiv).getHeight()+10 + 'px'});
            if (!$contentFrameDiv.id.endsWith('wide')) {
                if ($('right_frame_div').getHeight() > $('main_frame_div').getHeight())
                    $('main_frame_div').setStyle({'height' : $('right_frame_div').getHeight() + 'px'});
            }
            /* set the height of the right inner frame if needed */
            if ($('right_frame_div').className.match(/right_blue_bg$/i)) {
                highestSide = 0;
                var items = new Array('left_frame_div',$contentFrameDiv,'right_frame_div');
                items.each(function(element) {
                    if($(element).getHeight() > highestSide)
                        highestSide = $(element).getHeight();
                });
                $('right_frame_div').style.height = highestSide + 'px';
            }
        } catch (error) {}
            
      
    }
}


function TopMenu()
{
    this.container_div_id = 'top_nav_div';
    this.top_menu_prefix  = 'top_menu_parent';  
    this.timeoutId = null;
    this.config = {};
};

Object.extend(TopMenu.prototype, 
{
    init : function()
    {
        try {
            if ((arguments) && arguments.length > 0) 
                this.config = arguments[0];
            $$('#' + this.container_div_id + ' table td').each(function(parentItem) {    
                if (parentItem.firstChild) {
                    $A(parentItem.firstChild.childNodes).each(function(item) {      
                        if (item.nodeName.match(/li/i)) {
                            if ((item.lastChild) && item.lastChild.nodeName.match(/ul/i)) {
                                item.className += " over";
                                myTopMenu.defineSubmenus(item);
                                item.className = item.className.replace(/\s*over/i, "");
                            }
                            item.onmouseover = function() {
                                if (!item.className.empty()) {
                                   item.className += " over";
                                } else {
                                    item.className = "over";
                                }
                            }
                            item.onmouseout = function() {
                                this.className = this.className.replace(/\s*over/i, "");
                            }
                            /* correct dummy links */
                            if (item.firstChild.href == '#') {
                                item.firstChild.onclick = function(event){
                                    Event.stop(event);
                                }
                            }
                        }
                    });
                }
            });
        } catch(error) {}
    },
    
    defineSubmenus : function(parentItem)
    {
        var maxWidth = 0;
        // define the max width
        $A(parentItem.lastChild.childNodes).each(function(subElement) {
            if ((!subElement.firstChild.style || !subElement.firstChild.style.width) && (subElement.firstChild.offsetWidth > maxWidth))
                if (parentItem.firstChild.offsetWidth <= subElement.firstChild.offsetWidth) {
                    maxWidth = subElement.firstChild.offsetWidth;
                } else {
                    maxWidth = parentItem.firstChild.offsetWidth;
                }
            subElement.onmouseover = function() {
                subElement.className += " over";
            }
            subElement.onmouseout = function(){
                subElement.className = subElement.className.replace(/ ?over/, '');
            }
            /* correct dummy links */
            if (subElement.firstChild.href == '#') {
                subElement.firstChild.onclick = function(e) {
                    Event.stop(e);
                }
            }
        });
        // set the max width
        if (maxWidth > 0) {
            //parentItem.style.width = maxWidth + 'px';
            parentItem.firstChild.style.display = 'block';
            //parentItem.firstChild.style.width = maxWidth + 'px';
            $A(parentItem.lastChild.childNodes).each(function(subElement) {
                subElement.style.width = maxWidth + 'px';
                subElement.firstChild.style.display = 'block';
                subElement.firstChild.style.width = maxWidth + 'px';
            });
        }
    }
});

function initTopMenu() {
    myTopMenu = new TopMenu();
    myTopMenu.init();
}

if ((toLoadJsObjects.length < 1) || toLoadJsObjects.in_array('TopMenu'))
    document.observe("dom:loaded", initTopMenu);

function SiteMenu()
{
    this.container_div_id = 'site_nav_div';
    this.top_menu_prefix  = 'nav_site_menu';  
    this.timeoutId = null;
};

Object.extend(SiteMenu.prototype, 
{
    init : function()
    {
        try {
            if ((arguments) && arguments.length > 0)
                this.container_div_id = arguments[0];
            
            var parentContainer = $(this.container_div_id);
            $A(parentContainer.childNodes).each(function(parent) {
                $A(parent.firstChild.childNodes).each(function(item) {
                    if (item.nodeName.match(/li/i)) {
                        item.onmouseover = function() {
                            if (!item.className) {
                               item.className += " over";
                            } else {
                                item.className = "over";
                            }
                            //item.style.zIndex = 20;
                            if ((item.firstChild.nextSibling) && item.firstChild.nextSibling.nodeName.match(/ul/i))  
                                 mySiteMenu.defineSubmenus(item);
                        }
                        item.onmouseout = function() {
                            this.className = this.className.replace(/\s*over/i, "");
                        }
                    }
                });
            });
        } catch(error) {}
    },
    
    defineSubmenus : function(parentItem)
    {
        var maxWidth = 0;
        // define the max width
        $A(parentItem.lastChild.childNodes).each(function(subElement) {  
            if (subElement.firstChild.offsetWidth > maxWidth)
                maxWidth = subElement.firstChild.offsetWidth;
            subElement.onmouseover = function() {
                if (!subElement.className.empty()) {
                   subElement.className += " over";
                } else {
                    subElement.className = "over";
                }
                //subElement.style.zIndex = 50;
            }
            subElement.onmouseout = function() {
                subElement.className = subElement.className.replace(/\s*over/i, "");
            }
        });
        // set the max width
        $A(parentItem.lastChild.childNodes).each(function(subElement) {
            subElement.style.width = (maxWidth + 6) + 'px';
            if (subElement.firstChild && subElement.firstChild.nodeName == 'A') {
                subElement.firstChild.style.display = 'block';
                subElement.firstChild.style.width = maxWidth + 'px';
                if (subElement.firstChild.nextSibling && subElement.firstChild.nextSibling.nodeName == 'UL') {
                    subElement.firstChild.nextSibling.style.left = (maxWidth + subElement.firstChild.offsetLeft * 2 + 6) + 'px';
                    subElement.firstChild.nextSibling.style.width = maxWidth + 'px';
                    subElement.firstChild.nextSibling.firstChild.firstChild.style.width = maxWidth + 'px';
                    subElement.firstChild.nextSibling.style.width = 'auto';
                    mySiteMenu.defineSubmenus(subElement);
                }
            }
        });
    }
});

function initSiteMenu() {
    mySiteMenu = new SiteMenu();
    mySiteMenu.init();
}

if ((toLoadJsObjects.length < 1) || toLoadJsObjects.in_array('SiteMenu'))
    if (!location.search.match(/menutest=(1|\w)/))
        document.observe("dom:loaded", initSiteMenu);

AdPlacer = {

    start : function() {
            /* move zones */
            $$('div.ad').each(
                function (item)
                {
                    try {
                        if (!item.hasChildNodes() && item.id && item.id.match(/^ad_placeholder_zone_[0-9a-f]+/)) {
                            /* extract zone id */
                            var $matches = item.id.match(/^ad_placeholder_zone_([0-9a-f]+)/)
                            var $zoneId = $matches[1];
                            var $adElement = item.parentNode;
                            while (($adElement.nodeName != 'BODY') && (!$adElement.className || !$adElement.className.match(/Common_Ad/)))
                                $adElement = $adElement.parentNode;
                            if ($adElement.nodeName == 'BODY')
                                $adElement = null;
                            /* move ad */
                            if ($('ad_store') && $('ad_store_zone_' + $zoneId)) {
                                /* hide zone if no ad content */
                                if (!$adElement.className.match(/Common_Ad_DQnA/) && !$$('#ad_store_zone_' + $zoneId + ' > *:not(script):not(noscript):not([id^=beacon])').length) {
                                    $adElement.style.display = 'none';
                                } else {
                                    /* check if image and if normal size */
                                    if (
                                        !$$('#ad_store_zone_' + $zoneId + ' > object').length
                                            &&
                                        ($$('#ad_store_zone_' + $zoneId + ' > a > img').length == 1)
                                    ) {
                                        var $list = $$('#ad_store_zone_' + $zoneId + ' > a > img');
                                        var $el = $list[0];
                                        if ($el.height && ($el.height <= 1)) {
                                            $adElement.style.display = 'none';
                                        } else {
                                            $adElement.style.display = 'block';
                                        }
                                    } else {
                                        $adElement.style.display = 'block';
                                    }
                                }
                                /* move it */
                                item.appendChild($('ad_store_zone_' + $zoneId));
                                /* trigger IE6 render update */
                                if (navigator.userAgent.match(/\([^\)]*\bMSIE\s*6\./) && $adElement.nextSibling)
                                    setTimeout('document.getElementById("' + $adElement.nextSibling.id + '").hide().show();', 1000);
                            }
                        }
                    } catch(error) {
                    }
                }
            );
        }

}

if ((toLoadJsObjects.length < 1) || toLoadJsObjects.in_array('AdPlacer')) {
	 Event.observe(window, 'load', function() {
		AdPlacer.start
	}); 
}
    
/* Window functions */
windowInnerWidth = 500;
windowInnerHeight = 500;

windowOuterWidth = 500;
windowOuterHeight = 500;

function InnerWindowGet()
{
    /* from a script by Jan Peter Koch - quirksmode.org */
    if (window.innerHeight) {
        /* all except Explorer */
    	windowInnerWidth = window.innerWidth;
    	windowInnerHeight = window.innerHeight;
    } else if (document.documentElement && document.documentElement.clientHeight) {
        /* Explorer 6 Strict Mode */
    	windowInnerWidth = document.documentElement.clientWidth;
    	windowInnerHeight = document.documentElement.clientHeight;
    } else if (document.body) {
        /* other Explorers */
    	windowInnerWidth = document.body.clientWidth;
    	windowInnerHeight = document.body.clientHeight;
    }
    return new Array(windowInnerWidth, windowInnerHeight);
}

function OuterWindowSet(theWidth, theHeight)
{
    window.resizeTo(theWidth, theHeight);
    windowOuterWidth = theWidth;
    windowOuterHeight = theHeight;
    /* recalc inner size */
    InnerWindowGet();
    return new Array(windowOuterWidth, windowOuterHeight);
}

function ResizeWindow()
{
    /* parse params */
    myWishedWidth = 'auto';
    myWishedHeight = 'auto';
    if (ResizeWindow.arguments.length > 0) {
        myWishedWidth = ResizeWindow.arguments[0];
    }
    if (ResizeWindow.arguments.length > 1) {
        myWishedHeight = ResizeWindow.arguments[1];
    }
    if (ResizeWindow.arguments.length > 2) {
        myDiv = document.getElementById(ResizeWindow.arguments[2]);
    } else {
        myDiv = document.getElementById('site_frame_div_id');
    }
    /* determine sizing */
    if (myWishedWidth == 'auto') {
        myWishedWidth = myDiv.offsetWidth + 2 * myDiv.offsetLeft + document.body.offsetLeft;
    }
    if (myWishedHeight == 'auto') {
        myWishedHeight = myDiv.offsetHeight + 2 * myDiv.offsetTop + document.body.offsetTop;
    }
    /* resize */
    OuterWindowSet(myWishedWidth, myWishedHeight);
    myWidth = 2 * myWishedWidth - windowInnerWidth;
    myHeight = 2 * myWishedHeight - windowInnerHeight;
    /* remove scrollbars */
    OuterWindowSet(myWidth + 40, myHeight + 40);
    /* correct size */
    OuterWindowSet(myWidth + 1, myHeight + 1);
    /* correct for screen resolution */
    myResCorrect = false;
    if (screen && screen.availWidth && (windowOuterWidth > screen.availWidth)) {
        myResCorrect = true;
        windowOuterWidth = screen.availWidth;
    }
    if (screen && screen.availHeight && (windowOuterHeight > screen.availHeight)) {
        myResCorrect = true;
        windowOuterHeight = screen.availHeight;
    }
    if (myResCorrect) {
        OuterWindowSet(windowOuterWidth, windowOuterHeight);
        window.moveTo(0, 0);
    }
}

function topNavDivAdjust()
{
	try {
        var topNavDivOverFlow = false;
        if ($('top_nav_div_left').offsetHeight >= ($$('#top_nav_div td > ul > li').first().offsetHeight * 1.25))
                topNavDivOverFlow = true;
        if (topNavDivOverFlow) {
            var topNavDivNeededWidth = 0;
            $$('#top_nav_div td > ul > li').each(function(item){
                topNavDivNeededWidth += item.getWidth() + 1;
            });
            $('top_nav_div_left').setStyle({width : topNavDivNeededWidth + 'px'});
            $('top_nav_div').setStyle({width : topNavDivNeededWidth + 'px'});
        }
    } catch (error) {
    }
}
