function popup(url, ww, wh) {
    noteWindow = window.open(url, "noteWindowlet", "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=no,width="+ww+",height="+wh);
		noteWindow.focus();
}

function getRelp() {

	m = location.href.match('live/|elixir/');
	if ( m != null && m.length > 0 ) {
		return '../';
	}
	return '';
}

$(document).ready(function() {

		var relp = getRelp();

if (document.images) {

	on = '_purple.gif';
  off = '_orange.gif';

	$('#leftmenu img').each(function() {
			this.on = new Image(this.width,this.height);
			this.off = new Image(this.width,this.height);
			this.on.src = relp+"images/"+this.id+on;
			this.off.src = relp+"images/"+this.id+off;
		}
		);
}


$('#leftmenu img').hover(
function() {
	this.src = this.on.src;
},
function() {
	this.src = this.off.src;
});

$('#wh').hover(
function() {
	window.status="About this Image";
  return true;
},
function() {
	window.status="";
	return true;
});

$('#wh').click(function() {
		// get the baseurl. Unless the ajax call matches exactly the page base
		// url firefox will throw a security exception.
		var urlre = /^.*sufiorder.org\//; 
		var baseurl =	(window.location+"").match(urlre)[0];
		$(this).after("<div />");
		$(this).next().load(baseurl+"wingedheart.htmx");
		return false;
});


});

$(document).ready(function() {
		$('span.contact').each(function(i,val) { // this is the span; val is the span; i is the index
				o = $(val);
				sin = o.text();
				if ( sin == undefined || sin.length == 0 ) {
					return;
				}
				sa = "@";
				sd = ".";
				ss = "#";

				qstr = '';
				astr = '';
				// allows parameters to the mailto
				// strip this first
				qpos = sin.indexOf('?');
				if ( qpos > -1 ) {
					qstr = sin.substr(qpos);
					sin = sin.substr(0,qpos);
				}
				// alternate display text
				altp = sin.indexOf('|');
				if ( altp > -1 ) {
					astr = sin.substr(0,altp);
					sin = sin.substr(altp+1);
				}
				if ( sin.indexOf('#') < 1 ) { 
					// no marker for domain, default to host
					sout = sin + sa + "sufiorder" + sd + "org";
					if ( astr == "" ) {
						astr = sout;
					}
				  o.replaceWith('<a href="mailto:'+sout+qstr+'">'+astr+'</a>');
				} else {
					// domain is encoded, the last char stands for .com, .org, .net
          lc = sin.charAt(sin.length-1);
					sin = sin.substr(0,sin.length-1);
					// TODO: this is broken if country domain ends in one of these letters
					switch ( lc ) {
					case 'c' : sin = sin + sd + 'com'; break;
					case 'e' : sin = sin + sd + 'edu'; break;
					case 'o' : sin = sin + sd + 'org'; break;
					case 'n' : sin = sin + sd + 'net'; break;
					default  : sin = sin + lc; break;
					}
					sout = sin.replace(ss,sa);
					if ( astr == "" ) {
						astr = sout;
					}
					o.replaceWith('<a href="mailto:'+sout+qstr+'">'+astr+'</a>');
				}
		});

});
