var preloadimg;

/*window.onload=function(){

}*/

function attivaGallery(){
var links=document.getElementById("minipics").getElementsByTagName("a");
for(var i=0;i<links.length;i++)
    links[i].onclick=function(){Show(this);return(false)};
}

function Show(obj){
var bigimg=document.getElementById("bigimage");
var imagepath=obj.getAttribute("href");
var smallimg=obj.getElementsByTagName("img")[0];
bigimg.style.visibility="hidden";
bigimg.src=imagepath;
bigimg.title=smallimg.title;
bigimg.alt=smallimg.alt;
preloadimg=new Image();        //precarica l' immagine prima dell' effetto fade
preloadimg.src=imagepath;
Controlla();
bigimg.style.visibility="visible";
fadeIn("bigimage",0);
}

function attivaFade(){
var imgs=document.getElementById("minipics").getElementsByTagName("img");
for(var i=0;i<imgs.length;i++){
    imgs[i].onmouseover=function(){setOpacity(this,40)};
    imgs[i].onmouseout=function(){setOpacity(this,100)};
    }
}

function Controlla(){
if((preloadimg.width!=0) && (preloadimg.height!=0))
    return;
else window.setTimeout("Controlla()",100);
}

function setOpacity(obj,opacity){
opacity=(opacity==100) ? 99.999 : opacity;
obj.style.filter = "alpha(opacity:"+opacity+")";  // IE/Win
obj.style.KHTMLOpacity = opacity/100; // Safari<1.2, Konqueror
obj.style.MozOpacity = opacity/100;   // Older Mozilla and Firefox
obj.style.opacity = opacity/100;      // Safari 1.2, newer Firefox and Mozilla, CSS3
}

function fadeIn(objId,opacity) {
obj = document.getElementById(objId);
if(opacity <= 100){
  setOpacity(obj,opacity);
  opacity += 10;
  window.setTimeout("fadeIn('"+objId+"',"+opacity+")", 100);
  }
}













var slideShowSpeed = 3000

var crossFadeDuration = 2

var Pic = new Array()

Pic[0] = 'immagini/foto1-p.jpg'
Pic[1] = 'immagini/foto2-p.jpg'
Pic[2] = 'immagini/foto3-p.jpg'
Pic[3] = 'immagini/foto4-p.jpg'
Pic[4] = 'immagini/foto5-p.jpg'
Pic[5] = 'immagini/foto6-p.jpg'

isIE=document.all;
isNN=!document.all&&document.getElementById;
isN4=document.layers;
isHot=false;

function ddInit(e){
  topDog=isIE ? "BODY" : "HTML";
  whichDog=isIE ? document.all.theLayer : document.getElementById("theLayer");  
  hotDog=isIE ? event.srcElement : e.target;  
  while (hotDog.id!="titleBar"&&hotDog.tagName!=topDog){
    hotDog=isIE ? hotDog.parentElement : hotDog.parentNode;
  }  
  if (hotDog.id=="titleBar"){
    offsetx=isIE ? event.clientX : e.clientX;
    offsety=isIE ? event.clientY : e.clientY;
    nowX=parseInt(whichDog.style.left);
    nowY=parseInt(whichDog.style.top);
    ddEnabled=true;
    document.onmousemove=dd;
  }
}

function dd(e){
  if (!ddEnabled) return;
  whichDog.style.left=isIE ? nowX+event.clientX-offsetx : nowX+e.clientX-offsetx; 
  whichDog.style.top=isIE ? nowY+event.clientY-offsety : nowY+e.clientY-offsety;
  return false;  
}

function ddN4(whatDog){
  if (!isN4) return;
  N4=eval(whatDog);
  N4.captureEvents(Event.MOUSEDOWN|Event.MOUSEUP);
  N4.onmousedown=function(e){
    N4.captureEvents(Event.MOUSEMOVE);
    N4x=e.x;
    N4y=e.y;
  }
  N4.onmousemove=function(e){
    if (isHot){
      N4.moveBy(e.x-N4x,e.y-N4y);
      return false;
    }
  }
  N4.onmouseup=function(){
    N4.releaseEvents(Event.MOUSEMOVE);
  }
}

function hideMe(){
  if (isIE||isNN) whichDog.style.visibility="hidden";
  else if (isN4) document.theLayer.visibility="hide";
}

function showMe(){
  if (isIE||isNN) whichDog.style.visibility="visible";
  else if (isN4) document.theLayer.visibility="show";
}

document.onmousedown=ddInit;
document.onmouseup=Function("ddEnabled=false");

var t
var j = 0
var p = Pic.length

var preLoad = new Array()
for (i = 0; i < p; i++){
   preLoad[i] = new Image()
   preLoad[i].src = Pic[i]
}

function runSlideShow(){
if(!document.getElementById || !document.getElementsByTagName) return;
attivaGallery();    //ingrandimento nella stessa pagina
attivaFade();       //effetto rollover sulle miniature



   if (document.all){
      document.images.SlideShow.style.filter="blendTrans(duration=2)";
      document.images.SlideShow.style.filter="blendTrans(duration=crossFadeDuration)";
      document.images.SlideShow.filters.blendTrans.Apply();      
   }
   if (!isN4) document.images.SlideShow.src = preLoad[j].src;
   if (isN4) document.layers['theLayer'].document.images['SlideShow'].src = preLoad[j].src;
   if (document.all){
      document.images.SlideShow.filters.blendTrans.Play();
   }
   j = j + 1;
   if (j > (p-1)) j=0;
   t = setTimeout('runSlideShow()', slideShowSpeed);
}



function runSlideShow2(){


   if (document.all){
      document.images.SlideShow.style.filter="blendTrans(duration=2)";
      document.images.SlideShow.style.filter="blendTrans(duration=crossFadeDuration)";
      document.images.SlideShow.filters.blendTrans.Apply();      
   }
   if (!isN4) document.images.SlideShow.src = preLoad[j].src;
   if (isN4) document.layers['theLayer'].document.images['SlideShow'].src = preLoad[j].src;
   if (document.all){
      document.images.SlideShow.filters.blendTrans.Play();
   }
   j = j + 1;
   if (j > (p-1)) j=0;
   t = setTimeout('runSlideShow2()', slideShowSpeed);
}