Event.observe(window, 'load', function() {
    
    //hide last 2 Borders of related Content
    hideLastBorders('related_content', 2);
    
    //Schnellzugriff Sitemap anpassen
    setSitemapSelect('sidebar');
    
    //set active alternate Stylesheet
    var grau = new AlternateStylesheet('Graustufen', { testElement: $('dashboard'), testColor: '#333333' } );
    
});
Event.observe(window, "load", function(){
var max = 0;
    $("content").select('.single').each(function(element) {         
         max = Math.max(max, element.getHeight());
    });
    $("content").select('.single').each(function(element) {
        element.setStyle({height: max+'px'});
    });
});


function hideLastBorders(ID, count)
{
    var element = $(ID);
    
    var ULs = element.getElementsByTagName('ul');
    for (var x = 0; x < ULs.length; x++) {
        if ( ULs[x].nodeName == 'UL' ) {
            var LIs = ULs[x].getElementsByTagName('li');
             for (var key = 0; key < LIs.length; key++) {
                 if ( LIs[key].nodeName == 'LI' && (LIs.length - key) <= count  ) {
                     LIs[key].style.borderBottom = "none";
                 }
             }
        }
    }
}


var AlternateStylesheet = Class.create({
    
    initialize: function(title, options)
    {
        if (navigator.appName == "Microsoft Internet Explorer") {
            return false;
        }
        this.enabled = false;
        this.title = title;
        this.options = options;
        this.styleSheet = this.getStylesheet();
        if (this.styleSheet) {
            this.setListener();
            this.activate();
        }
    },
    
    getStylesheet: function()
    {
        var links = document.getElementsByTagName('link');
        for (var x = 0; x < links.length; x++) {
            if (links[x].title == this.title) {
                return links[x];
            }
        }
        return false;
    },
    
    activate: function() 
    {
        if (this.checkCookie()) {
            this.styleSheet.disabled = false;
            this.enabled = true;
        }
    },
    
    checkCookie: function()
    {
        if (document.cookie.indexOf(this.title+' enabled') != -1) {
            return true;
        }
        return false;
    },
    
    setCookie: function()
    {
        if (this.styleSheet.disabled == false) {
            if (!this.enabled) {
                document.cookie = this.title+ ' enabled';
                this.enabled = true;
            }
        } else {
            document.cookie = this.title+ ' disabled';
            this.enabled = false;
        }
    },
    
    setListener: function() 
    {
        this.intervalid = window.setInterval( this.setCookie.bind(this), 1000 );
    }
    
});



function setSitemapSelect(CONTAINER_ID)
{
    if (!$(CONTAINER_ID)) {
        return false;
    }
    var sitemap = $(CONTAINER_ID).getElementsByClassName('csc-menu');
    for (var x= 0; x < sitemap.length; x++) {
        sitemap[x].firstChild.firstChild.href='javascript: void(0)';
    }
}