﻿// This JScript file supports the TheUniverseLiesWithin site.
//alert('here');


//  To put this back into the page add ...
//  onclick="changeBannerViaCSS('Body_BigImage');"
//  to the <div id="Body_BigImage"> tag
var Idx = 0;
var myBanners = new Array();
myBanners[Idx] = "PlanetGirlWithGarland_Green3.jpg"; Idx = Idx + 1;
myBanners[Idx] = "PlanetGirlWithGarland_v10.jpg"; Idx = Idx + 1;
myBanners[Idx] = "PlanetGirlWithGarland_Green.jpg"; Idx = Idx + 1;
myBanners[Idx] = "PlanetGirlWithGarland_Green2.jpg"; Idx = Idx + 1;
myBanners[Idx] = "PlanetGirlWithGarland_Green3_Words.jpg"; Idx = Idx + 1;
myBanners[Idx] = "PlanetGirlWithGarland_Green3_Words_Light.jpg"; Idx = Idx + 1;

myBanners[Idx] = "PlanetGirlWithGarland_v06.jpg"; Idx = Idx + 1;
myBanners[Idx] = "PlanetGirlWithGarland_v07.jpg"; Idx = Idx + 1;
myBanners[Idx] = "PlanetGirlWithGarland_v08.jpg"; Idx = Idx + 1;

myBanners[Idx] = "PlanetGirlWithGarland_v09.jpg"; Idx = Idx + 1;
myBanners[Idx] = "PlanetGirlWithGarland_V01.jpg"; Idx = Idx + 1;
myBanners[Idx] = "PlanetGirlWithGarland_V02.jpg"; Idx = Idx + 1;
myBanners[Idx] = "PlanetGirlWithGarland_V03.jpg"; Idx = Idx + 1;
myBanners[Idx] = "PlanetGirlWithGarland_V04.jpg"; Idx = Idx + 1;
myBanners[Idx] = "PlanetGirlWithGarland_V05.jpg"; Idx = Idx + 1;

myBanners[Idx] = "PlanetGirlWithGarland_Blue.jpg"; Idx = Idx + 1;
myBanners[Idx] = "PlanetGirlWithGarland_Blue_Words.jpg"; Idx = Idx + 1;
myBanners[Idx] = "PlanetGirlWithGarland_Brown.jpg"; Idx = Idx + 1;
myBanners[Idx] = "PlanetGirlWithGarland_Brown_Words.jpg"; Idx = Idx + 1;
myBanners[Idx] = "PlanetGirlWithGarland_Red.jpg"; Idx = Idx + 1;
Idx = -1;

// setStyleById: given an element id, style property and 
// value, apply the style.
// args:
//  i - element id
//  p - property
//  v - value
//
function setStyleById(i, p, v) {
    var n = document.getElementById(i);
    n.style[p] = v;
}

function changeBannerViaCSS(divName) {
    //alert('here in changeBannerViaCSS(' + divName + ')');
    var oDiv = document.getElementById(divName);
    //alert(oDiv.style['backgroundImage'].value);
    Idx = Idx + 1;
    if (Idx >= myBanners.length) {
        Idx = 0;
    }
    var sImageValue;
    sImageValue = 'url("images/' + myBanners[Idx] + '")';
    //alert(sImageValue);
    setStyleById(divName, 'backgroundImage', sImageValue);

    var oTextPlace = document.getElementById("GarlandX");
    oTextPlace.innerHTML = Idx + '  ' + sImageValue;
    //works - - setStyleById(divName, 'backgroundImage', 'url("images/PlanetGirlWithGarland_Green.jpg")');
    //alert(oDiv);
    //var myStyle = oDiv.style;
    //var fFamily = myStyle             //.background_image;
    //alert(divName+" with ':\nfamily: "  + fFamily );

}


