﻿/* Script taken from leemessenger.co.uk - Please do not remove this line */
var RandomCurrentImage = -1;
var pathToImg = new Array()
var randomLinks = new Array()

function RotateSetup() {
    //preload images
    for (i = 0; i < random_images.length; i++) {
        pathToImg[i] = new Image()
        pathToImg[i].src = random_images[i]
    }
}

function ChangeCSSBgImg() {

    if (!document.getElementById) return false;

    if (!document.getElementById(MyElement)) return false;

    RandomCurrentImage = RandomCurrentImage + 1;
    if (RandomCurrentImage >= random_images.length) {
        RandomCurrentImage = 0;
    }

    var $header = document.getElementById(MyElement);
    var $backgroundurl = $header.style.backgroundImage;
    var ImgURL = "url(" + pathToImg[RandomCurrentImage].src + ")";
    //debugger;
    var link = null;
    /*if (document.getElementById("ctl00_ContentPlaceHolder1_template100_lnkMainSubtitle")) {
        link = document.getElementById("ctl00_ContentPlaceHolder1_template100_lnkMainSubtitle");
    }*/
    if (document.getElementById(MyLinks)) {
        link = document.getElementById(MyLinks);
    }
    if ($backgroundurl != ImgURL) {
        $header.style.backgroundImage = ImgURL;
        //debugger;
        if (link) {
            link.innerHTML = random_text[RandomCurrentImage];
            link.href = random_links[RandomCurrentImage];
        }
    }

    movement = setTimeout("ChangeCSSBgImg()", randomTimeout);
}

/* random number generator */
function rand(n) {
    return (Math.floor(Math.random() * n));
}

/* Custom onload function */
function addLoadEvent(func) {
    RotateSetup();
    
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
        window.onload = func;
    } else {
        window.onload = function() {
            oldonload();
            func();
        }
    }
}

