document.write('<style type="text/css">');
//document.write('ul.navi li.current_page_item li {display:none;}\r');
document.write('ul.navi li.current_page_parent li.current_page_item li {display:none;}');
document.write('</style>');


$(document).ready(function() {

	var z=10;
	var naviAlpha = 0.1;
	var currentPage;
	var state = "Abspielen"; 
	var depth;
	var duration;
	var position;
	var loading = false; 
	var ltext = ".";
	if ($(".current_page_item").length > 0)
	currentPage = $(".current_page_item").attr("class").match(/page-item-\d+/)[0];


	stateListener = function (eventData) {
	state = eventData.newstate;
		if (state == "PAUSED")
			state = "Abspielen";
		if (state == "PLAYING")
			state = "Pause";
		if (state == "COMPLETED")
			state = "Erneut abspielen";
		if (state == "IDLE")
			state = "Abspielen";
		$(".pause").text(state);
	};
	
	playTracker = function (eventData) {
		duration = eventData.duration;
		position = eventData.position;
		if (position){
	  	  	w = position / duration * 480;
	  	  	$("#scrollbar").width(w);
		 }
	};
	
	playerReady = function(obj) {
		player = document.getElementById(obj['id']);
		player.addModelListener('TIME','playTracker');
		player.addModelListener('STATE','stateListener');
	};
	
	var makeBody = function(){	
	 	depth = ($("#depth").val());  	
		if ($(".col").html() && $(".col").html().match("Flash Video Player")!=null){
			$("#sidebar").hide();
		  	//is Flash Video Site
		  	$(".col").addClass("overlay").removeClass("col");
		  	$(".overlay ").wrapInner('<div id="videoWin" />');
		  	$("#video0").after('<div id="scrollerBack"><div id="scrollbar" /></div><div id="playbar"><a href="#" class="pause" >'+state+'</a></div>');
		  	
			$("#scrollbar").width(0);
			
		  	$("#content").append('<div class="naviBack"><a href="#" class="close">zur&uuml;ck</a></div>');
		  	$(".close").click(function(){
		  		player.sendEvent('STOP');
		  		$("#sidebar").show();
			  	$(".overlay").fadeOut(500).html("");
			  	$(this).remove();
		  	});
		  	
		  	$(".pause").click(function(){
			  	player.sendEvent('PLAY');
				$(".pause").text(state);
		  	});
		  	
		  	$(".fullscreen").click(function(){
		  	  	//<a href="#" class="fullscreen"> +</a>
			  	player.sendEvent('FULLSCREEN',true);
		  	});
		  	
		  } else if (depth == 2){
		  	$("#content").css("margin-left","500px");
		  	
		  	$(".col").addClass("overlay").removeClass("col");
		  	$(".overlay ").css("z-index",1000);
		  	$(".overlay ").wrapInner('<div id="videoWin" />');
		  	$("#content").append('<div class="naviBack"><a href="#" class="close">zur&uuml;ck</a></div>');
		  	$(".close").click(function(){
		  		$("#sidebar").show();
			  	$(".overlay").fadeOut(500).html("");
			  	$(this).remove();
		  	});
		  	
		  }
		  if (depth == 2){
		  	var sub = $("li.current_page_parent ul").html();
		  	var sub = sub.split("<li class");
		  	var subna = new Array();
		  	for (var i = 0; i < sub.length;i++){
			  	if (!sub[i].match("current_page_item"))
			  		subna.push (sub[i]);
		  	}
		  	$("#videoWin").append('<div class="subnav"><ul>'+subna.join("<li class")+'</ul></div>');

		  }
	}
	
	$(".navi li ul li a").mouseenter(function(){
		l = $(this).closest("li");
		//state of child ul
		//$("#loc").text();
		var animateUl = (l.children("ul").children("li:visible").length == 0);
		animateNavItem(l);
		//untergeordnetet Navigationspunkte einblenden
		if (animateUl){
			l.children("ul").children("li").css("display","block").hide().fadeIn(300);
		} else {
			l.children("ul").children("li").css("display","block");
		}
	});

  
	function animateNavItem(l){
		$(".current_page_item").removeClass("current_page_item");
		$(".current_page_parent").removeClass("current_page_parent");
		$(".current_page_ancestor").removeClass("current_page_ancestor");
		$(".page_item").removeAttr("style");
		l.addClass("current_page_item");
		if(l.closest("li").parent().closest("li").length == 0){
			$(".navi").addClass("current_page_parent");
		}
		if(l.closest("li").parent().closest("li").parent().closest("li").length == 0){
			$(".navi").addClass("current_page_ancestor");
		}
		l.closest("li").parent().closest("li").addClass("current_page_parent");
		l.closest("li").parent().closest("li").addClass("current_page_ancestor");
		l.closest("li").parent().closest("li").parent().closest("li").addClass("current_page_ancestor");
	}
	//$("body").hide().fadeTo(500,1);
	makeBody();
});
