$(function() {
	initOverLabels();
	$("ul.piped-list>li:not(:last-child)").append("<span>|</span>");
});

// cookie functions http://www.quirksmode.org/js/cookies.html
function createCookie(name,value,days)
{
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
function eraseCookie(name)
{
	createCookie(name,"",-1);
}
// /cookie functions

function initOverLabels() {
	$("label.overlabel[@for]").each(function() {
		var label = $(this);
		label.attr("class", "overlabel-apply");
		var field = $("#" + label.attr("for"));
		if (field.val() != "")
			label.hide();
		field.focus(function() {
			label.hide();
		}).blur(function() {
			if (field.val() == "")
				label.show();
		});
		label.click(function() {
			field.trigger("focus");
		});
	});	
}

// used for links to objects like video. This will overlay the video on the screen. Requires jqModal.js.
$.fn.objectOverlay = function(w, h) {
	$(this).click(function() {
		var vid = $(this).attr("href");
		var objtag = "<div class=\"jqmWindow\">";
		objtag += "<a id=\"object-close\" class=\"jqmClose\" href=\"javascript:void(0);\">close X</a>";
		objtag += "<object id=\"vid\" width=\"" + w + "\" height=\"" + h + "\" data=\"" + vid + "\">";
		objtag += "<param name=\"src\" value=\"" + vid + "\"/>";
		objtag += "<p>Video for " + vid + "</p>";
		objtag += "</object></div>";
		$(objtag).appendTo("body").jqm({onHide: function(hash) {
			hash.w.remove();
			hash.o.remove();
			if ($.browser.msie)
				document.location = document.location;
		}}).jqmShow();
		return false;
	});
};