(function($){$.fn.extend({options:{},clientminiads:{},payingClientsCount:0,resultLimitReached:false,showPayments:false,loadBatchUrl:'/listing/loadSearchResultBatch',loadClientListingsUrls:'/listing/loadSearchedClientListings',loadBatchlink:false,itemsPerBatch:20,configure:function(config){$.fn.loadBatchlink=$('#moreSearchResult')[0];$.fn.options=config['searchOptions'];$.fn.payingClientsCount=config['payingClientsCount'];$.fn.clientminiads=config['clientminiads'];$.fn.loadBatchUrl=config['loadBatchUrl'];$.fn.loadClientListingsUrls=config['loadClientListingUrl'];$.fn.showPayments=config['showPayments'];$.fn.itemsPerBatch=(config['itemsPerBatch'])?config['itemsPerBatch']:20;var batchAnchors=$('a.resultBatchAnchor');for(var i=0;i<batchAnchors.length;i++){$(batchAnchors[i]).attr('name','p'+(i+1));}},loadSearchResults:function(targetBatch){if(targetBatch>0){var resultBatches=$('div.resultBatch');if(targetBatch>resultBatches.length){resultBatches.show();var el;var urlParams=[];for(el in $.fn.options){urlParams.push(el+'='+$.fn.options[el]);}
urlParams.push('fromBatch='+(resultBatches.length+1));urlParams.push('toBatch='+targetBatch);urlParams.push('payingClientsCount='+$.fn.payingClientsCount);urlParams.push('clientminiads='+$.fn.clientminiads);urlParams.push('showPayments='+$.fn.showPayments);$('#moreSearchResult').hide();$('#rsBatchImgLoading').show();$.ajax({type:'POST',data:urlParams.join('&'),url:$.fn.loadBatchUrl,cache:false,success:function(data,status){$('#rsBatchImgLoading').hide();$('#moreSearchResult').show();$('#listingsContainer').append(data);if($.fn.resultLimitReached){$('#resultOffset').text($('#resultTotal').text());$('#moreSearchResult').hide();}
else{$('#resultOffset').text((targetBatch-1)*$.fn.itemsPerBatch+$.fn.payingClientsCount);}
var batchAnchors=$('a.resultBatchAnchor');for(var i=0;i<batchAnchors.length;i++){$(batchAnchors[i]).attr('name','p'+(i+1));}
tb_init('a.thickbox');window.location.href='#p'+targetBatch;}});}
else{resultBatches.hide();for(var i=0;i<targetBatch;i++){if(resultBatches[i])$(resultBatches[i]).show();else break;}
$('#moreSearchResult').show();if(targetBatch>=resultBatches.length&&$.fn.resultLimitReached){$('#resultOffset').text($('#resultTotal').text());$('#moreSearchResult').hide();}
else{$('#resultOffset').text((targetBatch-1)*$.fn.itemsPerBatch+$.fn.payingClientsCount);}
if(targetBatch>1){window.location.href='#p'+targetBatch;}}}
if($.fn.loadBatchlink){$.fn.loadBatchlink.href='#p'+(targetBatch*1+1);}},loadClientListings:function(clientID){if($('li.ajaxlisting_'+clientID).length>0){$('li.ajaxlisting_'+clientID).show('slow');$('#clientUnLoadLink_'+clientID).show();$('#clientLoadLink_'+clientID).hide();return;}
var urlParams=[];for(el in $.fn.options){urlParams.push(el+'='+$.fn.options[el]);}
urlParams.push('clientID='+clientID);$('#clientImgLoading_'+clientID).show();$.ajax({type:'POST',data:urlParams.join('&'),url:$.fn.loadClientListingsUrls,cache:false,success:function(data,status){$('#clientListings_'+clientID).append(data);$('#clientImgLoading_'+clientID).hide();$('#clientLoadLink_'+clientID).hide();$('#clientUnLoadLink_'+clientID).show();}});},unloadClientListings:function(clientID){$('li.ajaxlisting_'+clientID).hide('slow');$('#clientUnLoadLink_'+clientID).hide();$('#clientLoadLink_'+clientID).show();},toggleListingDesc:function(listingID){if($('#listingDesc_'+listingID).is(':hidden')){$('#toggleControl_'+listingID).addClass('revealerHide');$('#listingDesc_'+listingID).show('slow');}
else{$('#toggleControl_'+listingID).removeClass('revealerHide');$('#listingDesc_'+listingID).hide('slow');}},listingTitleClick:function(listingID){if($('#listingDesc_'+listingID).is(':hidden')){$.fn.toggleListingDesc(listingID);return false;}
else{return true;}}});$(document).ready(function(){$(this).configure(searchResultConfig);});})(jQuery);