function changeBannerImage() 
{
    //    alert('here');
    var myBanners = new Array();
    myBanners[0] = "PlanetGirlWithGarland_Blue.jpg";
    myBanners[1] = "PlanetGirlWithGarland_Brown.jpg";
    myBanners[2] = "PlanetGirlWithGarland_Green.jpg";
    myBanners[3] = "PlanetGirlWithGarland.jpg";
    myBanners[4] = "PlanetGirlWithGarland_Blue.jpg";
    myBanners[5] = "PlanetGirlWithGarland_Blue.jpg";
    //myBanners[0] = "Image1.jpg";
    //myBanners[1] = "Image2.jpg";
    //myBanners[2] = "Image3.jpg";
    //myBanners[3] = "Image4a.jpg";
    //myBanners[4] = "Image5.jpg";
    //myBanners[5] = "Image6.jpg";
    //myBanners[6] = "Image7.jpg";
    //myBanners[7] = "Image8.jpg";
    //myBanners[8] = "Image9.jpg";
    //myBanners[9] = myBanners[0];

    //alert('here');
    var oImg = document.getElementById("HeaderPic");
    var sVal = oImg.getAttribute("src")
    //alert(oImg);
    //alert(sVal);
    //alert(oImg);
    //alert('='+oImg.style.backgroundImage+'=');

    newImage = "url(images/" + myBanners[Idx] + ")";
    //alert('=' + newImage + '=');
    oImg.style.backgroundImage = newImage;
    Idx = Idx + 1;
    if (Idx >= myBanners.length) {
        Idx = 0;
    }
    
    var i=0;
    while (i <= myBanners.length) {
        var myRegExp = myBanners[i];
        var matchPos1 = sVal.search(myRegExp);
        if (matchPos1 != -1) 
        {
            //  Tell the user which image is being displayed.
            var oLabel = document.getElementById("PicName");
            oLabel.innerHTML = myBanners[i+1];
            //oImg.style.background = "background-image: url('images/" + myBanners[i + 1] + "')";
            //oImg.style.backgroundImage = "url('images/" + myBanners[i + 1] + "')";
            newImage = "url('images/Image3.jpg')";
            //oImg.style.background=newImage;
            oImg.style.backgroundImage=newImage;
            //alert(oImg.style.background);
            
            // Set the image 
            sVal = sVal.replace(myBanners[i], myBanners[i + 1])
            //  alert(myBanners[i] + ' had a match - so move to ' + sVal);
            /////oImg.setAttribute("src", sVal);
            
            //max the index to just ont of the loop
            i = myBanners.length + 1;
        } //if

        i++;
    }  //  while



/*
    // Rotate Images between
    if (sVal == 'images/Banner_Trees.jpg')      { oImg.setAttribute("src", "images/Banner_Berries.jpg"); }
    if (sVal == 'images/Banner_Flowers3.jpg')   { oImg.setAttribute("src", "images/Banner_Trees.jpg"); }
    if (sVal == 'images/Banner_Flowers2.jpg')   { oImg.setAttribute("src", "images/Banner_Flowers3.jpg"); }
    if (sVal == 'images/Banner_Flowers1.jpg')   { oImg.setAttribute("src", "images/Banner_Flowers2.jpg"); }
    if (sVal == 'images/Banner_SunFlower2.jpg') { oImg.setAttribute("src", "images/Banner_Flowers1.jpg"); }
    if (sVal == 'images/Banner_SunFlower1.jpg') { oImg.setAttribute("src", "images/Banner_SunFlower2.jpg"); }
    if (sVal == 'images/Banner_Stream2.jpg')    { oImg.setAttribute("src", "images/Banner_SunFlower1.jpg"); }
    if (sVal == 'images/Banner_Stream1.jpg')    { oImg.setAttribute("src", "images/Banner_Stream2.jpg"); }
    if (sVal == 'images/Banner_Berries.jpg')    { oImg.setAttribute("src", "images/Banner_Stream1.jpg"); }
*/

}  //  function



//  This routine changes properties of a given object.
function FP_changeProp() 
{
    var args = arguments;           // Saves the params passed into this function as an array
    var d = document;
    var i, j;
    var id = args[0];               // the first param
    var o = FP_getObjectByID(id);   // The actual object with the given ID
    var s, ao, v, x;
    d.$cpe = new Array();
    if (o) {
        for (i = 2; i < args.length; i += 2) {  // Starting at param 2, there are pairs of settings and values
            v = args[i + 1];                    // value (to be set to)
            s = "o";                            // begin building a js command, it starts with the object specified by the ID
            ao = args[i].split(".");            // The setting param may be 'style.textDecoration', so split it up
            for (j = 0; j < ao.length; j++) 
            {
                s += "." + ao[j];
                if (null == eval(s)) // The eval() function evaluates a string and executes it as if it was script code.  It returns null if s was not CODE.
                {
                    s = null;
                    break;
                }
            }
            x = new Object;
            x.o = o;
            x.n = new Array();
            x.v = new Array();
            x.n[x.n.length] = s;
            eval("x.v[x.v.length]=" + s);
            d.$cpe[d.$cpe.length] = x;
            if (s) eval(s + "=v");      // Actually set the value to the property
        }
    }
}

//  This routine finds (and returns) an object by it's ID.
function FP_getObjectByID(id, o) 
{
    var c, el, els, f, m, n;
    if (!o) o = document;
    if (o.getElementById) 
    {
        el = o.getElementById(id);
    }
    else 
    {
        if (o.layers) 
        {
            c = o.layers;
        }
        else 
        {
            if (o.all) 
            {
                el = o.all[id];
            }
        }
    }
    if (el) return el;
    if (o.id == id || o.name == id) return o;
    if (o.childNodes) c = o.childNodes; 
    if (c)
        for (n = 0; n < c.length; n++) { el = FP_getObjectByID(id, c[n]); if (el) return el; }
    f = o.forms; if (f) for (n = 0; n < f.length; n++) {
        els = f[n].elements;
        for (m = 0; m < els.length; m++) { el = FP_getObjectByID(id, els[n]); if (el) return el; } 
    }
    return null;
}


