$(document).ready(
	function() {
	/*
			$.sifr({
				path: "flash/",
				save: true
			});
			$("h2").sifr({
				font: "ipecac",
				width: 700
			});
	*/
		var searchValue = $("label[for=q]").text();
		$("label[for=q]").hide();
		$("#q").val(searchValue);
		$(".search_field").bind("focus",
			function() {
				if (!$(this).attr("initval")) {
					var initVal = $(this).val();
					$(this).attr("initval",initVal);
				}
				if ($(this).val() == $(this).attr("initval")) {
					$(this).val("");
				}
			}
		).bind("blur",
			function() {
				console.log(this);
				if ($(this).val().match(/^\s*$/)) {
					var initVal = $(this).attr("initval");
					$(this).val(initVal);
				}
			}
		);
		$(".deletion").click(
			function() {
				var response = window.confirm("Are you sure you want to delete this item?");
				return response;
			}
		);
	
		$("a[rel='external']").each(
			function() {
				$(this).attr("target", "_blank");
			}
		);
	
		
		$("table").each(
			function() {
				if ($(this).hasClass("tour")) {
					// stripe every other 2 rows
					var rowClass = "alt";
					var rowIndex = 0;
					$(this).children("tbody").children("tr").each(
						function() {
							if (rowIndex % 2 == 0) {
								rowClass = (rowClass == "alt") ? "" : "alt";
							};
							$(this).addClass(rowClass);
							rowIndex++;
						}
					);
				}
				else {
					// stripe every other row
					$(this).find("tbody tr:odd").addClass("alt");
				}
			}
		);
	}
);


function externalLinks(target) {
	var domainList = new Array("localhost", "karl.local", "192.168.42.100", "ipecac.com", "antacidaudio.com");

	if (document.getElementsByTagName) {
		if (target) {
			var block = document.getElementById(target);
			var anchorList = block.getElementsByTagName("a");
		}
		else {
			var anchorList = document.getElementsByTagName("a");
		}
		var protocolStart = "^http[s]?:\/\/";
		var protocol = new RegExp(protocolStart, "i");
		var domains = "";
		for (var i = 0; i < domainList.length; i++) {
			domains += "(" + domainList[i] + ")";
			if (i < (domainList.length - 1)) {
				domains += "|";
			}
		}
		var mySites = new RegExp(protocolStart + "([a-z0-9-\.]*\.)?" + domains, "i");

		for (var i = 0; i < anchorList.length; i++) {
			if (anchorList[i].href.match(protocol) && !anchorList[i].href.match(mySites)) {
				anchorList[i].setAttribute("target", "_blank");
				anchorList[i].className = "external";
			}
		}
	}
}

