<?php

/**
 * include some common code (like we did in the 90s)
 * People still do this? ;)
 */
$rep = $_REQUEST['rep'];
include_once dirname(__FILE__).'/'.$rep.'/config.php';
// configuration
include 'common.php';

// todo :
// - gestion du parent.document.location mediafragment
// - limite taille vertical embed
// - ajouter la polemic timline en dessous de la video

if (is_array($config['metadata'])) {
    if (array_key_exists("metadata",$_GET) && array_key_exists($_GET['metadata'], $config['metadata'])) {
        $metadata_url = $config['metadata'][$_GET['metadata']]['url'];
    } else {
        $keys = array_keys($config['metadata']);
        $metadata_url = $config['metadata'][$keys[0]]['url'];
    }
} else {
    $metadata_url = $config['metadata'];
}

$protocol_level = (
    isset($_REQUEST['protocol_level'])
    ? $_REQUEST['protocol_level']
    : (
        isset($config['protocol_level'])
        ? $config['protocol_level']
        : 3
    )
);

$protocol_level = min(4,max(0, $protocol_level));

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Polemic Tweet Embedded Player</title>
    <script type="text/javascript" src="<?php echo(registry_url('metadataplayer','js'));?>"></script>

    <script type="text/javascript">
    IriSP.libFiles.defaultDir = "<?php echo(registry_url('libdir','js'));?>";
    IriSP.widgetsDir = "<?php echo(registry_url('ldtwidgets','js'));?>";
    IriSP.libFiles.locations.jwPlayerSWF = "<?php echo(URL_ROOT); ?>res/mediaplayer/player.swf";
    IriSP.language = "<?php echo($actual) ?>";

    var _metadata = {
        url: '<?php echo get_metadata_url($metadata_url) ?>?callback=?',
        format: 'ldt'
    };
    var _config = {
        width: 630,
        container: 'LdtPlayer',
        default_options: {
            metadata: _metadata
        },
        css:'<?php echo(registry_url('metadataplayer','css'));?>',
        widgets: [
            {
                type: "AutoPlayer",
                height: 300,
                dailymotionPlayerId: "x10ckq"
            },
            { type: "Slider" },
            {
                type: "Controller",
                disable_annotate_btn: true
            },
<?php if ($protocol_level > 1): ?>
            {
                type: "Polemic"
<?php if ($protocol_level < 4): ?>
                ,
                polemics: []
<?php endif; ?>
            },
<?php endif; ?>
<?php if ($protocol_level > 1): ?>
            {
                type: "Polemic",
                annotation_type: ["chat"],
                defaultcolor: "#9b8864",
                default_version: "3",
                max_elements: "100"
<?php if ($protocol_level < 4): ?>
                ,
                polemics: []
<?php endif; ?>
            },
<?php endif; ?>
            {
                type: "MultiSegments"
            },
            { type: "Tweet" },
            { type: "Mediafragment"}
        ]
    };
    </script>
	<style type="text/css">
		body{
			padding:0px;
			margin:0px;
		}
    	#LdtPlayer {
    	    margin-bottom: 2px;
    	}
	</style>
  </head>

        <div id="LdtPlayer"></div>
<script type="text/javascript">
    var _myPlayer = new IriSP.Metadataplayer(_config);
</script>
  </body>
</html>
