/**
 * Contains the main java script definitions.
 *
 * @author Jan Martin
 */

// preload images
jQuery.preloadImages = function()
{
	for(var i = 0; i<arguments.length; i++)
	{
		jQuery("<img>").attr("src", arguments[i]);
	}
}
$.preloadImages
(
	"../media/anfahrt_hover.gif",
	"../graphics/icon_external_hover.gif"
);

// clean whitespace
jQuery.fn.cleanWhitespace = function()
{
	textNodes = this.contents().filter
	(
		function()
		{
			return this.nodeType == 3 && !/\S/.test(this.nodeValue);
		}
	).remove();
}

/**
 * Definitions to load, when document is loaded.
 */
$(document).ready
(
	function()
	{
		// correct item margins
		$("#side nav li:first a").css("margin-top", "0");
		$("article p:last").css("margin-bottom", "0");
		$("article dd").find("p:last").css("margin-bottom", "0");
		$("article dl").find("dt:last").css("padding-bottom", "0");
		$("article dl").find("dd:last").css("padding-bottom", "0");
		$("article ul").find("ul:last").css("padding-bottom", "0");
		$("article section").find("h4:first").css("padding-top", "0");
		$("article ul.links:last").css("padding-bottom", "0");
		
		// remove last vertical line at navigations
		$("header nav li:last").css("background", "none");
		$("footer li:last").css("background", "none");
		
		// span legends for styling
		$("legend").wrapInner(document.createElement("span"));
		
		// add classes to inputs for styling
		$(":text").addClass("text");
		$(":button, :submit, :reset").addClass("button");
		$(":checkbox").addClass("checkbox");
		$(":radio").addClass("radio");
		$(":password").addClass("password");
		$("input:not(:submit), textarea").focusin
		(
			function()
			{
				$(this).addClass("focus");
			}
		);
		$("input:not(:submit), textarea").focusout
		(
			function()
			{
				$(this).removeClass("focus");
			}
		);
		$(":button, :submit, :reset").hover
		(
			function()
			{
				$(this).addClass("hover");
			},
			function()
			{
				$(this).removeClass("hover");
			}
		);
		
		// clean white-space for aside in IE6
		if($.browser.msie && $.browser.version.substr(0,1) == "6")
		{
			$("aside").cleanWhitespace();
		}
		
		// external link icon image hover effect
		$("a.external").hover
		(
			function()
			{
				$(this).css("background-image",
					"url(../graphics/icon_external_hover.gif)");
			},
			function()
			{
				$(this).css("background-image",
					"url(../graphics/icon_external.gif)");
			}
		);
		
		// external link icon image hover effect
		$("a.map img").hover
		(
			function()
			{
				$(this).attr("src", "../media/anfahrt_hover.png");
			},
			function()
			{
				$(this).attr("src", "../media/anfahrt.png");
			}
		);
		
		// gallery lightbox
		$("ul.gallery a").lightBox({fixedNavigation:true});
	}
)
