    // SITE INITIALIZATION GOES HERE.
        function setSite() {
        // cache some images
            cacheImages('/global/assets/images/bg/cal_bg_hdr.gif', '/global/assets/images/bg/cal_bg_lcap.gif', '/global/assets/images/bg/cal_bg_lcap2.gif', '/global/assets/images/bg/cal_bg_mcap.gif', '/global/assets/images/bg/cal_bg_mcap2.gif', '/global/assets/images/bg/cal_bg_rcap.gif', '/global/assets/images/bg/cal_bg_rcap2.gif', '/global/assets/images/bg/cal_bg_ucap.gif', '/global/assets/images/bg/cal_bg_ucap2.gif', '/global/assets/images/bg/cal_ovr_bg_hdr.gif', '/global/assets/images/bg/cal_ovr_bg_item.gif', '/global/assets/images/bg/cal_ovr_karet.gif', '/global/assets/images/nav/topnav_l_o.gif', '/global/assets/images/nav/topnav_l_o.png', '/global/assets/images/nav/topnav_l.gif', '/global/assets/images/nav/topnav_l.png', '/global/assets/images/nav/topnav_r_o.gif', '/global/assets/images/nav/topnav_r_o.png', '/global/assets/images/nav/topnav_r.gif', '/global/assets/images/nav/topnav_r.png', '/global/assets/images/nav/topnav_sub_l.gif', '/global/assets/images/nav/topnav_sub_r.gif');
        // begin inserting swf objects into dom
            handleDomReplace();
        // add menu support
            addMenuSupport()
        // initialize tables, if any
            if (typeof(setTables) == 'function') { setTables(); }
        // add support for sifr
            //sifrSupport();
            handleParkReplace();
        // handle external links
            handleLinkage();
        //  extraLnkTrack();
        //  var ads = new Ads();
        //  ads.insertAds();
        //  sc = new SiteCatalyst();
        //  sc.addLinkPositions();
        //  sc.track();
            window.setTimeout(replaceSeasonPass, 1000);
            var kl = new KickAppsListing();
            kl.bind();
            var pp = new PhotoPage();
            pp.bind();


            ExactTarget.init();
        }



        var allCals   = true;
        var allSwaps  = [];
        var allTables = [];



        function cacheImages() {
            var imgMarkup = '';
            var hiddenDiv = document.body.appendChild(document.createElement('div'));
                hiddenDiv.style.display = 'none';
            for (var loop = 0; loop < arguments.length; loop++) {
                var src = arguments[loop];
                var newImage = document.createElement('img');
                    newImage = hiddenDiv.appendChild(newImage)
                    newImage.src = src;
            }
        }

    // add in swf movies
        function handleDomReplace() {
            // get some divs
            var allDivs = document.getElementsByTagName('div');
        // loop through all divs
            for (var loop = 0; loop < allDivs.length; loop++) {
                var thisDiv = allDivs[loop];
            // isolate isSwfMovie divs
                if (thisDiv.getAttribute('domreplace') && thisDiv.getAttribute('domreplace') != '') {
                // get all attributes
                    var attbrs      = thisDiv.attributes;
                    var writeAttbrs = []
                // save custom attributes in a useful format
                    for (var loop2 = 0; loop2 < attbrs.length; loop2++) {
                        var name  = attbrs[loop2].name;
                        var value = attbrs[loop2].value;
                        if (value != '' && name != 'id' && name != 'class' && name != 'style') { writeAttbrs.push([name, value]) }
                    }
                    var thisElement = false;
                    switch(thisDiv.getAttribute('domreplace')) {
                    // handle swf movie replacement
                        case 'swfMovie':
                                    // get some attributes
                                        var swfUrl      = thisDiv.getAttribute('url');
                                        var swfWidth    = thisDiv.getAttribute('width');
                                        var swfHeight   = thisDiv.getAttribute('height');
                                    // make movie
                                            thisSwfMovie = swf.movie(swfUrl, swfWidth, swfHeight, 8, '/national/noflash.aspx');
                                    // write params
                                        for (var loop3 in writeAttbrs) {
                                            var paramName  = writeAttbrs[loop3][0]
                                            var paramValue = writeAttbrs[loop3][1]
                                            if (parkname && paramValue.indexOf('[PARKNAME]') != -1 ) { paramValue = paramValue.split('[PARKNAME]').join(parkname); }
                                            thisSwfMovie.setParam(paramName, paramValue);
                                        }

                                        thisDiv.style.overflow = 'hidden'; /*
                                        var BLOCKER                 = document.createElement('iframe');
                                            BLOCKER.style.position  = 'absolute';
                                            BLOCKER.style.top       = '0px;';
                                            BLOCKER.style.left      = '0px;';
                                            BLOCKER.style.width     = thisDiv.offsetWidth;
                                            BLOCKER.style.height    = thisDiv.offsetHeight;
                                            BLOCKER                 = thisDiv.appendChild(BLOCKER); */
                                        thisDiv.appendChild(thisSwfMovie);

                                        //handleLinkage();
                        break;
                    // handle image swapper replacement
                        case 'imageSwap':
                                    // get some attributes
                                        var thisUrl     = thisDiv.getAttribute('url');
                                        if (parkname) { thisUrl = thisUrl.split('[PARKNAME]').join(parkname); }
                                        var swfWidth    = thisDiv.getAttribute('width');
                                        var swfHeight   = thisDiv.getAttribute('height');
                                        var swfRate     = thisDiv.getAttribute('rate');
                                        var swfInterval = thisDiv.getAttribute('interval') || false;
                                        thisUrl += (thisUrl.indexOf('?') == -1 ) ? '?' : '&';
                                        if (parkname) { thisUrl += "parkname=" + parkname; } else { thisUrl += "parkname=national"; }
                                        thisUrl += (thisUrl.indexOf('?') == -1 ) ? '?' : '&';
                                        thisUrl += 'pageName=' + location.pathname;
                                    // create new swapper
                                        allSwaps[allSwaps.length] = new swapImg(thisUrl, swfWidth, swfHeight, swfRate, thisDiv, swfInterval);
                                        //handleLinkage();
                        break;
                        case 'dynTable':
                                        var styleArray          = thisDiv.getAttribute('data');
                                        var proxy               = thisDiv.getAttribute('proxy');
                                        allTables[styleArray]   = new dynTable(eval(styleArray), thisDiv, proxy);
                                        //handleLinkage();
                        break;
                        case 'calendar':
                                    // get some attributes
                                        var thisUrl             = thisDiv.getAttribute('thisUrl');
                                        if (parkname && thisUrl.indexOf('[PARKNAME]') != -1) { thisUrl = thisUrl.split('[PARKNAME]').join(parkname); }
                                        var calCount            = thisDiv.getAttribute('calCount');
                                        if (typeof(parkname) != 'undefined') { thisDiv.setAttribute('park', parkname); }
                                        var park                = thisDiv.getAttribute('park');
                                        var table               = thisDiv.getAttribute('table');
                                        allCals                 = new calHandler(thisDiv, thisUrl, calCount, park, table);
                                       // handleLinkage();
                        break;
                        case 'dropDown':
                                    // get attributes
                                        var label     = thisDiv.getAttribute('label');
                                        var doClick   = thisDiv.getAttribute('doClick');
                                        var maxHeight = thisDiv.getAttribute('maxHeight');
                                        var upDown    = thisDiv.getAttribute('upDown');
                                    // initialize it
                                        var thisDropdown = pulldown(label, doClick, maxHeight, upDown)
                                    // get children
                                        var allItems  = thisDiv.getElementsByTagName('span');
                                    // interpret children, as options
                                        for (var item = 0; item < allItems.length; item++) {
                                            var thisItem = allItems[item];
                                            thisDropdown.addItem(thisItem.getAttribute('label'), thisItem.getAttribute('value'))
                                        }
                                    // add it in
                                        thisDiv.innerHTML = '';
                                        thisDiv.appendChild(thisDropdown);
                        break;
                    }
                // insert DOM structure
                    if (thisElement) { thisDiv.appendChild(thisElement); }
                }
            }
        }



    // add in main navigation
        function addMenuSupport() {
        //first, we must set flags for the midNav Array by the page-specific inline var
            if (typeof(midNav) != 'undefined' && typeof(activeNode) != 'undefined') { activeNode.push(true); }
        // create, and post process menus
            if (document.getElementById('middleHeaderSection') && topNav) { createMajorNav(document.getElementById('middleHeaderSection'), topNav, 'topNavList', false, iePseudoClassSupport, false, true, true); }
            if (document.getElementById('midNav-bucket') && midNav) {
                var isIE6 = client.app == "msie" && parseInt(client.appRev) < 7;
                var isIE7 = client.app == "msie" && parseInt(client.appRev) < 8;
                if (parkname && parkname == 'national') {
                    createMajorNav(document.getElementById('midNav-bucket'), midNav, 'midNav-menu',    false, setBehaviour, true, false, false, isIE6 ? 185 : 160);
                } else {
                    createMajorNav(document.getElementById('midNav-bucket'), midNav, 'midNav-menu',    false, setBehaviour, false, false, false, (!isIE6 && !isIE7) ? -243 : -35);
                }
            }
            if (document.getElementById('botNav-bucket') && botNav) { createMajorNav(document.getElementById('botNav-bucket'), botNav, 'botNav',    false, iePseudoClassSupport); }
            //handleLinkage();
        }



    // set sifr headers
        function sifrSupport() {
        // get some headers
            var allH1s = document.getElementsByTagName('H1');
            var allSifrText = []
        // get just the relevant elements
            for (var loop =0; loop < allH1s.length; loop++) { if (allH1s[loop].className == 'sifrText') { allSifrText.push(allH1s[loop]); } }
        // transform relevant elements
            for (var loop in allSifrText) {
                if (qrystr.print == "true") {
                // replace classname with print if querystring("print") is true
                    var headObj       = allSifrText[loop];
                    headObj.className = "print";
                } else {
                // get the header info
                    var headObj    = allSifrText[loop]
                    var headCpy    = headObj.innerHTML
                    var headWidth  = headObj.offsetWidth;
                    var headHeight = headObj.offsetHeight;
                // create .swf object, demand version 6
                    var swfMovie = swf.movie('/global/func/sifr/futura_bold.swf', headWidth, headHeight, 8, '/noflash.aspx');
                    if (swfMovie) {
                    // if version adequate, add params
                        swfMovie.setParam('wmode', 'opaque');
                        swfMovie.setParam('quality', 'best');
                        swfMovie.setParam('flashVars', 'txt=' + headCpy + '&textcolor=#9A9A9A&w=' + headWidth + '&h=' + headHeight);
                        swfMovie.setParam('bgcolor', '#FFFFFF');
                    // clear header and append swf
                        headObj.innerHTML ='';
                        swfMovie = headObj.appendChild(swfMovie);
                        headObj.style.visibility = 'visible';
                    }
                }
            }
        }

    // add in park name to links
        function handleParkReplace() {
        // get some links
            var allLinks = document.getElementsByTagName("A");
            for (var i=0; i<allLinks.length; i++) {
                var thisLink = allLinks[i];
                var href = unescape(thisLink.href);
                if (href.indexOf("[PARKNAME]") > -1) {
                // replace [PARKNAME] with parkName var
                    var regEx = /\[PARKNAME\]/g;
                    thisLink.href = href.replace(regEx, parkname);
                }
            }
            //handleLinkage();
        }







    // additional tracking
            function extraLnkTrack() {
                if (typeof(hbx) != 'undefined') {
                    if (document.getElementById('Lodging')) {
                        var lodging  = document.getElementById('Lodging')
                        var allLinks = lodging.getElementsByTagName('a');
                        for (var loop = 0; loop < allLinks.length; loop++) {
                            var thisLink = allLinks[loop];
                            var thisHref = thisLink.href;
                            var inLodging  = false;
                            if (thisHref.indexOf('//') != -1 && thisHref.split('//')[1].split('/')[0].indexOf('sixflags.com') == -1) {
                                switch (hbx.pn) {
                                    case 'lodging':
                                        thisLink.setAttribute('name', 'lid=' + escape(hbxStrip(thisHref.split('://')[1])) + '&lpos=lodging');
                                    break;
                                }
                            }
                        }
                    }
                }
            }

