$(document).ready(function() {

	// For each link containing -off, set up a -on hover
	$("img[src*='-off']").each(function() {
	
		// Preload on state
		var img = new Image();
		img.src = $(this).attr("src").replace(/-off/,"-on");
		
		// Set up the hover switcher
		$(this).hover(function() {
			$(this).attr("src",$(this).attr("src").replace(/-off/,"-on"));
		}, function() {
			$(this).attr("src",$(this).attr("src").replace(/-on/,"-off"));
		});
	
	});
	
	// Set up marquees
	$('marquee')
		.marquee('pointer')
		.mouseover(function () {
			$(this).trigger('stop');
		})
		.mouseout(function () {
	  		$(this).trigger('start');
		})
		.mousemove(function (event) {
			if ($(this).data('drag') == true) {
				this.scrollLeft = $(this).data('scrollX') + ($(this).data('x') - event.clientX);
			}
		})
		.mousedown(function (event) {
			$(this).data('drag', true).data('x', event.clientX).data('scrollX', this.scrollLeft);
		})
		.mouseup(function () {
			$(this).data('drag', false);
		})
	;
	
	// Set up openable tools
	$(".expandable").each(function() {

		// If linking to this panel, open it and focus (ex: "whatever.php?#panelid")
		if (window.location.hash == "#" + $(this).attr("id"))
		{
			$(this).addClass("open");
			$(this).find("div.content").slideDown();
			$(this).find("input:first").focus();
		}

		// When the header is clicked
		$(this).find("a.title").click(function() {
			if (!$(this).parent().hasClass("open"))
			{
				$(this).parent().parent().find(".expandable.open").removeClass("open").find(".content").slideUp();
				$(this).parent().addClass("open");
				$(this).parent().find("div.content").slideDown();
				$(this).parent().find("input:first").focus();
			}
			else
			{
				$(this).parent().removeClass("open");
				$(this).parent().find("div.content").slideUp();
			}
		});
		
	});

});