/*
 * Activates special behaviour for specially-named link elements.
 *
 * @author scampbell
 * @date 29-09-2005
 */


/**
 * Adds popup behaviour for links with rel="popup" or rel="external".
 */
function init_popups() {
	if (!document.getElementsByTagName) {
		return;
	}

 	var links = document.getElementsByTagName('a');

 	for (var ii = 0; ii < links.length; ii++) {
		var link = links[ii];

		//check that this link has the attribute we are looking for
		if (link.getAttribute("rel") == null) {
			continue;
		}

		if (link.getAttribute("rel").indexOf("popup") != -1) {
			link.onclick = function() { return doPopup(this.href, "width=300,height=470,scrollbars=yes,resizable=yes"); }
		}
		if (link.getAttribute("rel").indexOf("external") != -1) {
			link.onclick = function() { return doPopup(this.href, "width=800,height=600,scrollbars=yes,resizable=yes,toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes"); }
		}
	}
}


/**
 * Activates a popup.
 *
 * @param href  Window target
 * @param attrs String of window attributes
 */
function doPopup(href, attrs) {
	var date = new Date();
	var time = date.getTime();
	window.open(href, "SearsonBuckWindow_"+time, attrs);
	return false;
}

var VIEW_IMAGE_PAGE = "http://www.searsonbuck.com.au/display.jspx";  //absolute to the page that calls view_image().

/** Open image window */
function view_image(path, w, h) {
  var image_request_url = VIEW_IMAGE_PAGE + '?path=' + path + '&w=' + w + '&h=' + h;
  var image_win_params = 'width=' + (w+20) + ',height=' + (h+20) + ',directories=0,location=0,menubar=0,resizable=1,scrollbars=0,status=0,toolbar=0';
  window.open(image_request_url, 'viewImage', image_win_params);

  return false; //to stop the browser following the 'actual' link.
}