function getEmbedContainer() {
    var pi = new PageIdentification();
    if (!pi.isHomePage()) {
        return document.body;
    }

    if (getParkName().toLowerCase() == "national") {
        var container = document.getElementById("national");
    }

    if (!container) {
        var divs = document.body.getElementsByTagName("div");
        for (var i = 0; i < divs.length; i++) {
            var div = divs[i];
            if (div.className == "container") {
                var container = div;
                break;
            }
        }
    }

    return container;
}

// function getFlash() {
//     var elNumber = 1;
//     if (getParkName().toLowerCase() == "national") {
//         elNumber = 2;
//     }
//     if (client.engine == "msie") {
//         return window['flashElement' + elNumber];
//     } else {
//         return document['flashElement' + elNumber][0];
//     }
// }
// 

var _Ie6FillWholePage = false;

function addEmbeddedVideo(embedCode){
    return addEmbeddedObject(embedCode, 'videoHolder', false, false, {});
}

function addEmbeddedObject(embedCode, contentId, fillWholePage, realignCloseButton, extraArgs){
    var pi = new PageIdentification();
    var embedContainer = getEmbedContainer();
    if (embedContainer) {
        var embedOverlayDiv = document.createElement('div');
        var id = "flashHeaderOverlay";
        if (!pi.isHomePage()) {
            id += "WholePage";
        }
        embedOverlayDiv.setAttribute("id", id);
        if (!(client.app == "msie" && parseInt(client.appRev) < 8)) { //navigator.appVersion.indexOf('MSIE 7.0') < 0 || navigator.appVersion.indexOf('MSIE 6.0') < 0 ) {
            embedOverlayDiv.setAttribute("class", "transparent");
        }
        var closeButtonId = 'closeEmbed';
        embedOverlayDiv.innerHTML = '<div id="' + contentId + '"><a onclick="removeEmbeddedObject()" id="' + closeButtonId + '">X</a>'+embedCode+'</div>';
        
        
        if (fillWholePage && (client.app == "msie" && parseInt(client.appRev) < 7)) {            
            // set the overlay as a sibling of the container
            embedOverlayDiv = embedContainer.parentNode.appendChild(embedOverlayDiv);
            _Ie6FillWholePage = true;
        } else {
            embedOverlayDiv = embedContainer.appendChild(embedOverlayDiv);
        }
        
        if (client.app == "msie" && parseInt(client.appRev) < 7) {
            embedOverlayDiv.style.height = document.body.clientHeight + ' px';
        }
        
        if (fillWholePage) {            
            // element associated with embedCode
            embedOverlayDiv.className += embedOverlayDiv.className ? ' wholePage' : 'wholePage';
        }

        if (_Ie6FillWholePage) {
            var htmlElem = document.getElementsByTagName("html")[0];
            htmlElem.style.overflow = 'hidden';
            htmlElem.style.overflowX = 'hidden';
            htmlElem.style.overflowY = 'hidden';
            
            // set the top of the overlay div to be the top of the viewport;
            // this is so the div can follow the viewport in case the user scrolls down
            embedOverlayDiv.style.cssText += ';top:' + htmlElem.scrollTop + 'px !important';
            
            // need to constrain image width in IE6 since max-width CSS isn't supported
            // note: the max width wouldn't be hardcoded if it could be correct-retrieved by using the width of the containing div
            if (extraArgs.objectWidth > 704) {
                extraArgs.objectWidth = 704;
                var $contentHolder = $('#' + contentId);
                // set the width of the embedded object
                $contentHolder.children(':last').width(extraArgs.objectWidth);
            }
        }
      
        // if we are to vertically-realign the close button so it's within the top right-hand corner of the embeded object
        if (realignCloseButton) {
            var $contentHolder = $('#' + contentId);
            var $closeButton = $('#' + closeButtonId);
            if (extraArgs.objectWidth < $contentHolder.width()) {
                var rightVal = ($contentHolder.width() - extraArgs.objectWidth) / 2;
                if (client.app != "msie" || parseInt(client.appRev) != 8) {
                    rightVal = Math.round(rightVal);
                }
                $closeButton.css('right', rightVal + 'px');
            }
        }
        
        if (!pi.isHomePage()) {
            var className = "whole_page";
            if (embedOverlayDiv.className) {
                className = embedOverlayDiv.className + " " + className;
            }
            embedOverlayDiv.className = className;
            embedOverlayDiv.setAttribute('class', className);
            // embedOverlayDiv.setAttribute('className', className);
        }
    }
}

