function initSubnav(){
	var subnav = document.getElementById('nav');
	var subnavas = subnav.getElementsByTagName('a');
	for (var a=0; a<subnavas.length; a++){
		var currenthref=String(subnavas[a].href);
		var currentloc=String(document.location);
		if (unescape(currenthref)==unescape(currentloc)){
			subnavas[a].className="current"
		}
	}
}

function initLinks(){
	var hostname = window.location.hostname;
	hostname = hostname.replace("www.","").toLowerCase();
	var a = document.getElementsByTagName("a");	
	this.check = function(obj){
		var href = obj.href.toLowerCase();
		return (href.indexOf("http://")!=-1 && href.indexOf(hostname)==-1) ? true : false;				
	};
	this.set = function(obj){
		obj.target = "_blank";
		obj.className += " external";
		obj.title += "This link will open in a new window.";
	};
	for (var i=0;i<a.length;i++){
		if(check(a[i])) set(a[i]);
		if (a[i].className.indexOf("photopop") != -1) addAnEvent(a.item(i),'click',photopop);
		if (a[i].className.indexOf("listenpop") != -1) addAnEvent(a.item(i),'click',listenpop);
	};		
};

function photopop(){
    appWindow = window.open (this.href,"appWindow","width=420,height=565,toolbar=0,resizable=1,scrollbars=1");
    appWindow.focus ();
    return false;
}

function listenpop(){
    appWindow = window.open (this.href,"appWindow","width=420,height=326,toolbar=0,resizable=0,scrollbars=0");
    appWindow.focus ();
    return false;
}

function initPhotos(){
	var img = document.getElementById("photos").getElementsByTagName("img");
	for (var i = 0; i < img.length; i++){
		if (img[i].className=="thumb") addAnEvent(img.item(i),'click',photoOn);
		else if (img[i].className=="close") addAnEvent(img.item(i),'click',photosOff);
		if ((i+1)%4 == 0) img[i].className+=" nomargin";
	}
	var height = document.getElementById("photos").offsetHeight-15;
	var div = document.getElementById("photos").getElementsByTagName("div");
	for (var j = 0; j < div.length; j++){
		div[j].style.minHeight = height+"px";
		if (navigator.userAgent.indexOf('MSIE 6.0')+1) div[j].style.height = height+"px";
	}
}

function photoOn(){
	var i = this.id.split("th");
	i = i[1]-1;
	var div = document.getElementById("photos").getElementsByTagName("div");
	div[i].style.display="block";
}

function photosOff(){
	var div = document.getElementById("photos").getElementsByTagName("div");
	for (var i = 0; i < div.length; i++){
		div[i].style.display="none";
	}
}

function siteEmail(user,host){
	document.write("<a href=" + "mail" + "to:" + user + "@" + host + ">" + user + "@" + host + "</a>")
}

function addAnEvent(target, eventName, functionName){
	eval('target.on'+eventName+'=functionName');
}

function initPage(){
	if (document.getElementById){
		if (document.getElementById("nav")) initSubnav();
		initLinks();
		if (document.getElementById("photos")) initPhotos();
	}
}

window.onload=initPage;