<?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(3,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: "JwpPlayer",
                live: true, 
                height: 300,
                provider: "rtmp"
            },
            { type: "Slider" },
            {
                type: "Controller",
                disable_annotate_btn: true
            },
<?php if ($protocol_level > 1): ?>
            {
                type: "Polemic"
<?php if ($protocol_level < 3): ?>
                ,
                polemics: []
<?php endif; ?>
            },
<?php endif; ?>
            {
                type: "MultiSegments"
            },
            { type: "Tweet" },
            { type: "Mediafragment"}
        ]
    };
    </script>
    <script type="text/javascript">
        var _gaq = _gaq || [];
        _gaq.push(['_setAccount', 'UA-23581291-1']);
        _gaq.push(['_trackPageview', location.pathname + location.search + location.hash]);
        _gaq.push(['_setAllowAnchor', true]);
      
        (function() {
            var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
            ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
            var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
        })();
    </script>
	<style type="text/css">
		body{
			padding:0px;
			margin:0px;
		}
    	#LdtPlayer {
    	    margin-bottom: 2px;
    	}
	</style>
	<script type="text/javascript">
		var _gaq = _gaq || [];
		_gaq.push(['_setAccount', 'UA-23581291-1']);
		_gaq.push(['_trackPageview', location.pathname + location.search + location.hash]);
		_gaq.push(['_setAllowAnchor', true]);
	  
		(function() {
		    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
		    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
		    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
		})();
	</script>
  </head>
  
        <div id="LdtPlayer"></div>
<script type="text/javascript">
    var _myPlayer = new IriSP.Metadataplayer(_config);
</script>
  </body>
</html>
