//MiniSlides by Alessandro Fulciniti - http://pro.html.it function StartShow(id,bk,fw){ if(document.getElementById && document.createElement){ document.write("<style type='text/css' media='screen'>div#"+id+",*.hide{position:absolute;top:-9999px}</style>"); document.write("<style type='text/css' media='print'>div#slidenav{display:none}</style>"); BuildShow(id,bk,fw); } } var index,current=1,nslides=0; //variabili globali function BuildShow(id,backButton,fwdButton){ var mainDiv=document.getElementById(id); if(mainDiv==null){ setTimeout("BuildShow('"+id+"','"+backButton+"','"+fwdButton+"')",100); return; } var v=mainDiv.getElementsByTagName("div"); //conta e nasconde le slides for(var i=0;i<v.length;i++){ if(v[i].parentNode==mainDiv){ v[i].id="p"+(++nslides); v[i].className="hide"; } } var slideNav=document.createElement("div"); //crea la navigazione slideNav.id="slidenav"; var x=CreateButton(backButton,"slide precedente"); x.id="prev"; x.onclick=function(){ Show(Prev())}; var y=CreateButton(fwdButton,"slide successiva"); y.onclick=function(){ Show(Next())}; y.id="next"; index=document.createElement("div"); index.appendChild(document.createTextNode("1/"+nslides)); index.id="index"; slideNav.appendChild(x); slideNav.appendChild(y); slideNav.appendChild(index); mainDiv.parentNode.insertBefore(slideNav,mainDiv); document.onkeypress=CaptureKey; //aggiunge la navigazione da tastiera Show(current); //mostra la prima diapositiva mainDiv.style.position="static"; } function CreateButton(img,txt){ var a=document.createElement("a"); a.href="#"; var b=document.createElement("img"); b.src=img; b.title=txt; b.alt=txt; a.appendChild(b); return(a); } function Show(wich){ document.getElementById("p"+current).className="hide"; document.getElementById("p"+wich).className=""; current=wich; index.removeChild(index.firstChild); index.appendChild(document.createTextNode(current+"/"+nslides)); } function Next(){ if(current<nslides) return(current+1); return(1); } function Prev(){ if(current>1) return(current-1); return(nslides); } function CaptureKey(e){ var key; if (!e) var e = window.event; if (e.keyCode) key=e.keyCode; else if (e.which) key=e.which; if(key==37) Show(Prev()); //freccia indietro if(key==39) Show(Next()); //freccia avanti }