﻿/****************************************************************************************
* Global Javascript file
* 
* Extends functionality of jQuery and instantiates commonly used interacitve elements
*/
/****************************************************************************************
* Brighthouse initialization code
*/
// Global variables
bhn = [];
pageLocalization = null;
overlayState = null;

$('#localize').click(function(e){e.preventDefault();});

// After markup has loaded
$(document).ready(function() {
    $.forceRefresh();
    $("#nav li, #sub-nav li").hoverize();
    $.mobileFilter();
    $('.divided-column-content, #footer .left-local, #callout').colfix();
    $('a[rel*=tooltip]').tooltip();
    $('a[rel=lightbox]').lightbox();
    $('a[rel*=reset]').override('ENU');
    $('a[target=_top]').redirectLocalization();
    $.initAnimations();
    $.manageLocalization();
    $.systemAlert();
    $.searchBox();
    //$.chatlinks(); Disable function for chat availability service - JR
    $.autoExecute();
});

// After images have loaded
$(window).load(function() {
    var loc = $.getLocalization();
    if ((!loc || loc.divisionid == 'ENU') && pageLocalization == 'force' ){
        $.forceLocalization();
    }else if (pageLocalization == 'prevent'){
        $.interceptLocalization();
    }else{
//        setTimeout("$.onceOnlyOverlay('welcome')", 2000);
    }
    $('.collapsible').collapsible();
});
/****************************************************************************************
* Global URLs
*/
// Determine which environment we are in
var proto = window.location.protocol;
var domain = document.domain;
var env = domain.substring(domain.lastIndexOf('.'));
env = (env == '.com') ? env : '.stage';
if (env == '.stage') {
    cmsBaseURL = 'http://corporate.brighthouse' + env;
    sitesearchURL = 'http://applications.brighthouse' + env + '/site-search/';
    areasWeServeURL = 'http://corporate.brighthouse' + env + '/corporate/about/service-areas';
    chatlinksWSURL = 'http://chatagentavailability.brighthouse' + env + '/ChatHoursForDisplay.ashx';
    systemAlertWSURL = 'http://wcf.brighthouse' + env + '/system-alerts/REST/GetMessages.ashx';
    flowPlayerSWF = 'http://corporate.brighthouse' + env + '/static/interactive/flowplayer.commercial-3.1.5.swf';
    flowPlayerControls = 'http://corporate.brighthouse' + env + '/static/interactive/flowplayer.controls-3.1.5.swf';
} else {
    // Link Suppression for .com 
    /*
    $(window).ready(function() {
        $("a").click(function(e) {
            if ($.LinkSuppression($(this).attr("href"))) {
                e.preventDefault();
                $.LinkSuppressionAction($(this));
                return false;
            }
        });
    });
    */
    cmsBaseURL = proto + '//brighthouse' + env;
    sitesearchURL = 'http://applications.brighthouse' + env + '/site-search/';
    areasWeServeURL = 'http://brighthouse' + env + '/corporate/about/service-areas';
    chatlinksWSURL = proto + '//chatagentavailability.brighthouse' + env + '/ChatHoursForDisplay.ashx';
    systemAlertWSURL = 'https://wcf.brighthouse' + env + '/system-alerts/REST/GetMessages.ashx';
    flowPlayerSWF = proto + '//brighthouse' + env + '/static/interactive/flowplayer.commercial-3.1.5.swf';
    flowPlayerControls = proto + '//brighthouse' + env + '/static/interactive/flowplayer.controls-3.1.5.swf';
}