function removeEmbeddedObject(){
    var embedContainer = getEmbedContainer();
    var embedOverlayDiv = document.getElementById('flashHeaderOverlay');
    if (embedContainer == document.body) {
        embedOverlayDiv = document.getElementById('flashHeaderOverlayWholePage');
    }

    if (_Ie6FillWholePage) {
        embedContainer.parentNode.removeChild(embedOverlayDiv);
            var htmlElem = document.getElementsByTagName("html")[0];
            // set it to the default (as determined by the development toolbar addon)
            htmlElem.style.overflow = 'scroll';
            htmlElem.style.overflowX = 'auto';
            htmlElem.style.overflowY = 'scroll';
    } else {
        embedContainer.removeChild(embedOverlayDiv);
    }
}

function getParkName() {
    var regex = /.com\/(\w+)\//i;
    if (document.location.href.indexOf(".com") == -1) {
        regex = /\/WORKAREA\/(\w+)\//i;
    }
    // var regex = /\/WORKAREA\/(\w+)\/|.com\/(\w+)\//;
    var matches = regex.exec(window.location);
    var parkName = matches[1] !== undefined ? matches[1] : matches[2];
    return parkName;
}
/**
 * Detects if the normal season pass swf exists. If not, it will add the non ecommerce
 * enabled swf file and pass in the URL to the current park
 * @author Jon Pettersson
 * @contributors Ryan McGrew
 */
