#!/usr/bin/perl

use strict;
use utf8;

require Encode;

# tiedoston mediaarkisto.pm kansio
use lib '../noweb';
use mediaarkisto ();

use CGI;

my $SEARCH_LOCALE = 'fi_FI.UTF-8';
my $VIDEO_PATH = '/albumi/file/video/';

$CGI::POST_MAX = 1024;     # max 1K posts
$CGI::DISABLE_UPLOADS = 1; # no uploads

#chdir('../file') || exit 1;
&main;
exit 0;

sub main()
{
	my $q = new CGI;

	binmode(*STDOUT, ':utf8');
	print $q->header(-type => 'text/html; charset=utf-8');
	return if (&CGI::request_method eq 'HEAD');

	my $file = $q->param('f');
	my $options = $q->param('o');
	utf8::decode($file);

	my $file2 = $file;
	$file2 =~ s{/.*}{};
	my @o = split(/x/,$options,2);
	$options = '"' . $o[0] . '","' . ($o[1] + 20) . '"';

	print '<html><head><title>FLV-video: ', $file, '</title>', "\n",
	'<script type="text/javascript" src="flv/swfobject.js"></script>', "\n",
	'</head><body>', "\n",
	'<noscript><p>Javascript tuki ei ole päällä, joten videon näyttö ',
	'ei toimi. Flash player:n testaus vaatii javascipt ',
	'tuen.</p></noscript>', "\n",
	'<p id="player"><a href="http://www.adobe.com/go/BONRN">Flash ',
	'Player</a> puuttuu.</p>', "\n";

	print '<script type="text/javascript">',"\n",
		'var s1 = new SWFObject("flv/flvplayer.swf","single",',
			$options, ',"7");', "\n",
		's1.addVariable("file","', $VIDEO_PATH, $file, '");', "\n",
		's1.addVariable("image","', $VIDEO_PATH, $file2, '/.thumb.jpg");', "\n",
		's1.addParam("allowfullscreen","true");', "\n",
		's1.write("player");', "\n",
		'</script>', "\n";

	print '</body></html>', "\n";
}
