//----------------------------------------------------------
//     _              _
//  __| |___ _ __    (_)___
// / _` / _ \ '  \ _ | (_-<
// \__,_\___/_|_|_(_)/ /__/
//                 |__/
//
//----------------------------------------------------------
// File      : dom.js
// Author    : Richard Lewis
// Project   : /mnt/web/localhost/htdocs/js/lib/
// Syntax    : javascript
// Date      : Mon 11 Feb 2008
// Copyright : Richard Lewis 2008
//----------------------------------------------------------
// dom.js - dom functions
//----------------------------------------------------------

function goMusic() {
    // music

    setupMusic();
}
//----------------------------------------------------------

function setupMusic() {
    // setup music

    var musicHolder = crtEle('div');
    musicHolder.style.width    = '32px';
    musicHolder.style.cssFloat = 'right';

    var blank = crtEle('div');
    blank.style.width    = '32px';
    blank.style.cssFloat = 'left';

    var img    = crtEle('img');
    img.src    = '/img/beautifulbalms/music.png';
    img.alt    = 'Beautiful Balms Music';
    img.title  = 'Beautiful Balms Music';
    img.width  = '32';
    img.height = '32';

    var a         = crtEle('a');
    a.href        = '/beautiful-balms-music.htm';
    a.title       = 'Beautiful Balms Music';
    a.target      = '_top';

    a.appendChild(img);
    musicHolder.appendChild(a);

    var header = getEle('header');

    header.insertBefore(blank, header.firstChild);
    header.insertBefore(musicHolder, header.firstChild);
}
//----------------------------------------------------------

function getEle(id) {
    // get document element by id

    if (document.getElementById(id))
        return document.getElementById(id);
    return false;
}
//----------------------------------------------------------

function crtEle(tag) {
    // create a document element from a tag

    if (document.createElement(tag))
        return document.createElement(tag);
    return false;
}
//----------------------------------------------------------

function crtTxt(txt) {
    // create textnode

    if (document.createTextNode)
        return document.createTextNode(txt);
    return false;
}
//----------------------------------------------------------

function nbsp(count) {
    // non breaking space

    var spc = "\u00a0";
    var spaces = new Array();

    for (var k = 0; k < count; ++k)
        spaces.push(spc);

    return crtTxt(spaces.join(""));
}
//----------------------------------------------------------

function br() {
    // return a line break

    var lb = crtEle('br');

    return lb;
}
//----------------------------------------------------------

function hr() {
    // return a hr

    var div = crtEle('div');

    div.className = "hr";

    return div
}
//----------------------------------------------------------

function clrEle(ele) {
    // clear element

    while(ele.firstChild)
        ele.removeChild(ele.firstChild);
}
//----------------------------------------------------------

function createXreq() {
    // create an X request

    if (window.XMLHttpRequest) {
        // Mozilla
        var xreq = new XMLHttpRequest();

        xreq.overrideMimeType('text/html');

        return xreq;
    }
    else if (window.ActiveXObject) {
        // IE

        return new ActiveXObject("Microsoft.XMLHTTP");
    }
    else { return false; }
}
//----------------------------------------------------------

//if (window.addEventListener)
//    window.addEventListener("load", goMusic, false);
//
//else if (window.attachEvent)
//    window.attachEvent("onload", goMusic);
//----------------------------------------------------------
