var brEndingSoon,brEndingSoonIds="",brCategories,BR_DATAREQUEST_INTERVAL=2000,BR_DATAREQUEST_INTERVAL_QUICK=1000,BR_COUNTDOWN_INTERVAL=1000,BR_UPDATE_CATEGORIES=600000,BR_ADD_BB_MESSAGE=3000,BR_UPDATE_WATCHER=2000,BR_DISCONNECT_TIMER_LIMIT=5000,BR_DISCONNECT_COUNT_LIMIT=3,brMainAuctionId=undefined,brAuctionElements=new Array(),brCountDownTimer,brReloadTimer,brReloadTimerInterval,brCategoriesTimer,brButtonUI,brBidPlaced=false,brStatesSelectHtml,brStatesTextboxHtml,stateFieldId,stateFieldName,pausedMsg="The auction is paused. Please wait until it resumes before bidding. <a href='help/1000010/'>Read more</a>.",countryFieldId,brWatcherTimer,brLastWatcherUpdate=0,brLastWatcherUpdateCount=0,everConnected=false,brIsDisconnected=false,brPrevIsDisconnected=false,normalHighBidderColor,normalCurrentPriceColor,brInitialRequestSent=false;var blockButtonTokens=new Object;function performActionOnce(b,a){if(typeof b=="undefined"){b="tempToken"}if(blockButtonTokens[b]==true){brShowAlert("Your request is being processed. Please wait patiently.<br />If nothing happens in one minute, please try again.");return false}blockButtonTokens[b]=true;setTimeout("blockButtonTokens[buttonToken]=false;",60*1000);return a()}function brAddToWatchlist(c,b){if(typeof c=="undefined"){return false}$("#watchlist_icon_"+c+" img").attr("src","/med/img/base/progress_small.gif");var a=brHost+"/auction/watchlist/add/"+c;$.getJSON(a,function(d){brUpdateWatchlistStatus(d,b)});return false}function brRemoveFromWatchlist(c,b){if(typeof c=="undefined"){return false}$("#watchlist_icon_"+c+" img").attr("src","/med/img/base/progress_small.gif");var a=brHost+"/auction/watchlist/remove/"+c;$.getJSON(a,function(d){brUpdateWatchlistStatus(d,b)});return false}function brUpdateWatchlistStatus(b,a){if(typeof a=="undefined"){a=""}if(!(b&&b.watchlist_sc&&b.id)){return}if(b.watchlist_sc=="-1"){$("#watchlist_icon_"+b.id).html("<a href='#' onclick='return brAddToWatchlist("+b.id+',"'+a+"\");'><img title='Add auction to watchlist' alt='Add auction to watchlist' src='/med/img/base/buttons/watchlist_add"+a+".png' /></a>")}else{if(b.watchlist_sc=="1"){$("#watchlist_icon_"+b.id).html("<a href='#' onclick='return brRemoveFromWatchlist("+b.id+',"'+a+"\");'><img title='Remove auction from watchlist' alt='Remove auction from watchlist' src='/med/img/base/buttons/watchlist_remove"+a+".png' /></a>")}else{$("#watchlist_icon_"+b.id+" img").html("")}}}function showLogin(){$("#header_signup").hide();$("#header_login_button").hide();$("#header_login").fadeIn("slow");return false}function updateBidBalance(a){if(a<=0){$("#bid_balance_text").html("You have <span class='hilite'>no</span> bids. <b><a href='/account/bids/buy/'>Buy some</a></b> to start bidding now")}else{if(a==1){$("#bid_balance_text").html("You have <span class='hilite'>"+a+"</span> bid left")}else{$("#bid_balance_text").html("You have <span class='hilite'>"+a+"</span> bids left")}}bidBalance=a}function brShowAlert(b,a){$.alerts.overlayOpacity=0.7;$.alerts.okButton="&nbsp;OK&nbsp;";jAlert(b,"Note",a);return false}function searchAuctions(a,b){if(document.search_auctions){document.search_auctions.action="/auction/search/"+a+"/"+b+"/";document.search_auctions.submit()}}function brBtnText(a){return"<i /><span />"+a}function brHandleButtonClick(a){return}function brFlashPrice(a){if(a){if($.browser.msie){a.fadeOut("slow").fadeIn("slow").fadeOut("slow").fadeIn("slow")}else{brAnimatePrice(a)}}}function brAnimatePrice(a){a.each(function(b){if($(this).attr("origFontSize")==null){$(this).attr("origFontSize",$(this).css("font-size"))}$(this).animate({fontSize:"+=220%"},300).animate({fontSize:$(this).attr("origFontSize")},600)})}var oddRowState=0;function brGetDisplayBidHistory(b){var a,c="";for(a=0;a<b.length;++a){c+='<tr><td class="bid '+(a%2==1-oddRowState?"alt":"")+'">'+brGetDisplayPrice(b[a].bp)+"</td><td username="+b[a].bn+' class="bidder clickable_username '+(a%2==1-oddRowState?"alt":"")+'">'+brGetDisplayUsername(b[a].bn,13)+'</td><td class="type '+(a%2==1-oddRowState?"alt":"")+'">'+(b[a].bt=="a"?"BidBuddy":"Manual")+"</td></tr>"}return c}function brUpdateCategories(a){if(a&&a.c){brCategories=a.c;$("#categories_menu").html(brGetDisplayCategories());$("#categories_menu.jd_menu").jdMenu();$(document).bind("click",function(){$("#categories_menu.jd_menu ul:visible").jdMenuHide()})}}function brShowNotRookieAlert(b){var a=b.split("-",3);if(a.length>1){if(a[1]=="0"){brShowAlert("You cannot bid on this rookie auction because you have already won too many auctions.")}else{brShowAlert("You cannot bid on this "+a[1]+"-win-limit auction because you have already won "+a[2]+" auctions.")}}else{brShowAlert("You cannot bid on this rookie auction because you have already won too many auctions.")}}function brUpdateDisplay(b,a){if(brBronco==null){if(typeof(a)!="undefined"){brBronco=a}else{return}}brUpdateWatcher();if(brBidPlaced&&b.m!="self_overbid"){if(oddRowState==1){oddRowState=0}else{oddRowState=1}}brBidPlaced=false;if(b&&b.m){if(b.m=="logout"){window.location="/login/?next="+window.location}if(b.m=="lockout"){brShowAlert("You have reached the limit of 2 won auctions per week.\nYou cannot place any bids until next Sunday")}if(b.m.match("^not_rookie")=="not_rookie"){brShowNotRookieAlert(b.m)}if(b.m=="paused"){brShowAlert(pausedMsg)}if(b.m=="too_late"){brShowAlert("Unfortunately, this auction had ended before we received your bid.<br>When you click at the last possible moment, there is a chance that your bid will not arrive in time.<br>See the <a href='/help/30/'>bidding help</a> for more details.")}}brEndingSoon=null;if(b&&b.a){brEndingSoon=b.a}if(b&&typeof(b.bb)!="undefined"){updateBidBalance(b.bb)}if(b.m=="self_overbid"){brShowAlert("You cannot place a bid if you already are the high bidder.")}if(b.sc){if(b.sc=="1"){if(b.ufm){$("#id_min_price").val("");$("#id_max_price").val("");$("#id_max_num_of_bids").val("");$("#id_bb_msg").html("")}}else{if(b.sc=="0"&&b.ufm){$("#id_bb_msg").html("");brShowAlert(b.ufm)}else{if(b.sc=="2"&&b.ufm){$("#id_min_price").val("");$("#id_max_price").val("");$("#id_max_num_of_bids").val("");$("#id_bb_msg").html("");brShowAlert(b.ufm)}}}}brCountDown(true)}function brGetDisplayCategories(){var e="<li>Categories &raquo;<ul>";if(brCategories){var c,b,d,a="&nbsp;&nbsp;&nbsp;&nbsp;";for(c=0;c<brCategories.length;++c){e+="<li><a href='"+(brCategories[c].url.length==0?"/auction/category/"+brCategories[c].id+"/7/1/":brCategories[c].url)+"' >"+brCategories[c].n+(brCategories[c].ct=="-1"?"":" ("+brCategories[c].ct+")")+"</a></li>";if(brCategories[c].c){var d=brCategories[c].c;for(b=0;b<d.length;++b){if(typeof d[b]=="undefined"){continue}e+="<li>"+a+"<a href='"+(d[b].url.length==0?"/auction/category/"+d[b].id+"/7/1/":d[b].url)+"' >"+d[b].n+(d[b].ct=="-1"?"":" ("+d[b].ct+")")+"</a></li>"}}}}e+="</ul></li>";return e}function brGetDisplayUsername(b,a){if(typeof a=="undefined"){a=20}if(b.length>0){if(b.length>20){return b.substring(0,a)+"..."}else{return b}}else{return"&nbsp;"}}function brGetDisplayPrice(a){return"$"+parseFloat(a).toFixed(2)}function brGetCookie(a){if(document.cookie.length>0){startpos=document.cookie.indexOf(a+"=");if(startpos!=-1){startpos+=(a.length+1);endpos=document.cookie.indexOf(";",startpos);if(endpos==-1){endpos=document.cookie.length}return unescape(document.cookie.substring(startpos,endpos))}}return""}function brSetupAuction(){var c=$(".auction_item");var a=false;for(var b=0;b<c.length;++b){if(c[b]){var f=c[b].attributes.id.value;if(f.indexOf&&f.indexOf("id_auction_")==0){var e=f.substr(f.lastIndexOf("_")+1);if(jQuery(c[b]).find(".future").size()==0){if(a){brEndingSoonIds+=","}else{a=true}brEndingSoonIds+=e;brAuctionElements[e]=c[b]}}}}var d=$("#ma_id");if(d&&d.size()>0){if(!d.find(".future")||d.find(".future").size()==0){brMainAuctionId=d.html()}}}function brStartReload(){brLoadEndingSoon();window.clearInterval(brReloadTimer);brReloadTimerInterval=BR_DATAREQUEST_INTERVAL;brReloadTimer=window.setInterval("brLoadEndingSoon()",BR_DATAREQUEST_INTERVAL);brLoadCategories();window.clearInterval(brCategoriesTimer);brCategoriesTimer=window.setInterval("brLoadCategories()",BR_UPDATE_CATEGORIES);window.clearInterval(brWatcherTimer);brWatcherTimer=window.setInterval("brCheckWatcher()",BR_UPDATE_WATCHER)}function brStartCountdown(){window.clearInterval(brCountDownTimer);brCountDownTimer=window.setInterval("brCountDown()",BR_COUNTDOWN_INTERVAL)}function brGetDisplayTime(d){if(d>0){var a=parseInt((d)/3600),b=parseInt((d-a*3600)/60),c=d%60;if(a<10){a="0"+a}if(b<10){b="0"+b}if(c<10){c="0"+c}return a+":"+b+":"+c}else{return"00:00:01"}}function brCountDown(k){if(typeof k=="undefined"){k=false}if(!brEndingSoon){return}if(!brEndingSoon.length){return}if(brEndingSoon.length<=0){return}var m=false;var e=999;var d=999;if(k){everConnected=true}for(var f=0;f<brEndingSoon.length;++f){var l=brEndingSoon[f];if(typeof(l)=="undefined"){continue}var g=brAuctionElements[l.id];if(!g){continue}var h=jQuery(g);if(!h){continue}var j=h.find(".time_left");if(j&&j.size()==1){if(!brIsDisconnected){if(l.tr=="pa"){j.html("Paused")}else{if(l.tr>0){if(!k){--l.tr}j.html(brGetDisplayTime(l.tr))}else{if(l.tr==0){j.html(brGetDisplayTime(l.tr))}else{if(l.tr<0){if(brUser&&brUser!=undefined&&l.hb.toLowerCase()==brUser.toLowerCase()){j.html("You won!")}else{j.html("Ended")}}}}if(l.tr<e){e=l.tr;d=l.mr}if(l.tr>=0&&l.tr<5){m=true}}}}if(l.b&&l.b.length>0){$("#id_auction_"+l.id+" .bid_history tbody").html(brGetDisplayBidHistory(l.b))}var b=h.find(".price");if(b&&b.size()>=1){if(!brIsDisconnected){b.html(brGetDisplayPrice(l.cp));if(b.attr("num")!=l.cp){b.attr("num",l.cp);brFlashPrice(b)}}}var c=h.find(".high_bidder");if(c&&c.size()==1){if(!brIsDisconnected){c.html(brGetDisplayUsername(l.hb))}}if(!c.hasClass("clickable_username")){c.addClass("clickable_username");c.attr({username:l.hb})}if(typeof(displayBidBuddies)!="undefined"&&l&&l.bbs){displayBidBuddies(l.bbs)}}if(m&&brReloadTimerInterval!=BR_DATAREQUEST_INTERVAL_QUICK){window.clearInterval(brReloadTimer);brReloadTimerInterval=BR_DATAREQUEST_INTERVAL_QUICK;brReloadTimer=window.setInterval("brLoadEndingSoon()",BR_DATAREQUEST_INTERVAL_QUICK)}else{if(!m&&brReloadTimerInterval!=BR_DATAREQUEST_INTERVAL){window.clearInterval(brReloadTimer);brReloadTimerInterval=BR_DATAREQUEST_INTERVAL;brReloadTimer=window.setInterval("brLoadEndingSoon()",BR_DATAREQUEST_INTERVAL)}else{if(e==1){window.clearInterval(brReloadTimer);window.setTimeout("brLoadEndingSoon()",d)}}}if(typeof(displayBidBuddyUI)!="undefined"){if(bidBalance!="undefined"){displayBidBuddyUI(bidBalance)}else{displayBidBuddyUI(0)}}if(k){brStartCountdown()}}function brGetCurrentDisplayPrice(c){var b=jQuery(c);if(!b){return"-1"}var a=b.find(".price");if(a){return a.attr("num")}else{return"-1"}}function brShowDisconnection(a){}function brShowReconnection(){}function brUpdateWatcher(){var b=new Date(),a=b.getTime();if(brLastWatcherUpdate==0){brLastWatcherUpdate=a}else{brIsDisconnected=((a-brLastWatcherUpdate)>BR_DISCONNECT_TIMER_LIMIT);if(!brIsDisconnected){brLastWatcherUpdate=a}}brLastWatcherUpdate=a}function brCheckWatcher(){brPrevIsDisconnected=brIsDisconnected;var b=new Date(),a=b.getTime();if(brLastWatcherUpdate>0){brIsDisconnected=((a-brLastWatcherUpdate)>BR_DISCONNECT_TIMER_LIMIT)}else{if(brLastWatcherUpdateCount<BR_DISCONNECT_COUNT_LIMIT){++brLastWatcherUpdateCount}else{brIsDisconnected=true}}if(everConnected){if(brIsDisconnected){if(!brPrevIsDisconnected){brShowDisconnection("Disconnected");brPrevIsDisconnected=true}brLastWatcherUpdateCount=0}else{if(brPrevIsDisconnected){brShowReconnection();brPrevIsDisconnected=false}}}}function tryBroncoInitialPrimary(a){$.getJSON(brBroncoPrim+a,function(b){brUpdateDisplay(b,brBroncoPrim)})}function tryBroncoInitialSecondary(a){$.getJSON(brBroncoSecond+a,function(b){brUpdateDisplay(b,brBroncoSecond)})}function brLoadEndingSoon(){if(brEndingSoonIds.length<=0){return}var a="/bronco/a?a="+brEndingSoonIds+"&w="+brWindowToken+"&dt="+brGetCurrentTimeForJSON()+"&callback=?";if(brMainAuctionId&&brMainAuctionId!=undefined&&brMainAuctionId.length>0){a+="&ad="+brMainAuctionId}if(brUser&&brUser!=undefined&&brUser.length&&brUser.length>0){if(brSession==undefined){if(brGetCookie){brSession=brGetCookie("sessionid")}}if(brSession&&brSession!=undefined){a+="&u="+brUser.toLowerCase()+"&s="+brSession}}if(brBronco==null&&!brInitialRequestSent){brInitialRequestSent=true;setTimeout("tryBroncoInitialPrimary('"+a+"')",0);setTimeout("tryBroncoInitialSecondary('"+a+"')",0)}else{if(brBronco!=null){var b=brBronco+a;$.getJSON(b,function(c){brUpdateDisplay(c)})}}}function brLoadCategories(){var a=brHost+"/auction/categories/?dt="+brGetCurrentTimeForJSON();$.getJSON(a,function(b){brUpdateCategories(b)})}function brGetCurrentTimeForJSON(){var d=new Date();var g=(d.getMonth()+1)<10?"0"+(d.getMonth()+1):(d.getMonth()+1);var b=d.getDate()<10?"0"+d.getDate():d.getDate();var c=d.getHours()<10?"0"+d.getHours():d.getHours();var e=d.getMinutes()<10?"0"+d.getMinutes():d.getMinutes();var f=d.getSeconds()<10?"0"+d.getSeconds():d.getSeconds();var a=(d.getTime()%1000)<10?"00"+(d.getTime()%1000):((d.getTime()%1000)<100?"0"+(d.getTime()%1000):(d.getTime()%1000));return""+d.getFullYear()+g+b+"@"+c+":"+e+":"+f+"."+a}function brConfigureButtons(){if(brGetCookie){brSession=brGetCookie("sessionid")}hover_function=function(){var d=$(this).children("span:first");if(d){if(brIsAuth){var b=null,e=this.id;e=e.substr(e.lastIndexOf("_")+1);if(brEndingSoon){for(var c=0;c<brEndingSoon.length;++c){if(brEndingSoon[c].id==e){b=brEndingSoon[c];break}}}if(b){if(b.tr>=0){if(bidBalance==0){d.html(brBtnText("Buy Bids"))}else{d.html(brBtnText("Bid"))}}else{if(brUser&&brUser!=undefined&&b.hb.toLowerCase()==brUser.toLowerCase()){d.html(brBtnText("Checkout"))}else{if(b.tr<0){d.html(brBtnText("Ended"))}}}}}else{d.html(brBtnText("Login"))}}};$(".auction_item .button .btn").hover(hover_function,function(){var a=$(this).children("span:first");if(a){a.html(brBtnText("Bid"))}});$(".auction_item .button .btn").click(function(){if(brIsAuth&&brSession&&brSession!=undefined){var e=$(this).attr("id"),b=null,e=this.id;e=e.substr(e.lastIndexOf("_")+1);if(brEndingSoon){for(var d=0;d<brEndingSoon.length;++d){if(brEndingSoon[d].id==e){b=brEndingSoon[d];break}}}if(!b){return}if(b.tr=="pa"){brShowAlert(pausedMsg+" (1253)")}else{if(b.tr>=0&&brBronco!=null){if(bidBalance==0){location.replace("/account/bids/buy/")}var c=brBronco+"/bronco/b?u="+brUser.toLowerCase()+"&w="+brWindowToken+"&s="+brSession+"&ba="+e+"&a="+brEndingSoonIds+"&dp="+brGetCurrentDisplayPrice(brAuctionElements[e])+"&dt="+brGetCurrentTimeForJSON()+"&callback=?";if(brMainAuctionId&&brMainAuctionId!=undefined&&brMainAuctionId.length>0){c+="&ad="+brMainAuctionId}brBidPlaced=true;$.getJSON(c,function(a){brUpdateDisplay(a)})}else{if(brUser&&brUser!=undefined&&brIsAuth&&b.hb.toLowerCase()==brUser.toLowerCase()){performActionOnce("byItem"+e,location.replace("/auction/buy/"+e+"/"))}else{brShowAlert("This auction has already ended.")}}}}else{location.replace("/login/?next="+window.location.pathname)}return false})}function brSetStatesHtml(){if($("#"+countryFieldId+" option:selected").val()=="US"){var b=$("#"+stateFieldId).val();$("#"+stateFieldId).parent().html(brStatesSelectHtml);try{$("#"+stateFieldId+" option:contains("+b+")").attr("selected",true)}catch(a){}}else{var b=$("#"+stateFieldId).val();$("#"+stateFieldId).parent().html(brStatesTextboxHtml);$("#"+stateFieldId).val(b)}}function brSetStates(b,a){if(typeof b=="undefined"){b="state"}if(typeof a=="undefined"){a="country"}fStateFieldId="id_"+b;fCountryFieldId="id_"+a;brStatesSelectHtml='<label for="'+fStateFieldId+'"> State<em>*</em></label><select id="'+fStateFieldId+'" name="'+b+'"></select>';brStatesTextboxHtml='<label for="'+fStateFieldId+'"> State/Province/Region</label><input id="'+fStateFieldId+'" type="text" name="'+b+'"/>';stateFieldId=fStateFieldId;stateFieldName=b;countryFieldId=fCountryFieldId;brLoadStates();brSetStatesHtml();$("#"+fCountryFieldId).change(brSetStatesHtml)}function brLoadStates(){if(typeof(US_STATES)!="undefined"&&US_STATES){var a,b="";for(a=0;a<US_STATES.length;++a){b+='<option value="'+US_STATES[a].code+'" >'+US_STATES[a].name+"</option>"}brStatesSelectHtml='<label for="'+stateFieldId+'"> State<em>*</em></label><select id="'+stateFieldId+'" name="'+stateFieldName+'">'+b+"</select>"}}function brSetupClickableUsernames(){$(".clickable_username").live("click",function(){var a=$(this).attr("username");if(a&&a.length&&a.length>0){window.location.replace("/account/user/"+a)}else{a=$(this).html();if(a.indexOf("...")==-1&&a.length>0){window.location.replace("/account/user/"+a)}}})}function brSetupClickableDisconnected(){$(".clickable_disconnected").live("click",function(){window.location.replace("/help/1000011/")})}$(document).ready(function(){brConfigureButtons();brSetupAuction();brStartReload();brSetupClickableUsernames();brSetupClickableDisconnected();brStartCountdown()});