<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<%@include file="/WEB-INF/jsp/includes.jsp"%>
<coeus:js src="/js/jwplayer6/jwplayer.js?2738" />
<coeus:js src="/js/jwplayer6/player.js?1" />
<coeus:js src="/js/plugins/jquery.swfobject.1-1-1.min.js" />
<div class="layout-wrap layout-video01">
	<div class="layout">
		<div class="video-view video-tview">
			<div class="video-play">
				<div id="mediaplayer"></div>
				<script type="text/javascript">
			    	$(function(){
				        var lastTime = 0;
				        var isOver = ${isOver};
                        var itemId = ${itemBo.itemId};
                        //$('.wscroll-pane').jScrollPane({animateScroll: true});
				        function onTimeCallback(param) {
				            var currentPosition = param.position;
				            currentPosition = Number(1000) * currentPosition;
				            //间隔60秒，之后存入数据库
				            var space = Number(currentPosition) - Number(lastTime);
				            var duration = parseInt(jwObj.getDuration()*1000);
				            if (Number(space)>60000) {
					            lastTime = currentPosition;
				                $.ajax( {
				                    type : "POST",
				                    url : CONTEXTPATH + "/study/updateDurationVideo.mooc",
				                    data : {
				                        itemId : itemId,
				                        isOver : 1,
				                        currentPosition : currentPosition,
                                        duration : duration
				                    },
				                    success : function(response) {
				                        //lastTime = response.lastTime;
				                    },
				                    error : function() {
				                    }
				                });
				            }
				        }

				        function onCompleteCallback(){
				        	var duration = jwObj.getDuration()*1000;
				        	$.ajax({
				                type : "POST",
				                url : CONTEXTPATH+"/study/updateDurationVideo.mooc",
				                dataType:"json",
				                data : {
				                    itemId : itemId,
				                    isOver : 2,
				                    duration : duration,
				                    currentPosition : duration
				                },
				                success : function(response) {
				                },
				                error : function() {

				                }
				            });
					    }

				        var width = $('#mediaplayer').css('width');
				        width = width.substring(0, width.indexOf('px'));
				        var height =  width*9/16;
			       		var allowseek = false;
			       		if (isOver==2){
							allowseek=true;
				       	}
				        var myDuration = ${myDuration};
				        var videoPic = '${itemBo.videoPic}';
				        var videoUrl = '${itemBo.videoFlvUrl}';
				        var options = {
		                            'onTimeCallback' : onTimeCallback,
		                            'autostart' : true,
		                            'defaultWidth' : width ,
		                            'defaultHeight' : height,
		                            'allowseek': allowseek,
		                            'seekTime':myDuration,
		                            'resourcePath':'${resourcePath}',
		                            'itemId':itemId,
		                            'logurl':true,
		                            'videoPic':videoPic,
		                            'videoUrl':videoUrl,
		                            'studyMode':true,
		                            'onCompleteCallback':onCompleteCallback
		                        };
				        initPlay('mediaplayer', options);
				    });
			    </script>
			</div>
		</div>
	</div>
</div>
