var BidsUpdater=new Class({ajax:null,usecomet:false,getUrl:function(){return window.bidsliveurl+'&'+window.ids+'&'+window.token+'&t='+$time();},setUrl:function(){killtime();if(!this.usecomet){this.ajax.url=this.getUrl();}
else{this.ajax.setUrl(this.getUrl());}},initialize:function(usecomet){bids_live_init();var url=this.getUrl();this.counter=-1;this.usecomet=usecomet;var self=this;if(!usecomet){this.ajax=new Ajax(url,{async:true,method:'get',onRequest:function(){},onComplete:function(){self.onComplete(false);}});}
else{this.ajax=new XHR.Comet({url:url,onPush:function(response){self.onComplete(response);}});window.addEvent('unload',this.ajax.cancel);}},keepalive:function(){if(this.counter>=60&&this.usecomet){this.counter=0;this.ajax.cancel();this.setUrl();this.ajax.send();}},onComplete:function(response){var resptext=(this.usecomet===true)?response:this.ajax.response.text;if(resptext==''){return true;}
this.counter++;if(!$defined(resptext)){return true;}
try{var resp=Json.evaluate(resptext.toString(),false);}
catch(err){}
if(window.is_admin&&resp&&$defined(resp.si)){for(prop in resp.si){$(prop).setHTML(resp.si[prop]);}}
if(resp&&resp.rows.length>0){if(resp&&$defined(resp.credits)){$('user_credits').setHTML(resp.credits);}
var lastbid;var lastbidcontainer;var lastbidlist;var listlength;var jsid;resp.rows.each(function(row){window.livefields.each(function(f){if($defined(row[f.idx])){jsid='e'+row['a'];switch(f.idx){case'n':window.liveelements[jsid]['e'].className='timer';window.liveelements[jsid]['e'].addClass(window.timerclasses[(row[f.idx]).toInt()]);break;case'g':if(row['h']==window.last_transactions[jsid]){break;}
window.liveelements[jsid][f.idx].setHTML(row[f.idx]);window.last_transactions[jsid]=row[f.idx];lastbidcontainer=window.liveelements[jsid][f.idx];if(lastbidcontainer.getFirst()){lastbidcontainer.getFirst().flash();}
break;case'h':window.last_transactions[jsid]=row[f.idx];break;case'i':if(window.is_admin){break;}
if(window.user_id!==0&&row[f.idx]!=window.user_id){$('placebid_'+row['a']).removeClass('inactive');}else{$('placebid_'+row['a']).addClass('inactive');}
break;case'o':break;case'm':window.bidbuttons[jsid].spawnMessage(row[f.idx],true);break;case'p':if($defined(row['o'])&&window.uid==row['o']){window.bidbuttons[jsid].spawnMessage(row[f.idx],true);}
break;case'q':if(row[f.idx]!==0){window.liveelements[jsid]['q'].setHTML(window.auto_bids_string+' ('+row[f.idx]+')');}
else{window.liveelements[jsid]['q'].setHTML(window.auto_bids_string);}
break;default:window.liveelements[jsid][f.idx].setHTML(row[f.idx]);break;}}});});}
this.keepalive();netstat(2);if(!window.init_complete){(function(){loading('auctionsgrid',false);}).delay(100);window.init_complete=true;}},run:function(){if(window.rescalingcolumns)return true;this.setUrl();if(!this.usecomet){if(!(this.ajax&&this.ajax.running))this.ajax.request();}
else{this.ajax.send();}},go:function(){this.run();if(!this.usecomet){this.timer=this.run.periodical(1000,this);}
else{this.run();}}});var Bid=new Class({ax:null,msgel:null,fx:null,spawnMessage:function(msg,persistent){var self=this;self.fx.set(0);self.msgel.setHTML(msg);self.fx.stop().start(1).chain(function(){(function(){if(!persistent){self.fx.start(0);}}).delay(700);});},initialize:function(el,aid){this.el=el;this.msgel=$('msg_'+aid);this.fx=new Fx.Style(this.msgel,'opacity',{duration:300,transition:Fx.Transitions.linear});var self=this;this.ax=new Ajax('',{autoCancel:true,async:true,method:'get',onRequest:function(){window.bid_in_progress=true;netstat(1);self.msgel.empty();self.msgel.getParent().addClass('loading');self.el.addClass('inactive');self.fx.set(0).start(1);},onComplete:function(){window.bid_in_progress=false;var resp=Json.evaluate(self.ax.response.text);self.msgel.getParent().removeClass('loading');if(resp.s!=200){self.el.removeClass('inactive');}
if($defined(resp.credits)){update_credits(resp.credits);}
self.spawnMessage(window.bids_errors[resp.msg],false);netstat(2);}});el.addEvent('click',function(ev){new Event(ev).stop();return false;});el.addEvent('click',function(){killtime();self.ax.url=window.bidsliveurl+'&task=placebid&aid='+aid+'&'+window.token;if(!self.ax.running){self.ax.request();}
else{self.ax.cancel();self.ax.request();}});}});function killtime(){if($defined(window.timeticker)){window.timeticker.cancel();}}
function loading(id,mode){var ovid='js_loading_overlay';var ovel=$(ovid);var id='overlay_container';var the_container=new Element('div',{'id':id,'class':'js_loading_overlay'});var bodyel=$$('html body')[0];the_container.injectInside(bodyel,'top');if(!ovel){ovel=new Element('div',{'id':ovid,'class':'overlay'});spinner=new Element('div',{'class':'spinner'});spinner.setHTML(window.loading_string);ovel.adopt(spinner);ovel.injectInside(the_container,'top');}
if(!$defined(window.ovfx)){window.ovfx=new Fx.Style(ovel,'opacity',{duration:350,transition:Fx.Transitions.linear});}
if(mode==true){ovel.setStyle('display','block');window.ovfx.set(0);window.ovfx.start(.6).chain(function(){bodyel.addClass('body_overlayed');});}
else{if($defined(window.equalcolumns)){window.equalcolumns.window_w=0;window.equalcolumns.resize_columns();}
window.ovfx.stop().start(0).chain(function(){bodyel.removeClass('body_overlayed');});}}
function netstat(state){if(!$defined(window.netstattimer)){window.netstattimer={};}
var theclass='idle';switch(state){case 1:theclass='send';break;case 2:theclass='receive';break;default:theclass='receive';break;}
if(!window.netstatel.hasClass(theclass)){if(window.netstattimer[theclass]){window.netstattimer[theclass]=$clear(window.netstattimer[theclass]);}
window.netstatel.addClass(theclass);window.netstattimer[theclass]=(function(){window.netstatel.removeClass(theclass);}).delay(250);}}
function update_credits(credits){if(window.credits_containers){window.credits_containers.each(function(el){el.setHTML(credits);});}}
function bids_live_init(){var led_element=(window.is_admin)?$('footer'):$('c1');window.init_complete=false;window.credits_containers=$$('.credits');window.bid_in_progress=false;var extern=new Element('div',{'id':'conn_stat'});var intern=new Element('div',{'id':'conn_img'});extern.adopt(intern);led_element.adopt(extern);window.netstatel=intern;window.liveelements=Array();window.bidbuttons=Array();window.timerclasses=Array();window.timerclasses[0]='near_end';window.timerclasses[1]='end';window.timerclasses[2]='regular';var id;window.livefields.each(function(f,index){$$('.'+f.cls).each(function(el){if(f.idx=='o')return true;var numeric_id=el.id.split('_')[1];id='e'+numeric_id;if(f.idx=='f'){window.bidbuttons[id]=new Bid(el,numeric_id);}
if(!$defined(window.liveelements[id]))window.liveelements[id]=Array();window.liveelements[id][f.idx]=el;});});}
var MAX_DUMP_DEPTH=10;function dumpObj(obj,name,indent,depth){if(depth>MAX_DUMP_DEPTH){return indent+name+": <Maximum Depth Reached>\n";}
if(typeof obj=="object"){var child=null;var output=indent+name+"\n";indent+="\t";for(var item in obj)
{try{child=obj[item];}catch(e){child="<Unable to Evaluate>";}
if(typeof child=="object"){output+=dumpObj(child,item,indent,depth+1);}else{output+=indent+item+": "+child+"\n";}}
return output;}else{return obj;}}