function replaceSeasonPass () {
    if (typeof jQuery == 'undefined') {
        var children = document.getElementById('topNav-bucket').getElementsByTagName('div');
        var thisSwfMovie = swf.movie('/global/assets/swf/season_pass_none.swf', 285, 115, 8, '/national/noflash.aspx');
        var parkName = getParkName();
        thisSwfMovie.setParam('flashVars', 'url=/' + parkName);
        thisSwfMovie.setParam('wmode', 'transparent');
        thisSwfMovie.className = "seasonpass";
        if (parkName.toLowerCase() != "national") {
            //children[6].appendChild(thisSwfMovie);
            var midNav = document.getElementById('midNav-bucket');
            var topNav = document.getElementById('topNav-bucket');
            var thisSwfMovie = topNav.insertBefore(thisSwfMovie, midNav.nextSibling);
        }
    }
}

function getElementsByClassName(classname, node)  {
    if (!node) {
        node = document.getElementsByTagName("body")[0];
    } 
    var a = [];
    var re = new RegExp('\\b' + classname + '\\b');
    var els = node.getElementsByTagName("*");
    for(var i = 0, j = els.length; i < j; i ++) {
        if (re.test(els[i].className)) {
            a.push(els[i]);
        }
    }

    return a;
}

function arrayContains(arr, searchElem) {
    for(var i = 0; i < arr.length; i++) {
        if(arr[i] === searchElem) {
            return true;
        }
    }
    return false;
}

