function Tab(){this.rows=[]
this.removedRows=[]
this.visibleRowsCount=10;this.loadChunckSize=50;this.type='';this.filterValue='';this.tldValue='';this.loadingParams={};this.newFilter=false;this.loading=false;this.updatingDarkening=false;this.updatingStartTime=0;this.visualMoveRows=true;this.category='';this.sendExistRowsIds=false;this.currentBlock;this.preloadRowsCount=15;this.loadedRows=this.preloadRowsCount;this.rowHeight=0;this.rowsCount=0;this.sortingField='';this.sortingAsc=true;this.sortingDefaultDesc={};this.getData=function(){var rowsCount=this.rowsCount+this.removedRows.length;var scrollTop=$('#'+this.type+'-auctions-table .scrollContent').attr('scrollTop')-$('#'+this.type+'TabTable .auction_block:visible').height();var showed=Math.ceil(scrollTop/this.getRowHeight())+this.visibleRowsCount;if(showed>this.loadedRows&&this.loadedRows<rowsCount){var limit=showed+this.loadChunckSize-this.loadedRows+this.removedRows.length;this.load(limit);}}
this.getRowHeight=function(){if(this.rowHeight){return this.rowHeight;}
return this.rowHeight=$.browser.msie?77:76;}
this.showListIsEmpty=function(){if(!$('#empty_'+this.type).length){var columnsCount=$('#'+this.type+'-auctions-table .tab-list-header')[0].cells.length;var row=$('<tr id="empty_'+this.type+'"><td colspan="'+columnsCount+'">List is empty.</td></tr>');$('#'+this.type+'-auctions-table .tab-list-header').after(row);}}
this.load=function(limit){if(this.loading){return false;}
this.loading=true;var params={'type':this.type,'limit':limit,'sortingField':this.sortingField,'sortingAsc':this.sortingAsc?1:0,'category':this.category}
if(this.filterValue){params['filter']=this.filterValue;}
if(this.tldValue){params['tld']=this.tldValue;}
if(this.newFilter){this.removedRows=[];params['count']=1;}else{if(this.sendExistRowsIds){var ids=[];for(var i in this.rows){ids.push(this.rows[i].id);}
params['exists']=ids.join('|');}else{params['offset']=this.loadedRows-this.removedRows.length;}}
for(var k in this.loadingParams){params[k]=this.loadingParams[k];}
this.requestData(params);}
this.requestData=function(params){var command=params['id']?'ajax.GetAuctionData':'ajax.GetAuctionsData';ajax.sendRequest(command,function(response){if(response.status=='OK'){var tab=app.tabs[response.type];if(tab.newFilter){tab.clear();$('#'+tab.type+'-auctions-table').scrollTop(0);tab.newFilter=false;}
if(typeof(response.count)!='undefined'){tab.rowsCount=response.count;if(tab.rowsCount==0){tab.showListIsEmpty();}}
if(response.data){tab.addRows([response.data]);tab.loadedRows=tab.rowsCount=1;}else{tab.addRows(response.rows);}
tab.loading=false;tab.updateBlockHeight();tab.showLoading(tab.loadedRows<tab.rowsCount&&response.rows.length);if(response.id){delete tab.loadingParams['id'];$('#'+tab.type+'_row_'+response.id).find('.expand').click();}else if(response.rows.length){tab.getData();}}},params);}
this.showLoading=function(value){if(value){$('#'+this.type+'TabTable').append($('#loading_'+this.type));$('#loading_'+this.type).show();}else{$('#loading_'+this.type).hide();}}
this.setCategory=function(value){if(typeof(value)=='undefined'||value=='All Categories'){this.category='';}else{this.category=value;}
this.loadedRows=0;this.newFilter=true;this.load(this.preloadRowsCount);}
this.filter=function(value,filterField){filterField=filterField||'filterValue';if(typeof(value)!='undefined'){this[filterField]=value;}
this.loadedRows=0;this.newFilter=true;this.load(this.preloadRowsCount);}
this.clear=function(){$('#'+this.type+'-auctions-table').find('tr').filter(':not(.tab-list-header):not(.loading)').remove();this.clearBeforeAdding=false;this.rows=[];}
this.addRows=function(data){for(var i in data){if(this.addRow(data[i])){this.loadedRows++;}}
if(this.type=='live'||this.type=='upcoming'){setAuctionsListIds();}}
this.rowExists=function(id){return $('#'+this.type+'_row_'+id).length>0?true:false;}
this.addRow=function(item,replace){var itemId=item['id'];var rowId=this.type+'_row_'+item['id'];if(this.rowExists(itemId)){for(var i in this.removedRows){if(this.removedRows[i]==item['id']){this.removedRows.splice(i,1);break;}}
return false;}
var newRow=$('<tr id="'+rowId+'"'+'></tr>');if(this.type=='live'){var auction_info=JSJaCJSON.parse(item['auction']['info']);this.addToLiveAuctions(itemId,auction_info,item['auction']['bids']);}
if(this.type=='upcoming'){var auction_info=JSJaCJSON.parse(item['auction']['info']);this.addToUpcomingAuctions(itemId,auction_info);}
if(item['json']){this.addRowData(JSJaCJSON.parse(item['json']));}
for(var j in item){if(j=='id'||j=='auction'||j=='json'||j=='css_class'){continue;}
newRow.append('<td class="td '+j+' '+(item['css_class']&&item['css_class'][j]?item['css_class'][j]:'')+'"'+(itemId&&this.type=='live'?' id="'+j+'_'+itemId+'"':'')+'><div class="name-fixed">'+item[j]+'<span class="transp"><!-- --></span></div></td>');}
if(replace){replace.replaceWith($(newRow));}else{$('#'+this.type+'TabTable').append($(newRow));}
return true;}
this.addRowData=function(data){this.rows.push(data);}
this.newRow=function(info){if(this.rowExists(info.id)){return false;}
this.rowsCount++;var pos=this.calculatePosition(info);if(pos){this.insertRow(info,pos.afterId,pos.position);return;}
if(this.rowsCount>=this.visibleRowsCount){this.showLoading(true);this.updateBlockHeight();}
this.getData();}
this.calculatePosition=function(info){var newVal=info[this.sortingField];var newId=info['id'];if(!this.rows.length){return{'afterId':0,'position':0};}else{var nextVal=this.rows[0][this.sortingField];var nextId=this.rows[0]['id'];if((this.sortingAsc&&(nextVal>newVal||(nextVal==newVal&&nextId>newId)))||(!this.sortingAsc&&(nextVal<newVal||(nextVal==newVal&&nextId<newId)))){return{'afterId':0,'position':0};}}
for(var i in this.rows){i=parseInt(i);if(this.rows[i+1]){var curVal=this.rows[i][this.sortingField];var nextVal=this.rows[i+1][this.sortingField];var curId=this.rows[i]['id'];var nextId=this.rows[i+1]['id'];if(this.sortingAsc){if(curVal<=newVal){if(nextVal&&(nextVal>newVal||(nextVal==newVal&&nextId>newId))){return{'afterId':curId,'position':i+1};}}}else{if(curVal>=newVal){if(nextVal&&(nextVal<newVal||(nextVal==newVal&&nextId<newId))){return{'afterId':curId,'position':i+1};}}}}}
return false;}
this.insertRow=function(info,afterId,rowsPos){if($('#'+this.type+'_row_'+info['id']).length){return false;}
this.loadedRows++;for(j=this.rows.length-1;j>=rowsPos;j--){this.rows[j+1]=this.rows[j];}
this.rows[rowsPos]=info;var row='<tr id="row_loading_'+info['id']+'" style="display: none"><td>&nbsp;</td></tr>';if(rowsPos>0){if($('#'+this.type+'_row_'+afterId).length){if($('#'+this.getBlockPrefix()+afterId).length){$('#'+this.getBlockPrefix()+afterId).after(row);}else{$('#'+this.type+'_row_'+afterId).after(row);}}else{$('#row_loading_'+afterId).after(row);}}else{$('#'+this.type+'TabTable').prepend(row);}
this.loadRowData(info['id']);}
this.loadRowData=function(id){this.showUpdating();ajax.sendRequest('ajax.GetAuctionData',function(response){var tab=app.tabs[response.type];if(response.data){$('#empty_'+response.type).remove();tab.addRow(response.data,$('#row_loading_'+response.id));if(tab.expandedRowMoved(response.id)){$('#'+tab.type+'-auctions-table .scrollContent').scrollTop($('#'+tab.type+'-auctions-table .scrollContent').scrollTop()+tab.getRowHeight());}
tab.updateBlockHeight();if(tab.type=='live'||tab.type=='upcoming'){setAuctionsListIds();}}else if(response.id){$('#row_loading_'+response.id).remove();var removed=false;for(var i in tab.rows){if(tab.rows[i].id==response.id){tab.rows.splice(i,1);removed=true;}}
if(removed){tab.rowsCount--;tab.loadedRows--;}}
tab.hideUpdating();},{'type':this.type,'id':id});}
this.expandedRowMoved=function(id){var moved=false;if($('.auction_block:visible').length){var expandedRowId=parseInt($('.auction_block:visible').attr('id').substr(14));for(var i in this.rows){if(this.rows[i].id==id){moved=true;break;}
if(this.rows[i].id==expandedRowId){break;}}}
return moved;}
this.removeRow=function(id,updateRowsCount,doNotRemoveHtml,deffered){if(!this.rowExists(id)){return false;}
if($('#'+this.getBlockPrefix()+id+':visible').length){$('#'+this.getBlockPrefix()+id).addClass('deffered_removing');return;}
if(!deffered){this.showUpdating();}
if((typeof(doNotRemoveHtml)=='undefined'||!doNotRemoveHtml)){this.loadedRows--;}
var expandedRowMoved=this.expandedRowMoved(id);var removed=false;for(var i in this.rows){if(this.rows[i].id==id){this.rows.splice(i,1);removed=true;}}
if(removed&&(typeof(updateRowsCount)=='undefined'||updateRowsCount)){this.rowsCount--;}
if(doNotRemoveHtml){this.hideUpdating();if(removed){this.removedRows.push(id);}
return;}
$('#'+this.type+'_row_'+id).remove();$('#'+this.getBlockPrefix()+id).remove();if(expandedRowMoved){$('#'+this.type+'-auctions-table .scrollContent').scrollTop($('#'+this.type+'-auctions-table .scrollContent').scrollTop()-this.getRowHeight());}
if(this.rowsCount==0){this.showListIsEmpty();}
this.updateBlockHeight();if(typeof(deffered)=='undefined'||!deffered){this.hideUpdating();}
this.showLoading(this.loadedRows<this.rowsCount);this.getData();}
this.removeDeffered=function(force){$('#'+this.type+'TabTable .auction_block.deffered_removing'+(force?'':':hidden')).each(function(i,e){var id=parseInt($(e).attr('id').substr(14));app.tabs[getTabName($(e))].removeRow(id,true,false,true);});}
this.updateRow=function(id,field,value,info){if(this.sortingField!=field){return;}
var i=0;for(var i in this.rows){if(this.rows[i].id==id){var row=this.rows[i];break;}}
if(row){row[field]=value;if(this.rowsCount>1){var pos=this.calculatePosition(row);if(pos&&this.rows.length>1&&this.rows.length-1!=pos.position){if(pos.position!=i&&pos.afterId!=id){this.moveRow(row,pos.afterId,pos.position);}}else{this.removeRow(row.id,false);this.getData();}}}}
this.moveRow=function(row,afterId,position){var newRows=[];for(var i in this.rows){if(i==position){newRows.push(row);}
if(this.rows[i].id!=row.id){newRows.push(this.rows[i]);}}
this.rows=newRows;if(this.visualMoveRows){if(afterId){$('#'+this.type+'_row_'+afterId).after($('#'+this.type+'_row_'+row.id));}else{$('#'+this.type+'TabTable').prepend($('#'+this.type+'_row_'+row.id))}}}
this.sort=function(field){if(this.sortingField!=field){this.sortingAsc=typeof(this.sortingDefaultDesc[field])=='undefined'||!this.sortingDefaultDesc[field];}else{this.sortingAsc=!this.sortingAsc;}
this.sortingField=field;$('#'+this.type+'-auctions-table .tab-list-header .sorting').remove();var sorting='<span class="sorting">'+(this.sortingAsc?'↑':'↓')+'</span>';$('#'+this.type+'-auctions-table .tab-list-header .'+field).append(sorting);this.loadedRows=0;this.newFilter=true;this.load(this.preloadRowsCount);}
this.updateBlockHeight=function(){var scrollContent=$('#'+this.type+'-auctions-table .scrollContent');if(this.loadedRows>=this.visibleRowsCount||this.loadedRows*this.getRowHeight()+$('#'+this.type+'TabTable .auction_block:visible').height()>=this.visibleRowsCount*this.getRowHeight()){scrollContent.css('height',this.visibleRowsCount*this.getRowHeight()+'px').css('overflow-x','hidden').css('overflow-y','auto');}else{scrollContent.css('height',null).css('overflow-x','visible').css('overflow-y','visible');}}
this.showUpdating=function(){if(this.updatingDarkening){this.updatingStartTime=new Date();$('#'+this.type+'-auctions-table').before('<div id="updating-tab-'+this.type+'" class="tabUpdating"><div class="background"><!-- --></div><div <div class="text">Updating...</div></div>');$('#updating-tab-'+this.type).show();}}
this.hideUpdating=function(){this.removeDeffered();if(this.updatingDarkening){var delta=new Date()-this.updatingStartTime;if(delta<800){setTimeout('app.tabs.'+this.type+'.hideUpdating()',800-delta);return;}
$('#updating-tab-'+this.type).remove();}}
this.setFilter=function(value){$('#'+this.type+'-filter').val(value).css('font-style','normal').css('color','black');this.filter(value);}
this.open=function(id,name){showTab(this.type,'list');$('#'+this.type+'-filter').val(name).css('font-style','normal').css('color','black');this.loadingParams.id=id;this.loadedRows=0;this.newFilter=true;this.load(1);}
this.getBlockPrefix=function(){return'auction_block_';}}
function LiveTab(){var tab=new Tab();tab.type='live';tab.sortingField='end_time';tab.sortingAsc=true;tab.sortingDefaultDesc={'bin_price':true,'bidoprice_sort':true}
tab.updatingDarkening=true;tab.sendExistRowsIds=true;tab.addToLiveAuctions=function(id,auctionInfo,auctionBids){var auc=new ShortAuction();auc.init(auctionInfo);var bids=eval(auctionBids);var fields=["id","amount","is_proxy","retracted","guarantee","absolute","user","hold","buy_it_now"];for(var i in bids){for(var field in fields){bids[i][fields[field]]=bids[i][fields[field]]?parseInt(bids[i][fields[field]]):0;}}
auc.addBids(bids);auc.update();app.live_auctions[id]=auc;startCountdown('timer_'+id,auctionInfo['timer'],null,6);startCountdown('block_timer_'+id,auctionInfo['timer']);startCountdown('block_timer_place_bid_'+id,auctionInfo['timer']);if(auc.status=='paused'){pauseCountdown('timer_'+id,true);pauseCountdown('block_timer_'+id,true);pauseCountdown('block_timer_place_bid_'+id,true);}}
return tab;}
Tab.removeDefferedFromAllTabs=function(){if(app.tabs){for(var i in app.tabs){app.tabs[i].removeDeffered(true);}}}
Tab.goTo=function(id,name){ajax.sendRequest('ajax.GetAuctionStatus',function(response){if(response.status=='OK'){if(response.auctionStatus=='closed'){app.tabs.past.open(response.id,response.name);return;}
if(response.auctionStatus=='not started'){app.tabs.upcoming.open(response.id,response.name);return;}
app.tabs.live.open(id,name);}},{'id':id,'name':name});}
function UpcomingTab(){var tab=new Tab();tab.type='upcoming';tab.sortingField='start_time';tab.sortingAsc=true;tab.sortingDefaultDesc={'bin_price':true,'bidoprice_sort':true}
tab.sendExistRowsIds=true;tab.addToUpcomingAuctions=function(id,auctionInfo){var auc=new ShortAuction();auc.init(auctionInfo);auc.nextBid=auc.getNextBid();app.upcoming_auctions[id]=auc;startCountdown('block_timer_'+id,auctionInfo['timer']);startCountdown('block_timer_place_bid_'+id,auctionInfo['timer']);}
return tab;}
function PastTab(){var tab=new Tab();tab.type='past';tab.sortingField='end_time';tab.sortingAsc=false;tab.sendExistRowsIds=true;return tab;}
function SubmittedTab(){var tab=new Tab();tab.type='submitted';tab.sortingField='days_sorting';tab.sortingAsc=false;tab.sortingDefaultDesc={'bin_price':true,'votes_count':true,'price':true}
tab.visualMoveRows=false;tab.updateVotesCount=function(id,value,info){$('#submitted_row_'+id+' .votes_count div').text(value);if(value==needDomainVotesCount){this.removeRow(id,false,true);}else{this.updateRow(id,'votes_count',value,info);}}
tab.getBlockPrefix=function(){return'domain_block_';}
tab.__clear=tab.clear;tab.clear=function(){$('#amount-votes-window').appendTo('body');tab.__clear();}
tab.goTo=function(id,name){ajax.sendRequest('ajax.GetBidoPriceRowStatus',function(response){if(response.status=='OK'){if(response.rowStatus=='auction_created'){Tab.goTo(response.auction_id,response.auction_name);return;}
if(response.rowStatus=='auction_upcoming'){document.location='/UpcomingAuction?item='+response.id;return;}
app.tabs.submitted.open(response.id,response.name);}},{'id':id,'name':name});}
return tab;}

