if ((document.getElementById && document.createElement("img")) &&
window.addEventListener || window.attachEvent) {

(function() {

    //Customize the counter here.

    //How many digits do you want in your counter?
    var counter_length = 10;

    //Choose a start value. If your "counter_length" is 7, "counter_start_from" MUST be 7 numbers long!
    var counter_start_from = "0000000000";

    //Gives a random hit anywhere from 0 to "random_timer" seconds.
    var random_timer = 48;


    //Nothing needs altering past here!

    var pics = [];
    var load = [];
    for (i = 0; i < 10; i++) {
        pics[i] = i + ".gif";
    }
    for (i = 0; i < pics.length; i++) {
        load[i] = new Image();
        load[i].src = "/content/images/counterdigits/" + pics[i];
    }

    var temp_stop = [];
    var stop;
    var c = "";
    for (i = 0; i < counter_length; i++) {
        temp_stop[i] = 9;
        stop = c += temp_stop[i];
    }

    var counter_end_at = parseInt(stop);

    if (counter_start_from.length != counter_length) {
        alert("You want the counter to be " + counter_length + " digits long.\nThe variable \"counter_start_from\" must be " + counter_length + " digits long too!\nYou have it set to " + counter_start_from.length + ".");
        return false;
    }

    //Stop Opera selecting anything whilst dragging! Not ideal, keep eye on this for future version probs.
    if (window.opera) {
        document.write("<input type='hidden' id='Q' value=' '>");
    }

    var y, x, z, temp1, temp2, dom;
    var n = 500;
    var dragOK = false;
    var timer = random_timer;
    //random_timer *= 1000;
    var disp = [];

    function do_counter() {
        var v1, v2, v3;
        timer = Math.round(random_timer);
        counter_start_from++;
        if (counter_start_from > counter_end_at) {
            clearTimeout(timer);
            vis(true, false);
            return false;
        }
        v1 = counter_start_from.toString();
        v2 = v1.split("");
        v3 = counter_length - v2.length;
        for (i = 0; i < v2.length; i++) {
            el = document.getElementById("dgts" + i);
            el.style.backgroundPosition = "0px " + (-v2[i] * 31) + "px";

        }
        setTimeout(do_counter, timer);
    }

    function check(e) {
        if (!e) e = window.event;
        dom = (typeof e.pageY == "number");
        if (dom) {
            dragOK = true;
        }
        else {
            dragOK = true;
        }
        if (dragOK) {
            if (window.opera) {
                document.getElementById("Q").focus();
            }
            z = (dom) ? e.target.style : e.srcElement.style;
            z.zIndex = n++;
            down(e);
        }
    }

    function down(e) {
        if (dom) {
            y = e.pageY - parseInt(z.top);
            x = e.pageX - parseInt(z.left);
        }
        else {
            temp1 = z.pixelLeft;
            temp2 = z.pixelTop;
            y = e.clientY;
            x = e.clientX;
        }
        document.onmousemove = move;
        if (dom) return false;
    }

    function move(e) {
        if (!e) e = window.event;
        if (dom) {
            z.top = parseInt(e.pageY) - y + 'px';
            z.left = parseInt(e.pageX) - x + 'px';
        }
        else {
            z.left = temp1 + e.clientX - x;
            z.top = temp2 + e.clientY - y;
        }
        return false;
    }

    function up() {
        document.onmousemove = null;
        z = null;
        dragOK = false;
    }

    function ext() {
        vis(false, true);
    }

    function vis(a, b) {
        var c = (!a) ? 'hidden' : 'visible';
    }

    function exp() {

    }

    function init() {
        if (document.getElementById("thecounter")) {
            
            var sTitle = document.getElementById("thecounter").getAttribute("title").valueOf();
            counter_start_from = sTitle.substring(0, sTitle.indexOf(" "));
            counter_length = counter_start_from.length;
            random_timer = sTitle.substring(sTitle.indexOf(" ") + 1); ;
            
            for (i = 0; i < counter_length; i++) {
                //                disp[i] = document.createElement("img");
                //                disp[i].setAttribute("src", load[0].src);
                //                disp[i].setAttribute("id", "dgts'+i+'");
                //                disp[i].setAttribute("width", "26");
                //                disp[i].setAttribute("height", "24");
                if (i > 0 && (counter_length - i) % 3 == 0) {
                    disp[i] = document.createElement("div");
                    disp[i].id = "dgtst" + i;
                    disp[i].className = "seccountercell_tecka";
                    disp[i].style.left = "76px";
                    document.getElementById("thecounter").appendChild(disp[i]);
                }

                disp[i] = document.createElement("div");
                disp[i].id = "dgts" + i;
                disp[i].className = "seccountercell";
                document.getElementById("thecounter").appendChild(disp[i]);
            }

            do_counter();
        }
    }

    if (window.addEventListener) {
        document.addEventListener("mousedown", check, false);
        document.addEventListener("mouseup", up, false);
        window.addEventListener("load", init, false);
    }
    else if (window.attachEvent) {
        window.attachEvent("onload", init);
        document.attachEvent("onmousedown", check);
        document.attachEvent("onmouseup", up);
    }
})();
}//End.
