var d3mls_search={buttonClass:"button",divId:"d3mls_search",init:function(divId,buttonClass)
{if(divId!='')
this.divId=divId;if(buttonClass!='')
this.buttonClass=buttonClass;this.setupSearchForm();},setupSearchForm:function()
{$("#"+this.divId+" a."+this.buttonClass).bind("click",function(e){e.preventDefault();$("#"+d3mls_search.divId+" input[type=text]").each(function(){if($(this).val()==$(this).attr("default"))
$(this).val("");});$("form[name=search_form]").append("<input type='text' class='hidden' name='scrolltops' value='"+d3mls_search.selectScrollTops.join(",")+"' />");$("form[name=search_form]").submit();});this.setupLoadingIcon();this.setupButtonsToActivateLoadingIcon();this.setupLocationsSelectInputs();},setupSearchTabs:function()
{$("#"+this.divId).tabs();},getSuggest:function(input)
{$input=$(input);if(($input.val().length>2&&parseInt($input.val()))||$input.val().length>5){$.post('/app/modules/d3mls/ninja_code/search_simple.php',{'loc':$input.val()},function(data){if(data.length>1)
$input.next().html(data).show();else
$input.next().hide();});}},locationSuggestFill:function(value,suggestResult)
{$(suggestResult).parent().prev().val(value);$("#suggestBox").hide();},$loadingBlanket:null,$loadingIcon:null,activateLoadingIcon:function()
{this.$blanket.show();this.$loadingIcon.show();},setupLoadingIcon:function()
{this.$blanket=$("<div class='loadingBlanket'></div>").css({height:$(document).height()}).appendTo(document.body);this.$loadingIcon=$("<img class='loadingIcon' src='/images/ajax-loader.gif' />").css({"top":($(window).height()/2)-(300/2),"left":($(window).width()/2)-(400/2)}).appendTo(document.body);},setupButtonsToActivateLoadingIcon:function()
{$("#"+this.divId+" ."+this.buttonClass).each(function(){$(this).bind("click",function(){d3mls_search.activateLoadingIcon();});});},selectedLocations:[[],[],[],[],[]],selectScrollTops:[0,0,0,0,0],setupLocationsSelectInputs:function()
{$("#"+this.divId+" > #generalSearchDiv >#locationsSection > #locationsSelectsContainer div.locations input[type=checkbox]").each(function()
{$(this).bind("click",function(event){d3mls_search.selectInputs($(this),parseInt($(this).attr("index")),event);});});},selectInputs:function($input,index,$event)
{this._dim($(".locationsSelects:eq("+(index)+")"),true);this.selectScrollTops[index]=$input.parents(".locationsSelects").scrollTop();var locations=$input.val().split("|");if($input.is(":checked")&&$.inArray(locations[index],this.selectedLocations[index])<0)
this.selectedLocations[index].push(locations[index]);else
this.selectedLocations[index]=this._removeElements([locations[index]],this.selectedLocations[index]);if(index<4)
{$.post("/app/modules/d3mls/xml/getLocations.php",{'locations':this.selectedLocations,'index':index},function(data,status)
{$("#locationsSelectsContainer").replaceWith(data);$(".locationsSelects").each(function(i){var scrollTopValue=d3mls_search.selectScrollTops[i+1];$(this).scrollTop(scrollTopValue);});});}},updateScrolltops:function(scrolltopsAr)
{this.selectScrollTops=scrolltopsAr;$(".locationsSelects").each(function(i){var scrollTopValue=d3mls_search.selectScrollTops[i+1];$(this).scrollTop(scrollTopValue);});},_dim:function($div,dim)
{$div.css({"color":"black","-ms-filter":"progid:DXImageTransform.Microsoft.Alpha(Opacity=40)","filter":"alpha(opacity="+((dim)?40:100)+")","-moz-opacity":((dim)?.40:1),"opacity":((dim)?.40:1)});},_removeElements:function(theseElements,fromThisArray)
{$.unique(theseElements);$.unique(fromThisArray);for(var i=0;i<theseElements.length;i++)
fromThisArray=$.grep(fromThisArray,function(value){return value!=theseElements[i];});return fromThisArray;},locationsAccordion:function(divId,openFirst)
{$('#'+divId+' .locationsSelectSection .locationsHeader').click(function(){var $locationsHeaderIcon=$(this).find("div.locationsHeaderIcon");if($locationsHeaderIcon.hasClass('locationsHeaderIconClicked'))
$locationsHeaderIcon.removeClass("locationsHeaderIconClicked");else
$locationsHeaderIcon.addClass("locationsHeaderIconClicked");$(this).next().toggle('slow');}).next().hide();if($('#'+divId+' > .locationsSelectSection').children().size()<4||openFirst)
{$('#'+divId).find(">:first-child .locationsHeader .locationsHeaderIcon").addClass("locationsHeaderIconClicked:eq(0)").end().find(".locationsContent:eq(0)").show();}
else
{$('#'+divId+' .locationsSelectSection .locationsContent input:checked').each(function(){$(this).parent().parent().parent().prev().find(".locationsHeaderIcon").addClass("locationsHeaderIconClicked").end().next().show();});}},accordion:function(divId)
{$('#'+divId+' .accordionPanel').click(function(){$(this).next().toggle('slow');}).next().hide();}};
