var lpi=0;var rN;var rr=20;var rw=new Array();var nrw=new Array();var dl=0;var exc=new Array();var va=0;var sr="";var nw;var bu="http://spy.macrumors.com/";var su;var ig;var bd;
function spy_i(){spy_h();spy_g();spy_ex()}
function spy_x(){if(window.XMLHttpRequest){rN=new XMLHttpRequest()}else if(window.ActiveXObject){try{rN=new ActiveXObject("Msxml2.XMLHTTP")}catch(e){try{rN=new ActiveXObject("Microsoft.XMLHTTP")}catch(e){}}}}
function spy_s(){spy_x();var nid=(Math.round(Math.random()*2000)+100);if(rN){if(sr=='p'){url=bu+'?do=xml&lpi='+lpi+"&"}else{url=bu+'spy.xml?'}rN.onreadystatechange=spy_p;rN.open("GET",url+nid,true);rN.send(null)}setTimeout("spy_s()",rr*1000)}
function spy_p(){if(rN.readyState==4){if(rN.status==200){var ps=rN.responseXML.getElementsByTagName("post");if(ps.length>0){spy_pr(ps);lpi=parseInt(ps[0].getElementsByTagName("postid")[0].firstChild.nodeValue);dl=(rr/nrw.length)*1000;spy_d()}}}}
function spy_p2(){if(rN.readyState==4){if(rN.status==200){var ps=rN.responseXML.getElementsByTagName("post");var rv=new Array();if(ps.length>0){for(i=ps.length-1;i>=5;i--){rv.push(ps[i])}spy_pr(rv);lpi=parseInt(ps[5].getElementsByTagName("postid")[0].firstChild.nodeValue);rw=nrw;spy_g();spy_s()}}}}
function spy_pr(ps){nrw=new Array();for(i=0;i<ps.length;i++){if(parseInt(ps[i].getElementsByTagName("postid")[0].firstChild.nodeValue)>lpi){var isu=0;var igd=0;var 
ibd=0;for(j=0;j<su.length;j++){if(su[j]==ps[i].getElementsByTagName("id")[0].firstChild.nodeValue){isu=1}}for(j=0;j<ig.length;j++){if(ig[j]==ps[i].getElementsByTagName("userid")[0].firstChild.nodeValue){igd=1}}for(j=0;j<bd.length;j++){if(bd[j]==ps[i].getElementsByTagName("userid")[0].firstChild.nodeValue){ibd=1}}if(!igd){rc=ps[i].getElementsByTagName("replycount")[0].firstChild.nodeValue;var inf=new Array(ps[i].getElementsByTagName("forumid")[0].firstChild.nodeValue,"<tr>"+"<td class='alt1'"+(ibd?" style='background:rgb(255,255,204);'":"")+">"+"<span class='smallfont' style='float:right'><span class='time'>"+spy_ha(parseInt(ps[i].getElementsByTagName("hour")[0].firstChild.nodeValue))+":"+ps[i].getElementsByTagName("minute")[0].firstChild.nodeValue+" "+ps[i].getElementsByTagName("ampm")[0].firstChild.nodeValue+"</span></span><a style='text-decoration:none' href='http://forums.macrumors.com/member.php?u="+ps[i].getElementsByTagName("userid")[0].firstChild.nodeValue+"'"+(nw==''?" target='_blank'":"")+">"+ps[i].getElementsByTagName("username")[0].firstChild.nodeValue.unescapeHTML()+"</a>"+"</td>"+"<td class='alt2'"+(ibd?" style='background:rgb(255,255,204);'":"")+">"+(isu?"<span style='float:right'><img class='inlineimg' src='http://media.macrumorslive.com/f/images/misc/subscribed.gif' alt='You are subscribed to this thread' title='You are subscribed to this thread' /></span>":"")+"<div>"+(rc==0?"<strong>":"")+"<a style='text-decoration:none' href='http://forums.macrumors.com/showthread.php?t="+ps[i].getElementsByTagName("id")[0].firstChild.nodeValue+"'"+(nw==''?" target='_blank'":"")+"><img src='http://media.macrumorslive.com/f/images/buttons/sortdesc.gif' width='12' height='12' alt='Go to first post' title='Go to first post' border='0' class='inlineimg' /></a> <a style='text-decoration:none' href='http://forums.macrumors.com/showthread.php?p="+ps[i].getElementsByTagName("postid")[0].firstChild.nodeValue+"#post"+ps[i].getElementsByTagName("postid")[0].firstChild.nodeValue+"'"+(nw==''?" target='_blank'":"")+">"+ps[i].getElementsByTagName("title")[0].firstChild.nodeValue.unescapeHTML()+"</a>"+(rc==0?"</strong>":"")+"</div>"+"</td>"+"<td class='alt1' align='center'"+(ibd?" style='background:rgb(255,255,204);'":"")+">"+spy_nf(rc)+"</td>"+"<td class='alt2'"+(ibd?" style='background:rgb(255,255,204);'":"")+">"+"<a style='text-decoration:none' href='http://forums.macrumors.com/forumdisplay.php?f="+ps[i].getElementsByTagName("forumid")[0].firstChild.nodeValue+"'"+(nw==''?" target='_blank'":"")+">"+ps[i].getElementsByTagName("forumname")[0].firstChild.nodeValue+"</a></td>"+"</td>"+"</tr>");nrw.push(inf)}}}}
function spy_d(){if(nrw.length==0)return 0;rw.push(nrw.pop());spy_g();if(nrw.length>0){setTimeout("spy_d()",dl)}}
function spy_h(){var nid=(Math.round(Math.random()*2000)+100);spy_x();if(rN){rN.onreadystatechange=spy_p2;rN.open("GET",bu+"?do=xml&lpi="+lpi+"&"+nid,true);rN.send(null)}}
function spy_g(){var m="";for(i=rw.length-1;i>=Math.max(0,rw.length-120);i--){var ds=1;for(j=0;j<exc.length;j++){if(va==0&&exc[j]==rw[i][0]){ds=0}}if(ds==1){m=m+rw[i][1]}}$("postsdiv").innerHTML="<table class='tborder' cellpadding='6' cellspacing='1' border='0' width='100%' align='center'><tr>"+"<td class='thead' width='20%'><span style='float:right'>When</span>Who</td>"+"<td class='thead' align='center' nowrap='nowrap'>What</td>"+"<td class='thead' align='center' nowrap='nowrap'>Replies</td>"+"<td class='thead' width='25%'>Where</td>"+"</tr>"+m+"</table>";if(m==""){$("postsdiv").innerHTML=$("postsdiv").innerHTML+"<p align='center'>Loading posts, please wait...</p><hr/>"}}
function spy_ex(){if(exc.length>1){$("exc_option").innerHTML=" | <form name='excludeform'><input type='radio' name='excludeoption' onClick='va=1;document.excludeform.excludeoption[1].checked=false;spy_g();'"+(va==1?" checked":"")+" /> View all <input type='radio' name='excludeoption' onClick='va=0;document.excludeform.excludeoption[0].checked=false;spy_g();'"+(va==0?" checked":"")+" /> Ignore your "+(exc.length-1)+" excluded  forum"+(exc.length-1!=1?"s":"")+"</form>"}else{$("exc_option").innerHTML=""}}
function spy_sp(){var ag="";exc=new Array();exc.push('41');for(i=0;i<document.preferences_form.fx.length;i++){if(document.preferences_form.fx[i].checked==false){ag=ag+document.preferences_form.fx[i].value+",";exc.push(document.preferences_form.fx[i].value)}}if(document.preferences_form.nw.checked==false){nw=1}else{nw=''}var aj=new Ajax.Request("http://spy.macrumors.com/",{method:'get',parameters:"do=saveprefs&nw="+nw+"&fx="+ag,onComplete:sr})}
function spy_os(){$('preferencestable').style.display='block';return true}
function spy_oc(){if(nw==1){document.preferences_form.nw.checked=false}else{document.preferences_form.nw.checked=true}for(i=0;i<document.preferences_form.fx.length;i++){document.preferences_form.fx[i].checked=true;for(j=0;j<exc.length;j++){if(exc[j]==document.preferences_form.fx[i].value){document.preferences_form.fx[i].checked=false}}}$('preferencestable').style.display='none';return false}
function spy_ov(){spy_sp();$('preferencestable').style.display='none';spy_ex();spy_g();return false;}
function spy_sr(){spy_ex()}
function spy_nf(nStr){nStr+='';k=nStr.split('.');k1=k[0];k2=k.length>1?'.'+k[1]:'';var rgx=/(\d+)(\d{3})/;while(rgx.test(k1)){k1=k1.replace(rgx,'$1'+','+'$2')}return k1+k2}
function spy_ha(hr){hr=hr-hd;if(hr<0){hr=hr+12}else if(hr>12){hr=hr-12}return hr}