function SiteCatalyst () {
    this.channel;
    this.hierarchy;
    this.pageName;
    this.server;
    this.subClass;
    this.topLevelSiteSection;
    this.page = new PageIdentification();
    this.linkTrackVars = [];
    this.linkTrackEvents = [];
    this.properties = {};
    this.linkPositions = {
        "topnav" : "midNav-menu",
        "topnav_text" : "topNav",
        "bottomnav_callout" : "hours",
        "bottomnav_promos" : "footer-promos",
        "footer_text" : "botNav-bucket",
        "promo_rightnav" : "promo",
        "main" : "main"
    };

    this.addLinkPositions = function _addLinkPositions() {
        var parents = {};
        for (var i in this.linkPositions) {
            var element = document.getElementById(this.linkPositions[i]);
            if (!element) {
                element = getElementsByClassName(this.linkPositions[i])[0];
            }
            parents[i] = element;
        }
        var links = document.getElementsByTagName("a");
        for (var i = 0; i < links.length; i++) {
            var link = links[i];
            var sc = this;
            (function() {
                for (var i  in  parents) {
                    if (sc._hasParent(link, parents[i])) {
                        // console.log(link);
                        // console.log(i);
                        // console.log("____________________________________");
                        link.setAttribute("name", "?LPOS=" + i);
                        return;
                    }
                }
            })();
        
        }
    };

    this._hasParent = function __hasParent(element, parent) {
        while (element && (element != document.body)) {
            if (element == parent) {
                return true;
            }
            element = element.parentNode;
        }

        return false;
    };

    this.track = function _track() {
        this.properties.prop1    = this.getTopLevelSiteSection();
        this.properties.pageName = this.getPageName();
        this.properties.server   = this.getServer();
        this.properties.channel  = this.getChannel();
        this.trackLead();
        this.trackEmail();
        this.trackPrint();

        try {
            if (s !== undefined) {
                s.linkTrackVars += "," + this._getPropertyList(this.linkTrackVars);
                s.linkTrackEvents += "," + this._getPropertyList(this.linkTrackEvents);
                this.setProperties(s, this.properties);

                s.pageType = "";
                /* Conversion Variables */
                s.campaign = "";
                s.state = "";
                s.zip = "";
                s.events = "";
                s.products = "";
                s.purchaseID = "";
                s.eVar1 = "";
                /* Hierarchy Variables */
                s.hier1 = "";
                if (window.console) {
                    window.console.log(this.properties);
                    window.console.log(this.linkTrackVars);
                    window.console.log(this.linkTrackEvents);
                }
                /************* DO NOT ALTER ANYTHING BELOW THIS LINE ! **************/
                var s_code=s.t();if(s_code)document.write(s_code);//-->
            }
        } catch (e) {
            if (window.console) {
                console.log(e);
            }
        }
    };
    
    this._getPropertyList = function __getPropertyList(properties) {
        if (properties.length) {
            if (this.linkTrackVars instanceof Array) {
                return this.linkTrackVars.join(",");
            } else {
                return this.linkTrackVars;
            }
        }

        return "";
    };
    
    this.setProperties = function _setProperties(obj, properties)
    {
        if (properties ===  undefined) {
            properties = this.properties;
        }
        for (var idx in properties) {
            s[idx] = properties[idx];
        }
    };

    this.trackLink = function _trackLink(element, vars, propValues, linkName, linkType) {
        try {
            if (vars instanceof Array) {
                s.linkTrackVars = vars.join(",");
            } else {
                s.linkTrackVars = vars;
            }
            for (var idx in propValues) {
                var prop = propValues[idx];
                s[idx] = prop;
            }
            if (window.console) {
                window.console.log(vars);
                window.console.log(propValues);
            }
            s.tl(element, linkType, linkName);
        } catch(e) {
            if (window.console) {
                window.console.log(e);
            }
        }
        
    };

    this.flashLink = function _flashLink(linkName, linkPosition) {
        this.trackLink(true, 'o', linkName);
    };

    this.trackLead = function _trackLead() {
        if (this.page.hasForm() && document.getElementById("form_cmdSubmit")) {
            this.linkTrackVars.push("prop28");
            this.linkTrackVars.push("evar28");
            this.linkTrackEvents.push("event25");
            this.properties.prop28 = this.getFormTitle();
            this.formSubmission();
        }
    };

    this.formSubmission = function _formSubmission() {
        var vars = ["evar28"];
        var propValues = {
            evar28 : this.getFormTitle(),
            events : "event26"
        };
        
        var submit         = document.getElementById("form_cmdSubmit");
        if (submit) {
            var onclickHandler = submit.onclick;
            var sc = this;
            if (typeof onclickHandler == "function") {
                submit.onclick = function() {
                    if (onclickHandler()) {
                        sc.trackLink(this, vars, propValues, "submit", 'o');
                    } else {
                        return false;
                    }
                }
            } else {
                submit.onclick = function() {
                    sc.trackLink(this, vars, propValues, "submit", 'o');
                }
            }
        }
    };

    this.trackPrint = function _trackPrint() {
        var print = document.getElementById("print");
        if (print) {
            var vars  = [];
            var propValues = {
                events : "event27"
            };
            var sc = this;
            print.onclick = function() {
                sc.trackLink(this, vars, propValues, 'print', 'o');
            }
        }
    };

    this.trackEmail = function _trackEmail() {
        var email = document.getElementById("email");
        if (email) {
            var vars  = [];
            var propValues = {
                events : "event28"
            };
            var sc = this;
            email.onclick = function() {
                sc.trackLink(this, vars, propValues, 'email', 'o');
            }
        }
    };

    this.getFormTitle = function _getFormTitle() {
        if (document.getElementsByTagName("h1").length > 0) {
            var formTitle = document.getElementsByTagName("h1")[0].innerHTML;
            return this.page.getParkName() + ":" + formTitle;
        }
    };

    this.pickAPark = function _pickAPark(element) {
        var linkName = element.innerHTML;
        var linkType = "o";
        var vars = "prop2,evar2";
        var propValues = {
            prop2 : linkName
        };
        this.trackLink(element, vars, propValues, linkName, linkType);
    };

    this.merge = function _merge(first, second) {
        var i = first.length, j = 0;

        if (typeof second.length === "number") {
            for ( var l = second.length; j < l; j++ ) {
                first[ i++ ] = second[ j ];
            }

        } else {
            while (second[j] !== undefined) {
                first[i++] = second[j++];
            }
        }

        first.length = i;

        return first;
    };

    this.getServer = function _getServer() {
        if (!this.server) {
            this.server = document.location.host;
        }

        return this.server;
    };

    this.getHierarchy = function _getHierarchy() {
        if (!this.hierarchy) {
            var path = document.location.pathname;
            var regex = /^\/[\w|\-|\/]+\/WORKAREA/i;
            path = path.replace(regex, "");

            var hierarchy = path.split("/");
            if (hierarchy.length > 0 && hierarchy[0] == "") {
                hierarchy = hierarchy.splice(1, hierarchy.length);
            }
            this.hierarchy = hierarchy;
        }

        return this.hierarchy;
    };

    this.getPageName = function _getPageName() {
        if (!this.pageName) {
            var pageName = this.getHierarchy().join(":").toLowerCase();
            pageName = pageName.replace(/.aspx|.html/i, "");
            this.pageName = pageName;
        }

        return this.pageName;
    };

    this.getChannel = function _getChannel() {
        if (!this.channel) {
            var channel = this.getHierarchy().slice(0, -1);
            if (this.getSubClass() != "" && this.getSubClass() != channel.slice(-1).shift()) {
                channel.push(this.getSubClass());
            }

            channel = channel.join(":").toLowerCase();
            if (this.getPageName().match(/index/i)) {
                channel += ":home";
            }

            this.channel = channel;
        }

        return this.channel;
    };

    this.getTopLevelSiteSection = function _getTopLevelSiteSection() {
        if (!this.topLevelSiteSection) {
            var hierarchy = this.getHierarchy();
            if (hierarchy.length > 2) {
                this.topLevelSiteSection = hierarchy.slice(0,2).join(":");
            } else if (hierarchy.length == 2){
                this.topLevelSiteSection = this.getChannel();
            }
        }

        return this.topLevelSiteSection;
    };

    this.getSubClass = function _getSubClass() {
        if (!this.subClass) {
            if (document.evaluate) {
                var xpath = "//div[@class='crumbs']/a[last()]/text()";
                var subClass = document.evaluate(xpath, document, null, XPathResult.STRING_TYPE, null).stringValue;
                this.subClass = subClass.replace("\s+", "").toLowerCase();
            } else {
                var crumbs = getElementsByClassName("crumbs");
                if (crumbs.length > 0) {
                    crumbs = crumbs[0];
                } else {
                    return "";
                }
                var anchors = crumbs.getElementsByTagName("a");
                if (anchors.length > 0) {
                    var anchor = anchors[anchors.length - 1];
                    this.subClass = anchor.innerHTML;
                } else {
                    this.subClass = "";
                }
            }
        }

        return this.subClass;
    };
}

