
var nw;

function showPics(sWhich) {
	if (nw && nw.open && !nw.closed)
		nw.focus();
	else {
		nw = window.open(sWhich + '.html','nw','height=500,width=550,resizable=1,scrollbars=1');
	}
}

var lw;

function getFile(sFile, w, h) {
	w = w || 450;
	h = h || 400;
	if (lw && lw.open && !lw.closed) {
		if (lw.location.href.substring(lw.location.href.lastIndexOf("/") + 1) != sFile + ".html") {
			lw.location.href = "/library/" + sFile + ".html";
		}
		lw.focus();
	}
	else lw = window.open("/library/" + sFile + ".html","lw","width="+w+",height="+h+",resizable,scrollbars");
}

function writeEmail(sText) {
	sText = sText || [["jeff","jeffemminger"].join("@"),"com"].join(".");

	document.write('<a href="mailto:jeff@jeff'+
		'emminger.com">'+sText+'</'+'a>');
}

function showLarge(img) {
	var w = img.width == 150 ? 640 : 483;
	var h = img.height == 150 ? 640 : 483;
	
	self.large = window.open("large.php?i=" + img.src.replace("150", "640"), "large", "width=" + w + ", height=" + h);
	self.large.onclick = function() {window.close();};
	self.large.focus();
}

function toggleBookmarks(elHeader) {
	var id = elHeader.getAttribute("id").split("_")[1];
	var elArrow = document.getElementById("ca_" + id);
	var elBookmarks = document.getElementById("bc_" + id);
	
	//  if className is currently "down", then we will be closing the bookmark container
	var closed = elArrow.className == "category-arrow-down";
	
	elArrow.className = closed ? "category-arrow-up" : "category-arrow-down";
	elBookmarks.className = closed ? "bookmark-container-closed" : "bookmark-container-open";
	
	setBookmarkState(id, closed);
}

function setBookmarkState(id, closed) {
	var c = document.cookie;	
	var ids = c.match(/bmc_closed=([^;]*)/);
	
	if (ids == null) {
		ids = [];
	}
	else {
		ids = ids[1].split(",");
	}
		
	//  attempt to remove id from array
	for (var x = 0; x < ids.length; x++) {
		if (ids[x] == id) {
			ids.splice(x, 1);
			break;
		}
	}
	
	//  if closed, add id back to array
	if (closed) {
		ids.push(id);
	}
	
	//  expire one year from now
	var exp = new Date(new Date().getTime() + new Date().setTime(1000*60*60*24*365));
	
	//  add array to cookie
	document.cookie = "bmc_closed=" + (ids.join(","))
		+ "; expires=" + exp;
	
}


