var cur = 0;
var arr = new Array();
//functions
function load() {
	// check to see browser supports the getElementsByTagName method
	// if not, exit the loop 
	if (!document.getElementsByTagName) {
		return false; 
	} 
	// create an array of objects of each link in the document 
	var popuplinks = document.getElementsByTagName("a");
	// loop through each of these links (anchor tags) 	
//	var arr = new Array();
 
	for (var i=0; i < popuplinks.length; i++) {	
		// if the link has a class of "popup"...	
//		if (popuplinks[i].getAttribute("className") == "thumbs") {
		if (popuplinks[i].className == "thumbs") {
                        imgLink = popuplinks[i].firstChild.src;
                        splitIndex = imgLink.indexOf('thumbs');
                        imagename = imgLink.substring(0,splitIndex) + imgLink.substring(splitIndex+7,imgLink.length)
                        imgId = imgLink.substring(splitIndex+7,imgLink.length);
                        popuplinks[i].firstChild.id = imgId;
			// add onclick event on fly  to pass the href attribute	
			// of the link to our second function, openPopUp 	
                        popuplinks[i].href = "javascript: showFullImage('" + imagename + "','" + imgId + "','img'," + arr.length + ")";
                        popuplinks[i].imageName = imagename;
                        arr[arr.length] = popuplinks[i];
                }
		// if the link has a class of "links"...	
//		if (popuplinks[i].getAttribute("className") == "links") {
		if (popuplinks[i].className == "links") {
                        imgLink = popuplinks[i].href;	
                        imgId = "links" + i;
                        popuplinks[i].firstChild.id = imgId;
                        popuplinks[i].href = "javascript: showFullImage('" + imgLink + "','" + imgId + "','span')";
//                        popuplinks[i].href = "javascript: showFullImage('" + imgLink + "')";
                        popuplinks[i].imageName = imgLink;
                        arr[arr.length] = popuplinks[i];
                }
	} 

	if(arr.length >0) {
//		var i = Math.floor(Math.random()*arr.length);
		cur = Math.floor(Math.random()*arr.length);
		arr[cur].firstChild.className = "active";
		document.getElementById("fullimage").src = arr[cur].imageName;

		//add title
		if(document.getElementById("title")) 
			document.getElementById("title").innerHTML = arr[cur].firstChild.title; 
		if(document.getElementById("dim"))  {
			document.getElementById("dim").innerHTML = arr[cur].firstChild.alt; 
			document.getElementById("series").innerHTML = "earth on canvas";
		}
	}
} 

function prev() {
	cur = (cur>0) ? cur-1 : arr.length-1;
	showFullImage(arr[cur].imageName,arr[cur].firstChild.id,'img',cur);
}

function next() {
	cur = (cur<arr.length-1) ? cur+1 : 0;
	showFullImage(arr[cur].imageName,arr[cur].firstChild.id,'img',cur);
}

function showFullImage(imgname, imgid, tagtype, idx) {
	if(typeof imgid != 'undefined') {
		var popuplinks = document.getElementsByTagName(tagtype);
		for (var i=0; i < popuplinks.length; i++) {	
			// if the link has a class of "popup"...	
//			if (popuplinks[i].getAttribute("className") == "active") {
			if (popuplinks[i].className == "active") {
				popuplinks[i].className = "inactive";
			}
		} 
		document.getElementById(imgid).className = "active";
		document.getElementById(imgid).blur();
		cur = idx;
	}
        document.getElementById("fullimage").src = imgname;

	//add title
	if(document.getElementById("title")) 
		document.getElementById("title").innerHTML = document.getElementById(imgid).title; 
	if(document.getElementById("dim"))  {
		document.getElementById("dim").innerHTML = document.getElementById(imgid).alt; 
		document.getElementById("series").innerHTML = "earth on canvas";
	}
}

function openPopUp(linkURL) {
	if (!newwindow.closed && newwindow.location) {
		newwindow.loadimage(linkURL);
	}
	else {
		newwindow=window.open("http://www.exitart.org/site/pub/support/auction_popup.html",'Catalogue','height=550,width=950');
		curimg = parseInt(linkURL);
		if (!newwindow.opener) newwindow.opener = self;
	}
	if (window.focus) {newwindow.focus()}
}
	
