// rollover.js
var remote;
var tcount=0;
var icount=0;
var timers = new Array();
var itimers = new Array();

function fullImage(title,image,width,height) {
// create a new window or open an existing one and 
// write a simple page to it

var url="./fullimage.php";
var maxwidth = 1000;
var maxheight = 700;
var windowwidth;
var windowheight;
var windowoptions;
var wborder=20;
var hborder=130;

    url += "?img=" + image;
    url += "&caption=" + title;
    url += "&width=" + width;
    url += "&height=" + height;
    url += "&popup=1";

    if (width + wborder < maxwidth)
	windowwidth = width+wborder;
    else
	windowwidth=maxwidth;
    if (height + hborder < maxheight)
	windowheight = height+hborder;
    else
	windowheight=maxheight;
    windowOptions = "directories=0,menubar=1,personalbar=0,status=0,resizable=1,scrollbars=1";
    windowOptions += ",width=" + windowwidth + ",height=" + windowheight;
    remote = window.open(url,"fullsize",windowOptions)
    remote.resizeTo(windowwidth,windowheight);
}
function showRolloverInNewWindow(title,image,width,height) {
    // create a new window or open an existing one and 
    // write a simple page to it
    windowwidth = 800;
    windowheight = 600;
    windowOptions = "directories=0,menubar=1,personalbar=0,status=0,resizable=1,scrollbars=1";
    windowOptions += ",width=" + windowwidth + ",height=" + windowheight;
//     windowOptions += ",screenX=0,screenY=0";
     imgstr = '<img border=0 src=' + image + ' width=' + width + ' height=' + height + '>'
     title = unescape(title);
     remote = window.open("","fullsize",windowOptions)
     remote.resizeTo(windowwidth,windowheight);
     remote.document.open()
     remote.document.writeln('<html lang="en"><head><title>' + title + '</title>');
     remote.document.writeln('<LINK REL="stylesheet" HREF="./photos.css">');
     remote.document.writeln('</head><body bgcolor=#ffffff><h1>' + title + '</h1>')
     remote.document.writeln(imgstr)
     remote.document.writeln('<br /><hr noshade /><br />');
     remote.document.writeln('<a href="javascript:self.close()"><img border=0 src="furniture/close.png" height=7 width=7>&nbsp;Close this window</a></body></html>');
     remote.document.close();

}

function overlayImage (imageID,newimage) {  
    // replace an image
    if (document.images[imageID]) {
	document.images[imageID].src = newimage;
    }
}

function multirollover (ids,images) { 
    // replace lots of images
    for(var i=0;i<ids.length;i++) {
	if (i>images.length) {
	    break;
	}
	overlayImage(ids[i],images[i]);
    }
}

function rollmultiandloop (ids,images,timeout) {
    // for each id rollover a new image
    // then for any remaining images do a loop for the first id

    var loop = new Array();
    var j=0;
    multirollover(ids,images);

    if (ids.length >= images.length) {
	// nothing to loop. cancel existing
	for(var i=0;i<tcount;i++) {
	    clearTimeout(timers[i]);
	}
	for(var i=0;i<icount;i++) {
	    clearInterval(itimers[i]);
	}
	return; 
    }
    // build an array of the remaining images
    for(var i=ids.length;i<images.length;i++) {
	loop[j] = images[i];
	j++;
    }	
    if (!timeout) timeout=1000;
    loopImages(ids[0],loop,timeout);
}

function loopImages (id,images,timeout) {
    // set a timeout for each images
    var delay;
    if (images.length > 0) {
	delay = timeout/images.length;
    }   
    for(var i=0;i<images.length;i++) {
	timers[tcount] =
    setTimeout("startloop('"+id+"','"+images[i]+"','"+timeout+"','"+i+"')",
    delay * i );
	  tcount++;
    }
}

function startloop (id,image,timeout,i) {
    // called when the timeout expires
    // updates the appropriate image
    itimers[icount] = 
	setInterval("overlayImage('"+id+"','"+image+"')", timeout);
    icount++;
}

