function opensubmenu(openelement) {
	$('#' + openelement).fadeIn('fast', function() {
		$('body').click(function() {
			$('#' + openelement).fadeOut('slow');
		});
		$('#' + openelement).hover(function() {
			clearTimeout(closetimer);
		}, function() {
			closetimer = window.setTimeout(function() {
				$('#' + openelement).fadeOut('slow');
			}, 2000);
		});
	});
}

$(document).ready(function() {
	$("div.player-overlay").width($(window).width()-80);
	$("div.player-overlay").height($(window).height()-80);

	$("a.kuka-player").each(function(index) {
		var displayControls = 1;
		var toolbar = $(this).parent().find("div.player-toolbar").get(0);
		var defaults = {
			clip: {
				autoPlay: false,
				autoBuffering: true,
				scaling: 'fit'
			},
			canvas: {
				backgroundGradient: 'none'
			},
			plugins: {
				controls: null
			},
			onBeforeFullscreen: function() {
				overlayElement = $("div.player-overlay").clone();

				(function(elem, player) {
					$(elem).overlay({
						////expose: '#123448',
						onLoad: function() {
							var embed = $(player.getParent()).children().first();
							embed.css({
								width:parseInt($("div.player-overlay").width()) -80,
								height:parseInt($("div.player-overlay").height()) -80,
								left: $(window).scrollLeft() - $(embed).offset().left + 80,
								top: $(window).scrollTop() - $(embed).offset().top + 80,
								zIndex: 20001
							});
							$f().resume();
						},

						onClose: function() {
							var embed = $(player.getParent()).children().first();
							var current_toolbar = $(player.getParent()).siblings("div.player-toolbar").first();

							if ($(current_toolbar).hasClass("autohide")) {
								$(current_toolbar).hide();
							} else {
								$(current_toolbar).show();
							}
							$(embed).css({top: null, left: null, width: null, height: null, zIndex: 10000});
							$(current_toolbar).removeClass("fullscreenHide");
							$(this).remove();
						}
					});
				})(overlayElement, this);

				$(this.getParent()).siblings("div.player-toolbar").hide().addClass("fullscreenHide");
				overlayElement.overlay().load();
				this.hide().pause();
				return false;
			},
			onKeyPress : function(key) {
				if (key == 27) {
					overlayElement.overlay().close();
				}
			}
		};

		if (($(this).attr("rel") != "undefined") && ($(this).attr("rel") != null)) {
			var rel = $(this).attr("rel").split("|");

			if (rel.length > 0) {
				defaults.clip.autoPlay = rel[0] == "1";

				if (rel.length > 1) {
					displayControls = parseInt(rel[1]);
				}
			}
		}

		var player = flowplayer(this, {src: "/res/inlines/flowplayer-3.1.5.swf", wmode: "opaque" }, defaults);

		if (displayControls > 0) {
			player.controls(toolbar, {autohide: (displayControls == 2)});
		} else {
			$(toolbar).addClass("autohide").hide();
		}
	});
});
$(window).bind('resize', function() {
	$("div.player-overlay").width($(window).width()-80);
	$("div.player-overlay").height($(window).height()-80);
});
$(document).ready(function() {
	$("div.swfobject").each(function(index) {
		var id = "__swf__"+index+"__";
		$(this).attr("id", id);
		swfobject.embedSWF($(this).attr("rel"), id, parseInt($(this).css("width")), parseInt($(this).css("height")), "9.0.0");
	});
});
