var cv;

$(document).ready(function() {

	$(".video-description").hide();
	$(".video-wrapper").each(function(i) {
		$(this).mouseenter(function() {
			$("#"+this.id+" .video-description").show();
		});
		$(this).mouseleave(function() {
			$("#"+this.id+" .video-description").hide();
		});
	});
	$("#latest").mouseenter(function() {
		$("#video1 .video-description").show();
	});
	$("#latest").mouseleave(function() {
		$("#video1 .video-description").hide();
	});
	
	$('#video-player').hide();
	$('#audio-player').hide();
	
	/*
	$("#button-lennert").mouseenter(function() {
		$("#home-background").css("background", "url('static/img/home-background-lennert.jpg') no-repeat");
	});
	$("#button-lennert").mouseleave(function() {
		$("#home-background").css("background", "url('static/img/home-background.jpg') no-repeat");
	});
	$("#button-lennert").click(function() {
		location.href = "./lennert/biography/";
	});
	$("#button-moritz").mouseenter(function() {
		$("#home-background").css("background", "url('static/img/home-background-moritz.jpg') no-repeat");
	});
	$("#button-moritz").mouseleave(function() {
		$("#home-background").css("background", "url('static/img/home-background.jpg') no-repeat");
	});
	$("#button-moritz").click(function() {
		location.href = "./moritz/biography/";
	});
	*/
	
});

function loadVideo(i) {
	cv = i;
	$.get("application/ajax/home-video.php",
	{ i: i },
	function(c){
		eval("c = "+c);
		playVideo(c.url+c.file, c.title, c.subtitle);
	});
}

function playVideo(file, title, subtitle) {
	var prev = 'true';
	if(cv == 0) {
		prev = '';
	}
	var next = 'true';
	if(cv == 3) {
		next = '';
	}
	$("#latest").hide();
	$('#video-player').show();
	$('#video-player').flash({
		swf: 'static/swf/VideoPlayer.swf',
		width: 970,
		height: 542,
		params: {
			wmode: "transparent",
			allowFullscreen: true
		},
		flashvars: {
			file: file,
			title: title,
			subtitle: subtitle,
			prev: prev,
			next: next
		}
	});
}

function actionscript(v) {
	if(v == "close" || v == "reachedend") {
		setTimeout("hideDelay()", 500);
	}
	if(v == "previous") {
		loadVideo(cv-1);
	}
	if(v == "next") {
		loadVideo(cv+1);
	}
}

function hideDelay() {
	$('#video-player').hide();
	$('#video-player').html("");
	$("#latest").show();
}
