var index;var data;var startl;window.addEvent("domready",function(){var A=new Request.JSON({url:"/dbquery.php",method:"get",onComplete:function(B){data=B;show_random()}});A.get({w:"t"})});function show_random(){index=Math.floor(Math.random()*data.length);load_image()}function load_image(){d=new Date();startl=d.getTime();preloadImage(data[index].image,show_image)}function preloadImage(A,B){var C=new Image();if($("together_image")){$("together_image").fade(0)}if($("togetherdescr")){$("togetherdescr").fade(0)}C.onload=B;C.src=www_root+"images/together/"+A+".jpg"}function show_image(){image=new Element("img",{src:www_root+"images/together/"+data[index].image+".jpg",alt:"&copy; Perugi Artecontemporanea",opacity:0,title:data[index].descr});descr=new Element("span");descr.appendText(data[index].descr);if($("togetherdescr")){descr.replaces($("togetherdescr"))}else{descr.inject($("together_dida_div"))}descr.set("id","togetherdescr");if($("together_image")){image.replaces($("together_image"))}else{image.inject($("together_next"))}image.set("id","together_image");now=new Date();now=now.getTime();if((now-startl)>=msecleast){image.fade(1)}else{setTimeout(function(){image.fade(1)},msecleast-(now-startl))}}function next(){new_idx=index+1;index=(new_idx<data.length)?new_idx:0;load_image()};