function PageIdentification () {
    this._isPage = function __isPage(re) {
        var href = document.location.href;
        return re.test(href);
    };

    this.isHomePage = function _isHomePage() {
        var parkName = this.getParkName();
        var re = new RegExp(parkName + '\/(index.aspx)?(.*)?$', 'i');
        return this._isPage(re);
    };

    this.isSpanishPage = function _isSpanishPage() {
        var re = /espanol.aspx$/i;
        return this._isPage(re);
    };

    this.isEventsLandingPage = function _isEventsLandingPage() {
        var re = /events\/CalendarEvents.aspx$/i;
        return this._isPage(re);
    };
    
    this.isTicketsLandingPage = function _isTicketsLandingPage() {
        var re = /tickets\/index.aspx$/i;
        return this._isPage(re);
    };
    
    this.isSeasonPassPage = function _isSeasonPassPage() {
        var re = /[playpass|seasonpass].aspx$/i;
        return this._isPage(re);
    };

    this.isParkInfoPage = function _isParkInfoPage() {
        var re = /info\/parkInfo.aspx$/i;
        return this._isPage(re);
    };

    this.isDirectionsPage = function _isDirectionsPage() {
        var re = /info\/directions.aspx/i;
        return this._isPage(re);
    };

    this.isFaqPage = function _isFaqPage() {
        var re = /info\/[faq|faqs].aspx$/i;
        return this._isPage(re);
    };

    this.isSearchPage = function _isSearchPage() {
        var re = /search\/search.aspx$/i;
        return this._isPage(re);
    };

    this.hasForm = function _hasForm() {
        return document.forms.length > 0;
    };

    this.getParkName = function _getParkName() {
        var regex = /.com\/(\w+)\//i;
        if (document.location.href.indexOf(".com") == -1) {
            regex = /\/WORKAREA\/(\w+)\//i;
        }
        var matches = regex.exec(window.location);
        var parkName = matches[1] !== undefined ? matches[1] : matches[2];
        return parkName;
    };
}

