/**
 * 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://poprule.com/',cdnUrl:'http://static.poprule.com/',pageCache:{},cacheOrder:[],cachePos:-1,interactTime:0,startTime:0,clickCount:0,partnerId:false,secs:0,timer:null,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){var toeval=theScripts[i].innerHTML;toeval=toeval.replace(/<!--|\/?\/?.*-->/g,"");toeval=toeval.replace(/\/\/.*<!\[CDATA\[/g,"");toeval=toeval.replace(/\/\/.*\]\]>/gi,"");toeval=toeval.replace(/<(?:.|\s)*?>/gi,"");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={};}
if($.a.server=='test'){$.f.baseUrl='http://test.poprule.com/';$.f.cdnUrl='http://test-static.poprule.com/';}
else if($.a.server=='dev'){$.f.baseUrl='http://dev.poprule.com/';$.f.cdnUrl='http://static.poprule.com/';}
$.a.client='globalgreen';$.f.requestStylesheet('globalgreen.css');$.f.buildStructure();theScripts[i].parentNode.insertBefore($.c,theScripts[i]);theScripts[i].parentNode.removeChild(theScripts[i]);break;}}},leave:function(){if($.f.startTime!=0){var d=new Date();$.f.interactTime+=(d.getTime()-$.f.startTime);}
$.f.loadContent('report_engage','&source=widget&time='+($.f.interactTime/1000)+'&clicks='+$.f.clickCount,false);return true;},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;$.w.onmouseover=function(){$.f.logTime('enter');};$.w.onmouseout=function(){$.f.logTime('exit');};var de=document.documentElement;$.f.windowHeight=self.innerHeight||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);$.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.idiv.ttl.innerHTML='GLOBAL GREEN';$.w.idivii.appendChild($.w.idiv.ttl);$.w.iframe=document.createElement('iframe');$.w.iframe.scrolling="no";$.w.idivii.appendChild($.w.iframe);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/globalgreen/loader.gif" />';$.w.p.appendChild($.w.p.loading);$.w.p.m=document.createElement('a');$.w.p.m.className='pr-mst';$.w.p.m.innerHTML='&nbsp;';$.w.p.m.target='_blank';$.w.p.appendChild($.w.p.m);$.w.p.dyn=document.createElement('div');$.w.p.dyn.className='pr-content';$.w.p.appendChild($.w.p.dyn);$.w.style.position='static';$.w.p.className+=' pr-full';$.f.loadContent('api/globalgreen/primary','&tabs=1',true);$.w.p.foot=document.createElement('div');$.w.p.foot.className='pr-ftr';$.w.p.ia=document.createElement('a');$.w.p.ia.href='http://poprule.com/';$.w.p.ia.innerHTML='Powered by PopRule';$.w.p.ia.target="_blank";$.w.p.ia.className='pr-logo';$.w.p.foot.appendChild($.w.p.ia);$.w.p.appendChild($.w.p.foot);$.w.appendChild($.w.p);$.c.appendChild($.w);},loadContent:function(src,args,refresh){var url=$.f.baseUrl+src+'?key='+$.a.client+args;if($.f.partnerId){url+='&ref='+$.f.partnerId;$.f.clickCount++;}
else{if($.a.page){url+='&t=adserver&ref='+escape($.a.page);}
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;$.f.runFunction[n]=function(r){$.f.pageCache[preCB]=r;delete($.f.runFunction[n]);$.f.removeScript(id);$.f.renderResult(r);$.w.p.loading.style.display='none';};if($.a.redirect){url+='&r='+$.a.redirect;}
url+='&callback='+id;$.f.runScript(url,id);}},switchTab:function(tab){var tabs=$.w.p.foot.getElementsByTagName('a');for(var i=0;i<6;i++){tabs[i].className='pr-tab '+tabs[i].title;}
tab.className='pr-tab '+tab.title+' '+tab.title+'-on';},formatLink:function(o,front){l=document.createElement('a');l.className='pr-lnk';if(o['type']!=false){ls=document.createElement('span');ls.className='pr-'+o['type'];ls.innerHTML=o['type'].toUpperCase();l.appendChild(ls);}
l.innerHTML+=' '+o['title'];if(!o['html']){if(o['url']){l.href=o['url'];l.target='_blank';}
else{if(!o['callback_args']){o['callback_args']='';}
l.href='#';l.onclick=function(){$.f.loadContent(o['callback'],o['callback_args'],true);return false;};}}
return l;},goBack:function(home){if($.f.cachePos!=0){if(home){$.f.cachePos=0;}
else{$.f.cachePos--;}
$.f.renderResult($.f.pageCache[$.f.cacheOrder[$.f.cachePos]]);}},logTime:function(dir){var d=new Date();if(dir=='enter'){$.f.startTime=d.getTime();}
else if(dir=='exit'){$.f.interactTime+=(d.getTime()-$.f.startTime);$.f.startTime=0;}},showOverlay:function(url){$.w.iframe.src=url;$.w.idiv.style.left=(($.f.windowWidth-710)/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.idiv.style.display='none';},resize:function(){$.f.windowHeight=self.innerHeight||(de&&de.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';},renderResult:function(r){if(!$.f.partnerId){$.f.partnerId=r.pid;}
if(r.masthead){var mastUrl=$.f.baseUrl+'clicktrack?source=widget&ref='+$.f.partnerId+'&key='+$.a.client+'&u='+escape(r.masthead);if(!$.a.redirect){$.w.p.m.href=mastUrl;}
else{$.w.p.m.href=$.a.redirect+escape(mastUrl);}}
n=document.createElement('div');if(r.tabs){for(cl in r.tabs){var nextTab=document.createElement('a');nextTab.className='pr-tab '+cl;nextTab.href='#';nextTab.rel=r.tabs[cl].cb;nextTab.title=cl;nextTab.onclick=function(){$.f.loadContent(this.rel,'',true);return false;};nextTab.innerHTML=r.tabs[cl].title;$.w.p.foot.appendChild(nextTab);}}
if(r.type=='html'){if(r.videos){cDiv=document.createElement('div');cDiv.innerHTML=r.html_content;n.appendChild(cDiv);vDiv=document.createElement('div');vDiv.className='pr-vdiv';for(i=0;i<r.videos.length;i++){vidA=document.createElement('a');vidA.href=r.videos[i].link;vidA.innerHTML=r.videos[i].img;vidA.title=r.videos[i].title;vidA.id=r.videos[i].id;vidA.className='pr-vid';vidA.onclick=function(){$.f.loadContent('api/youtube/'+this.id,'&width=278&autoplay=1',true);return false;};vDiv.appendChild(vidA);}
n.appendChild(vDiv);if(r.links){lDiv=document.createElement('div');lDiv.className='pr-flnks';for(i=0;i<r.links.length;i++){var nextTab=document.createElement('a');nextTab.className='pr-btn';nextTab.innerHTML=r.links[i].title;if(r.links[i].url){nextTab.href=r.links[i].url;nextTab.target='_blank';}
else{nextTab.href='#';if(r.links[i].title=='Pledge'){var em_url=$.f.baseUrl+'frame/any?url='+escape('https://secure3.convio.net/ggusa/site/Advocacy?cmd=display&page=UserAction&id=167#beanForm')+'&full=1&ref='+$.f.partnerId;nextTab.onclick=function(){$.f.showOverlay(em_url);return false;};}
else{nextTab.rel=r.links[i].cb;if(r.links[i].args){nextTab.title=r.links[i].args;}
else{nextTab.title='';}
nextTab.onclick=function(){$.f.loadContent(this.rel,this.title,true);return false;};}}
lDiv.appendChild(nextTab);}
n.appendChild(lDiv);}}
else{n.innerHTML=r.html_content;if(r.follow_page){var sharetw=document.createElement('a');sharetw.className='pr-icbtn pr-ictwt';sharetw.href='#';sharetw.onclick=function(){$.f.loadContent('api/globalgreen/follow','&twitter=1',true);return false;};sharetw.innerHTML='Follow Us on Twitter';n.appendChild(sharetw);var sharefb=document.createElement('a');sharefb.className='pr-icbtn pr-icfb';sharefb.href='#';sharefb.onclick=function(){$.f.loadContent('api/globalgreen/follow','&fb=1',true);return false;};sharefb.innerHTML='Become a Fan on Facebook';n.appendChild(sharefb);}}}
else if(r.type=='links'){if(!r.error){for(i=0;i<r.results.length;i++){n.appendChild($.f.formatLink(r.results[i],true));}
if(!r.front){n.c=document.createElement('div');n.c.className='pr-srch-nav';n.p=document.createElement('a');n.p.className='pr-srch-prev';n.p.href='#';n.p.onclick=function(){$.f.goBack();return false;};if(r.start!=0){n.p.innerHTML='&lt; Previous';}
else{n.p.innerHTML='&lt; Back';}
n.c.appendChild(n.p);if(!r.end){n.nxt=document.createElement('a');n.nxt.className='pr-srch-next';n.nxt.href='#';n.nxt.innerHTML='Next &gt;';qString='&start='+(r.start*1+3)+'&max='+r.max;if(r.query){qString+='&query='+escape(r.query);}
if(r.ntype){qString+='&type='+r.ntype;}
if(r.nextargs){qString+=r.nextargs;}
n.nxt.onclick=function(){$.f.loadContent(r.nexturl,qString,true);return false;};n.c.appendChild(n.nxt);}
n.appendChild(n.c);}}
else{err=document.createElement('p');err.innerHTML='Your search returned no results.';n.appendChild(err);}}
$.w.p.dyn.innerHTML='';$.w.p.dyn.appendChild(n);},calcage:function(num1,num2){s=((Math.floor($.f.secs/num1))%num2).toString();if(s.length<2)
s="0"+s;return s;},countBack:function(){if($.f.secs<0){$.w.ctr.innerHTML="The party is on!";return;}
$.w.ctr.u[0].innerHTML=$.f.calcage(86400,100000);$.w.ctr.u[1].innerHTML=$.f.calcage(3600,24);$.w.ctr.u[2].innerHTML=$.f.calcage(60,60);$.w.ctr.u[3].innerHTML=$.f.calcage(1,60);$.f.secs--;$.f.timer=setTimeout($.f.countBack,1000);},createCounter:function(){clearTimeout($.f.timer);var dthen=new Date("3/3/2010 8:00 PM UTC-0700");var dnow=new Date();var ddiff=new Date(dthen-dnow);$.f.secs=Math.floor(ddiff.valueOf()/1000);$.w.ctr=document.createElement('div');$.w.ctr.className='pr-ctr';var units=['Days','Hours','Minutes','Seconds'];$.w.ctr.u=new Array();for(i=0;i<4;i++){nDiv=document.createElement('div');nDiv.className='pr-unit';$.w.ctr.u[i]=document.createElement('span');nDiv.appendChild($.w.ctr.u[i]);nDivDiv=document.createElement('div');nDivDiv.innerHTML=units[i];nDiv.appendChild(nDivDiv);$.w.ctr.appendChild(nDiv);}
$.f.countBack();},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?:\/\/[^\/]*poprule.com\/js\/globalgreen.js$/;if(typeof window.addEventListener!=='undefined'){window.addEventListener('load',function(){$.f.init(thisScript);},false);window.addEventListener('unload',function(){$.f.leave();},false);window.addEventListener('resize',function(){$.f.resize();},false);}else if(typeof window.attachEvent!=='undefined'){window.attachEvent('onload',function(){$.f.init(thisScript);});window.attachEvent('onbeforeunload',function(){$.f.leave();});window.attachEvent('onresize',function(){$.f.resize();},false);}})();