
var total = 0;
var AjaxCLM=function(handler) {
   var xmlHttp;
   var url = "/2009/get_random_pictures";
   try {
      xmlHttp=new XMLHttpRequest();
   } catch(e) {
      try{
         xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      } catch(e) {
         try {
            xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
         } catch(e) {
            alert("Your browser does not support AJAX!");
            return false;
         }
      }
   }
   xmlHttp.onreadystatechange = function(){
      if(xmlHttp.readyState==4){
         handler(xmlHttp);
      }
   }
   xmlHttp.open("GET",url,true);
   xmlHttp.send(null);
};

function drop_div(id) {
   if (id != "slide0") {
      var el = document.getElementById(id);
      var padre = el.parentNode;
      padre.removeChild(el);
   }
}

function show_slide() {
   $("slide"+(total+1)).appear();
   var slide_name = "slide"+total;
   //alert(slide_name);
   var func = "drop_div(\""+slide_name+"\");";
   setTimeout(func, 3000);
   total++;
}

function load_slideshow() {
   var handler = function(transport) {
      var pictures=transport.responseXML.getElementsByTagName('pict');
      for(var i=0;i<pictures.length;i++) {
         var pict_path=pictures[i].getAttribute('path');
         var id=pictures[i].getAttribute('id');
         var img = document.getElementById("pic_"+(total+1)+"_"+i);
         img.src = pict_path;
         var map = document.getElementById("map"+i);
         map.href = "/2009/galeria/motion/"+id;
      }
      if (total == 0) {
         setTimeout("show_slide()",3000);
      } else {
         setTimeout("show_slide()",10000);
      }
   }
   var container = document.getElementById("slideshow");
   var new_slide = document.createElement("div");
   new_slide.style.display = "none";
   new_slide.style.height = "1%";
   new_slide.id = "slide"+(total+1);
   var img1 = document.createElement("img");
   var img2 = document.createElement("img");
   var img3 = document.createElement("img");
   var img4 = document.createElement("img");
   var img5 = document.createElement("img");
   var img6 = document.createElement("img");
   var img7 = document.createElement("img");
   var imgt = document.createElement("img");
   img1.id = "pic_"+(total+1)+"_0";
   img2.id = "pic_"+(total+1)+"_1";
   img3.id = "pic_"+(total+1)+"_2";
   img4.id = "pic_"+(total+1)+"_3";
   img5.id = "pic_"+(total+1)+"_4";
   img6.id = "pic_"+(total+1)+"_5";
   img7.id = "pic_"+(total+1)+"_6";
   imgt.id = "pic_"+(total+1)+"_t";
   img1.style.border = "none"; img1.style.position = "absolute"; img1.style.top = "70px"; img1.style.left = "0px"; img1.style.height ="226px";img1.style.width="256px";
   img2.style.border = "none"; img2.style.position = "absolute"; img2.style.top = "10px"; img2.style.left = "140px"; img2.style.height = "212px"; img2.style.width="248px";
   img3.style.border = "none"; img3.style.position = "absolute"; img3.style.top = "0px"; img3.style.left = "330px"; img3.style.height = "212px"; img3.style.width="248px";
   img4.style.border = "none"; img4.style.position = "absolute"; img4.style.top = "0px"; img4.style.left = "530px"; img4.style.height = "197px"; img4.style.width="238px";
   img5.style.border = "none"; img5.style.position = "absolute"; img5.style.top = "70px"; img5.style.left = "620px"; img5.style.height = "226px"; img5.style.width="256px";
   img6.style.border = "none"; img6.style.position = "absolute"; img6.style.top = "70px"; img6.style.left = "190px"; img6.style.height = "212px"; img6.style.width="248px";
   img7.style.border = "none"; img7.style.position = "absolute"; img7.style.top = "70px"; img7.style.left = "440px"; img7.style.height = "212px"; img7.style.width="248px";
   imgt.style.border = "none"; imgt.style.position = "absolute"; imgt.style.top = "0px"; imgt.style.left = "0px"; imgt.style.height = "300px"; imgt.style.width="873px";
   imgt.src = "/2009/content/images/transparent.gif";
   imgt.useMap="#Map";
   container.appendChild(new_slide);
   new_slide.appendChild(img1);
   new_slide.appendChild(img2);
   new_slide.appendChild(img3);
   new_slide.appendChild(img4);
   new_slide.appendChild(img5);
   new_slide.appendChild(img6);
   new_slide.appendChild(img7);
   new_slide.appendChild(imgt);
   AjaxCLM(handler);
}

function refresh_slideshow() {
   load_slideshow();
   setTimeout("refresh_slideshow();", 10000);
}

refresh_slideshow();