
var binsniper={};var timeerr=0;var sidx=0;var maxsidx=0;var items=[];var fetchcnt=20;var loading=false;var paused=false;var delay=1;var errcnt=0;var slowed=0;var version="1.7";$(document).ready(function(){var max=10;var appid="BINSnipe-23f1-4320-1412-04463a4d65c3";$.ajaxSetup({cache:false,timeout:10000});var srch=$.query.get('s');var delay=$.cookie('d');if(!isNum(delay)||(delay!=2&&delay!=5)){delay=5;}
if(delay==2){$("#sp").attr('src','/images/fast.png');}else{$("#sp").attr('src','/images/slow.png');}
var sArray={};if(srch!='')sArray=srch.split('^');var x=0;var searches={};for(var sitem in sArray){var srchstr=sArray[sitem];var pts=srchstr.split('|');searches[x]={};searches[x]['pgm']=pts[0];searches[x]['kw']=pts[1];searches[x]['cats']=pts[2];searches[x]['pmin']=pts[3];searches[x]['pmax']=pts[4];}
$(function(){$(document).oneTime(400,function(i){$("#livefeedstat").html("JavaScript found, jQuery loaded...");$(document).oneTime(200,function(i){$("#livefeedstat").html("Configuring streamer...");starttimers();loadCfg();});});});var starttimers=function(){$(document).everyTime(1800070,function(i){$(document).stopTime("loop");loadCfg();});};var loadCfg=function(){var url="/webcfg.php?n=binsniperweb&v="+version+"&s="+srch;$.ajax({url:url,dataType:'json',error:function(){$("#livefeedstat").append("<br/>Unable to connect to streamer.");},success:loadStage2});return true;};var loadStage2=function(data){binsniper['pgms']=JSON.stringify(data['pgms']);binsniper['chksum']=data['chksum'];binsniper['alert']=data['alert'];binsniper['errors']=data['errors'];binsniper['urls']=data['urls'];maxsidx=binsniper['urls'].length-1;sidx=maxsidx;binsniper['times']={};for(var idx in binsniper['urls']){binsniper['urls'][idx]=binsniper['urls'][idx].replace(appid,unescape(binsniper['chksum']));binsniper['times'][idx]='2004-08-04T19:09:02.768Z';}
if(binsniper['alert']){$("#alertsdiv").html(binsniper['alert']);}
$(document).oneTime(100,function(i){var msg="BINSniper web version "+version+" loaded. ";if(count(sArray)==0){msg+="Showing default search. Use the search options at the right to customize.";}else{msg+="Using your saved searches.";}
$("#livefeedstat").html(msg);$(document).oneTime(800,function(i){$("#livefeedstat").append("<br/>Connecting to eBay....");firstTime();});});};var firstTime=function(){getListings();startLoop();};var startLoop=function(){$(document).stopTime("loop");$(document).everyTime(delay*1000,"loop",nextItem);};var nextItem=function(i){if(!paused){if(!loading&&slowed==0){if(sidx>=0){getListings();sidx--;}else{fetchcnt=30;if(count(items)<10){sidx=maxsidx;getListings();sidx--;}}}
showOneListing();}
if(slowed>0){if(count(items)==0){$("#stsdiv").html("Idle");$("#livefeedstat").html("No matching items were found. BINSniper will continue waiting for new listings and display them as they arrive. You may want to broaden your search.");}else{$("#livefeedstat").html("Loading listings...");}
slowed--;}};var insertEntry=function(content){if(max>0){max--;}else{$('#livefeed li:last-child').remove();}
$('#livefeed li:first-child').before(content);$("#livefeed li:first-child div").animate({height:"90px"},300);$("#livefeed li:first-child").click(function(){paused=true;$('#pp').attr("src",'images/playmsg.png');});};var getAd=function(){ads=['<a href="http://www.tkqlhce.com/click-5551063-10687130" target="_blank"><img src="http://www.awltovhc.com/image-5551063-10687130" width="728" height="90" alt="Laptop Cop - 20% Off" border="0"/></a>','<a href="http://www.anrdoezrs.net/click-5551063-10438302" target="_blank"><img src="http://www.tqlkg.com/image-5551063-10438302" width="468" height="60" alt="" border="0"/></a>','<a href="http://www.anrdoezrs.net/click-5551063-10744258" target="_blank"><img src="http://www.awltovhc.com/image-5551063-10744258" width="728" height="90" alt="Save Big at PsPrint.com!" border="0"/></a>'];var idx=Math.floor(Math.random()*ads.length);var ad=ads[idx];return ad;};var getListings=function(){loading=true;$("#stsdiv").html("Waiting for eBay items");var url=binsniper['urls'][sidx].replace("[TIME]",binsniper['times'][sidx]);url+="&paginationInput.entriesPerPage="+fetchcnt;url+="&affiliate.networkId=9&affiliate.trackingId=1234567890&affiliate.customId="+sidx;$.jsonp({url:url,callbackParameter:"callback",timeout:10000,dataType:'jsonp',error:commErr,success:eBayItems});};var commErr=function(){errcnt++;if(errcnt>3)errcnt=3;errmsg("Temporary communications problem");loading=false;};var eBayItems=function(data){if(!data||!data.findItemsAdvancedResponse){commErr();return;}
if(data.findItemsAdvancedResponse[0].ack=="Failure"){var msg="Error in search: "+data.findItemsAdvancedResponse[0].errorMessage[0].error[0].message+'';errmsg(msg);return;}
var needsidx=1;errcnt--;if(errcnt<0)errcnt=0;errmsg("");var timestamp=data.findItemsAdvancedResponse[0].timestamp;var itemlist=data.findItemsAdvancedResponse[0].searchResult[0].item;var cnt=data.findItemsAdvancedResponse[0].searchResult[0]["@count"];for(var idx in itemlist){var itemidx=count(items);items[itemidx]={};items[itemidx]['type']=itemlist[idx].listingInfo[0].listingType;items[itemidx]['itemid']=itemlist[idx].itemId;items[itemidx]['title']=itemlist[idx].title;items[itemidx]['country']=itemlist[idx].country;items[itemidx]['cat']=itemlist[idx].primaryCategory.categoryId;items[itemidx]['time']=itemlist[idx].listingInfo[0].startTime;items[itemidx]['gid']=itemlist[idx].globalId;if(itemlist[idx].galleryURL){items[itemidx]['imgurl']=itemlist[idx].galleryURL;}else{items[itemidx]['imgurl']="images/nopic.png";}
if(needsidx){var iurl=itemlist[idx].viewItemURL+' ';var startidx=iurl.indexOf('&customid=');var thisidx=iurl.substring(startidx+10,startidx+11);binsniper['times'][thisidx]=timestamp;needsidx=0;}
var bin=itemlist[idx].listingInfo[0].buyItNowAvailable;var currstr='';if(bin=='true'){currstr=itemlist[idx].listingInfo[0].buyItNowPrice[0]["@currencyId"];}else{currstr=itemlist[idx].sellingStatus[0].convertedCurrentPrice[0]["@currencyId"];}
if(bin=='true'){items[itemidx]['price']=itemlist[idx].listingInfo[0].buyItNowPrice[0].__value__;}else{items[itemidx]['price']=itemlist[idx].sellingStatus[0].convertedCurrentPrice[0].__value__;}
items[itemidx]['price']=formatPrice(items[itemidx]['price'],currstr,items[itemidx]['gid']);items[itemidx]['postal']=itemlist[idx].postalCode;items[itemidx]['loc']=itemlist[idx].location;}
if(count(items)!=cnt){items.sort(timeSorter);}
if(count(items)<10)slowed=4;if(count(items)<4)slowed=10;loading=false;};var showOneAd=function(){var content="<li><div class='itemdiv'>"+getAd()+"</div></li>";insertEntry(content);};function rawurlencode(str){str=(str+'').toString();str=encodeURIComponent(str);str=str.replace(/!/g,'%21');str=str.replace(/'/g,'%27');str=str.replace(/\(/g,'%28');str=str.replace(/\)/g,'%29');str=str.replace(/\*/g,'%2A');};var showOneListing=function(){if(count(items)>0){var item=items.shift();var itemid=item['itemid'];var title=item['title'];var type=item['type'];var imgurl=item['imgurl'];var gid=item['gid']+'';var shortgid=gid.substring(5);var price=item['price'];if(item['binprice'])price=item['binprice'];var postal=item['postal'];var loc=item['loc'];var country=item['country'];var content="<li><div class='itemdiv'><div class='itemimg'><img src='"+imgurl+"' width=90></div><div><span class='itemtitle'>"+title+"</span><BR><span class='itemprice'>"+price+"</span>";if(type=="AuctionWithBIN")content+="&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;BIN price (open auction with no bids or a reserve price)";content+="<BR><a href='/addon/redirectweb.php?a=binsniperweb&v="+version+"&f=I&i="+itemid+"&t0=E&c="+shortgid+"' target=_blank>View Item Details</a> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href='/addon/redirectweb.php?a=binsniperweb&v="+version+"&f=B&i="+itemid+"&t0=E&c="+shortgid+"' target=_blank>Buy/Offer Page</a><BR><span class='itemdtls'>Item number: "+itemid+" &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Located in: "+loc+"</span></div></div></li>";insertEntry(content);$("#stsdiv").html(count(items)+" items in queue");}};function count(array){var c=0;for(i in array)c++;return c;}
function isNum(o){return typeof o==='number'&&isFinite(o);}
function errmsg(msg){$("#errdiv").html(msg);}
$("#pp").click(function(){if(paused){paused=false;$('#pp').attr("src",'images/pausemsg.png');}else{paused=true;$('#pp').attr("src",'images/playmsg.png');}});$("#sp").click(function(){if(delay==2){delay=5;$('#sp').attr("src",'images/slow.png');}else{delay=2;$('#sp').attr("src",'images/fast.png');}
startLoop();});function timeSorter(a,b){if(a['time']<b['time']){return-1;}else{return a['time']>b['time'];}}
function formatPrice(price,itemcurrency,gid){var itemprice=new String(price);dec=itemprice.indexOf(".");if(dec>0){dollars=itemprice.substring(0,dec);cents=itemprice.substring(dec+1,9999);}else{dollars=itemprice;cents="00";}
if(cents.length==1)cents=cents+"0";switch(itemcurrency){case"AUD":fmtprice="AU $"+dollars+"."+cents;break;case"CAD":if(gid=="EBAY-FRCA"){fmtprice=dollars+","+cents+" $C";}else{fmtprice="C$"+dollars+"."+cents;}
break;case"CHF":fmtprice="CHF "+dollars+","+cents;break;case"CNY":fmtprice="Y "+dollars+"."+cents;break;case"EUR":if(gid=="EBAY-IE"){fmtprice="EUR "+dollars+"."+cents;}else{if(gid=="EBAY-ES"||gid=="EBAY-BE"||gid=="EBAY-FR"){fmtprice=dollars+","+cents+" EUR";}else{fmtprice="EUR "+dollars+","+cents;}}
break;case"GBP":fmtprice="GBP "+dollars+"."+cents;break;case"HKD":fmtprice="HK $"+dollars+"."+cents;break;case"INR":fmtprice="Rs. "+dollars+"."+cents;break;case"MYR":fmtprice="RM "+dollars+"."+cents;break;case"PHP":fmtprice="PHP "+dollars+"."+cents;break;case"PLN":fmtprice=dollars+","+cents+" zl";break;case"SEK":fmtprice=dollars+" kr";break;case"SGD":fmtprice="S$ "+dollars+"."+cents;break;case"TWD":fmtprice="NT $ "+dollars+"."+cents;break;case"USD":default:fmtprice="US$ "+dollars+"."+cents;break;}
return fmtprice;};});
