var $j=jQuery.noConflict(),url="/stabilimento.html",divId="#stabilimenti",loadingImg="/images/new/clessidra_148x111.gif",template='<li id="box_" onclick="location.href=\'#\'" style="cursor: pointer" title="nome stabilimento"><h3><a href="#">-Stabilimento-</a></h3><img src="'+loadingImg+'" alt="-title-" style="width:140px; height:111px;"><div><div class="dove">-localit\u00e0-</div><div class="info"><span>posti disponibili</span>n.d.</div></div></li>',templateSx='<li id="box_" onclick="location.href=\'#\'" style="margin-left:-140px; cursor: pointer" title="nome stabilimento"><h3><a href="#">-Stabilimento-</a></h3><img src="'+ loadingImg+'" alt="-title-" style="width:140px; height:111px;"><div><div class="dove">-localit\u00e0-</div><div class="info"><span>posti disponibili</span>n.d.</div></div></li>',firstBeach,lastBeach,liId=1,newLi=null,lbId=0,maxCharInTitle=19; $j(document).ready(function(){$j("#form_pattern").submit(function(){checkSubmit()});ul=$j("#stabilimenti ul");$j("#stabilimenti").attr("style","overflow:hidden; width:"+(ul.outerWidth()-1)+"px;");ul.attr("style","width:"+(ul.outerWidth()+$j("#stabilimenti li").outerWidth())+"px; height:257px;");firstBeach=getFirstId();$j("#prevBtn").hide();$j("#nextBtn").bind("click",slideBtnEvent);$j("#prevBtn").bind("click",slideBtnEvent);$j.getJSON("/lastbeach.html",function(a){lbId=a.id})}); function slideBtnEvent(a){this.id=="prevBtn"?(id=getFirstId(),getFirstId()!=firstBeach?(lastLi=$j(divId+" li:last"),firstLi=$j(divId+" li:first"),firstLi.before(templateSx),firstLi=$j(divId+" li:first"),firstLi.animate({marginLeft:0},function(){lastLi.remove();newLi=$j(divId+" li:first");direction="prev";getLocation(id,direction,liId)})):($j("#prevBtn").hide(),$j("#nextBtn").show()),direction="prev"):($j("#prevBtn").show(),id=getLastId(),firstLi=$j(divId+" li:first"),$j(divId+" li:last").after(template), firstLi.animate({marginLeft:-firstLi.outerWidth()},function(){firstLi.remove();newLi=$j(divId+" li:last");direction="next";getLocation(id,direction,liId)}));disableBtns(!0);a.preventDefault()}function getFirstId(){var a=$j(divId+" li:first");return $j(a).attr("id").substr(4)}function getLastId(){var a=$j(divId+" li:last");return $j(a).attr("id").substr(4)}function getLocation(a,b,c){$j.getJSON("/"+a+"/"+b+"/"+c+url,function(a){disableBtns(!1);loadLocation(a)})} function loadLocation(a){a.success=="OK"?(newBeach=template,newBeach=newBeach.replace("-Stabilimento-",trunc(a.title)),newBeach=newBeach.replace("nome stabilimento",a.title),newBeach=newBeach.replace(loadingImg,a.image),newBeach=newBeach.replace("-localit\u00e0-",a.location),newBeach=newBeach.replace("n.d.",a.totalPlaces),newBeach=newBeach.replace("box_","box_"+a.id),newBeach=newBeach.replace("location.href='#'","location.href='"+a.onclickRef+"'"),newBeach=newBeach.replace("-title-","immagine di "+ a.title),$j(newLi).replaceWith(newBeach),a.id==firstBeach&&$j("#prevBtn").hide(),a.id==lbId&&$j("#nextBtn").hide()):a.success=="EMPTY"&&($j("#nextBtn").hide(),newBeach=template,newBeach=newBeach.replace("-Stabilimento-","Servizio non disponibile"),newBeach=newBeach.replace(loadingImg,a.image),newBeach=newBeach.replace("-localit\u00e0-","&nbsp;"),newBeach=newBeach.replace("n.d.","&nbsp;"),newBeach=newBeach.replace("box_","box_end"),$j(newLi).replaceWith(newBeach))} function disableBtns(a){a?($j("#prevBtn").hide(),$j("#nextBtn").hide()):($j("#prevBtn").show(),$j("#nextBtn").show())}function trunc(a){var b=["",""];if(a.length>maxCharInTitle){var a=a.split(" "),b=0,c="",d=a.length;do c+=a[b],b<d-1&&(c+=" ");while(++b<d&&(c+a[b]).length<maxCharInTitle);b=c+"..."}else b=a;return b}function checkSubmit(){intext=$j("#form_pattern input:[type=text]");intext.val()==intext.attr("title")&&intext.val("italia")};