function Ads () {
    this.adUrl = "http://ad.doubleclick.net/adi/";
    this.site = "";
    this.zone = "";
    this.park = null;
    this.page = null;
    this.bannerDimensions = "728x90";
    this.bottomBannerId = "footer-banner"
    this.bottomBannerPosition = "bottomban";
    this.upperBannerId = "header-banner"
    this.upperBannerPosition = "topban";
    this.skyScraperId = "right-column-ad";
    this.skyscraperPosition = "rightcol";
    this.skyscraperDimensions = "160x600";
    this.tile = 1;
    this.parkTypes = {
        "america": "theme",
        "discoverykingdom": "animal",
        "fiestatexas": "theme",
        "greatadventure": "animal",
        "greatamerica": "theme",
        "greatescape": "theme",
        "hurricaneharborla": "water",
        "hurricaneharbornj": "water",
        "hurricaneharbortexas": "water",
        "magicmountain": "theme",
        "national": null,
        "newengland": "theme",
        "overgeorgia": "theme",
        "overtexas": "theme",
        "stlouis": "theme",
        "whitewater": "water"
    };
    
    this._isPage = function __isPage(re) {
        var href = document.location.href;
        return re.test(href);
    };

    this.isHomePage = function _isHomePage() {
        var parkName = this.getParkName();
        var re1 = new RegExp(parkName + '\/index.aspx(\\?.*)?$', 'i');
        var re2 = new RegExp(parkName +'\/(index.aspx)?$', 'i');
        return this._isPage(re1) || this._isPage(re2);
    };
    
    this.isSpanishPage = function _isSpanishPage() {
        var re = /espanol.aspx$/i;
        return this._isPage(re);
    };
    
    
    this.isEventsLandingPage = function _isEventsLandingPage() {
        var re = /events\/CalendarEvents.aspx$/i;
        return this._isPage(re);
    };
    
    this.isTicketsLandingPage = function _isTicketsLandingPage() {
        var re = /tickets\/index.aspx$/i;
        return this._isPage(re);
    };
    
    this.isSeasonPassPage = function _isSeasonPassPage() {
        var re = /[playpass|seasonpass].aspx$/i;
        return this._isPage(re);
    };
    
    this.isParkInfoPage = function _isParkInfoPage() {
        var re = /info\/parkInfo.aspx$/i;
        return this._isPage(re);
    };
    
    this.isDirectionsPage = function _isDirectionsPage() {
        var re = /info\/directions.aspx/i;
        return this._isPage(re);
    };
    
    this.isFaqPage = function _isFaqPage() {
        var re = /info\/[faq|faqs].aspx$/i;
        return this._isPage(re);
    };
    
    this.getParkName = function _getParkName() {
        var regex = /.com\/(\w+)\//i;
        if (document.location.href.indexOf(".com") == -1) {
            regex = /\/WORKAREA\/(\w+)\//i;
        }
        var matches = regex.exec(window.location);
        var parkName = matches[1] !== undefined ? matches[1] : matches[2];
        return parkName;
    };

    this.getSite = function _getSite() {
        return "six." + this.getParkName().toLowerCase();
    };
    
    this.getZone = function _getZone() {
        if (this.isHomePage()) {
            return "home";
        }
        var regex = new RegExp(this.getParkName() + "\/(\\w+)\/(\\w+.aspx)?$", "i");
        var matches = document.location.href.match(regex);
        if (matches && matches.length && matches.length > 1) {
            return matches[1];
        } else {
            return "home";
        }
        return "";
    };
    
    this.getParkType = function _getParkType() {
        try {
            return this.parkTypes[this.getParkName().toLowerCase()];
        } catch (e){
            return null;
        }
    }
    
    this.getPage = function _getPage() {
        if (this.isHomePage()) {
            return "home";
        } else if (false) {
            return "ticket";
        } else if (this.isTicketsLandingPage()) {
            return "ticketlanding";
        } else if (this.isEventsLandingPage()) {
            return "eventlanding";
        } else if (this.isSpanishPage()) {
            return "spanish";
        } else if (this.isParkInfoPage()) {
            return "parkinfo";
        } else if (this.isDirectionsPage()) {
            return "directions";
        } else if (this.isFaqPage()) {
            return "faq";
        } else if (this.isSeasonPassPage()) {
            return "seasonpass";
        }
        return null;
    };

    this.insertAds = function _insertAds() {
        this.site     = this.getSite();
        this.zone     = this.getZone();
        this.page     = this.getPage();
        this.parkType = this.getParkType();
        this.insertHeaderBanner();
        this.insertFooterBanner();
        this.insertSkyScraper();
    };
    
    this._insertAd = function __insertAd(id, dimensions, position) {
        var el = document.getElementById(id);
        if (el) {
            el.innerHTML = this.generateAd(dimensions, position);
            this.tile++;
        }
    }

    this.insertFooterBanner = function _insertFooterBanner() {
        this._insertAd(
            this.bottomBannerId, 
            this.bannerDimensions, 
            this.bottomBannerPosition
        );
    };
	
    this.insertHeaderBanner = function _insertHeaderBanner() {
    /*    if (!this.isHomePage()) {
            var topNav = document.getElementById("topNav-bucket");
            topNav.className = topNav.className + " header-tall";
            this._insertAd(
                this.upperBannerId,
                this.bannerDimensions, 
                this.upperBannerPosition
            );
        }
	*/
    };
    
    this.insertSkyScraper = function _insertSkyScraper() {
        this._insertAd(
            this.skyScraperId,
            this.skyscraperDimensions, 
            this.skyscraperPosition
        );
    };
        
    this.generateUrl = function _generateUrl(size, position) {
        var ord = window.ord || Math.floor(Math.random()*1E16);
        var url = this.adUrl + this.site + "/" + this.zone + ";pos=" + position;
        if (this.page) {
            url += ";page=" + this.page;
        }
        if (this.parkType) {
            url += ";park=" + this.parkType;
        }
        url += ";tile=" + this.tile + ";sz=" + size + ";ord=" + ord + "?";
        return url;
    };

    this.generateAd = function _generateAd(size, position) {
        var url = this.generateUrl(size, position);
        var width = size.split("x")[0];
        var height = size.split("x")[1];
        var html = "<iframe src='" + url + "' width='" + width + 
                   "' height='" + height + "' marginwidth='0' marginheight='0'" + 
                   " frameborder='0' scrolling='no'>";
        if (navigator.userAgent.indexOf("Gecko") == -1)
        {
            html +='<script type="text/javascript" src="' + url + '?"><\/script>';
        }
        html += "</iframe>"
        return html;
    };
}

function KickAppsListing() {
    
    this.bind = function _bind() {
        var videoContainer = document.getElementById('videos');
        if (videoContainer) {
            var videos = videoContainer.getElementsByTagName('li');
            for (var i = 0; i < videos.length; i++) { 
                var video = videos[i];

                video.onmouseover = function() {
                    var popups = getElementsByClassName('info_popup');
                    for (var i = 0; i < popups.length; i++) {
                        var popup = popups[i];
                        popup.style.display = 'none';
                    }

                    popup = this.getElementsByTagName('div')[1];
                    popup.style.display = 'block';
                }

                video.onmouseout = function() {
                    var popup = this.getElementsByTagName('div')[1];
                    popup.style.display = 'none';
                }
                
                var play_btn = video.getElementsByTagName('div')[0];
                var playLink = play_btn.getElementsByTagName('a')[0];
                playLink.onclick = function() {
                    var embedCode = this.parentNode.parentNode.getElementsByTagName('span')[0].innerHTML;
                    if (embedCode.replace(/\s+/, "") != "") {
                        addEmbeddedObject(embedCode, 'videoHolder', true, false, {});
                    }
                    //addEmbeddedVideo(embedCode);
                    return false;
                }
            }

        }
    }
}

