<script type="text/javascript">
    // Charge le player
    flowplayer("player", "<?php echo flash_path('flowplayer-3.1.2.swf') ?>",
               {
                   clip: {url: "<?php echo film_video_path($video['file']); ?>",
                          autoPlay: false,
                          autoBuffering: true,
                          onSeek: function() {
                              playerSeek();
                          }
                         },
                   plugins: {

                       content: {url: "<?php echo flash_path('flowplayer.content-3.1.0.swf') ?>",
                                 backgroundColor: 'transparent',
                                 display: 'none',
                                 style: {p: {fontSize: 15}}
                                }

                   },

                   onLoad: function() {
                       playerLoaded(this);
                   },

                   onUnload: function() {
                       playerUnloaded(this);
                   },
                   onError: function(code,msg) {
                       alert(msg);
                   }
               });


               function loadSegments() {

                   if ($f().getClip() == undefined) {
                       window.setTimeout("loadSegments()",2000);
                       return false;
                   }

                   var duration = Math.round($f().getClip().fullDuration*10) * 100;


                   var segments = tagTool.segments;

                   for (var seg in segments) {
                       var segd = parseInt(segments[seg]['out']) - parseInt(segments[seg]['in']);
                       var percent = Math.round(segd * 100 / duration);
                       var offset = Math.round(parseInt(segments[seg]['in']) * 100 / duration);
                       var c = $('#seg_container_template').clone().removeAttr("id");
                       $("#segments").append(c);
                       $("span", c).html('<strong>' + tagTool.segments[seg].tags.join(', ') +'</strong> par ' + segments[seg].user);
                       $("#seg_0", c).css({'margin-left': offset+'%', 'width': percent+'%'});
                       c.attr('id', 'seg_' + seg);


                       $(".segtimeline", c).each(function() {
                    	   var seg_id = seg;
                         $(this).click(function() {
                           tagTool.playSegment(seg_id, $("#pauseAfter").val());
                         });
                       });
                       c.show();
                   }
               }


               function playerSeek() {
                   tagTool.rebuildCurrentTags(tagTool.player.getTime() * 1000);
               }


               function playerLoaded(player) {
                   // Charge les tags
    				       $("#segmentMarkerButtons").css("opacity",1);
                   $("#btMarkIn").removeAttr("disabled");
                   $.getJSON("<?php echo url_for("@segmentListJson?film_slug={$film->getSlugUrl()}");?>", "", function(data) {
                       tagTool.segments = data;
                       tagTool.setupHandlers($f("player"));
                       window.setTimeout("loadSegments()", 2000);
                    });

                   tagTool.player = $f("player");
                   tagTool.showTagInPage = false;

               }
</script>
<div id="editor">
	<h1><?php

		echo $film->getTitle();
		// original title if exist

		if($film->getOriginalTitle()!= null)
		{
			echo " <span class=\"ost\">{".$film->getOriginalTitle()."}</span>";
		}
	?>
	<span class="film-infos">De <?php echo thd_render_flat_list($film->getDirectorsArray(), 'name'); ?></span></h1>
	<div class="section">
		<div id="player" class="player-ba"></div>
		<div id="segmentMarkerButtons" style="text-align:center;opacity:0.5">
			<button type="button" id="btMarkIn" class="submit" disabled onClick="segmentMarker.markIn()">Marquer le début</button>
			<button type="button" id="btMarkOut" class="submit" disabled onClick="segmentMarker.markOut()">Marquer la fin</button>
			<button type="button" id="btPlaySegment" class="submit" disabled onClick="segmentMarker.playSegment()">Lire la séquence</button>

		 <form action="<?php echo url_for("@editVideoSegment?film_slug={$film->getSlugUrl()}");?>" method="post" id="segment-add" style="display:none">
		    <h3>Enregistrer votre segment</h3>
		    <p>Vous aller créer un segment, entre <span id="mkin">0</span> secondes et <span id="mkout">0</span> secondes.</p>
		    <span style="text-align: center;">
		      <label>Vos tags</label>&nbsp;:&nbsp;<input type="text" name="tags" />
		      <input type="hidden" name="frmIn" id="frmIn" value="0" />
		      <input type="hidden" name="frmOut" id="frmOut" value="0" />
		      <input type="submit" value="Enregistrer" class="submit" />
		    </span>
		 </form>
		 </div>
	</div>
</div>