(function(jQuery){jQuery.fn.__bind__=jQuery.fn.bind;jQuery.fn.__unbind__=jQuery.fn.unbind;jQuery.fn.__find__=jQuery.fn.find;var hotkeys={version:'0.7.9',override:/keypress|keydown|keyup/g,triggersMap:{},specialKeys:{27:'esc',9:'tab',32:'space',13:'return',8:'backspace',145:'scroll',20:'capslock',144:'numlock',19:'pause',45:'insert',36:'home',46:'del',35:'end',33:'pageup',34:'pagedown',37:'left',38:'up',39:'right',40:'down',109:'-',112:'f1',113:'f2',114:'f3',115:'f4',116:'f5',117:'f6',118:'f7',119:'f8',120:'f9',121:'f10',122:'f11',123:'f12',191:'/'},shiftNums:{"`":"~","1":"!","2":"@","3":"#","4":"$","5":"%","6":"^","7":"&","8":"*","9":"(","0":")","-":"_","=":"+",";":":","'":"\"",",":"<",".":">","/":"?","\\":"|"},newTrigger:function(type,combi,callback){var result={};result[type]={};result[type][combi]={cb:callback,disableInInput:false};return result;}};hotkeys.specialKeys=jQuery.extend(hotkeys.specialKeys,{96:'0',97:'1',98:'2',99:'3',100:'4',101:'5',102:'6',103:'7',104:'8',105:'9',106:'*',107:'+',109:'-',110:'.',111:'/'});jQuery.fn.find=function(selector){this.query=selector;return jQuery.fn.__find__.apply(this,arguments);};jQuery.fn.unbind=function(type,combi,fn){if(jQuery.isFunction(combi)){fn=combi;combi=null;}
if(combi&&typeof combi==='string'){var selectorId=((this.prevObject&&this.prevObject.query)||(this[0].id&&this[0].id)||this[0]).toString();var hkTypes=type.split(' ');for(var x=0;x<hkTypes.length;x++){delete hotkeys.triggersMap[selectorId][hkTypes[x]][combi];}}
return this.__unbind__(type,fn);};jQuery.fn.bind=function(type,data,fn){var handle=type.match(hotkeys.override);if(jQuery.isFunction(data)||!handle){return this.__bind__(type,data,fn);}
else{var result=null,pass2jq=jQuery.trim(type.replace(hotkeys.override,''));if(pass2jq){result=this.__bind__(pass2jq,data,fn);}
if(typeof data==="string"){data={'combi':data};}
if(data.combi){for(var x=0;x<handle.length;x++){var eventType=handle[x];var combi=data.combi.toLowerCase(),trigger=hotkeys.newTrigger(eventType,combi,fn),selectorId=((this.prevObject&&this.prevObject.query)||(this[0].id&&this[0].id)||this[0]).toString();trigger[eventType][combi].disableInInput=data.disableInInput;if(!hotkeys.triggersMap[selectorId]){hotkeys.triggersMap[selectorId]=trigger;}
else if(!hotkeys.triggersMap[selectorId][eventType]){hotkeys.triggersMap[selectorId][eventType]=trigger[eventType];}
var mapPoint=hotkeys.triggersMap[selectorId][eventType][combi];if(!mapPoint){hotkeys.triggersMap[selectorId][eventType][combi]=[trigger[eventType][combi]];}
else if(mapPoint.constructor!==Array){hotkeys.triggersMap[selectorId][eventType][combi]=[mapPoint];}
else{hotkeys.triggersMap[selectorId][eventType][combi][mapPoint.length]=trigger[eventType][combi];}
this.each(function(){var jqElem=jQuery(this);if(jqElem.attr('hkId')&&jqElem.attr('hkId')!==selectorId){selectorId=jqElem.attr('hkId')+";"+selectorId;}
jqElem.attr('hkId',selectorId);});result=this.__bind__(handle.join(' '),data,hotkeys.handler)}}
return result;}};hotkeys.findElement=function(elem){if(!jQuery(elem).attr('hkId')){if(jQuery.browser.opera||jQuery.browser.safari){while(!jQuery(elem).attr('hkId')&&elem.parentNode){elem=elem.parentNode;}}}
return elem;};hotkeys.handler=function(event){var target=hotkeys.findElement(event.currentTarget),jTarget=jQuery(target),ids=jTarget.attr('hkId');if(ids){ids=ids.split(';');var code=event.which,type=event.type,special=hotkeys.specialKeys[code],character=!special&&String.fromCharCode(code).toLowerCase(),shift=event.shiftKey,ctrl=event.ctrlKey,alt=event.altKey||event.originalEvent.altKey,mapPoint=null;for(var x=0;x<ids.length;x++){if(hotkeys.triggersMap[ids[x]][type]){mapPoint=hotkeys.triggersMap[ids[x]][type];break;}}
if(mapPoint){var trigger;if(!shift&&!ctrl&&!alt){trigger=mapPoint[special]||(character&&mapPoint[character]);}
else{var modif='';if(alt)modif+='alt+';if(ctrl)modif+='ctrl+';if(shift)modif+='shift+';trigger=mapPoint[modif+special];if(!trigger){if(character){trigger=mapPoint[modif+character]||mapPoint[modif+hotkeys.shiftNums[character]]||(modif==='shift+'&&mapPoint[hotkeys.shiftNums[character]]);}}}
if(trigger){var result=false;for(var x=0;x<trigger.length;x++){if(trigger[x].disableInInput){var elem=jQuery(event.target);if(jTarget.is("input")||jTarget.is("textarea")||jTarget.is("select")||elem.is("input")||elem.is("textarea")||elem.is("select")){return true;}}
result=result||trigger[x].cb.apply(this,[event]);}
return result;}}}};window.hotkeys=hotkeys;return jQuery;})(jQuery);