function PhotoPage() {
    this.bind = function _bind() {
        var photoGrid = document.getElementById('photo_grid');
        if (!photoGrid) {
            return;
        }

        var photoGroups = getElementsByClassName('photos', photoGrid);
        if (!photoGroups) {
            return;
        }

        for (var groupIndex = 0; groupIndex < photoGroups.length; groupIndex++) {
            var photoGroup = photoGroups[groupIndex];
            var photos = photoGroup.getElementsByTagName('li');
            for (var i = 0; i < photos.length; i++) { 
                var photo = photos[i];

                photo.onmouseover = function() {
                    var popups = getElementsByClassName('info_popup');
                    // hide any popup that is currently displayed
                    for (var i = 0; i < popups.length; i++) {
                        var popup = popups[i];
                        popup.style.display = 'none';
                    }
    
                    popup = this.getElementsByTagName('div')[0];
                    // if the popup has content to show
                    if (!arrayContains(popup.className.split(' '), 'no_data')) {
                        popup.style.display = 'block';
                    }
                }
    
                photo.onmouseout = function() {
                    var popup = this.getElementsByTagName('div')[0];
                    popup.style.display = 'none';
                }
                
                var imageLinks = photo.getElementsByTagName('a');
                if (imageLinks) {
                    var imageLink = imageLinks[0];
                    imageLink.onclick = function() {
                        var imageSpan = this.getElementsByTagName('span')[0];
                        var largeImageMarkup = imageSpan.innerHTML;
                        // note: we have to use the image's span width instead of the image's width due to incorrect
                        // width values returned in Firefox
                        if (largeImageMarkup.replace(/\s+/, "") != "") {
                            addEmbeddedObject(largeImageMarkup, 'photoHolder', true, true, {'objectWidth': $(imageSpan).width()});
                        }
                    return false;
                    }
                }
            }
        }
    }
}




/******************************************************************************/
/*                          EXACT TARGET CODE                                 */
/******************************************************************************/

var ExactTarget = {
    params: {},
    xml : "",
    tag : "",
    jobId : "",
    memberId : "",
    email : "",
    list : "",
    originalLinkId: "",
    batchId : "",
    conversionLinkId : "2",
    linkAlias : "",
    displayOrder : "2",
    dataSet : "",

    init : function() {
        this.list           = this.getParam('l');
        this.email          = this.getParam('e');
        this.jobId          = this.getParam('j');
        this.batchId        = this.getParam('jb');
        this.memberId       = this.getParam('m');
        this.originalLinkId = this.getParam('u');
        this.linkAlias      = document.title;

        this.track();
    },

    track : function() {
        document.body.appendChild(this.getTag());
    },

    getParam : function(key) {
        if (this.params.length <= 0) {
            this.getParams();
        }

        return this.params[key] ? this.params[key] : '';
    },

    getParams : function() {
        var query = document.location.search;
        query = query.substring(1, query.length);
        var keyValues = query.split('&');
        for (var i = 0; i < keyValues.length; i++) {
            var keyValue = keyValues[i];
            var pos = keyValue.indexOf("=");
            if (pos > 0) {
                var key = keyValue.substring(0, pos);
                var value = keyValue.substring(pos + 1);
                this.params[key] = value;
            }
        }
    },

    getXml : function() {
        if (!this.xml) {
            this.xml = "<system><system_name>tracking</system_name><action>conversion</action>"
                     + "<member_id>" + this.memberId + "</member_id>"
                     + "<job_id>" + this.jobId + "</job_id>"
                     + "<email>" + this.email + "</email>"
                     + "<list>" + this.list + "</list>"
                     + "<original_link_id>" + this.originalLinkId + "</original_link_id>"
                     + "<BatchID>" + this.batchId + "</BatchID>"
                     + "<conversion_link_id>" + this.conversionLinkId + "</conversion_link_id>"
                     + "<link_alias>" + this.linkAlias + "</link_alias>"
                     + "<display_order>" + this.displayOrder + "</display_order>"
                     + "<data_set>" + this.dataSet + "</data_set>"
                     + "</system>";
        }

        return this.xml;
    },

    getTag : function() {
        if (!this.tag) {
            this.tag = document.createElement("img");
            this.tag.src = "http://click.exacttarget.com/conversion.aspx?xml=" + this.getXml();
            this.width = "1";
            this.height = "1";
        }

        return this.tag;
    }
}

var ExpireDays = 90;
//Do not change anything below this line
qstr = document.location.search;
qstr = qstr.substring(1, qstr.length)
function SetCookie(cookieName, cookieValue, nDays)
{
    var today = new Date();
    var expire = new Date();
    if (nDays == null || nDays == 0) nDays = 1;
    expire.setTime(today.getTime() + 3600000 * 24 * nDays);
    document.cookie = cookieName + "=" + escape(cookieValue) + ";expires=" + expire.toGMTString() + ";domain=sixflags.com; path=/;";
}

thevars = qstr.split("&");
for (i = 0; i < thevars.length; i++) {
    var aryVariable
    aryVariable = thevars[i].split('=');
    switch (aryVariable[0]) {
        case "e":
            thevars[i] = thevars[i].replace("=", "='") + "'";
            eval(thevars[i]);
            SetCookie("EmailAddr", e, ExpireDays);
            break;
        case "j":
            thevars[i] = thevars[i].replace("=", "='") + "'";
            eval(thevars[i]);
            SetCookie("JobID", j, ExpireDays);
            break;
        case "l":
            thevars[i] = thevars[i].replace("=", "='") + "'";
            eval(thevars[i]);
            SetCookie("ListID", l, ExpireDays);
            break;
        case "u":
            thevars[i] = thevars[i].replace("=", "='") + "'";
            eval(thevars[i]);
            SetCookie("UrlID", u, ExpireDays);
            break;
        case "mid":
            thevars[i] = thevars[i].replace("=", "='") + "'";
            eval(thevars[i]);
            SetCookie("MemberID", mid, ExpireDays);
            break;
        default:
            if (thevars[i] && thevars[i].indexOf('=') != -1) {
                thevars[i] = thevars[i].replace("=", "='") + "'";
                eval(thevars[i]);
            }
            break;
    }
}


