var margin=5,border=3,duration=1,pause=500,urlbase="/",sUrl="receptslide_json_ajax.php",lastAdded=0,ajax_source=1,optimalWidth=0,curWidth=0,tobeloaded=0;function scrollIt(b,d){var a={scroll:{to:[b,0]}},c=new YAHOO.util.Scroll(d,a,duration);c.animate();return c}function setFitWidth(e){var f=document.getElementById(e),b=f.getElementsByTagName("img").length,d=f.getElementsByTagName("a"),a=0,c;for(c=0;c<b;c++){a+=d[c].offsetWidth+margin}f.style.width=a+"px";f.parentNode.scrollLeft=0}function setFitWidthAjax2(b){var f=document.getElementById("belso"),e,d,c,a=0;tobeloaded=b.length;for(c=0;c<b.length;c++,lastAdded++){d=document.createElement("a");d.href=urlbase+"index.php?page=recept&id="+b[c].name;e=new Image();e.onload=function(){checkAllLoaded()};e.src=urlbase+"recept_img/slide_"+b[c].kep_nev;e.tip=b[c].title;e.onmousemove=function(g){mylogin.showMsg(g||event,this.tip)};e.onmouseout=function(){buborek.hide()};d.appendChild(e);f.appendChild(d);a+=parseInt(b[c].width)+margin+2*border}f.style.width=a+"px";f.parentNode.scrollLeft=0;curWidth=optimalWidth=a}function checkAllLoaded(){--tobeloaded;if(tobeloaded<=0){doCarousel()}}function setFitWidthAjax(b){var c=document.getElementById(b),a;if(c==null){return}a=c.parentNode.offsetWidth;sendRequest(0,a,1,function(d){setFitWidthAjax2(d)})}function circulate(e,b){var a=document.getElementById(e),d=a.firstChild,c;a.removeChild(d);if(a.appendChild(d)==null){alert("Hiba az elem áthelyezésénél!")}c=d.offsetWidth;a.parentNode.scrollLeft=a.parentNode.scrollLeft-c-b}function circulateAjax(e,c){var a=document.getElementById(e),d=a.firstChild,b=d.firstChild.width;sendRequest(lastAdded,b,0,function(f){circulateAjax2(f)})}function circulateAjax2(b){var e=document.getElementById("belso"),g=e.firstChild,d,c,f,a;curWidth-=(g.offsetWidth+margin);e.removeChild(g);a=0;for(d=0;(d<b.length)&&(b[d].name!="-1")&&(curWidth<optimalWidth);d++,lastAdded++){c=document.createElement("a");c.href=urlbase+"index.php?page=recept&id="+b[d].name;f=document.createElement("img");f.src=urlbase+"recept_img/slide_"+b[d].kep_nev;f.tip=b[d].title;f.onmousemove=function(h){mylogin.showMsg(h||event,this.tip)};f.onmouseout=function(){buborek.hide()};c.appendChild(f);e.appendChild(c);a+=parseInt(b[d].width)+margin+2*border;curWidth+=parseInt(b[d].width)+margin+2*border}a+=b.length*margin;e.style.width=(e.offsetWidth+a)+"px";e.parentNode.scrollLeft=0;if(b[b.length-1].name=="-1"){lastAdded=0}setTimeout("doCarousel()",pause)}function doCarousel(){var b=document.getElementById("belso").firstChild.offsetWidth,a=scrollIt(b+margin,"kepes_ajanlo");a.onComplete.subscribe(doCarousel2)}function doCarousel2(){if(ajax_source){circulateAjax("belso",margin)}else{circulate("belso",margin)}}function sendRequest(g,d,f,c){var b="first="+g+"&pixelnum="+d+"&init="+f,a=function(k){if(k.responseText!==undefined){var j=[];try{j=YAHOO.lang.JSON.parse(k.responseText)}catch(i){alert("JSON Parse failed!\n"+i+"\nresponse: "+k.responseText);return}c(j)}else{alert("Hibás választ kaptam a szervertől!")}},e=function(j){var i="Hiba a szerverrel való kommunikációnál:\n";if(j.responseText!==undefined){i+="Transaction id: "+j.tId+"\n";i+="HTTP status: "+j.status+"\n";i+="<li>Status code message: "+j.statusText}},h={success:a,failure:e};YAHOO.util.Connect.asyncRequest("POST",urlbase+sUrl,h,b)};