
    // 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();
        // replace parknames in links
            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');
                                    // mobile device detection
                                        if (!$.browser.mobile) {
                                        // make movie
                                                thisSwfMovie = swf.movie(swfUrl, swfWidth, swfHeight, 10, '/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') {
                    if (isIE6) {
                        createMajorNav(
                            document.getElementById('midNav-bucket'), 
                            midNav,
                            'midNav-menu',
                            false, 
                            setBehaviour, 
                            true, 
                            false, 
                            false, 
                            185
                        );
                    } else {
                         createMajorNav(
                             document.getElementById('midNav-bucket'), 
                             midNav,
                             'midNav-menu',
                             false, 
                             setBehaviour, 
                             true, 
                             false, 
                             false, 
                             160
                         );
                    }
                } else {
                    if (isIE6) {
                        createMajorNav(
                            document.getElementById('midNav-bucket'), 
                            midNav, 
                            'midNav-menu',    
                            false, 
                            setBehaviour, 
                            false, 
                            false, 
                            false,  
                            35
                        );
                    } else if (isIE7) {
                        createMajorNav(
                            document.getElementById('midNav-bucket'), 
                            midNav, 
                            'midNav-menu',    
                            false, 
                            setBehaviour, 
                            false, 
                            false, 
                            false, 
                            35
                        );
                    } else {
                        createMajorNav(
                            document.getElementById('midNav-bucket'), 
                            midNav, 
                            'midNav-menu',    
                            false, 
                            setBehaviour, 
                            false, 
                            false, 
                            false, 
                            45
                        );
                    }
                }
            }
            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 10
                    var swfMovie = swf.movie('/global/func/sifr/futura_bold.swf', headWidth, headHeight, 10, '/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 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, 10, '/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;
}
