var dimages=new Array();
var numImages=4;

dimages[0]=new Image();
dimages[0].src="gallery/oasis.jpg";
dimages[1]=new Image();
dimages[1].src="gallery/superbowl.jpg";
dimages[2]=new Image();
dimages[2].src="gallery/welcome_inn_04.jpg";
dimages[3]=new Image();
dimages[3].src="gallery/wifi.jpg";
var curImage=0;
var timerid=0;
function swapPicture(way, timeoutID, target)
{
  if(target)
  	curImage=0;
  clearTimeout(timeoutID);
  if (document.images)
  {
    var nextImage=curImage+way;
    if (nextImage>=numImages)
      nextImage=0;
	if (nextImage<0)
      nextImage=numImages-1;  
    if (dimages[nextImage] && dimages[nextImage].complete)
    {
      var target=0;
      if (document.images.myImage)
        target=document.images.myImage;
      if (document.all && document.getElementById("myImage"))
        target=document.getElementById("myImage");
  
      // make sure target is valid.  It might not be valid
      //   if the page has not finished loading
      if (target)
      {
        changeOpac(0, "myImage");		
        target.src=dimages[nextImage].src;
		// add something like this in for different links. var href = dhref[nextImage]; 
        curImage=nextImage;
		opacity("myImage",0, 100, 500);
		changeTab(nextImage);
      }
	  timerid = setTimeout("swapPicture(1, timerid)", 4500);
	  return timerid;
    }
    else
    {
      timerid = setTimeout("swapPicture(way, null)", 500);
    }	
  } 
}
timerid = setTimeout("swapPicture(1, timerid)", 4500);

function opacity(id, opacStart, opacEnd, millisec) { 
    //speed for each frame 
    var speed = Math.round(millisec / 100); 
    var timer = 0; 

    //determine the direction for the blending, if start and end are the same nothing happens 
    if(opacStart > opacEnd) { 
        for(i = opacStart; i >= opacEnd; i--) { 
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 
    } else if(opacStart < opacEnd) { 
        for(i = opacStart; i <= opacEnd; i++) 
            { 
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 
    } 
} 

//change the opacity for different browsers 
function changeOpac(opacity, id) { 
    var object = document.getElementById(id).style; 
    object.opacity = (opacity / 100); 
    object.MozOpacity = (opacity / 100); 
    object.KhtmlOpacity = (opacity / 100); 
    object.filter = "alpha(opacity=" + opacity + ")"; 
}
function changeTab(id) {
	var ad = document.getElementById("vPanel" + id).style;
	var ad2 = document.getElementById("vCont" + id).style;
	for(var i=0;i<numImages;i++) {
		document.getElementById("vPanel" + i).style.marginRight="20px";
		document.getElementById("vPanel" + i).style.borderColor="#CCC";
		document.getElementById("vCont" + i).style.display="none";

	}
	ad.marginRight = "0";
	ad.borderColor = "#999";
	ad2.display = "block";
}
