function msover(image_name)
{
	eval("document."+image_name).src="../images/subnav_" + image_name + "_ms.gif";
} 

function msout(image_name)
{
	eval("document."+image_name).src="../images/subnav_" + image_name + ".gif";
}

function scroll_iframe(framename, distance, direction) 
{
  if (timer_id) clearTimeout(timer_id);
  if (window.frames[framename]) {
    if (direction == "vertical") window.frames[framename].scrollBy(0, distance);
    else window.frames[framename].scrollBy(distance, 0);
    timer_id = setTimeout("scroll_iframe('" + framename + "'," + distance + ",'" + direction + "')", 20);
  }
}

function stopScroll() { if (timer_id) clearTimeout(timer_id); }


function openPortfolioLink()
{
	if (portfolio_href!="")
		{
			window.open("imagewindow.asp?img="+imageBasePath+portfolio_href,"fwindow","toolbar=no,menubar=no,resizeable=yes,status=no,titlebar=no",true);

			}
}

function SetPortfolioPiece( img, imagelocation, livelocation )
{
	top.document.bigvisual.src= imageBasePath + imagelocation; 
	top.portfolio_href=livelocation;
	var commentaryElement = top.document.getElementById("commentary");	
	var commentaryText = img.getAttribute("comment");	
	if (commentaryElement.innerText) 
		commentaryElement.innerText = commentaryText;
	else if (commentaryElement.textContent)
		commentaryElement.textContent = commentaryText;
}

function ImageSnapshot()
{
	var iframe_document;
	if (document.frames)
		iframe_document = document.frames[frameName].document;
	else
		iframe_document = document.getElementById(frameName).contentDocument;

	var imgs = iframe_document.getElementsByTagName("img");
	
	var currentCommentElement = top.document.getElementById("commentary");
	var currentComment = (currentCommentElement.textContent) ? currentCommentElement.textContent : currentCommentElement.innerText;
	currentComment = currentComment.replace(/\n\s*/gi,"");
	
	for(var i=0;i<imgs.length;i++)
	{
		var imgComment = imgs[i].getAttribute("comment");	
		if (currentComment == imgComment)
		{
			this.previousImage = imgs[(i>0)?i-1:imgs.length-1];
			this.currentImage = imgs[i];
			this.nextImage = imgs[(i<imgs.length-1)?i+1:0];
			return this;
		}
	}
	return null;

}

function PreviousImage()
{
	var imgs = new ImageSnapshot();
	if (!imgs || !imgs.previousImage){
		 alert("none.");
		 return;
   }

   var setPiece = imgs.previousImage.getAttribute("onclick");
   if((typeof setPiece) != "string")
		 setPiece = setPiece.toString().replace(/^(.|\n|$)*(Set.*?\n)(.|\n)*/gi,"$2");	
	setPiece = setPiece.replace(/this/gi,"imgs.previousImage");
	
	eval(setPiece);	
}

function NextImage()
{
	var imgs = new ImageSnapshot();
	if (!imgs || !imgs.nextImage){
		 alert("none.");
		 return;
   }

   var setPiece = imgs.nextImage.getAttribute("onclick");
   if((typeof setPiece) != "string")
		 setPiece = setPiece.toString().replace(/^(.|\n|$)*(Set.*?\n)(.|\n)*/gi,"$2");	
	setPiece = setPiece.replace(/this/gi,"imgs.nextImage");
	
	eval(setPiece);	
}