/********************************************************************************************
* Plugins
*/
if (jQuery) (function($) {
    /****************************************************************************************
    * Global Methods
    *
    ****************************************************************************************/
    jQuery.extend(jQuery.fn, {
        /**************************************************
        * Dynamic Style Sheet Embed
        */
        addStyleSheet: function(src) {
            // Exit if no value is passed.
            if (!src) return;
            // Create style sheet link
            this.each(function() {
                var $this = $(this);
                $this.append("<link>");
                css = $this.children(":last");
                css.attr({
                    rel: "stylesheet",
                    type: "text/css",
                    href: src
                });
            });
        },
        /**************************************************
        * Cookie Override
        */
        override: function(div) {
            this.each(function() {
                var a = $(this);
                a.click(function(e) {
                    e.preventDefault();
                    var url = a.attr('href') + '?divisionid=' + div + '&zipcode=%20&divisionname=%20';
                    document.location.href = url;
                });
            });
        },
        /**************************************************
        * Localized Links
        */
        redirectLocalization: function() {
            this.each(function() {
                var a = $(this);
                var loc = $.getLocalization();
                if (!loc || loc.divisionid == 'ENU') {
                    a.click(function(e) {
                        e.preventDefault();
                        $.redirectLocalization(a.attr('href'));
                    });
                } else {
                    a.attr('target', '');
                }
            });
        },
        /**************************************************
        * Hoverize
        */
        hoverize: function(o) {
            // Defaults
            if (!o) var o = {};
            if (o.selectedClass == undefined) o.selectedClass = 'selected';
            if (o.hoverClass == undefined) o.hoverClass = 'hover';
            this.each(function() {
                var $this = $(this);
                $this.hover(function() {
                    if (!$this.hasClass(o.selectedClass)) {
                        $this.addClass(o.hoverClass);
                    }
                }, function() {
                    if (!$this.hasClass(o.selectedClass)) {
                        $this.removeClass(o.hoverClass);
                    }
                }
            );
            });
        },

        /**************************************************
        * Collaspible Panel
        */
        collapsible: function(o) {
            var defaults = {
                toggle: '<a href="#" class="toggle">+</a>'
            };
            var opts = $.extend(defaults, o);

            this.each(function() {
                var panel = $(this);
                panel.addClass('collapsed');
                var header = panel.children('.panel-header');
                if (!header.children(":first").hasClass('toggle')) {
                    header.prepend(opts.toggle);
                    header.css({ cursor: 'pointer' });
                    header.click(function(e) {
                        panel.toggleClass('collapsed');
                    });
                    var toggle = header.children(":first");
                    toggle.click(function(e) {
                        toggle.blur();
                        e.preventDefault();
                    });
                }
            });
        },
        /**************************************************
        * Tooltip
        *
        */
        tooltip: function(options) {
            var defaults = {
                wrapper: '<div id="tooltip"></div>',
                title: '<span id="tooltip-title"></span>',
                content: '<div id="tooltip-content"></div>',
                close: '<a id="tooltip-close" href="#">close</a>',
                indicator: '<div id="tooltip-indicator"></div>'
            };
            /**
            * Example HTML this plugin is looking for:
            *  
            * <a href="#" class="help" rel="tooltip" title="Optional Title">
            *    ?
            *    <span class="info">
            *        Tooltip text
            *    </span>
            * </a> 
            *
            *  
            * Example HTML this plugin renders:
            *     
            *  <div id="tooltip">
            *      <a class="close" href="#">close</a>
            *      <div id="tooltip-content" class="info">
            *            <span id="tooltip-title">Optional Title.</span>
            *            Tooltip text
            *      </div>
            *      <div id="tooltip-indicator"></div>
            *  </div> 
            *
            */
            // initial variables
            var opts = $.extend(defaults, options);
            return this.each(function() {
                var a = $(this);
                a.click(function(e) {
                    a.blur();
                    e.preventDefault();
                    // permits the tooltip to be closed by clicking a second time
                    if (a.hasClass('active')) {
                        a.removeClass('active');
                        $('#tooltip').remove();
                        return false;
                    }
                    // ensures only one tooltip displays at a time
                    if ($('#tooltip')) $('#tooltip').remove();
                    $('a.help.active').removeClass('active');
                    tip = jQuery(opts.wrapper);
                    // add basic elements to wrapper
                    tip.prepend(opts.close + opts.content + opts.indicator);
                    // create quick references to the tooltip's elements
                    t_content = tip.find('#tooltip-content');
                    close_btn = tip.find('#tooltip-close');
                    // grab values from the anchor
                    var span = a.find('span').clone();
                    var type = span.attr('class');
                    var em = span.find('em');
                    var title = (em)? em.html(): a.attr("title");
                    em.remove();
                    var content = span.html();
                    // populate the elements in the tooltip with values               
                    t_content.addClass(type);
                    t_content.html(content);
                    if (title) {
                        t_content.prepend(opts.title);
                        t_title = tip.find('#tooltip-title');
                        t_title.html(title);
                    }
                    // prepare close button click action
                    close_btn.click(function(e) {
                        e.preventDefault();
                        a.removeClass('active');
                        tip.remove();
                    });
                    //$(opts.wrapper).prepend(a.attr('title'));
                    //alert(tip.html())
                    //title = a.attr('title').wrap(opts.title)
                    //content = a.find("span").wrap(opts.content)
                    $('body').append(tip);
                    // position tooltip
                    var offset = a.offset();
                    tip.css({
                        'top': offset.top - tip.height() - 8 + 'px',
                        'left': offset.left - tip.width() + 32 + 'px',
                        'display': 'block'
                    });
                    // top = offset.top - tip.height() + 5;
                    // right = offset.right - 5;
                    //alert(tip.height());
                    a.addClass('active');
                });
            });
        },

        /*
        <div class="modal-content">
        <h3>Thank You for Visiting Bright House Networks</h3>
        <p class="dynamic-text"></p>
        <p>You will be tranfered to <span class="dynamic-link">www.onlinesalescentral.com</span> in <span class="countdown-timer">10</span> second or click continue to go there now.</p>
        </div>
    
*/

        /**************************************************
        * External Link Redirect
        */
        externalURL: function(msg) {
            this.each(function() {
                var a = $(this);
                message = (msg) ? msg : a.attr('title');
                var href = a.attr('href');
                var str = href.substring(href.indexOf('//' + 2));
                var domain = str.substring(str.indexOf('/') + 2, str.lastIndexOf('/'));
                // establish modal options for both external and internal
                var options = {
                    cssclass: 'modal',
                    filter: '.modal-container',
                    unloadOnHide: true,
                    modal: true,
                    title: ' ',
                    closeText: ' ',
                    afterShow: function() {
                        // if custom message
                        if (message) $('.overlay-wrapper .modal-head p').html(message);
                        //if (message) $('.overlay-wrapper .dynamic-text').html(message + ' ');
                        $('.overlay-wrapper .dynamic-link').html(domain + ' ');
                        $('.overlay-wrapper .button').attr('href', href)
                        // begin timer
                        timer = setTimeout("window.location.href = '" + href + "'", 10000)
                    },
                    beforeUnload: function() {
                        clearTimeout(timer);
                        // Reset overlayState
                        overlayState = null;
                        $('#prototypes').append($('#redirect'))
                    }
                };
                a.click(function(e) {
                    e.preventDefault();
                    // find the overlay's content
                    if ($('#prototypes #redirect').length) {
                        // if the overlay content is present on the page
                        var content = $('#redirect');
                        // create overlay
                        new Overlay(content, options);
                        return;
                    } else {
                        // load the content from url
                        content = cmsBaseURL + '/corporate/structural/redirect-modal';
                        // create overlay
                        Overlay.load(content, options);
                    }
                });
            });
        },

        /**************************************************
        * Lightbox (requires jquery.overlay.js)
        *
        */
        lightbox: function(options) {
            var defaults = {};
            var opts = $.extend(defaults, options);
            /**
            * Example HTML this plugin is looking for:
            *  
            * <a href="image.jpg" rel="lightbox" title="Optional Title||PARAMS||FLASHVARS">
            *    Link name
            * </a> 
            * <div class="info">
            *     <div class="subtitle">Optional Subtitle</div>
            *     Description goes here
            * </span>
            */
            return this.each(function() {
                // define default params
                var params = {
                    'width': 'auto',
                    'height': 'auto'
                };
                var a = $(this);
                var info = a.next('.info').clone();
                var title = a.attr('title');
                var subtitlediv = info.find('.subtitle');
                
                a.next('.info').css('display','none');
                // If Params and/or FlashVars exist
                if (title && title.indexOf('||') >= 0) {
                    var pflag = title.indexOf('||');
                    var fflag = (title.lastIndexOf('||') != pflag) ? title.lastIndexOf('||') : title.length;
                    var paramstemp = title.substring((pflag + 2), fflag).split('&');
                    a.attr('params', paramstemp);
                    var flashvarstemp = '';
                    if (fflag != title.length) var flashvarstemp = title.substring(fflag + 2).split('&');
                    a.attr('flashvars', flashvarstemp);
                    a.attr('title', title.substring(0, (pflag)));
                }
                // If image is dynamically generated without ext (i.e. google map)
                if (a.attr('href').indexOf('&size=') >= 0) {
                    var str = a.attr('href').substr((a.attr('href').indexOf('&size=') + 6));
                    var size = str.substr(0, str.indexOf('&'));
                    size = size.split('x');
                    a.attr('params', 'width=' + size[0] + ',height=' + size[1]);
                }
                a.click(function(e) {
                    e.preventDefault();
                    var href = a.attr('href');
                    //var span = a.find('span').clone();
                    var title = a.attr('title');
                    // is this a dynamic image? (i.e. google map)
                    if (href.lastIndexOf('?ext') >= 0) {
                        var linktype = href.substring((href.lastIndexOf('.') + 1), (href.lastIndexOf('?ext')));
                    } else if (href.lastIndexOf('?') >= 0) {
                        var linktype = href.substring((href.lastIndexOf('.') + 1), (href.lastIndexOf('?')));
                    } else {
                        var linktype = href.substring((href.lastIndexOf('.') + 1));
                    }                    if (info.html()) {
                        var subtitle = "";
                        if (subtitlediv.html()){
                            if (!title){
                                title = subtitlediv.html();
                            }else{
                                subtitle = subtitlediv.html();
                            }
                        }
                        subtitlediv.remove();
                    }
                    if (a.attr('params')) {
                        var paramstemp = a.attr('params').split(',');
                        $.each(paramstemp, function(i, string) {
                            var temp = string.split('=');
                            params[temp[0]] = temp[1];
                        });
                    }
                    if (a.attr('flashvars')) {
                        var flashvarstemp = a.attr('flashvars').split(',');
                        var flashvars = {};
                        $.each(flashvarstemp, function(i, string) {
                            var temp = string.split('=');
                            flashvars[temp[0]] = temp[1];
                        });
                    };
                    switch (linktype) {
                        // if link is to an image                                                                                                                           
                        case 'jpg':
                        case 'png':
                        case 'gif':
                            
                            // join content
                            var sizetest = (params['width'] != 'auto') ? 'width="' + params['width'] + '" height="' + params['height'] + '"' : '';
                            var content = "<div><img src='" + href + "' " + sizetest + " />";
                            if (title && info.html()) {
                                content += "<div><h3>" + title + "</h3>";
                                content += info.html() + "</div>";
                            }
                            content += '</div>'
                            // preload image
                            var preloadImg = new Image();
                            
                            // image load success
                            preloadImg.onload = function() {
                                // create lightbox
                                new Overlay(content, {
                                    type: 'lightbox',
                                    title: ' '
                                });
                            }
                            // image load fail
                            preloadImg.onerror = function() {
                                $.errorModal('Error', '<p>The image failed to load.</p>')
                            }
                            preloadImg.src = href;
                            break;

                        // if link is to video or flash                                                                                                       
                        case 'flv':
                            // join content
                            var content = '<div id="FlashPlayer" style="width: ' + params['width'] + 'px; height: ' + params['height'] + 'px;"></div>';
                            if (title && info.html()) {
                                content += "<div><h3>" + title + "</h3>";
                                content += info.html() + "</div>";
                            }
                            // create lightbox
                            new Overlay(content, {
                                type: 'lightbox', title: ' ',
                                afterShow: function() {
                                    $f("FlashPlayer", { src: flowPlayerSWF, wmode: 'transparent' }, {
                                        key: '#@8e7d8db6061317a54fc',
                                        clip: { url: href, autoPlay: true, autoBuffering: true },
                                        controls: { url: flowPlayerControls }
                                    });
                                }
                            });
                            break;
                        case 'swf':
                            // join content
                            var content = '<div id="FlashPlayer" style="display: block; width: ' + params['width'] + 'px; height:  ' + params['height'] + 'px;"></div>';
                            if (title && info.html()) {
                                content += "<div><h3>" + title + "</h3>";
                                content += info.html() + "</div>";
                            }
                            // create lightbox
                            new Overlay(content, {
                                type: 'lightbox', title: ' ',
                                afterShow: function() {
                                    var flashparams = { wmode: "transparent" };
                                    swfobject.embedSWF(href, "FlashPlayer", params['width'], params['height'], "9", "expressInstall.swf", flashvars, flashparams);
                                }
                            });
                            break;
                        default:
                            // join content
                            var content = '<div class="modal-container">';
                            if (title && info.html()) {
                                content += '<div class="modal-head"><h3>' + title + '</h3><p>' + subtitle + '</p></div>';
                                content += '<div class="modal-content">' + info.html() + '</div>';
                            }
                            content += '</div>'
                            // create lightbox
                            new Overlay(content, {
                                type: 'modal',
                                title: ' '
                            });
                            break;
                    }
                });
            });
        },

        /**************************************************
        * Column fix (height and last column)
        */
        colfix: function(o) {
            this.each(function() {
                var $this = $(this);
                var height = null;
                if (!$this.children('.lastcol')[0]) {
                    var last = $this.children('.col:last');
                    last.addClass('lastcol');
                    last.removeClass('col');
                }
                $this.children('.col').height('auto');
                $this.children('.col').each(function() {
                    var col = $(this);
                    if (o) alert(col.height());
                    if (height < col.height()) height = col.height();
                });
                if ($.support.minHeight()) {
                    $this.children('.col').css({ 'min-height': height + 20 });
                } else {
                    $this.children('.col').css({ 'height': height + 20 });
                }
            })
        }
    });
    /****************************************************************************************
    * Global Functions
    *
    ****************************************************************************************/
    /**************************************************
    * String editors
    */
    jQuery.Left = function(str, n) {
        if (n <= 0)
            return "";
        else if (n > String(str).length)
            return str;
        else
            return String(str).substring(0, n);
    }
    jQuery.Right = function(str, n) {
        if (n <= 0)
            return "";
        else if (n > String(str).length)
            return str;
        else {
            var iLen = String(str).length;
            return String(str).substring(iLen, iLen - n);
        }
    }
    //returns true if link should be surpressed
    jQuery.LinkSuppression = function(linkUrl) {
        if(linkUrl == null || linkUrl == "")
            return false;
 
        //hack for chat - we want all other contacts to be enabled
        if(linkUrl.indexOf("/support/contact/chat") >= 0)
            return true;
 
        var whiteListUrls = new Array("/support/contact",
            "/support/phone/battery",
            "/support/moving",
            "/support/seasonal",
            "/support/tv/program-remote");
 
        for (i = 0; i < whiteListUrls.length; i++) {
            if (linkUrl.indexOf(whiteListUrls[i]) >= 0) {
                //alert("white listed");
                return false;
            }
        }
        
        var urlsToSuppress = new Array("/support",
            "//support.brighthouse.",
            "//login.brighthouse.",
            "/shop/order",
            "/my-services/voice-mail",
            "/my-services/call-history",
            "/my-services/easy-gadget");

        
        for(i = 0; i < urlsToSuppress.length; i++) {
            if(linkUrl.indexOf(urlsToSuppress[i]) >= 0)
            {
                //alert("black listed");
                return true;
            }
        }
        return false;
    }
    
    jQuery.LinkSuppressionAction = function($link)
    {
        var title = $link.attr("title");
        if(title == null || title == "")
            title = "Disabled link";
        $.errorModal(title, "This link is not available during the employee release of the new Brighthouse.com website.");
    }



    /**************************************************
    * min-height detection
    */
    jQuery.extend(jQuery.support, {
        minHeight: function() {
            var id = "minheightsupport" + (new Date).getTime();
            $("<div></div>").attr("id", id)
                       .css({
                           height: "1px",
                           minHeight: "2px",
                           overflow: "hidden",
                           border: "none",
                           padding: "0",
                           margin: "0"
                       })
                       .appendTo("body");
            var iscorrectheight = document.getElementById(id).offsetHeight == 2;
            $("#" + id).remove();
            return iscorrectheight;
        }
    });

    /**************************************************
    * URL Encoding/Decoding
    */
    jQuery.URLEncode = function(c) {
        var o = ''; var x = 0; c = c.toString(); var r = /(^[a-zA-Z0-9_.]*)/;
        while (x < c.length) {
            var m = r.exec(c.substr(x));
            if (m != null && m.length > 1 && m[1] != '') {
                o += m[1]; x += m[1].length;
            } else {
                if (c[x] == ' ') o += '+'; else {
                    var d = c.charCodeAt(x); var h = d.toString(16);
                    o += '%' + (h.length < 2 ? '0' : '') + h.toUpperCase();
                } x++;
            }
        } return o;
    },
    jQuery.URLDecode = function(s) {
        var o = s; var binVal, t; var r = /(%[^%]{2})/;
        while ((m = r.exec(o)) != null && m.length > 1 && m[1] != '') {
            b = parseInt(m[1].substr(1), 16);
            t = String.fromCharCode(b); o = o.replace(m[1], t);
        } return o;
    }
    /**************************************************
    * Scroll To
    */
    (function(h) { var m = h.scrollTo = function(b, c, g) { h(window).scrollTo(b, c, g) }; m.defaults = { axis: 'y', duration: 1 }; m.window = function(b) { return h(window).scrollable() }; h.fn.scrollable = function() { return this.map(function() { var b = this.parentWindow || this.defaultView, c = this.nodeName == '#document' ? b.frameElement || b : this, g = c.contentDocument || (c.contentWindow || c).document, i = c.setInterval; return c.nodeName == 'IFRAME' || i && h.browser.safari ? g.body : i ? g.documentElement : this }) }; h.fn.scrollTo = function(r, j, a) { if (typeof j == 'object') { a = j; j = 0 } if (typeof a == 'function') a = { onAfter: a }; a = h.extend({}, m.defaults, a); j = j || a.speed || a.duration; a.queue = a.queue && a.axis.length > 1; if (a.queue) j /= 2; a.offset = n(a.offset); a.over = n(a.over); return this.scrollable().each(function() { var k = this, o = h(k), d = r, l, e = {}, p = o.is('html,body'); switch (typeof d) { case 'number': case 'string': if (/^([+-]=)?\d+(px)?$/.test(d)) { d = n(d); break } d = h(d, this); case 'object': if (d.is || d.style) l = (d = h(d)).offset() } h.each(a.axis.split(''), function(b, c) { var g = c == 'x' ? 'Left' : 'Top', i = g.toLowerCase(), f = 'scroll' + g, s = k[f], t = c == 'x' ? 'Width' : 'Height', v = t.toLowerCase(); if (l) { e[f] = l[i] + (p ? 0 : s - o.offset()[i]); if (a.margin) { e[f] -= parseInt(d.css('margin' + g)) || 0; e[f] -= parseInt(d.css('border' + g + 'Width')) || 0 } e[f] += a.offset[i] || 0; if (a.over[i]) e[f] += d[v]() * a.over[i] } else e[f] = d[i]; if (/^\d+$/.test(e[f])) e[f] = e[f] <= 0 ? 0 : Math.min(e[f], u(t)); if (!b && a.queue) { if (s != e[f]) q(a.onAfterFirst); delete e[f] } }); q(a.onAfter); function q(b) { o.animate(e, j, a.easing, b && function() { b.call(this, r, a) }) }; function u(b) { var c = 'scroll' + b, g = k.ownerDocument; return p ? Math.max(g.documentElement[c], g.body[c]) : k[c] } }).end() }; function n(b) { return typeof b == 'object' ? b : { top: b, left: b} } })(jQuery);
    
    
    /**************************************************
    * Mobile Detection
    */
    jQuery.mobileFilter = function(){
            // only execute if there is mobile contextual content    
            if ($('.mobile-content')[0]){
                var isMobile = function(a,b){if(/android|avantgo|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i.test(a)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|e\-|e\/|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(di|rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|xda(\-|2|g)|yas\-|your|zeto|zte\-/i.test(a.substr(0,4)))
                                             return b}(navigator.userAgent||navigator.vendor||window.opera,true);
                if(isMobile){
                    // mobile data renders by default
                    return
                }else{
                    $('.mobile-content').remove();
                    $('.desktop-content').show();
                }    
            }
    };


    /**************************************************
    * Mobile Redirect for mobile landing page. Only applies for home page.
    */
    jQuery.mobileRedirect = function(){
        var isMobile = function(a,b){if(/android|avantgo|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i.test(a)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|e\-|e\/|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(di|rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|xda(\-|2|g)|yas\-|your|zeto|zte\-/i.test(a.substr(0,4)))
            return b}(navigator.userAgent||navigator.vendor||window.opera,true);
        return isMobile;
    };


    /**************************************************
    * Cookie Read/Write
    */
    jQuery.cookie = function(name, value, options) {
        if (typeof value != 'undefined') { // name and value given, set cookie
            options = options || {};
            if (value === null) {
                value = '';
                options.expires = -1;
            }
            var expires = '';
            if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
                var date;
                if (typeof options.expires == 'number') {
                    date = new Date();
                    date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
                } else {
                    date = options.expires;
                }
                expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
            }
            // CAUTION: Needed to parenthesize options.path and options.domain
            // in the following expressions, otherwise they evaluate to undefined
            // in the packed version for some reason...
            var path = options.path ? '; path=' + (options.path) : '';
            var domain = options.domain ? '; domain=' + (options.domain) : '';
            var secure = options.secure ? '; secure' : '';
            document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
        } else { // only name given, get cookie
            var cookieValue = null;
            if (document.cookie && document.cookie != '') {
                var cookies = document.cookie.split(';');
                for (var i = 0; i < cookies.length; i++) {
                    var cookie = jQuery.trim(cookies[i]);
                    // Does this cookie string begin with the name we want?
                    if (cookie.substring(0, name.length + 1) == (name + '=')) {
                        cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                        break;
                    }
                }
            }
            return cookieValue;
        }
    };
    /**************************************************
    * Force refresh
    */
    jQuery.forceRefresh = function() {
        // Forces refresh when back button is used
        var e = $('#refreshed');
        if (e.attr('value') == 'no') {
            e.attr('value','yes');
        } else if (e.attr('value') == 'yes') {
            e.attr('value', 'no');
            location.reload();
        }
    };

    /**************************************************
    * Animations
    */
    jQuery.initAnimations = function() {
        // Establish default display values
        $('#sub-nav li .dropdown').css({ 'height': '0px', 'overflow': 'hidden' })
        $('#sub-nav li .dropdown img').css({ 'opacity': '0' })
        
        // Reveal Dropdown
        $('#sub-nav li:has(.dropdown)').mouseenter(function(e) {
            var dropdown = $(this).find('.dropdown');
            dropdown.css('z-index', 1000)
            dropdown.animate({ 'height': '272px' }, { duration: 300, queue: false, complete: function() {
                dropdown.find('img').animate({ 'opacity': '1' }, 500)
            } 
            });
        });
        // Hide Dropdown
        $('#sub-nav li:has(.dropdown)').mouseleave(function(e) {
            var dropdown = $(this).find('.dropdown');
            dropdown.css('z-index', 100)
            dropdown.find('img').css({ 'opacity': '0' })
            dropdown.animate({ 'height': '0px' }, { duration: 300, queue: false, complete: function() {
                dropdown.css({ 'display': 'none' })
            } 
            })
        });
    };

    /**************************************************
    * Search
    */
    jQuery.searchBox = function() {
        var input = $('#search-box input');
        var button = $("#search-box button");
        var searchURL = sitesearchURL;
        // fix z-indexing on IE6 and 7
        $('#nav').css({ position: 'static' });
        $('#nav').css({ position: 'relative', 'z-index': 1001 });
        // Establish core interactivity
        $('#search-trigger').click(function() {
            $('#search-box').css({ display: 'block' });
            input.focus();
            $('#search-box .close').click(function(e) {
                e.preventDefault();
                $(this).blur();
                $('#search-box').css({ display: 'none' });
            });
        });
        // Handle search submit
        button.click(function(e) {
            e.preventDefault();
            var search = jQuery.trim(input.val());
            if (search != null && search != "") {
                $('#search-box').css({ display: 'none' });
                var params = '?' + input.attr('name') + '=' + $.URLEncode(input.val());
                top.location = searchURL + params;
            }
        });
        input.keyup(function(e) {
            if (e.keyCode == 13) {
                button.trigger('click');
                return false;
            }
        });
    };
    /**************************************************
    * Get Localization
    */
    jQuery.getLocalization = function() {
        var cookie = $.cookie("divisionid");
        if (!cookie) return false;
        var divisionid = parseCookie(cookie);
        var divisionname = parseCookie($.cookie("divisionname"));
        var zipcode = parseCookie($.cookie("zipcode"));
        var localization = {
            'divisionid': divisionid,
            'divisionname': divisionname,
            'zipcode': zipcode
        };
        function parseCookie(cookieValue) {
            if (!cookieValue) return false;
            var parsedValue = '';
            if (cookieValue.indexOf("rdecookie") < 0) {
                parsedValue = cookieValue;
            } else {
                parsedValue = cookieValue.substring(49);
                parsedValue = parsedValue.replace(/\.3/g, "");
                parsedValue = parsedValue.replace(/\.20/g, " ");
            }
            return parsedValue;
        }
        if(divisionid.indexOf("rdecookie") >= 0){
            $.cookie("divisionid", "", {expires : -1, path: '/', domain: '.brighthouse'+ env });
            $.cookie("divisionname", "", {expires : -1, path: '/', domain: '.brighthouse'+ env });
            $.cookie("zipcode", "", {expires : -1, path: '/', domain: '.brighthouse'+ env });
            $.cookie("priordivisionid", "", {expires : -1, path: '/', domain: '.brighthouse'+ env });
            $.cookie("priordivisionname", "", {expires : -1, path: '/', domain: '.brighthouse'+ env });
            $.cookie("priorzipcode", "", {expires : -1, path: '/', domain: '.brighthouse'+ env });
            return false;
        }

        return localization;
    };
    /**************************************************
    * Redirect Localization
    */
    jQuery.redirectLocalization = function(url, t, m) {
        // Overwrite default localization title, message, and URL
        var title = (t) ? t : '';
        var message = (m) ? m : '';
        var defaultclose = true;
        // force localization modal (with updates)
        $.forceLocalization(title, message, url, defaultclose);
        return;
    };
    /**************************************************
    * Intercept Localization
    */
    jQuery.interceptLocalization = function(title, message) {
        // If this application needs to prevent localization
        if (!title || !message) {
            title = "We're Sorry!";
            message = "<p>The page is not available from the location you are choosing. Please return to the <a href='" + cmsBaseURL + "'>Home page</a> and try again.</p>"; 
        }
        $('#localize').attr('rel', '');
        $('#localize').unbind('click');
        $('#localize').click(function(e) {
            e.preventDefault();
            $.errorModal(title, message);
        });
        return;
    };
    /**************************************************
    * Update Localization Status
    * 
    */
    jQuery.updateLocalization = function(divisionname, zipcode) {
        // if user is localized
        var localization = $.getLocalization();
        if (!localization && divisionname) {
            localization = {
                'divisionname': divisionname,
                'zipcode': zipcode
            };
        }
        // if not National, find spans and update their values
        if (localization && localization.divisionid != 'ENU') {
            if (localization.zipcode && localization.divisionname) {
                $('#loc-name').html(localization.divisionname);
                $('#loc-zip').html(', ' + localization.zipcode + '. ');
            } else if (localization.zipcode) {
                $('#loc-name').html('');
                $('#loc-zip').html(' ' + localization.zipcode + '. ');
            } else if (localization.divisionname) {
                $('#loc-name').html(localization.divisionname) + ' ';
            }
        }
    };
    /**************************************************
    * Manage Localization
    * 
    */
    jQuery.manageLocalization = function(title, message) {
        $.updateLocalization();
        // update (Change) link click event if external app
        var subdomain = window.location.host.split('.');
        switch (subdomain[0]) {
            // INTERNAL                                                                                                                                                                                             
            case 'bh':
            case 'tamp21potmgt1':
            case 'tamp21potmgt2':
            case 'brighthouse':
            case 'corporate':
            case 'corpdev':
            case 'corpstage':
            case 'wa':
            case 'www':
            case 'www1':
            case 'www2':
                break;
            // EXTERNAL                           
            case 'applications':
            case 'tlogin':
            default:
                // Prevent default overlay implimentation
                $('#localize').attr('rel', '');
                $('#localize').unbind('click');
                $('#prototypes form').each(function() {
                    var form = $(this);
                    var action = form.attr('action');
                    var urlBase = cmsBaseURL;
                    form.attr('action', urlBase + action);
                    var desturl = form.find('input[name=desturl]');
                    if (desturl.attr('value')) {
                        var desturlval = desturl.attr('value').replace(/\.htm/g, "");
                        desturl.attr('value', desturlval);
                    }
                });
                // Get localization div
                if ($('#localization').length) {
                    // Get localization div
                    var content = $('#localization');
                    // Prepare modal
                    $('#localize').click(function(e) {
                        e.preventDefault();
                        new Overlay(content, {
                            cssclass: 'modal-alt',
                            filter: '.modal-container',
                            unloadOnHide: true,
                            modal: true,
                            title: ' ',
                            closeText: ' ',
                            afterShow: function() {
                                overlayState = 'active';
                                // Style select option lists
                                $('.overlay-wrapper select').sSelect({
                                    ddMaxHeight: 260,
                                    ddMinWidth: 139,
                                    ddMaxWidth: 310,
                                    ulWidthOffset: 8
                                });
                                // instantiates solo-input validation 
                                $('.input-solo').restrict('input[name=zipcode]','zipcode')
                                // instantiates select validation 
                                $('form[name=area_form]').restrict('select','select')
                            },
                            beforeUnload: function() {
                                // If using a prototype, return it to the prototypes container
                                if ($('#prototypes').length) {
                                    // Prevent multiple instances of select option lists
                                    $('.overlay-wrapper select').resetSS();
                                    $('.overlay-wrapper .newListSelected').remove();
                                    $('#prototypes').append($('#localization'))
                                };
                                // Reset overlayState
                                overlayState = null;
                            }
                        });
                    });
                } else {
                    // Handle Failure
                    $('#localize').click(function(e) {
                        e.preventDefault();
                        $.errorModal('Localization Error', '<p>This application is having trouble accessing the localization form.</p>');
                    });
                }
                break;
        }
    };
    /**************************************************
    * Force Localization 
    */
    jQuery.forceLocalization = function(title, message, url, defaultclose) {
        // Pevents multiple localization overlays from occuring
        if (overlayState) return;
        overlayState = 'active';
        // establish modal options for both external and internal
        var options = {
            cssclass: 'modal-alt',
            filter: '.modal-container',
            unloadOnHide: true,
            modal: true,
            title: ' ',
            closeText: ' ',
            afterShow: function() {
                // if custom title and message
                if (title && message) {
                    $('.modal-head').html('<h3>' + title + '</h3><p>' + message + '</p>');
                }
                // if altering redirect url
                if (url) {
                    $('.overlay-wrapper form').each(function() {
                        var form = $(this);
                        var desturl = form.find('input[name=desturl]');
                        var defaultVal = desturl.attr('value');
                        desturl.attr('defaultval', defaultVal);
                        desturl.attr('value', url);
                    });
                }
                // if not commonly closable
                if (!defaultclose) {
                    $('.overlay-wrapper .close').unbind('click');
                    $('.overlay-wrapper .close').click(function() {
                        this.blur();
                        // if has history, move back, otherwise go to Areas We Serve
                        if (history.length > 1) {
                            history.back();
                        } else {
                            window.location = areasWeServeURL;
                        }
                        return false;
                    }).mousedown(function(evt) { evt.stopPropagation(); });
                };
                // Prevent users from localizing to national
                $('.overlay-wrapper select option[value=ENU]').remove();
                // Style select option lists
                $('.overlay-wrapper select').sSelect({
                    ddMaxHeight: 260,
                    ddMinWidth: 139,
                    ddMaxWidth: 310,
                    ulWidthOffset: 8
                });
                // instantiates solo-input validation 
                $('.input-solo').restrict('input[name=zipcode]','zipcode')
                // instantiates select validation 
                $('form[name=area_form]').restrict('select','select')
            },
            beforeUnload: function() {
                // If using a prototype, return it to the prototypes container
                if ($('#prototypes').length) {
                    // Prevent multiple instances of select option lists
                    $('.overlay-wrapper select').resetSS();
                    $('.overlay-wrapper .newListSelected').remove();
                    // Reset desturl value
                    $('.overlay-wrapper form').each(function() {
                        var form = $(this);
                        var desturl = form.find('input[name=desturl]');
                        var defaultVal = desturl.attr('defaultval');
                        if(!desturl.attr('value'))desturl.attr('value', defaultVal);
                    });
                    $('#prototypes').append($('#localization'))
                };
                // Reset overlayState
                overlayState = null;
            }
        };
        // handle external apps differently then internal
        var subdomain = window.location.host.split('.');
        switch (subdomain[0]) {
            // INTERNAL                                                                                                                                                                                            
            case 'bh':
            case 'tamp21potmgt1':
            case 'tamp21potmgt2':
            case 'brighthouse':
            case 'corporate':
            case 'corpdev':
            case 'corpstage':
            case 'redesign':
            case 'wa':
            case 'www':

                        case 'www1':
                        case 'www2':
                var localizeUrl = $('#localize').attr('href');
                $.ajax({
                    url: localizeUrl,
                    cache: false,
                    success: function(html) {
                        var html = $(html)
                        // Call modal
                        new Overlay(html.filter('.modal-container'), options);
                    }
                });
                break;
            // EXTERNAL                                                                                                                                                             
            case 'applications':
            default:
                if ($('#prototypes').length) {
                    // Get localization div
                    var content = $('#localization');
                    // Call modal
                    new Overlay(content, options);
                } else {
                    // Handle Failure
                    $.errorModal('Localization Error', '<p>This application does not currently support localization.</p>');
                }
                break;
        }
    };
    /**************************************************
    * Chat Links 
    */
    jQuery.chatlinks = function() {
        if ($('.chat-hours').html()){
            // Hide hours
            $('.chat-hours').hide();
    
            // Define webservice location
            var ws = chatlinksWSURL;
            // Establish division
            var localization = $.getLocalization();
            // If no division found, do nothing
            if (!localization) return;
            // Update link with division
            var wsChatLinkHREF = ws + "?division=" + localization.divisionid + "&callback=?";
            // Call web service and get availablity
            $.getJSON(wsChatLinkHREF, function(data) {
            if (data.Response.length) {
                    // Insert link into all .chat-hours areas
                    var hours = data.Response[0].message;
                    $('.chat-hours').html(hours)
                }
            });
            $('.chat-hours').show();
        }
    };    
    /**************************************************
    * Ajax Form Posts (Requiring Confirmation)
    */
    jQuery.postForConfirmation = function(url, params, callback) {
        $.ajax({
            url: url,
            data: params,
            success: function(data) {
                if (callback) eval(callback);
                data = $('<div>' + data + '</div>');
                var title = data.find('#title').html();
                var body = data.find('#body').html();
                $.errorModal(title, body);
            },
            type: 'POST'
        });
    };


    /**************************************************
    * System Alerts
    */
    jQuery.systemAlert = function() {
        // Define webservice location
        var ws = systemAlertWSURL;
        // Establish division
        var localization = $.getLocalization();
        // Update link params with contextual values
        var params = "?applicationID=6b5814f1-cefd-4ad3-91c4-b5205b56817c";
        params += "&clientUrl=" + encodeURIComponent(window.location.href);
        params += "&primaryPostalCode=" + localization.zipcode;
        params += "&division=" + localization.divisionid;
        params += "&count=1";
        params += "&responseType=jsonp";
        params += "&callback=?";
        var sysAlertHREF = ws + params;
        var markup = {
            wrapper: '<div id="system-alert"></div>',
            container: '<div class="container"></div>',
            content: '<div class="message"></div>',
            close: '<a href="#" class="close">Close</a>'
        };
        // Call web service and retrieve message
        $.getJSON(sysAlertHREF, function(data) {
            if (data.length) {
                // Prepare system alert
                var wrapper = jQuery(markup.wrapper);
                var container = jQuery(markup.container);
                var content = jQuery(markup.content);
                var close = markup.close;
                content.html('<h3>' + data[0].title + '</h3>' + data[0].value + close);
                container.append(content);
                wrapper.append(container);
                // Insert system alert
                $('body').prepend(wrapper);
                // Prepare close link
                $('#system-alert .close').click(function(e) {
                    e.preventDefault();
                    $('#system-alert').remove();
                })
            }
        });
    };

    /**************************************************
    * Once Only Modal Overlay
    */
    jQuery.onceOnlyOverlay = function(cookiename, overlayURL) {
        var notified = $.cookie(cookiename);
        if (!notified && !overlayState) {
            // establish options
            var options = {
                cssclass: 'modal',
                filter: '.modal-container',
                unloadOnHide: true,
                modal: true,
                title: ' ',
                closeText: ' ',
                afterShow: function() {
                    overlayState = 'active';
                    $('.overlay-wrapper select').sSelect({
                        ddMaxHeight: 250,
                        ddMinWidth: 139,
                        ddMaxWidth: 310,
                        ulWidthOffset: 8
                    });
                    // instantiates solo-input validation 
                    $('.input-solo').restrict('input[name=zipcode]','zipcode')
                    // instantiates select validation 
                    $('form[name=area_form]').restrict('select','select')
                },
                beforeUnload: function() {
                    // write cookie on close to ensure user has seen content
                    notified = $.cookie(cookiename, 'notified', { expires: 720, path: '/', domain: '.brighthouse'+ env });
                    overlayState = null;
                }
            }
            // find the overlay's content
            if ($('#prototypes #' + cookiename).length) {
                // if the overlay content is present on the page
                var content = $('#' + cookiename);
                // create overlay
                new Overlay(content, options);
                return;
            } else if (overlayURL) {
                // if a URL is provided
                content = overlayURL;
            } else {
                // assume the cookiename and page name are the same
                content = cmsBaseURL + '/corporate/structural/' + cookiename;
            }
            // create overlay
            Overlay.load(content, options);
        }
    };

    jQuery.autoExecute = function() {
        var href = document.location.href;
        var hash = href.substring(href.indexOf('#') + 1);
        var flag = hash.substring(0, hash.indexOf('_'));
        if (flag) {
            switch (flag) {
                case 'modal':
                case 'modal-alt':
                case 'modal-tabs':
                    var url = hash.substring(hash.indexOf('_') + 1);
                    // establish modal options for both external and internal
                    bhn['overlay'].options.cssclass = flag;
                    Overlay.load(url, bhn['overlay'].options);
                    break;
                deafult: return false;
            }
        }
    };

})(jQuery);
