// JavaScript Document

// Retrieve a reference to an object in the document
function getObj(objID) {
    if (document.getElementById) {
        return document.getElementById(objID);
    } else if (document.all) {
        return document.all[objID];
    } else if (document.layers) {
        return document.layers[objID];
    }
}

// Retrieve a reference to an object in the parent's dom
function getParentObj(objID) {
    if (document.getElementById) {
        return parent.document.getElementById(objID);
    } else if (document.all) {
        return parent.document.all[objID];
    } else if (document.layers) {
        return parent.document.layers[objID];
    }
}


// Homepage Featurette Slider, with delayed preloading
function featuretteObj(name, cards, delay) {
    this.name = name;
    this.cards = cards;
    this.viewed = 0;
    this.delay = delay;
    this.current = "x";
    this.active = 0;
    this.x = "";
    this.y = "";
    this.amountSlid = 0;
    this.running = false;
    this.hover = false;
    this.count = cards.length;
    
    this.buttons = new Array();

    this.init = function () {
        this.name = this.name;
        this.viewed = 0;

        this.x = getObj("cardX");
        this.y = getObj("cardY");
        this.current = "x";
        this.active = 0;

      
        for (var i = 0; i <= (this.count - 1); i++) {
            this.buttons[i] = getObj("febtn_" + i);
        }

        this.loadCard("y", this.determineNext());
        autoslide = setInterval(this.name + ".next()", (this.delay * 2));
    }

    this.jump = function (key) {
        try { clearInterval(autoslide); } catch (err) { }

        if (this.running == false) {

            this.x = getObj("cardX");
            this.y = getObj("cardY");

            this.running = true;
            this.preset();

            if (this.current == "x") { var slot = "y"; } else { var slot = "x"; }
            if (key >= 0 && key <= (this.count - 1)) { var place = key } else { var place = 0 }

            this.loadCard(slot, place);
            this.active = place;
            if (this.current == "x") { this.y.style.display = ""; } else { this.x.style.display = ""; }
            slider = setInterval(this.name + ".slide()", 50);
        }
    }

    this.preset = function () {
        if (this.current == "x") {
            //this.x.style.top = "0px";
            this.x.style.left = "0px";
            this.x.style.zIndex = 5;

            //this.y.style.top = ""; //"-239px";
            this.y.style.left = "491px";
            this.y.style.zIndex = 6;
        }
        else {
            //this.y.style.top = "0px";
            this.y.style.left = "0px";
            this.y.style.zIndex = 5;

            //this.x.style.top = ""; //"-239px";
            this.x.style.left = "491px";
            this.x.style.zIndex = 6;
        }
        this.amountSlid = 0;
    }

    this.determineNext = function () {
        var projectedNext = (this.active + 1)
        if (projectedNext >= (this.count)) {
            projectedNext = 0;
        }

        

        return projectedNext
    }

    this.next = function () {
        if (this.hover == false && this.running == false) {
            clearInterval(autoslide);
            this.running = true;
            this.preset();
            this.active = this.determineNext();
            if (this.current == "x") { this.y.style.display = ""; } else { this.x.style.display = ""; }
            slider = setInterval(this.name + ".slide()", 50);
        }
    }

    this.loadCard = function (slot, place) {
        if (slot == "y") { var destination = this.y; } else { var destination = this.x; }

        destination.innerHTML = '<p><a   href="' + this.cards[place][2] + '" class="title">' + this.cards[place][1] + '</a><br />' + this.cards[place][3] + '</p>';
        destination.onclick = function () { window.location = feats.cards[place][2]; }
        destination.title = this.cards[place][1];
        if (this.cards[place][6] == true) {
            destination.style.backgroundImage = 'url(Upload/Banners/' + this.cards[place][0] + '.jpg?c=9)';


        }
    }

    this.pause = function (state) {
        this.hover = state;
    }

    this.slide = function () {
        if (this.running == true) {
            if (this.amountSlid < (490 - 220)) {
                // Deincriment card position
                this.amountSlid = (this.amountSlid + 220);
                if (this.current == "x") {
                    this.y.style.left = (490 - this.amountSlid) + 'px';
                }
                else {
                    this.x.style.left = (490 - this.amountSlid) + 'px';
                }
            }
            else {
                // Finish slide and preset variables for next go and preload next card
                clearInterval(slider);
                this.amountSlid = 0;
                if (this.current == "x") {
                    this.current = "y";
                    this.x.style.display = "none";
                    this.preset();
                    this.loadCard("x", this.determineNext());
                }
                else {
                    this.current = "x";
                    this.y.style.display = "none";
                    this.preset();
                    this.loadCard("y", this.determineNext());
                }
                for (x = 0; x <= (this.count - 1); x++) 
                {
                    if (this.active == x) 
                    {

                       
                            getObj("febtn_" + x).setAttribute("className", "current");
                            getObj("febtn_" + x).setAttribute("class", "current");

                        

                    }
                    else 
                    {


                        getObj("febtn_" + x).setAttribute("className", "");
                        getObj("febtn_" + x).setAttribute("class", "");

                    }
                }
                this.running = false;
               autoslide = setInterval(this.name + ".next()", this.delay);
            }
        }
    }
}




















