

/*=========================================*/
/* prevent firebug console problems in IE
----------------------------------------------*/
if (!window.console || !console.firebug){
    var names = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml",
    "group", "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"];

    window.console = {};
    for (var i = 0; i < names.length; ++i){
        window.console[names[i]] = function() {};
    }
}

/* define the overall mirus namespace
------------------------------------------------------*/
var __mr__ = {};
// console.info('is this thing on?');

/* define the core code namespace
----------------------------------------------*/
__mr__.__core__ = {};

//-- the generic reference tool
//  pass any length list of items, by ID or reference, and get an array back of references
//  pass a single item can be used instead of document.getElementById();
//  e.g. mr$('foo'); vs. document.getElementById('foo');
// only created if another library hasn't already taken it
if (!window.mr$){
    function mr$() {
        var elements = new Array();
        for (var i = 0; i < arguments.length; i++) {
            var element = arguments[i];
            if (typeof element == 'string'){
                element = document.getElementById(element);
            }
            if (arguments.length == 1){
                return element;
            }
            elements.push(element);
        }
        return elements;
    };
};

/* http://www.dustindiaz.com/rock-solid-addevent/
------------------------------------------------------*/
__mr__.__core__.addEvent = function( obj, type, fn ) {
    if (obj.addEventListener) {
        obj.addEventListener( type, fn, false );
        __mr__.__core__.EventCache.add(obj, type, fn);
    }
    else if (obj.attachEvent) {
        obj["e"+type+fn] = fn;
        obj[type+fn] = function() { obj["e"+type+fn]( window.event ); };
        obj.attachEvent( "on"+type, obj[type+fn] );
        __mr__.__core__.EventCache.add(obj, type, fn);
    }
    else {
        obj["on"+type] = obj["e"+type+fn];
    }
};

__mr__.__core__.EventCache = function(){
    var listEvents = [];
    return {
        listEvents : listEvents,
        add : function(node, sEventName, fHandler){
            listEvents.push(arguments);
        },
        flush : function(){
            var i, item;
            for(i = listEvents.length - 1; i >= 0; i = i - 1){
                item = listEvents[i];
                if(item[0].removeEventListener){
                    item[0].removeEventListener(item[1], item[2], item[3]);
                };
                if(item[1].substring(0, 2) != "on"){
                    item[1] = "on" + item[1];
                };
                if(item[0].detachEvent){
                    item[0].detachEvent(item[1], item[2]);
                };
                item[0][item[1]] = null;
            };
        }
    };
}();
__mr__.__core__.addEvent(window,'unload',__mr__.__core__.EventCache.flush);


/* --------- Start __mr__.__core__.domready
 *
 * function whenDOMReady
 * Copyright (C) 2006-2007 Dao Gottwald
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * Contact information:
 *   Dao Gottwald  <dao at design-noir.de>
 *
 * @version  1.3
 * @url      http://design-noir.de/webdev/JS/whenDOMReady/
 *
------------------------------------------------------*/
__mr__.__core__.domready = function(fn){
    var f = arguments.callee;
    if ("listeners" in f) { // already initialized
        if (f.listeners) // still loading
            f.listeners.push(fn);
        else // DOM is ready
            fn();
        return;
    }
    f.listeners = [fn];
    f.callback = function() {
        __mr__.__core__.removeEvent(window, "load", f.callback);
        if (document.removeEventListener)
            document.removeEventListener("DOMContentLoaded", f.callback, false);
        if (f.listeners) {
            while (f.listeners.length)
                f.listeners.shift()();
            f.listeners = null;
        }
    };
    if (document.addEventListener)
        document.addEventListener("DOMContentLoaded", f.callback, false);
    /*@cc_on @if (@_win32) else
        document.write("<script defer src=\"//:\""+
                       " onreadystatechange=\"if (this.readyState == 'complete')"+
                       " __mr__.__core__.domready.callback();\"><\/script>");
    @end @*/
    __mr__.__core__.addEvent(window, "load", f.callback);
};

/* --------- End __mr__.__core__.domready
------------------------------------------------------*/


