// JavaScript Document
/*
ThumbnailsIntoFooter = function(){	
	//Move the gallery from content into footer
	if(document.getElementById("thumbnails")){
		var existingcontainer = document.getElementById("my-thumbnails");
		var targetcontainer = document.getElementById("thumbnails");
		var showcontainer = document.getElementById("big");
		
		//if there is only one image show the image and don't show thumbnails
		number_of_images = 0;
			navRoot = document.getElementById("my-thumbnails").getElementsByTagName("A");
			for (i=0; i<navRoot.length; i++) {				
					if(i==0) bigImageUrl=navRoot[i].getAttribute("href");
				number_of_images ++;	
  			}
		
		if(number_of_images>2){ 				
		targetcontainer.innerHTML = existingcontainer.innerHTML;
		existingcontainer.innerHTML = "";		
		}
		else{
			existingcontainer.innerHTML = "";
		}
			

		//var imageHTML='<img src="'+number_of_images+'" style="border-width: 0" />'
		var imageHTML='<img src="'+bigImageUrl+'" style="border-width: 0" />';
		showcontainer.innerHTML+=imageHTML;		
		init();
	}
}
*/

CaptionForHomepage = function(){
  if(document.getElementById("home")){
    navRoot = document.getElementById("maincontent").getElementsByTagName("IMG");
    for (i=0; i<navRoot.length; i++) {				
					mycaption=navRoot[i].getAttribute("alt");
  			}
    document.getElementById("caption").innerHTML = mycaption;
  }
}

ThumbnailsIntoFooter = function(){	
	//Move the gallery from content into footer
	if(document.getElementById("thumbnails")){
		var targetcontainer = document.getElementById("thumbnails");
		var showcontainer = document.getElementById("big");
		
		//if there is only one image show the image and don't show thumbnails
		number_of_images = 0;
			navRoot = document.getElementById("my-thumbnails").getElementsByTagName("A");
			for (i=0; i<navRoot.length; i++) {				
					if(i==0) bigImageUrl=navRoot[i].getAttribute("href");
				number_of_images ++;	
  			}
			
			navRoot = document.getElementById("my-thumbnails").getElementsByTagName("IMG");
			for (i=0; i<navRoot.length; i++) {	
					navRoot[i].style.marginTop = 121-navRoot[i].height+"px";
  			}
		
		if(number_of_images<2){ 				
		targetcontainer.innerHTML = "";
		}
		

		//var imageHTML='<img src="'+number_of_images+'" style="border-width: 0" />'
		var imageHTML='<img src="'+bigImageUrl+'" style="border-width: 0" />';
		showcontainer.innerHTML+=imageHTML;		
		init();
	}
}


loadimage = function(linkobj){
var imagepath=linkobj.getAttribute("href") //Get URL to enlarged image
var showcontainer=document.getElementById(linkobj.getAttribute("rev").split("::")[0]) //Reference container on page to show enlarged image in
var dest=linkobj.getAttribute("rev").split("::")[1] //Get URL enlarged image should be linked to, if any
var imageHTML='<img src="'+imagepath+'" style="border-width: 0" />' //Construct HTML for enlarged image

showcontainer.innerHTML=imageHTML
}

hideimage = function(linkobj){
var showcontainer=document.getElementById(linkobj.getAttribute("rev").split("::")[0]) //Reference container on page to show enlarged image in
showcontainer.innerHTML=""
}

init = function(){ //Initialize thumbnail viewer script
	var pagelinks=document.getElementsByTagName("a");
	var preloadedimages = [];
	for (var i=0; i<pagelinks.length; i++){ //BEGIN FOR LOOP
		if (pagelinks[i].getAttribute("rel") && /enlargeimage:/i.test(pagelinks[i].getAttribute("rel"))){ //Begin if statement: Test for rel="enlargeimage"
			preloadedimages[preloadedimages.length]=new Image()
			preloadedimages[preloadedimages.length-1].src=pagelinks[i].href
			
			pagelinks[i]["onclick"]=function(){ //Cancel default click action
				return false
			}
		
			pagelinks[i]["onmouseover"]=function(){ //Load enlarged image based on the specified display type (event)
				loadimage(this) //Load image
				return false
			}
		
			//pagelinks[i]["onmouseout"]=function(){
			//	hideimage(this)
			//}
			//this.targetlinks[this.targetlinks.length]=pagelinks[i] //store reference to target link
		} //end if statement
	} //END FOR LOOP
}


function addEvent(obj, evType, fn){ 
 if (obj.addEventListener){ 
   obj.addEventListener(evType, fn, false); 
   return true; 
 } else if (obj.attachEvent){ 
   var r = obj.attachEvent("on"+evType, fn); 
   return r; 
 } else { 
   return false; 
 } 
}

addEvent(window, 'load', ThumbnailsIntoFooter);
addEvent(window, 'load', CaptionForHomepage);







