$(document).ready(function(){
	$("#upLevelPanel > .nav a").wrapInner("<span />").wrapInner("<span />").wrapInner("<span />");
	$("#upLevelPanel > .nav a").hover(function(){
		$("span", this).fadeIn(100);
	},function(){
		$("span", this).fadeOut(100);
	});
	
	
	$("body.programmeThemes").each(function(){
		$("#secondary").each(function(){
			$(".section", this).css("display","none");
			$(".section:first-child", this).css("display","block");
		});
		$("#themes", this).each(function(){
			$("li", this).each(function(){
				$(this).append('<span style="display: none;">' + $("a",this).text() + "</span>");
			});
			$("li:first-child", this).addClass("cur")
				.each(function(){
					$("span", this).css("display", "block");
					$("a", this).css("display", "none");
				});
			$("li > a", this).click(function(){
				$("body.programmeThemes #secondary .section").css("display","none");
				var classes = $(this).parents("li").attr("className").split(" ");
				$("#" + classes[0]).css("display","block");
				$("body.programmeThemes #themes li.cur")
					.removeClass("cur")
					.each(function(){
						$("span", this).css("display", "none");
						$("a", this).css("display", "inline-block");
					});
				$(this)
					.css("display", "none")
					.next("span").css("display", "block")
					.parents("li").addClass("cur");
				return false;
			});
		});
		var th_last = $("#themes li:last");
		var th_w = th_last.position().left + th_last.outerWidth();
		if(th_w > $("#themes ul").outerWidth()){
			$('#themes').jcarousel({
				scroll:10
			});
		}
	});
	
	$(".dialog-link").click(function(){
		$(this).after('<div class="dynamic-dialog" title="' + $(this).attr('title') + '"></div>');
		$('.dynamic-dialog')
			.dialog({ height:500, width:500, resizable: false, close: function() { $('.dynamic-dialog').remove(); }})
			.append('<object data="' + $(this).attr("href") + '" type="text/html" width="470" height="445"></object>');
		return false;
	});
	
});
