/******************************************************************************
 * LOTS (Leipzig Online Training System)                                      *
 *     Copyright (C) (2007) University Leipzig (Germany) - Database Group     *
 *                                                                            *
 *     This program is free software; you can redistribute it and/or modify   *
 * it under the terms of the GNU General Public License as published by the   *
 * Free Software Foundation; either version 2 of the License, or (at your     *
 * option) any later version.                                                 *
 *                                                                            *
 *     This program is distributed in the hope that it will be useful, but    *
 * WITHOUT ANY WARRANTY; without even the implied warranty of                 *
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General   *
 * Public License for more details.                                           *
 *                                                                            *
 *     You should have received a copy of the GNU General Public License      *
 * along with this program; if not, write to the Free Software Foundation,    *
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA                   *
 *                                                                            *
 * Contact:                                                                   *
 *     Prof. Dr.-Ing. Erhard Rahm                                             *
 *     Leipzig University - Database Group                                    *
 *     P.O. Box 100920                                                        *
 *     04009 Leipzig                                                          *
 *     Germany                                                                *
 *                                                                            *
 * e-mail: rahm@informatik.uni-leipzig.de                                     *
 * WWW: http://dbs.uni-leipzig.de                                             *
 * SourceForge: http://lots.sourceforge.net                                   *
 ******************************************************************************/

/*
    This script add drop shadows to various HTML elements.

    After ideas from Roger Johansson, http://www.456bereastreet.com/
*/
var dropShadow = {

    init : function() {

        // Check for DOM support
        if (!document.getElementsByClassName || !document.createElement) {
            return;
        }

        dropShadow.initHeader();
        dropShadow.initMainNavi();
        dropShadow.initBoxes();
        dropShadow.initHeadLines();
    },

    initHeader : function() {

        // Create drop shadows on the header
        var pageHead = document.getElementById("page-head");
        if (pageHead) {
            var leftShadow = document.createElement("div");
            leftShadow.id = "page-head-shadow-left";
            pageHead.appendChild(leftShadow);

            var rightShadow = document.createElement("div");
            rightShadow.id = "page-head-shadow-right";
            pageHead.appendChild(rightShadow);

            var uniShadow = document.createElement("div");
            uniShadow.id = "page-head-uni-shadow";
            pageHead.appendChild(uniShadow);
        }
    },

    initMainNavi : function() {

        // Create drop shadows on the main navi
        var pageNavi = document.getElementById("page-navi");
        if (pageNavi) {
            var leftShadow = document.createElement("div");
            leftShadow.id = "page-navi-shadow-left";

            var rightShadow = document.createElement("div");
            rightShadow.id = "page-navi-shadow-right";

            pageNavi.parentNode.replaceChild(rightShadow, pageNavi);
            rightShadow.appendChild(leftShadow);
            leftShadow.appendChild(pageNavi);
        }
    },

    initBoxes : function() {

        // Create drop shadows on boxes
        var boxes = document.getElementsByClassName("box", null);
        for (var i = 0; i < boxes.length; i++) {
            var box = boxes[i];

            // Create the dropshadowbox
            var dropShadowBox = document.createElement("div");
            dropShadowBox.className = "dropshadowbox";

            // Create the top left box
            var tl = document.createElement("div");
            tl.className = "topleft";

            // Create the top right box
            var tr = document.createElement("div");
            tr.className = "topright";

            // Create the bottom left box
            var bl = document.createElement("div");
            bl.className = "bottomleft";

            // Replace the old box with the dropshadowbox
            box.parentNode.replaceChild(dropShadowBox, box);

            // Put the old box into the dropshadowbox
            dropShadowBox.appendChild(bl);
            bl.appendChild(tl);
            tl.appendChild(tr);
            tr.appendChild(box)
        }

    },

    initHeadLines : function() {

        // Create drop shadows on all h2 headlines in the right content
        var contentRight = document.getElementById("content-right");
        if (contentRight) {
            var headlines = contentRight.getElementsByTagName("h2");
            for (var i = 0; i < headlines.length; i++) {
                var headline = $(headlines[i]);
                var parentOfHeadline = headline.up();

                // Process only direct children of content-right
                if (parentOfHeadline == contentRight ||
                    parentOfHeadline.nodeName.toLowerCase() == "form" ||
                    parentOfHeadline.hasClassName("show") ||
                    parentOfHeadline.hasClassName("column")) {

                    // Create the dropshadowbox
                    var dropShadowHeadline = document.createElement("div");
                    if (headline.className == "") {
                        dropShadowHeadline.className = "dropshadowheadline";
                    } else {
                        dropShadowHeadline.className = "dropshadowheadline " + headline.className;
                    }

                    // Create the top left box
                    var tl = document.createElement("div");
                    tl.className = "topleft";

                    // Create the top right box
                    var tr = document.createElement("div");
                    tr.className = "topright";

                    // Create the bottom left box
                    var bl = document.createElement("div");
                    bl.className = "bottomleft";

                    // Replace the old box with the dropshadowheadline
                    headline.parentNode.replaceChild(dropShadowHeadline, headline);

                    // Put the old box into the dropshadowheadline
                    dropShadowHeadline.appendChild(bl);
                    bl.appendChild(tl);
                    tl.appendChild(tr);
                    tr.appendChild(headline)
                }
            }
        }
    }
}

addEvent(window, 'load', function() {
    dropShadow.init();
});