var site = 'http://www.cs.toronto.edu/~kmregan/';

//
// DOM needs to look something like this
//	
// 		pub
//			...
//				...
//					tag that holds onclick
// 			abstract

function toggle(obj,className) {

	// Find abstract node
	var node = obj;
	while (node.className != 'pub') {
		node = node.parentNode;
	}
	var children = node.childNodes;
	var child = null;
	for (var i = 0; i < children.length; i++) {
		child = children[i];
		if (child.className == className) break;
	}

	var isOn = (child.style.display == 'block');
	child.style.display = (isOn) ? 'none' : 'block';
	return false;
}

function toggleAbstract(obj) {

	// Find abstract node
	var node = obj;
	while (node.className != 'pub') {
		node = node.parentNode;
	}
	var children = node.childNodes;
	var child = null;
	for (var i = 0; i < children.length; i++) {
		child = children[i];
		if (child.className == 'abstract') break;
	}

	var isOn = (child.style.display == 'block');
	child.style.display = (isOn) ? 'none' : 'block';
	return false;
}



//
// Take an array of nodes and return an array
// with only nodes whose tag matches tagname
//

function filterByClass(nodes, tagName) {
	var filteredNodes = new Array();
	for (var i = 0; i < nodes.length; i++) {
		if (nodes[i].className == tagName) {
			filteredNodes[filteredNodes.length] = nodes[i];
		}
	}
	return filteredNodes;
}


var proxyURL = site + "flickr/proxy.cgi";

function switchPhoto(img)
{	
	if(img.parentNode.href) return;
    var client = new XMLHttpRequest();
    client.open("GET", proxyURL);
	client.onreadystatechange = function() {
      
      if (client.readyState == 4) {
 
       	var text = client.responseText;
       	var json = eval( '(' + text + ')' );
       	img.src = json.img;
       	img.title = json.title + ' taken by ' + json.ownername;
       	img.alt =   json.title + ' taken by ' + json.ownername;
       	img.parentNode.href = json.web;
       	
       	//img.parentNode.parentNode.style.opacity = '1';
        img.onload = function () { img.parentNode.parentNode.style.opacity ='1'; }
        //img.onload = null;
      }
      
    }
	client.send(null);
}

function PreloadImage(imgSrc, callback){
    var objImagePreloader = new Image();

    objImagePreloader.src = imgSrc;
    if(objImagePreloader.complete){
        callback();
        objImagePreloader.onload=function(){};
    } else {
        objImagePreloader.onload = function() {
            callback();
          //    clear onLoad, IE behaves irratically with animated gifs otherwise
            objImagePreloader.onload=function(){};
        }  
    }
}

function setSize(img, width, height)
{	
	img.style.width = "" + width + "em";
	img.style.height = "" + height + "em";
}

