/**
 * PopRule Action Engine UI
 * Copyright 2009-2010 PopRule, LLC
 * All Rights Reserved
 */
( function() {
   var trueName = '';
   for (var i = 0; i < 16; i++) {
      trueName += String.fromCharCode(Math.floor(Math.random() * 26) + 97);
   }
   window[trueName] = {};
   var $ = window[trueName];
   $.f = function() {
      return {
         runFunction : [],
         baseUrl : 'http://gocampaignlive.com/',
         cdnUrl : 'http://campaignlive.s3.amazonaws.com/',
         pageCache : {},
         cacheOrder : [],
         cachePos : -1,
         interactTime: 0,
         startTime: 0,
         clickCount: 0,
         actionIds: [],
         curAction: 0,
         windowHeight: 0,
         closeTimer : null,
         partnerId: false,
         init : function(target) {
            var theScripts = document.getElementsByTagName('SCRIPT');
            for (var i = 0; i < theScripts.length; i++) {
               if (theScripts[i].src.match(target)) {
                  if (theScripts[i].innerHTML) {
                    // Replace CDATA and HTML in the arguments
                    
                    var matches = theScripts[i].innerHTML.match(/{([^}]*)}/);
                    
                    toeval = matches[0];

                    if (/^[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]+$/.test(toeval.replace(/\\./g, '@').replace(/"[^"\\\n\r]*"/g, ''))) {
                      try {
                        $.a = eval( '(' + toeval + ')' );
                      }
                      catch(err) { }
                    }
                  }
                  if (typeof $.a !== 'object') {
                     $.a = {};
                  }
                  
                  $.a.client = 'candidate';
                  
                  // Determine what server to use
                  if($.a.server == 'test') {
                    $.f.baseUrl = 'http://test.gocampaignlive.com/';
                    $.f.cdnUrl = 'http://test-static.poprule.com/';
                  }
                  else if($.a.server == 'dev') {
                    $.f.baseUrl = 'http://dev.gocampaignlive.com/';
                    $.f.cdnUrl = 'http://campaigndev.s3.amazonaws.com/';
                  }
                  
                  $.f.requestStylesheet('main.css');
                  
                  if($.a.nativeApp == 1) {
                    $.f.requestStylesheet('native.css');
                  }
                  else {
                    if($.a.brand) {
                      $.f.requestStylesheet($.a.brand + '.css');
                    }
                  }
  
                  $.f.buildStructure();
                  
                  theScripts[i].parentNode.insertBefore($.c, theScripts[i]);
                  theScripts[i].parentNode.removeChild(theScripts[i]);
                  break;
               }
            }
         },
         requestStylesheet: function(sheet) {
            stylesheet = document.createElement("link");
            stylesheet.rel = "stylesheet";
            stylesheet.type = "text/css";
            stylesheet.href = $.f.cdnUrl + 'css/' + sheet;
            stylesheet.media = "all";
            document.lastChild.firstChild.appendChild(stylesheet);
         },
         buildStructure : function() {         
           $.c = document.createElement('div');
        
           $.w = document.createElement('div');
           $.w.className = 'pr-wdgt';
           $.w.id = trueName;
           
           var de = document.documentElement;
           $.f.windowHeight = self.innerHeight || (document.documentElement && document.documentElement.clientHeight ) || document.body.clientHeight;
           $.f.windowWidth = self.innerWidth || document.body.clientWidth;
             
           $.w.shade = document.createElement('div');
           $.w.shade.id = 'pr-shade';
           $.w.shade.style.height = $.f.windowHeight + 'px';
           $.w.shade.style.display = 'none';
           document.body.appendChild($.w.shade);
           
           //Specify iframe to display. Change src and other attributes except "position" and "left/top":
           $.w.idiv = document.createElement('div');
           $.w.idiv.id = 'pr-overlay';
           $.w.idiv.style.display = 'none';

           $.w.idivi = document.createElement('div');
           $.w.idivi.className = 'pr-overmid';
           $.w.idiv.appendChild($.w.idivi);
             
           $.w.idivii = document.createElement('div');
           $.w.idivii.className = 'pr-overinner';
           $.w.idivi.appendChild($.w.idivii);
           
           $.w.icl = document.createElement('a');
           $.w.icl.href='#';
           $.w.icl.className = 'pr-close';
           $.w.icl.innerHTML = 'close';
           $.w.icl.onclick = function() {
           $.f.hideOverlay();
             return false;
           };
           
           $.w.idivii.appendChild($.w.icl);
           
           $.w.idiv.ttl = document.createElement('div');
           $.w.idiv.ttl.className = 'pr-ttl';
  
           $.w.idivii.appendChild($.w.idiv.ttl);
           
           $.w.iframe = document.createElement('iframe');
           $.w.iframe.scrolling = "yes";
           
           $.w.idivii.appendChild($.w.iframe);
           
           // Create share popup
           $.w.ifpop = document.createElement('div');
           $.w.ifpop.className = 'pr-shareOut';
           
           // Create share buttons
           var btns = {"pr-ptwt":"twitter", "pr-pfb":"facebook", "pr-pmysp":"myspace", "pr-pmail":"e-mail"}
           $.w.ifpops = [];
           
           for(var i in btns) {
             $.w.ifpops[i] = document.createElement('a');
             $.w.ifpops[i].innerHTML = btns[i];
             $.w.ifpops[i].className = i;
             $.w.ifpops[i].href = '#';
             $.w.ifpops[i].target = '_blank';
             
             $.w.ifpops[i].onmouseover = function() {
               $.f.cancelClose(false, $.w.ifpop);
             };
             
             $.w.ifpops[i].onmouseout = function() {
               $.f.setClose($.w.ifpop);
             }
          
             $.w.ifpop.appendChild($.w.ifpops[i]);
           }
           
           $.w.idivii.appendChild($.w.ifpop);
           
           // Create buttons
           $.w.ifbtns = document.createElement('div');
           $.w.ifbtns.className = 'pr-bottom-btns';
           
           $.w.ifvol = document.createElement('a');
           $.w.ifvol.href = '#';
           $.w.ifvol.className = 'pr-btn pr-ifbtn';
           $.w.ifvol.innerHTML = 'Volunteer';
           $.w.ifvol.onclick = function() {
             $.f.showOverlay(this.href);
             return false;
           };
           $.w.ifbtns.appendChild($.w.ifvol);
           
           $.w.ifdon = document.createElement('a');
           
           $.w.ifdon.className = 'pr-btn pr-ifbtn';
           $.w.ifdon.innerHTML = 'Donate';
		   $.w.ifdon.href = '#';
		   $.w.ifdon.onclick = function() {
			 $.f.showOverlay(this.href);
			 return false;
		   };
           $.w.ifbtns.appendChild($.w.ifdon);
           
           $.w.ifshr = document.createElement('a');
           $.w.ifshr.href = '#';
           $.w.ifshr.className = 'pr-btn pr-ifbtn';
           $.w.ifshr.innerHTML = 'Share';
           $.w.ifshr.onmouseover = function() {
             $.f.cancelClose(true, $.w.ifpop);
           }
           $.w.ifshr.onmouseout = function() {
             $.f.setClose($.w.ifpop);
           };
           $.w.ifbtns.appendChild($.w.ifshr);
           
           $.w.idivii.appendChild($.w.ifbtns);

           document.body.appendChild($.w.idiv);
           
                        
           $.w.p = document.createElement('div');
           $.w.p.className = 'pr-act';
           
           $.w.p.loading = document.createElement('div');
           $.w.p.loading.className = 'pr-load';
           $.w.p.loading.innerHTML = '<img src="' + $.f.cdnUrl + 'img/' + $.a.client + '/loader.gif" />';
           $.w.p.appendChild($.w.p.loading);
           
           // Create Masthead
           $.w.p.m = document.createElement('a');
           $.w.p.m.target = '_blank';
           
           $.w.p.m.className = 'pr-mst';
           
           $.w.p.m.h = document.createElement('span');
           $.w.p.m.h.className = 'pr-hdr';
           $.w.p.m.appendChild($.w.p.m.h);
           
           $.w.p.m.hh = document.createElement('span');
           $.w.p.m.hh.className = 'pr-sbhdr';
           $.w.p.m.appendChild($.w.p.m.hh);
           
           $.w.p.appendChild($.w.p.m);
           
           // Create content area
           $.w.p.dyn = document.createElement('div');
           $.w.p.dyn.className = 'pr-content'; 
           $.w.p.appendChild($.w.p.dyn);

           var pieces = window.location.href.split('%23');

           if($.a.nativeApp && pieces[1] != undefined) {           
             $.f.loadContent('api/primary/' + $.a.client, '&spage=' + pieces[1], true);
           }
           else {
             $.f.loadContent('api/primary/' + $.a.client, '', true);
           }
            
           $.w.appendChild($.w.p);
            
           // Create footer
           $.w.p.foot = document.createElement('div');
           $.w.p.foot.className = 'pr-ftr';
           
           // Powered by PopRule
           $.w.p.ia = document.createElement('a');
           $.w.p.ia.href = 'http://gocampaignlive.com/';
           $.w.p.ia.innerHTML = 'Powered by PopRule';
           $.w.p.ia.target = "_blank";
           $.w.p.ia.className = 'pr-logo';
           $.w.p.appendChild($.w.p.ia);
           
           $.w.p.appendChild($.w.p.foot);
           
           $.c.appendChild($.w);
         },
         goBack : function(home) {
           if($.f.cachePos != 0) {
             if(home) {
               $.f.cachePos = 0;
             }
             else {
               $.f.cachePos--;
             }
             
             $.f.renderResult($.f.pageCache[$.f.cacheOrder[$.f.cachePos]]);
           }
         },
         externalClick : function() {
           if($.f.clickCount == 0) { 
             $.f.clickCount++;
           }
         },
         loadContent : function(src, args, refresh) {     
           var url = $.f.baseUrl + src + '?key=' + $.a.client + args;
           
           url += '&cand_id=' + $.a.cand_id;
           
           if($.f.partnerId) { 
             url += '&ref=' + $.f.partnerId;
           }
           else { 
             url += '&t=' + escape(document.title) + '&ref=' + escape(location.href.replace(/\?.*|#/,'')); 
           }
           
           $.f.cachePos++;
           $.f.cacheOrder[$.f.cachePos] = url;
           
           if($.f.pageCache[url]) {
             $.f.renderResult($.f.pageCache[url]);
           }
           else {
             if(refresh) {
               $.w.p.loading.style.display = 'block';
             }
         
             var n = $.f.runFunction.length;
             var id = trueName + '.f.runFunction[' + n + ']';
             
             var preCB = url;
             
             // Log unique click
             if($.f.partnerId) {
               $.f.clickCount++;
               
               // Is this the initial click?
               if($.f.clickCount == 1) { 
                 url += '&initial=1';
               }
             }
             else {
               url += '&configure=1&issue=politics';
             }
             
             $.f.runFunction[n] = function(r) {
               delete($.f.runFunction[n]);
               $.f.removeScript(id);
               $.f.renderResult(r);
               
               $.f.pageCache[preCB] = r;

               $.w.p.loading.style.display = 'none';   
             };
             
             if($.a.brand) {
               url += '&brand=' + $.a.brand;
             }
             
             url += '&callback=' + id;
             
             $.f.runScript(url, id);
           }
         },
         showOverlay: function(url, scroll, noUpdate) {
           window.scroll(0,0);
         
           $.w.iframe.src = url;
           
           if(scroll) {
             $.w.iframe.scrolling = scroll;
           }
           else {
             $.w.iframe.scrolling = 'yes';
           }
           
           // Set share urls
           if(!noUpdate) {
             var shttl = escape('I support ' + $.w.idiv.ttl.innerHTML);
             var btns = {
               "pr-ptwt": $.f.baseUrl + "share/any/twitter/0/widget?t=" + shttl + '&u=' + escape(url) + '&ref=' + $.f.partnerId + '&key=' + $.a.client + '_' + $.a.cand_id, 
               "pr-pfb": $.f.baseUrl + "share/any/facebook/0/widget?t=" + shttl + '&u=' + escape(url) + '&ref=' + $.f.partnerId + '&key=' + $.a.client + '_' + $.a.cand_id, 
               "pr-pmysp": $.f.baseUrl + "share/any/myspace/0/widget?t=" + shttl + '&u=' + escape(url) + '&ref=' + $.f.partnerId + '&key=' + $.a.client + '_' + $.a.cand_id, 
               //"pr-pmail": "mailto:?subject=" + shttl + '&body=' + escape(url), 
               "pr-pmail": $.f.baseUrl + "share/any/email/0/widget?t=" + shttl + '&u=' + escape(url) + '&ref=' + $.f.partnerId + '&key=' + $.a.client + '_' + $.a.cand_id
             };
           
             for(var i in btns) {
               if(i == 'pr-pmail') {
                 $.w.ifpops[i].href = '#';
                 $.w.ifpops[i].onclick = function() {
                   $.f.showOverlay(btns[i], 'no', true);
                   return false;
                 };
               }
               else {
                 $.w.ifpops[i].onclick = function() { return true; };
                 $.w.ifpops[i].href = btns[i];
               }
             }
           }
           
           if($.w.idiv.style.display == 'none') {
             $.w.idiv.style.left = (($.f.windowWidth - 710) / 2) + "px";
             //$.w.idiv.style.top = (($.f.windowHeight - 610) / 2) + "px";
             $.w.idiv.style.top = "50px";
             $.w.shade.style.display = 'block';
             $.w.idiv.style.display = 'block';
           }
         },
         hideOverlay: function() {
           $.w.shade.style.display = 'none';
           $.w.iframe.src = '';
           $.w.idiv.style.display = 'none';
         },
         closeShare: function(popup) {
           $.f.closeTimer = null;
           popup.style.display = "none";
         },
         cancelClose: function(show, popup) {
           if($.f.closeTimer) {
             window.clearTimeout($.f.closeTimer);
             $.f.closeTimer = null;
           }
  
           if(show) {
             popup.style.display = "block";
           }
         },
         setClose: function(popup) {
           $.f.closeTimer = window.setTimeout(function() {$.f.closeShare(popup)}, 500);
         },
         resize: function() {
           $.f.windowHeight = self.innerHeight || (document.documentElement && document.documentElement.clientHeight ) || document.body.clientHeight;
           $.f.windowWidth = self.innerWidth || document.body.clientWidth;
           
           //$.w.idiv.style.top = (($.f.windowHeight - 610) / 2) + "px";
           $.w.idiv.style.left = (($.f.windowWidth - 710) / 2) + "px";

           $.w.shade.style.height = $.f.windowHeight + 'px';
         },
         formatLink: function(o) {
           l = document.createElement('a');
           
           l.href = '#';
               
           if(o['callback']) {
             if(!o['callback_args']) { o['callback_args'] = ''; }
           
             l.onclick = function() {
               $.f.loadContent(o['callback'], o['callback_args'], true);
               return false;
             };
           }
           else if(o['overlay']) {
             l.onclick = function() {
               $.f.showOverlay(o['overlay'], o['scroll']);
               return false;
             };
           }
           else if(o['url']) {
             l.href = o['url'];
             l.target = '_blank';
           }
           else if(o['special'] == 'back') {
             l.onclick = function() {
               $.f.goBack();
               return false;
             };
           }

           return l;
         },
         engageLink : function(source, url) {
           $.f.clickCount++;
               
           // Is this the initial click?
           if($.f.clickCount == 1) { 
             url += '&initial=1';
           }
         },
         switchTab : function(tab) {
           var tabs = $.w.p.foot.getElementsByTagName('a');
           
           for(var i=0;i<tabs.length;i++) {
             tabs[i].className = 'pr-tab';
           }
           
           tab.className = 'pr-tab pr-tab-on';
         },
         renderTree: function(h, n) {
           for(var i=0;i<h.length;i++) {
             if(h[i]['elem'] == 'button') {
               var nextElem = $.f.formatLink(h[i]);
             }
             else {
               var nextElem = document.createElement(h[i]['elem']);
             }
             
             if(h[i]['class']) {
               nextElem.className = h[i]['class'];
             }
             
             if(h[i]['background']) {               
               nextElem.style.backgroundImage = 'url("' + h[i]['background'] + '")';
               nextElem.style.backgroundPosition = '0 0';
             }
             
             if(h[i]['html']) {
               if($.a.cand_id == 'A000045' && h[i]['class'] == 'pr-lftcol') {
                 nextElem.innerHTML = '<img class="pr-shimg" src="http://campaignlive.blob.core.windows.net/drupal-sync/styles/candidate_ad/clfiles/tap/jplwideflagIMG_0005.jpg" />';
               }
               else {
                 nextElem.innerHTML = h[i]['html'];
               }
             }
             
             if(h[i]['html_list']) {
               $.f.renderTree(h[i]['html_list'], nextElem);
             }
           
             n.appendChild(nextElem);
           }
         },
         renderResult: function(r) {         
           if(!$.f.partnerId) {
             $.f.partnerId = r.pid;
           }
            
           if(r.masthead) {
             $.w.p.className += ' ' + r.css_class;
             
             $.w.idiv.ttl.className += ' ' + r.ttl_class;
             
             $.w.p.m.href = r.masthead;
             
             $.w.ifvol.href = r.volunteer;
             $.w.ifdon.href = r.donate;
             
             $.w.p.m.h.innerHTML = r.headline;
             $.w.p.m.hh.innerHTML = r.subheadline;
             
             $.w.ifdon.innerHTML = r.primary_button;
             $.w.ifvol.innerHTML = r.secondary_button;
             
             if(r.issue_app) {
               $.w.idiv.ttl.innerHTML = r.headline;
             } 
             else {
               $.w.idiv.ttl.innerHTML = r.cand_name + ' for ' + r.cand_office;
             }
             
             // Set colors
             if(r.theme) {
               $.w.p.style.borderColor = r.theme['border'];
               
               if(r.theme['hide_text'] == 1) {
                 $.w.p.m.h.style.display = 'none';
                 $.w.p.m.hh.style.display = 'none';
               }
               else {
                 $.w.p.m.h.style.color = r.theme['header_text'];
                 $.w.p.m.hh.style.color = r.theme['header_text'];
               }
               
               $.w.idiv.ttl.style.color = r.theme['header_text'];
               $.w.icl.style.color = r.theme['header_text'];
               
               var custom_css = document.createElement("style");
               custom_css.type = "text/css";
               
               if(r.theme['header_bg'] != 'default') {
                 $.w.p.m.style.backgroundColor = r.theme['header_bg'];
                 $.w.idiv.ttl.style.backgroundColor = r.theme['header_bg'];
                 $.w.idiv.ttl.style.backgroundImage = 'none';
                 
                 if($.a.brand == 'mobile') {
                   var mobcss = 'a.pr-lnk, a.pr-icbtn, .pr-more a { background-color: ' + r.theme['header_bg'] + '; }';
                   
                   if(r.theme['backdrop']) {
                     mobcss += '.pr-shimg { background-image: none; }';
                   }
                   
                   if(location.hash != '#preview') {
                     custom_css.innerText += mobcss;
                   }
                   else {
                     if(!custom_css.styleSheet) {
                       custom_css.innerHTML += mobcss;
                     }
                     else {
                       custom_css.styleSheet.cssText += mobcss;
                     }
                   }
                 }
               }
               
               if(r.theme['header_image'] != 0) {
                 $.w.p.m.style.backgroundImage = 'url("' + r.theme['header_image'] + '")';
               }
               
               if(r.theme['body_bg'] != 'default') {
                 $.w.p.dyn.style.backgroundColor = r.theme['body_bg'];
                 
                 if(r.theme['body_bg'] != r.theme['header_bg']) {
                   $.w.p.dyn.style.backgroundImage = 'url("' + $.f.cdnUrl + 'img/head_shadow.png")';
                   $.w.p.dyn.style.backgroundRepeat = 'repeat-x';
                   $.w.p.dyn.style.backgroundPosition = '0 0';
                 }
               }
               
               if(r.theme['backdrop']) {
                 $.w.p.dyn.style.backgroundImage = 'url("' + r.theme['backdrop'] + '")';
                 $.w.p.dyn.style.backgroundRepeat = 'no-repeat';
                 $.w.p.dyn.style.backgroundPosition = '0 100%';
               }
               
               $.w.p.dyn.style.color = r.theme['body_text'];
               
               if(r.theme['body_links'] != 'default') {
                 var a_color = '#' + trueName + ' .pr-act a { color: ' + r.theme['body_links'] + '; }';
               
                 if($.a.brand == 'mobile' && location.hash != '#preview') {
                   custom_css.innerText += a_color;
                 }
                 else {
                   if(!custom_css.styleSheet) {
                     custom_css.innerHTML += a_color;
                   }
                   else {
                     custom_css.styleSheet.cssText += a_color;
                   }
                 }
               }
               
               var h_color = '#' + trueName + ' .pr-content h3 { color: ' + r.theme['body_text'] + '; }';
               
               if($.a.brand == 'mobile' && location.hash != '#preview') {
                 custom_css.innerText += h_color;
               }
               else {
                 if(!custom_css.styleSheet) {
                   custom_css.innerHTML += h_color;
                 }
                 else {
                   custom_css.styleSheet.cssText += h_color;
                 }
               }
                 
               document.lastChild.firstChild.appendChild(custom_css);
             }
             
             // Create share popup
             $.w.shpop = document.createElement('div');
             $.w.shpop.className = 'pr-shareIn';
             $.w.shpop.id = 'prUnknwblShrr';
           
             var btns = {"pr-ptwt":"twitter", "pr-pfb":"facebook", "pr-pmysp":"myspace", "pr-pmail":"e-mail"}
           
             var shttl = escape($.w.idiv.ttl.innerHTML);
             
             var links = {
               "pr-ptwt": $.f.baseUrl + "share/any/twitter/0/widget?t=" + shttl + '&u=' + encodeURIComponent(r.masthead) + '&ref=' + $.f.partnerId + '&key=' + $.a.client + '_' + $.a.cand_id, 
               "pr-pfb": $.f.baseUrl + "share/any/facebook/0/widget?t=" + shttl + '&u=' + encodeURIComponent(r.masthead) + '&ref=' + $.f.partnerId + '&key=' + $.a.client + '_' + $.a.cand_id, 
               "pr-pmysp": $.f.baseUrl + "share/any/myspace/0/widget?t=" + shttl + '&u=' + encodeURIComponent(r.masthead) + '&ref=' + $.f.partnerId + '&key=' + $.a.client + '_' + $.a.cand_id, 
               "pr-pmail": $.f.baseUrl + "share/any/email/0/widget?t=" + shttl + '&u=' + encodeURIComponent(r.masthead) + '&ref=' + $.f.partnerId + '&key=' + $.a.client + '_' + $.a.cand_id
             };
             
             if($.a.brand == 'mobile') {
               links['pr-pmail'] = 'mailto:?subject=' + shttl + '&body=' + escape(r.masthead);
             }
           
             for(var i in btns) {
               var nextItem = document.createElement('a');
               nextItem.innerHTML = btns[i];
               nextItem.className = i;
               nextItem.href = links[i];
               
               if(i == 'pr-pmail' && $.a.brand != 'mobile') {
                 nextItem.onclick = function() {
                   $.f.showOverlay(this.href, 'no', true);
                   return false;
                 };
               }
               
               nextItem.target = '_blank';
             
               nextItem.onmouseover = function() {
                 $.f.cancelClose(false, $.w.shpop);
               };
             
               nextItem.onmouseout = function() {
                 $.f.setClose($.w.shpop);
               }
          
               $.w.shpop.appendChild(nextItem);
             }
           
             $.w.p.appendChild($.w.shpop);
           }
            
           if(r.tabs) {
             var i = 0;
             for(var tag in r.tabs) {
               if(!($.a.brand == 'mobile' && r.tabs[tag].title == 'Grab')) {
             
               var nextTab = document.createElement('a');
               nextTab.className = 'pr-tab';
               
               if(i==0) {
                 nextTab.className += ' pr-tab-on';
                 i++;
               }
               
               nextTab.href = '#';
               
               if(r.tabs[tag].callback) {
                 nextTab.rel = r.tabs[tag].callback;
                
                 if(r.tabs[tag].callback_args != '') {
                   nextTab.title = r.tabs[tag].callback_args;
                 }
                 else {
                   nextTab.title = '';
                 }
                 nextTab.onclick = function() {
                   $.f.switchTab(this);
                   $.f.loadContent(this.rel, this.title, true); 
                   return false; 
                 };
               }
               else if(r.tabs[tag].overlay) {
                 nextTab.rel = r.tabs[tag].overlay;
                   
                 nextTab.onclick = function() {
                   $.f.showOverlay(this.rel);
                   return false;
                 };
               }
               else if(r.tabs[tag].tag == 'share') {
                 nextTab.onmouseover = function() {
                   $.f.cancelClose(true, $.w.shpop);
                 };
                 nextTab.onmouseout = function() {
                   $.f.setClose($.w.shpop);
                 };
                 nextTab.onclick = function() {
                   return false;
                 };
               }
                 
               nextTab.innerHTML = r.tabs[tag].title;
               $.w.p.foot.appendChild(nextTab);
               
               }
             }
             
             r.tabs = false;
           }
           
           var a;
           n = document.createElement('div');
            
           if(r.type == 'canvas') {
             $.f.renderTree(r.html_content, n);
           }
           else if(r.type == 'html') {
             n.innerHTML = r.html_content;
           }
            
           $.w.p.dyn.innerHTML = '';
           $.w.p.dyn.appendChild(n);
           
           if($.a.brand == 'mobile' && !$.a.nativeApp) {
             window.setTimeout(function() {window.scrollTo(0,1);}, 1000);
           }
         },
         runScript : function(url, id) {
           var s = document.createElement('script');
           s.id = id;
           s.type ='text/javascript';
           s.src = url;
           document.getElementsByTagName('body')[0].appendChild(s);
         },
         removeScript : function(id) {
            var s = '';
            if (s = document.getElementById(id)) {
               s.parentNode.removeChild(s);
            }
         }
      };
   }();
   var thisScript = /^https?:\/\/[^\/]*[campaigndev.s3.amazonaws.com|campaignlive.s3.amazonaws.com]\/js\/campaignlive.js$/;
   if(typeof window.addEventListener !== 'undefined') {
      window.addEventListener('load', function() { $.f.init(thisScript); }, false);
      window.addEventListener('resize', function() { $.f.resize(); }, false);
   } else if(typeof window.attachEvent !== 'undefined') {
      window.attachEvent('onload', function() { $.f.init(thisScript); });
      window.attachEvent('onresize', function() { $.f.resize(); }, false);
   }
} )();
