﻿function getElement(obj) {
    if (document.getElementById) {
        return document.getElementById(obj);
    }
    else if (document.all) {
        return document.all(obj);
    }
    else {
        return null;
    }
};

function BrokerSetup() {

    if (!ourCustomMotif.isFirefox()) {
        ourCustomMotif.findThisAssett();
    }
    else {
        // in firefox, inject a small pause after the broker buttons were inserted into the dom, otherwise expand/collapse will fail
        setTimeout("FindAssett()", 500);
    }
}

function FindAssett() {
    ourCustomMotif.findThisAssett();
}

//Motif Vars
var myInterval;
var ARR_tagsMotif = null;
var ourCustomMotif = new customMotifAdHandler();

//Domani Vars
var interval;
var lastscroll;

// Set the Motif Variables
var eURL1, eURL2, eURL3, eURL4, eURL5, tID1, tID2, tID3, tID4, tID5;

function register(URL, ID, POS) {
    this["eURL" + POS] = URL;
    this["tID" + POS] = ID;
}

function checkLoad() {
    try {
        if (eURL1 != undefined && eURL2 != undefined && eURL3 != undefined && eURL4 != undefined && eURL5 != undefined) {
            if (window.ourCustomMotif && ourCustomMotif.setMotifVars)
                ourCustomMotif.setMotifVars();
        }
    }
    catch (ex) { }
}

function flashLoaded() {
    myInterval = window.setInterval(checkLoad, 100);
}

//Our customMotifAdHandler object
function customMotifAdHandler() {
    this.motifMovie = null;
    this.creativeIdentifier = null;
    this.flash = null;
    this.div = null;
    this.definedHeight = 115;

    function toObject(variableName) {
        if (document.layers) {
            return (document.layers[variableName]) ? eval(document.layers[variableName]) : null;
        }
        else if (document.all && !document.getElementById) {
            return (eval("window." + variableName)) ? eval("window." + variableName) : null;
        }
        else if (document.getElementById && document.body.style) {
            return (document.getElementById(variableName)) ? eval(document.getElementById(variableName)) : null;
        }
    }
    this.toObject = toObject;

    function isFirefox() {
        var appUserAgent = navigator.userAgent.toUpperCase();
        if (appUserAgent.indexOf("GECKO") != -1) {
            if (appUserAgent.indexOf("FIREFOX") != -1) {
                var version = parseFloat(appUserAgent.substr(appUserAgent.lastIndexOf("/") + 1));
                return (version >= 1) ? true : false;
            }
            else if (appUserAgent.indexOf("NETSCAPE") != -1) {
                var version = parseFloat(appUserAgent.substr(appUserAgent.lastIndexOf("/") + 1));
                return (version >= 8) ? true : false;
            }
        }
        else
            return false;
    }
    this.isFirefox = isFirefox;


    function findThisAssett() {
        //For IE, get OBJECT
        if (!this.isFirefox() && document.all) {
            var ARR_tags = document.all.tags("DIV");
            for (var x = 0; x < ARR_tags.length; x++) {
                if (ARR_tags[x].id.substr(0, 4) == "DIV_") {
                    ARR_tagsMotif = ARR_tags[x].all.tags("OBJECT");
                    if (ARR_tags[x].id.substr(4) == ARR_tagsMotif[0].id.substr(6) && ARR_tagsMotif[0].height == this.definedHeight) {
                        this.motifMovie = ARR_tagsMotif[0].name;
                        this.flash = this.toObject(this.motifMovie);
                    }
                }
            }
        }
        //For NN/FF get EMBED
        else {
            var ARR_tags = document.getElementsByTagName("DIV");
            for (var y = 0; y < ARR_tags.length; y++) {
                if (ARR_tags[y].id.substr(0, 4) == "DIV_") {
                    ARR_tagsMotif = ARR_tags[y].getElementsByTagName("EMBED");
                    if (ARR_tags[y].id.substr(4) == ARR_tagsMotif[0].id.substr(6) && ARR_tagsMotif[0].height == this.definedHeight) {
                        this.motifMovie = "FLASH_" + ARR_tags[y].id.substr(4);
                        this.flash = this.toObject(this.motifMovie);
                    }
                }
            }
        }
        this.setMotifVars();
    }
    this.findThisAssett = findThisAssett;

    function setMotifVars() {
        clearInterval(myInterval);

        try {
            if (this.flash) {
                this.flash.SetVariable("eURL1", eURL1);
                this.flash.SetVariable("eURL2", eURL2);
                this.flash.SetVariable("eURL3", eURL3);
                this.flash.SetVariable("eURL4", eURL4);
                this.flash.SetVariable("eURL5", eURL5);
                this.flash.SetVariable("tID1", tID1);
                this.flash.SetVariable("tID2", tID2);
                this.flash.SetVariable("tID3", tID3);
                this.flash.SetVariable("tID4", tID4);
                this.flash.SetVariable("tID5", tID5);
            }
        }
        catch (ex)
	    { }
    }
    this.setMotifVars = setMotifVars;
}