$(document).ready(function()
{

	$("a[href^='http://'],a[href$='.mp3']:not([href*='mp3=']),a[href$='.pdf'],#downloads a.morelink,").each(function()
	{
		$(this).attr("target", "_blank");
	});
	
	initSkiplist();
	initAudioLinks();
	initVideoLinks();
	initImgLinks();
});

function initSkiplist()
{
	$(".skiplist a").click(function()
	{
		$("#content").load($(this).attr("href").split("#")[0] + " #content>*", function(){ initSkiplist(); });
		return false;
	});
}

function initAudioLinks()
{
	$("#bookdetail .imgbox a[href*='mp3=']").click(function()
	{
		$("#bookdetail .imgbox:first").load($(this).attr("href").split("#")[0] + " #bookdetail .imgbox:first>*", function(){ initAudioLinks(); });
		return false;
	});
	$("#audio a[href*='mp3=']").click(function()
	{
		$("#content").load($(this).attr("href").split("#")[0] + " #content>*", function(){ initAudioLinks(); });
		return false;
	});
}


function initVideoLinks()
{
	$("#video a[href*='vid=']").click(function()
	{
		/*
		$("#player").remove();
		var boxNr = $("div.textbox").index($(this).parents("div.textbox"));
		$("div.textbox:eq(" + boxNr + ")").load($(this).attr("href") + " div.textbox:eq(" + boxNr + ")>*", function(){ initVideoLinks(); });
		*/
		var contentHeight = $("#content").height();
		$("#content").css({
			minHeight: contentHeight
		});
		$("#content").load($(this).attr("href").split("#")[0] + " #content>*", function(){ initVideoLinks(); });
		return false;
	});
}

function initImgLinks()
{
	if(!document.all)
	{
		$("a[href$='.jpg']").css({
			cursor: "-webkit-zoom-in",
			cursor: "-moz-zoom-in"
		});
	}
	
	$("a[href$='.jpg']").click(function()
	{
		$("body").append("<div id=\"shader\"></div><div id=\"box\"><img src=\"" + $(this).attr("href") + "\" /></div>");
		$("#shader,#box").fadeTo(0, 0.01);
		$("#shader").css({
			position: "fixed",
			zIndex: 100,
			width: "100%",
			height: "100%",
			left: 0,
			top: 0,
			background: "#000000"
		});
		
		$("#box").css({
			position: "fixed",
			zIndex: 101,
			padding: "20px",
			background: "#FDF1DE"
		});
		
		$("#box img").css({
			display: "block"
		});
		
		$("#box img").load(function(){
			$("#box").css({
				width: $(this).width(),
				height: $(this).height(),
				left: parseInt(($("#shader").width() - $(this).width()) / 2 - 20) + "px",
				top: parseInt(($("#shader").height() - $(this).height()) / 2 - 20) + "px"
			});

			$("#shader").fadeTo(500, 0.4);
			$("#box").fadeTo(500, 1);
		});

		$("#shader,#box").click(function()
		{
			$("#shader,#box").fadeOut(500, function(){ $("#shader,#box").remove(); });
		});

		return false;
	});
}