/* access a flash swf
----------------------------------------------*/
__mr__.__core__.get_swf = function(swf_name){
    if (navigator.appName.indexOf("Microsoft")!= -1) {
        return window[swf_name];
    } else {
        return document[swf_name];
    }
};


/* add a node to the dom
--------------------------------------*/
__mr__.__core__.addNode = function(nodeText,nodeParent,nodeType,otherProp,styleProp){
    var np = mr$(nodeParent)?mr$(nodeParent):mr$(document.body);
    var nt = nodeType?nodeType:"span";
    var t = (nodeText == "" || !nodeText)?null:nodeText;

    if (otherProp && otherProp.id && mr$(otherProp.id) && mr$(otherProp.id).tagName.toLowerCase() == nt.toLowerCase()){
        var n = mr$(otherProp.id);
    }else{
        var n = document.createElement(nt);
    }
    //if (t){n.innerHTML = t;}

    if (otherProp){
        for (var p in otherProp){
            n[p] = otherProp[p];
        }
    }
    if (styleProp){
        for (var p in styleProp){
            n.style[p] = styleProp[p];
        }
    }
    //can't use this to add a string of <td></td><td></td> to a <tr> in IE
    //must add each <td> on its own, as a seperate node. Who knows why.
    if (t && nodeType != "tr" && nodeType != "trd"){n.innerHTML = t;}
    np.appendChild(n);
    return n;
};



/*  POST only method to send form data to any url
    and avoid cross-domain issues
----------------------------------------------*/
__mr__.__core__.postdata = function(url,data,callback,callback_argument_array){
    // establish the iframe target
    // console.info('posting to:',url);
    // console.info('data:',data);
    // create the parent form to store post data
    if (!__mr__.iframe_id){
        __mr__.iframe_id    = 'mr_emarfi' + __mr__.visit_id;
        __mr__.iframe       = __mr__.__core__.addNode('',document.body,'iframe',{'id':__mr__.iframe_id,'name':__mr__.iframe_id,'src':'about:blank','width':'500px','height':'200px'},{'border':'none','display':'none'});
        self.frames[__mr__.iframe_id].name = __mr__.iframe_id;
    }
    if (mr$(__mr__.iframe_id)){
        var tmp_form = __mr__.__core__.addNode('',document.body,'form',{'name':('tmp_form_' + __mr__.__core__.rnd()),'action':url,'method':'POST','target':__mr__.iframe_id},{'display':'none'});
        // write the data values
        for (var d in data){ 
            // var val = encodeURIComponent(data[d]);  // not needed as we're posting normally
            __mr__.__core__.addNode('',tmp_form,'input',{'name':d,'value':data[d],'type':'text'},{'display':'none'});
        }
        tmp_form.submit();
        tmp_form.parentNode.removeChild(tmp_form);
    }
};


/* get the page scroll offset
-------------------------------------------*/
__mr__.__core__.get_scroll = function() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return {'x':scrOfX, 'y':scrOfY};
};

/* get the browser window size
-------------------------------------------*/
__mr__.__core__.get_win_size = function(){
    var win_width = 0, win_height = 0;
    if( typeof(window.innerWidth) == 'number' ) {
        //Non-IE
        win_width = window.innerWidth;
        win_height = window.innerHeight;
    } else if(document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight)){
        //IE 6+ in 'standards compliant mode'
        win_width = document.documentElement.clientWidth;
        win_height = document.documentElement.clientHeight;
    } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
        //IE 4 compatible
        win_width = document.body.clientWidth;
        win_height = document.body.clientHeight;
    }
    return {'x':win_width, 'y':win_height};
};

/* provider a wrapper for swf trace debugging
-------------------------------------------*/
__mr__.__core__.trace = function(msg){
    console.info(msg);
};


/*  random 6 digit number generator
----------------------------------------------*/
__mr__.__core__.rnd = function(){
    return Math.round(Math.random()*999999);
};

__mr__.__core__.run_start = new Date();
__mr__.__core__.get_runtime = function(){
    now = new Date();
    return (now - __mr__.__core__.run_start);
};


/* track some generic values
------------------------------------------------------*/
// __mr__.hostname     = location.hostname;    // set defaults for hostname references
__mr__.visit_id     = __mr__.__core__.rnd();  // get a timestamp for this visit to indicate a visiting session
__mr__.is_framed    = (top != self);

