$(document).ready(function(){$("#searchFormMiddle form").attr("autocomplete","off");$("#menu-add-shop").click(function(){$.getJSON("ajax/add",function(d){if(d.status=="ok"){ajaxOverlay(d.html,function(){var g=null;$('input[name="add-search"]').focus(function(){$(".addInputField").removeClass("addInputFieldFocus");$(this).parent().parent().parent().addClass("addInputFieldFocus");});$('input[name="add-name"]').focus(function(){$(".addInputField").removeClass("addInputFieldFocus");$(this).parent().parent().parent().addClass("addInputFieldFocus");});$('input[name="add-address"]').focus(function(){$(".addInputField").removeClass("addInputFieldFocus");$(this).parent().parent().parent().addClass("addInputFieldFocus");});$('select[name="add-type"]').focus(function(){$(".addInputField").removeClass("addInputFieldFocus");$(this).parent().parent().parent().addClass("addInputFieldFocus");});var h=new google_map("map");var f=h.create();$("#addInputButtonAddress").click(function(){var j=$('input[name="add-address"]').val();h.locationFromAddress(j,function(k){if(k){g=k;e(j);h.removeEvent("click");h.setCenter(k,16);var l=h.setMarker({position:k,icon:"images/beer.png",draggable:true});h.addEvent("dragend",function(m){g=m;var n=h.addressFromLocation(m,function(o){e(o);});},l);}else{showInfoBox(lang.locNotFound);}});return false;});h.addEvent("click",function(j){g=j;var l=h.addressFromLocation(j,function(m){e(m);});var k=h.setMarker({position:j,icon:"images/beer.png",draggable:true});h.addEvent("dragend",function(m){g=m;var n=h.addressFromLocation(m,function(o){e(o);});},k);h.removeEvent("click");});function e(j){$('input[name="add-address"]').val(j);$("#addInputButtonAddress").hide();}$("#addInputButtonSearch").click(function(){var j=$('input[name="add-search"]').val();h.locationFromAddress(j,function(k){h.setCenter(k,13);});return false;});$("#addInputs form").submit(function(){var n=false;if($('input[name="add-name"]').val()==""){$('input[name="add-name"]').addClass("err");n=true;}else{$('input[name="add-name"]').removeClass("err");}if(!g){$('input[name="add-address"]').addClass("err");n=true;}else{$('input[name="add-address"]').removeClass("err");}if(!n){var j=$('input[name="add-name"]').val();var p=$('input[name="add-address"]').val();var l=$('select[name="add-type"]').val();var k=$('input[name="add-more"]:checked').val();var o=g.lat();var m=g.lng();$.getJSON("ajax/addShop",{name:j,address:p,type:l,lat:o,lng:m},function(q){if(q.status=="ok"){if(k=="on"){showInfoBox(lang.shopAdded);g=null;$('input[name="add-name"]').val("");$('input[name="add-address"]').val("");h.clearMap();$("#addInputButtonAddress").show();h.addEvent("click",function(r){g=r;var t=h.addressFromLocation(r,function(u){e(u);});var s=h.setMarker({position:r,icon:"images/beer.png",draggable:true});h.addEvent("dragend",function(u){g=u;var v=h.addressFromLocation(u,function(w){e(w);});},s);h.removeEvent("click");});}else{closeOverlay(false);showInfoBox(lang.shopAdded);}}});}return false;});});}});return false;});setTimeout(b,1000);function b(){$.getJSON("ajax/lastNews",function(d){if(d.status=="ok"){c(d.news.header,d.news.text);}});}function c(e,d){$("#newsBox .close").click(function(){a();return false;});$("#newsBoxTitleLeft span").html(e);$("#newsBoxBody").html(d);$("#newsBox").show().animate({top:"28px"});setTimeout(a,1000*12);}function a(){$("#newsBox").fadeOut(100,function(){$(this).css("top","-110px");});}$("#footerAdmin .adminButton").click(function(){var e=false;var d=false;$("#footerAdminLogin").fadeIn("fast");$('input[name="admin-login-username"]').focus(function(){if(!e){$(this).val(null);e=true;}});$('input[name="admin-login-clear"]').focus(function(){if(!d){$("#footerAdminLogin .clear").hide();$("#footerAdminLogin .password").show().focus();d=true;}});$("#footerAdminLogin form").submit(function(){var g=$('input[name="admin-login-username"]').val();var f=$('input[name="admin-login-password"]').val();$('input[name="admin-login-username"]').removeClass("err");$('input[name="admin-login-password"]').removeClass("err");$('input[name="admin-login-clear"]').removeClass("err");if(g==""||!e){$('input[name="admin-login-username"]').addClass("err");}if(f==""||!d){$('input[name="admin-login-password"]').addClass("err");$('input[name="admin-login-clear"]').addClass("err");}if(g&&f&&e&&d){$.getJSON("ajax/login",{username:g,password:f},function(h){if(h.status=="ok"){window.location.reload();}else{$('input[name="admin-login-password"]').addClass("err");$('input[name="admin-login-username"]').addClass("err");}});}return false;});return false;});$("#catContact").click(function(){$.getJSON("ajax/contact",function(d){ajaxOverlay(d.html,function(){var e=$(".contactSelectList ul li a:first").html();$(".contactSelectText").html(e);$(".contactSelectToggle").toggle(function(){$(".contactSelectList").slideDown("fast");return false;},function(){$(".contactSelectList").slideUp("fast");return false;});$(".contactSelectList ul li a").click(function(){var f=$(this).attr("class");var g=$(this).html();$(".contactSelectText").html(g);$('input[name="contact-type"]').val(f);$(".contactSelectToggle").trigger("click");return false;});$("#contactForm form").submit(function(){$("#contactFormContent .err").hide();var g=$('input[name="contact-email"]').val();var h=$('input[name="contact-type"]').val();var f=$('textarea[name="contact-body"]').val();if(g&&h&&f){$.getJSON("ajax/sendMsg",({email:g,type:h,body:f}),function(j){if(j.status=="ok"){closeOverlay(false);showInfoBox(lang.msgSent);}else{closeOverlay(false);showInfoBox(lang.undefinedError);}});}else{$("#contactFormContent .err").fadeIn("fast");}return false;});});});return false;});$('input[name="myLocation"]').focus(function(){if($(this).val()==lang.sampleLocation){$(this).val("");}});$("#infoBoxClose").click(function(){hideInfoBox();return false;});$('input[name="myLocation"]').focus(function(){var f=$(this).attr("alt");var d=$(this).position();var e=$('<div class="toolTipLeft"><div class="toolTipLeftLeft"></div><div class="toolTipLeftMiddle">'+f+'</div><div class="toolTipLeftRight"></div></div>');$(e).appendTo("body");$(e).css("left",(d.left-195)+"px");$(e).css("top",d.top+"px");$(e).fadeIn("fast");});$('input[name="myLocation"]').blur(function(){$(".toolTipLeft").fadeOut("fast",function(){$(this).remove();});});$(".distance").click(function(){$(".distance").each(function(){$(this).removeClass("distanceSelected");});$(this).addClass("distanceSelected");return false;});$("#searchForm form").submit(function(){return false;});$("button#formSearch").click(function(){if($('input[name="myLocation"]').val()!=lang.sampleLocation&&$('input[name="myLocation"]').val()!=""){var f=$(".distanceSelected").attr("id").split("_")[1];var d=$('input[name="myLocation"]').val();if(d=="google"){window.location.href="http://www.google.com";exit;}var e=new google_map(null);e.locationFromAddress(d,function(g){if(g){var j=g.lat();var h=g.lng();$.getJSON("ajax/map",({address:d,distance:f,lat:j,lng:h}),function(k){if(k.status=="ok"){ajaxOverlay(k.html,function(){var p=new google_map("map");var m=p.create();var q=new google_directions();q.create(m);var n;switch(f){case"1":n=14;break;case"2":n=13;break;case"5":n=12;break;}p.setCenter(g,n);p.setMarker({position:g,icon:"images/my_position.png"});for(i in k.shops){var l=p.setMarker({position:p.makePoint(k.shops[i].lat,k.shops[i].lng),icon:"images/beer.png",title:k.shops[i].name});p.addEvent("click",function(r){o(r.id,true);},l,{id:k.shops[i].id});}if(typeof(admin)=="boolean"&&admin){appendAdminMap(p);}$("#mapListCountainer").tinyscrollbar();$(".listEntrySelect").click(function(){var r=$(this).parent().attr("id").split("_")[1];o(r,false);return false;});function o(t,r){p.clearMap();p.setMarker({position:g,icon:"images/my_position.png"});$.getJSON("ajax/getShop",({shop_id:t}),function(v){if(v.status=="ok"){var u=p.setMarker({position:p.makePoint(v.shop.lat,v.shop.lng),icon:"images/beer.png",title:v.shop.name});q.route(g,p.makePoint(v.shop.lat,v.shop.lng));}else{showInfoBox(lang.error0);}});$(".listEntrySelected").removeClass("listEntrySelected");$("#entry_"+t).addClass("listEntrySelected");if(r){var s=$("#entry_"+t).position();$("#mapListCountainer").tinyscrollbar_update(s.top);$("#mapListCountainer").tinyscrollbar_update("relative");}}$(".vote").hover(function(){var r=$(this).attr("id").split("-")[1];$(this).parent().children(".vote_s").removeClass("vote_s");var s=0;$(this).parent().children(".vote").each(function(){if(s<r){$(this).addClass("vote_s");}s++;});},function(){$(this).parent().children(".vote_s").removeClass("vote_s");$(this).parent().children(".vote_p").addClass("vote_s");});$(".vote").click(function(){var r=$(this);var u=$(this).parent().parent().parent().attr("id").split("_")[1];var s=$(this).attr("id").split("-")[1];$.getJSON("ajax/vote",({shop_id:u,vote:s}),function(t){if(t.status=="ok"){$(r).parent().html(t.html);}else{$(r).parent().html(t.html);}});return false;});$(".addComment").click(function(){var r=$(this).parent().parent().attr("id").split("_")[1];$("#entry_"+r).children(".listEntryComment").slideUp("fast",function(){if($(this).parent().children(".listEntryCommentEx").length==0){$.getJSON("ajax/comments",({shop_id:r}),function(s){if(s.status=="ok"){$("#entry_"+r).children(".listEntryComment").after(s.html);$("#entry_"+r).children(".listEntryCommentEx").slideDown("fast",function(){$("#mapListCountainer").tinyscrollbar_update("relative");if(typeof(admin)=="boolean"&&admin){appendAdminComment();}$(".addCommentForm form").submit(function(){var u=$(this).parent().parent().parent().attr("id").split("_")[1];var t=$(this).children(".right").children('input[name="comment_name"]').val();var v=$(this).children(".right").children('textarea[name="comment_text"]').val();$("#commentName-"+u).removeClass("emptyInputBorder");$("#commentText-"+u).removeClass("emptyInputBorder");if(t&&v){$(this).hide();$.getJSON("ajax/addComment",({shop_id:u,user:t,comment:v}),function(w){if(w.status=="ok"){$(".listEntry#entry_"+u).children().children(".commentsList").prepend(w.html);}});}else{if(!t){$("#commentName-"+u).addClass("emptyInputBorder");}if(!v){$("#commentText-"+u).addClass("emptyInputBorder");}}return false;});});}$(".hideComment").click(function(){var u=$(this);$(u).parent().slideUp("fast",function(){$(u).parent().parent().children(".listEntryComment").slideDown("fast",function(){$("#mapListCountainer").tinyscrollbar_update("relative");});});return false;});});}else{$("#entry_"+r).children(".listEntryCommentEx").slideDown("fast",function(){$("#mapListCountainer").tinyscrollbar_update("relative");});}});return false;});$(".reportMore").click(function(){$(this).parent().children("form").children("select").show();$(this).hide();$(this).parent().children(".reportFinish").show();return false;});$(".reportFinish").click(function(){var s=$(this);var r=$(this).parent().children("form").children("select").val();var u=$(this).parent().parent().attr("id").split("_")[1];$.getJSON("ajax/report",({shop_id:u,type:r}),function(t){if(t.status=="ok"){showInfoBox(lang.reportOk);$(s).parent().slideUp(100);}else{showInfoBox(lang.reportErr);$(s).parent().slideUp(100);}$("#mapListCountainer").tinyscrollbar_update("relative");});return false;});$("#mapListCopy button").click(function(){$("#mapListCopy input").focus();return false;});$("#mapListCopy input").focus(function(){$(this).select();});});}else{showInfoBox(lang.notFound);}});}else{showInfoBox(lang.notFound);}});}return false;});$("button#formFindMe").click(function(){if(navigator.geolocation){$(this).attr("disabled",true);var d=$(this).position();var e=$('<div class="findMeWait"></div>');$(e).appendTo("body");$(e).css("left",(d.left+155)+"px");$(e).css("top",(d.top+4)+"px");$(e).fadeIn("normal");navigator.geolocation.getCurrentPosition(rewriteAddress,geoErrorHandle,{timeout:9000});}else{showInfoBox(lang.geoNotSupported);}});if((array=perseURL())!=false){switch(array[0]){case"address":$('input[name="myLocation"]').val(array[1]);$("#formSearch").trigger("click");break;case"contact":$("#catContact").trigger("click");break;}}setInterval(onlineRefresh,1000*10);});function onlineRefresh(){$.getJSON("ajax/onlineRefresh",function(a){$("#headOnline span").html(a.count);});}function rewriteAddress(a){$("button#formFindMe").removeAttr("disabled");$(".findMeWait").fadeOut("normal",function(){$(this).remove();});var e=a.coords.latitude;var b=a.coords.longitude;var d=new google_map(null);var c=d.makePoint(e,b);d.addressFromLocation(c,function(f){if(f){$("#searchFormMiddle input").val(f);showInfoBox(lang.geoFinished);}else{showInfoBox(lang.geoFailed);}});}function geoErrorHandle(a){$("button#formFindMe").removeAttr("disabled");$(".findMeWait").fadeOut("normal",function(){$(this).remove();});showInfoBox(lang.geoFailed);}var infoIntervalHandler;function showInfoBox(a){if($("#infoBox").css("display")=="block"){$("#infoBox").fadeOut("normal",function(){$("#infoBoxMessage").html(a);$("#infoBox").fadeIn("normal");});}else{$("#infoBoxMessage").html(a);$("#infoBox").fadeIn("normal");}infoIntervalHandler=setInterval("hideInfoBox()",13000);}function hideInfoBox(){$("#infoBox").fadeOut("normal");clearInterval(infoIntervalHandler);}function ajaxOverlay(a,b){if($("#ajaxOverlay").length>0){closeOverlay(function(){showAjaxOverlay(a,b);});}else{showAjaxOverlay(a,b);}}function showAjaxOverlay(c,d){var a=$("body").height();var b=$('<div id="ajaxOverlay">'+c+"</div>");$(b).appendTo("body");$("#closeOverlayButton").click(function(){closeOverlay();return false;});$(b).css("height",(a-60)+"px");$(b).fadeIn("fast");$(window).resize(function(){var e=$("body").height();$(b).css("height",(e-60)+"px");$("#mapListCountainer").tinyscrollbar_update();});d();}function closeOverlay(a){$("#ajaxOverlay").fadeOut("fast",function(){$(this).remove();if(a){a();}});}function perseURL(){var b=window.location.href;if(b.search("#!")>-1){var a=b.split("#!")[1];var d;var c;if(a.search("address:")>-1){c=decodeURI(a.split("address:")[1]);d="address";return new Array(d,c);}else{if(a.search("contact")>-1){d="contact";return new Array(d);}}}return false;}
