/**
  * The Silk Icon Factory Converter
  * $Id: silk.iconset.js 15 2008-08-18 02:39:24Z sven $
  *
  * `Silk Icons` is a huge iconset with about 1000 PNG files. Using them
  * by the traditional way, e.g.
  *
  * <ul class="dir">
  *    <li class="txt"><a href="textfile.txt">A textfile</a></li>
  *    <li class="png">...</li>
  *    ...
  * </ul>
  *
  * with having a CSS which contains lines like (yes I've had such CSS files)
  *
  * ul.dir  li.dir   { background-image: url(/icons/folder.gif); }
  * ul.sdir li.dir   { background-image: url(/icons/small/folder.gif); }
  * 
  * ul.dir  li.text  { background-image: url(/icons/text.gif); }
  * ul.sdir li.text  { background-image: url(/icons/small/text.gif); }
  * 
  * ul.dir  li.img   { background-image: url(/icons/image2.gif); }
  * ul.sdir li.img   { background-image: url(/icons/small/image2.gif); }
  * 
  * ul.dir  li.box   { background-image: url(/icons/box2.gif); }
  * ul.dir  li.script{ background-image: url(/icons/script.gif); }
  * ul.dir  li.html  { background-image: url(/icons/layout.gif); }
  * ul.dir  li.tar   { background-image: url(/icons/tar.gif); }
  * ul.dir  li.zip   { background-image: url(/icons/compressed.gif); }
  *
  * ...
  *
  * is quite inflexible. Therefore I've written the following small peace of
  * javascript. With it you can simply write
  * 
  * <ul class="icons">
  *    <li class="basket">A basket</li>
  *    <li class="cd_delete">Delete my CD</li>
  *    <li class="cross">Deleted file</li>
  * </ul>
  *
  * On page loading, it will parse your <ul>s and attach all these <li> tags
  * the corresponding silk icon. That's making customization quite comfortable :-)
  *
  * -- Sven, 26.07.2008
  **/

/// icons_pattern: Where the icons are stored...
var icons_pattern = "/src/img/silk.iconset/cross.png";
/// icons_replace: This string will be replaced with the classname of the <li>s.
var icons_replace = /cross/;
/// icons_ul_classname: The classname of the <ul>s which are supposed to contain
///                     silk icon <li>s.
var icons_ul_classname = "icons";
/// icons_generic: Generic icon if no icon for the <li> is set.
var icons_generic = "page";

function ParseIcons() {
    var all_lists = document.getElementsByTagName("ul");
    for(x=0; x<all_lists.length; x++) {
        // ul.icons styles setzen
        if(all_lists[x].className == icons_ul_classname) {
            /*
              common styles for ul.icons:
                margin: 5px;
                padding: 0;
                list-style: none;
            */
            all_lists[x].style.margin = "5px";
            all_lists[x].style.padding = "0";
            all_lists[x].style.listStyle = "none";

            var e = all_lists[x].childNodes;
            for(y=0; y<e.length; y++) {
                // alle li-Nodes durchgehen
                if(!e[y].nodeName || e[y].nodeName != 'LI') continue;
                /*
                  common styles for ul.icons li:
                     padding-left: 20px;
                     background: url(/icons/small/generic.gif) top left no-repeat;
                     line-height: 140%;
                */
                e[y].style.paddingLeft = "20px";
                e[y].style.backgroundPosition = "top left";
                e[y].style.backgroundRepeat = "no-repeat";
                e[y].style.backgroundImage = "url(" + icons_pattern.replace(icons_replace,
                  e[y].className ? e[y].className : icons_generic) + ")";
                // alert(e[y].style.getAttribute("background-image"));
            } // for <li> in <ul>
        } // if <ul class="..">
    } // for <ul>
} // function ParseIcons


if(window.addEventListener) window.addEventListener('load', ParseIcons, false);
else if(window.attachEvent) window.attachEvent("onload", ParseIcons);