__mr__.domain_name  = null;
__mr__.url_path     = null;
__mr__.package_id   = null;

__mr__.__core__.addEvent(window,'load',function(){
    if (__mr__.is_framed){    
    //     // __mr__.hostname     = 'pound.mirusresearch.com';    // set defaults for hostname references
    //     // console.info(top);
    //     // console.info(self.name);
        var data = eval(self.name);
    //     // console.info(data);
        __mr__.domain_name  = data.domain_name;
        __mr__.url_path     = data.url_path;
        __mr__.package_id   = data.package_id;
    }
    // }else if (__mr__.is_mirror){        
    // console.info(__mr__);
    if (__mr__.is_mirror){
        if (typeof(dojo) != 'undefined' && dojo.xhr){
            // console.info('overriding dojo.xhr...');
            var oldXhr = dojo.xhr; // clone the original function
            dojo.xhr = function(/*String*/ method, /*dojo.__Scrags*/ args, /*Boolean?*/ hasBody){
                var cloneargs = dojo.mixin( {}, args );
                if (cloneargs.url) {
                    // cloneargs._original_xhr_url     = cloneargs.url;
                    // cloneargs._original_xhr_method  = method;
                    cloneargs.url = '/xhri/?url=' + encodeURIComponent(cloneargs.url);
                }
                // console.info('method',method);
                // console.info('cloneargs',cloneargs);
                // console.info('hasBody',hasBody);

                return oldXhr.apply( dojo, [ method, cloneargs, hasBody]);
            };
        };
    }
});


/* Client-side access to querystring name=value pairs
    Version 1.3
    28 May 2008
    
    License (Simplified BSD):
    http://adamv.com/dev/javascript/qslicense.txt
*/
__mr__.__core__.querystring = function(qs) { // optionally pass a querystring to parse
    this.params = {};
    
    if (qs == null) qs = location.search.substring(1, location.search.length);
    if (qs.length == 0) return;

    // Turn <plus> back to <space>
    // See: http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.13.4.1
    qs = qs.replace(/\+/g, ' ');
    var args = qs.split('&'); // parse out name/value pairs separated via &
    
    // split out each name=value pair
    for (var i = 0; i < args.length; i++) {
        var pair = args[i].split('=');
        var name = decodeURIComponent(pair[0]);
        
        var value = (pair.length==2)
            ? decodeURIComponent(pair[1])
            : name;
        
        this.params[name] = value;
    }
};

__mr__.__core__.querystring.prototype.get = function(key, default_) {
    var value = this.params[key];
    return (value != null) ? value : default_;
};

__mr__.__core__.querystring.prototype.contains = function(key) {
    var value = this.params[key];
    return (value != null);
};

// setup mixpanel goodness
// ------------------------------------------------------ //
var mpq = [];
mpq.push(["init", "458ced327ac1ad230ea7cbf8e8504c40"]);
(function() {
    var mp = document.createElement("script"); mp.type = "text/javascript"; mp.async = true;
    mp.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') + "//api.mixpanel.com/site_media/js/api/mixpanel.js";
    var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(mp, s);
})();

/*=========================================*/

/* initialize the __trk__ object
------------------------------------------------------*/
__mr__.__trk__ = {};

/* track clicks on a page
------------------------------------------------------*/
__mr__.__trk__.click = function(evt,data){
    if (evt && !data){
        var ob = (evt.srcElement || evt.target);
        if (ob.parentNode.tagName.toUpperCase() == 'A'){
            ob = ob.parentNode;
        }
    
        data = {};
        data.associate_id   = __mr__.associate_id;
        data.domain_name    = __mr__.domain_name;
        data.server_name    = __mr__.server_name;
        data.url_path       = __mr__.url_path;
        data.visit_id       = __mr__.visit_id;
        data.site_key       = __mr__.sitekey;
        data.sitekey        = __mr__.sitekey;
    
        data.clicked_id =(ob.id)?(ob.id):null;
        data.clicked_tag = (ob.tagName)?(ob.tagName):null;
        data.clicked_source = (ob.src)?(ob.src):null;
        data.clicked_destination = (ob.href)?(ob.href):null;
        data.clicked_link_text = (ob.href && ob.innerHTML)?(ob.innerHTML):null;
        data.clicked_link_title = (ob.href && (ob.title || ob.alt))?((ob.title || ob.alt)):null;
        data.clicked_x = evt.clientX;
        data.clicked_y = evt.clientY;
    }
    data.visit_id = __mr__.visit_id;
    // console.log('t');
    mpq.push(["track", "click", data]);
    // __mr__.__core__.postdata('http://' + __mr__.stats_host + '/trk/click/',data);
};


