function labelInInputClick(el, defaultString) {
	if ($(el).val() == defaultString) {
		$(el).val('')
	}
}

function labelInInputBlur(el, defaultString) {
	if ($(el).val() == '') {
		$(el).val(defaultString);
	}
}

(function($) {
	$.fn.stabs = function(options) {
		var options = $.extend({
			selectedClass: "active",
			selected: 0
		}, options);

		$(this).find("a").click(function() {
			$(this).parents("ul:first").find("li").removeClass(options.selectedClass);

			$(this).parents("ul:first").find("a").each(function(i, el) {
				$($(el).attr("href")).hide();
			});
			$(this).parents("li:first").addClass(options.selectedClass);
			$($(this).attr("href")).show();
			return false;
		});

		$(this).find("a:eq("+options.selected+")").click();
	};
})(jQuery);

$(document).ready(function() {
	$("a.lightbox").fancybox({
		overlayOpacity: 0.6,
		speedIn: 100,
		speedOut: 100,
		type: "image",
		titlePosition: "inside",
		// hack for flash in the background... Take a look at wmode transparent?
		onStart: function() {
			$("object").hide();
		},
		onClosed: function() {
			$("object").show();
		}
	});

	$("table.hoverable tr").hover(function() {
		$(this).toggleClass("hover");
	}, function() {
		$(this).toggleClass("hover");
	});

	$(".switch input:checkbox").click(function() {
		var $target = $($(this).attr("rel"));
		if (!$target.size()) {
			alert("SWITCH: Unknown target");
			return false;
		}

		if ($(this).attr("checked")) {
			$target.slideDown("fast");
		} else {
			$target.slideUp("fast");
		}
	});

	$(".switch input:checkbox").each(function(i, checkbox) {
		if (!$(checkbox).attr("checked") && $(this).attr("rel") != undefined) {
			$($(this).attr("rel")).hide();
		}
	});

	/**
 * Open window handler
 */
function openWindow(url, menu, name) {
	var menuString = 'yes';
	if (menu === false || menu == 'no') {
		menuString = 'no';
	}

	var winName = name;
	if (name == undefined) {
		var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
		var string_length = 8;
		var randomstring = '';
		for (var i=0; i<string_length; i++) {
			var rnum = Math.floor(Math.random() * chars.length);
			randomstring += chars.substring(rnum,rnum+1);
		}

		winName = randomstring;
	}

	winParams = "toolbar=no,menubar=" + menuString + ",location=no,directories=no,scrollbars=yes,resizable=no,status=no,width=100,height=100";
	newWindow = window.open(url, winName, winParams);
	try {newWindow.focus();} catch(e) {}
	return newWindow;
}

	$("a.window").click(function() {
		openWindow($(this).attr("href"), 'no');
		return false;
	});

});