// QR code tracking
// ------------------------------------------------------ //
__mr__.__trk__.qr_code = function(){
    if (window.location.href.indexOf('/qr/') >= 0){
        var tokens = window.location.href.replace('http://','').replace('https://','').split('/');
        var last, qr_code;
        for (var i=0; i < tokens.length; i++) {
            var t = tokens[i];
            if (last === 'qr'){
                qr_code = t;
                break;
            }else{
                last = t;
            }
        };
        if (qr_code){
            var data = {
                qr_code         : qr_code
                , domain        : __mr__.domain_name
                , server_name   : __mr__.server_name
                , sitekey       : __mr__.sitekey
                , state         : __mr__.state
                , referrer      : __mr__.referrer
                , user_agent    : __mr__.user_agent
                , user_agent    : __mr__.user_agent
                , ip_address    : __mr__.ip_address
                , server_name   : __mr__.server_name
            };
            // console.log('pushing qr_code:',data);
            mpq.push(["track", "qr_code", data]);
        }
    }
};

/* --------- End __mr__.__trk__.click
------------------------------------------------------*/



/* --------- Start __mr__.__trk__.hit
------------------------------------------------------*/
__mr__.__trk__.hit = function(){
    var data = {};
    data.domain_name    = __mr__.domain_name;
    data.server_name    = __mr__.server_name;
    data.url_path       = __mr__.url_path;
    data.visit_id       = __mr__.visit_id;
    data.site_key       = __mr__.site_key;
    // console.info(data);
    // __mr__.__core__.postdata('http://' + __mr__.stats_host + '/trk/hit/',data);
};

/* --------- End __mr__.__trk__.hit
------------------------------------------------------*/

// turn on the click tracking under certain conditions
setTimeout(function(){
    if (__mr__.is_mirror){
        __mr__.__trk__.qr_code();
        __mr__.__core__.addEvent(document,'click',__mr__.__trk__.click);
    }
},500);




/*=========================================*/

                // ~~~~~~~ dynamic values ~~~~~~~~~//;
                __mr__.domain_name         = 'null';
__mr__.referrer            = 'null';
__mr__.site_key            = '521505';
__mr__.sitekey             = '521505';
__mr__.user_agent          = 'CCBot/1.0 (+http://www.commoncrawl.org/bot.html)';
__mr__.state               = '52';
__mr__.ip_address          = '38.107.179.244';
__mr__.server_name         = 'interloper1';
__mr__.mobile_browser_type = '';
__mr__.server_name         = 'interloper1';
__mr__.associate_id        = 'F7W8X1YS000';
__mr__.is_mobile_browser   = ('false' === 'true');
__mr__.is_mirror           = ('true' === 'true');
__mr__.source_hostname     = 'www.statefarm.com';
__mr__.source_url          = 'http://www.statefarm.com/agent/US/NY/Cicero/Bill-Meyer-F7W8X1YS000';

// fix the language selection links in the appropriate circumstance
// by turning off the .click() event added via JS by SF
// added by AH @ Mirus on 2011-11-6
// updated to new href ID & logic by AH @ Mirus on 2011-12-19
$(document).ready(function() {
    setTimeout(function(){
        // overwrite the MP.init to use the correct source url
        MP.init = function() {
            if (MP.UrlLang.indexOf('p_js_') == 1) {
                MP.SrcUrl = __mr__.source_url;
                MP.UrlLang = MP.SrcLang;
            }
        };
    },500);
});
                ;__mr__.stats_host="nb.mirusresearch.com";
                
                
