
var plugin
var main

var updateTimeCodesInt
var controlsTimer
var checkMediaInt

var objsArr=new Array()
var _root_xmouse=0
var _root_ymouse=0
var fullsize = 0

var hoverbut = null
//window.onresize = resize;

function sessionOne(sender, url) {

    vid.stop()
	vid.AutoPlay="False"
    vid.Source = "http://download.microsoft.com/documents/uk/teched/berlin_3.wmv";
    vid.AutoPlay="True"
	document.getElementById("playbut1").src = "/resources/Content_Files/playing.gif";
	document.getElementById("playbut2").src = "/resources/Content_Files/playoff.gif";
	hoverbut = "one"

}

function sessionTwo(sender, url) {

    vid.stop()
	vid.AutoPlay="False"
    vid.Source = "http://download.microsoft.com/documents/uk/teched/bco-imagefilm-en-16-9.wmv";
    vid.AutoPlay="True"
	//document.getElementById("playbut2").src = "/resources/Content_Files/playing.gif";
	//document.getElementById("playbut1").src = "/resources/Content_Files/playoff.gif";
	hoverbut = "two"

}

function sessionLong(sender, url) 
{
    vid.stop()
	vid.AutoPlay="False"
    vid.Source = "http://download.microsoft.com/documents/uk/teched/MSTECHEDVSN2.wmv";
    vid.AutoPlay="True"
}
function sessionShort(sender, url) 
{
    vid.stop()
	vid.AutoPlay="False"
    vid.Source = "http://download.microsoft.com/documents/uk/teched/MSTECHEDSHORT.wmv";
    vid.AutoPlay="True"
}
function sessionPeter(sender, url) 
{
    vid.stop()
	vid.AutoPlay="False"
    vid.Source = "http://download.microsoft.com/documents/uk/teched/PETER_BRYANT.wmv";
    vid.AutoPlay="True"
}





function mainCanvasLoaded(s) {

	//alert("main loaded")
	
	main=s.findName("mainCanvas")
	main.opacity=0 //hide while resizing
	plugin = s.getHost()
	
	objsArr["Playhead"]=new Object()
	objsArr["Playhead"].el=s.findName("Playhead")
	
	objsArr["volumeSlider"]=new Object()
	objsArr["volumeSlider"].el=s.findName("volumeSlider")
	
	vid=main.findName("videoElement")
	dpcToken=vid.addEventListener("downloadProgressChanged", updateDownloadProgress)
	vid.addEventListener("bufferingProgressChanged", handleBufferProgressChanged)
	

//	var ph=main.findName("Playhead")
//	ph.addEventListener("mouseLeftButtonDown", PlayheadPress)
//	ph.addEventListener("mouseLeftButtonUp", PlayheadRelease)
//	ph.addEventListener("mouseEnter", PlayheadEnter)

	var lp=main.findName("LoadedPath")
	lp.addEventListener("mouseLeftButtonDown", progressBarPress)
	lp.addEventListener("mouseEnter", PlayheadEnter)	

    plugin.content.onfullScreenChange = onFullScreenChanged;
	
	togglePlayPauseBtn(s.findName("thePlayBtn"))
	
//	if (navigator.userAgent.indexOf("Firefox")!=-1){
//		s.findName("theFullBtn").opacity = 0	
//	}
	
	//plugin.content.onResize = resize	
	

}

function toggle_fullScreen(sender, args)
{
    var silverlightPlugin = sender.getHost();
    silverlightPlugin.content.fullScreen = !silverlightPlugin.content.fullScreen;  
   
}

function onFullScreenChanged(sender, args)
{
    var silverlightPlugin = sender.getHost();
    
    var mediaPlayer = sender.findName("videoElement");
    mediaPlayer.width = silverlightPlugin.content.actualWidth;
    mediaPlayer.height = silverlightPlugin.content.actualHeight;
    
	if (fullsize == 0){ 
		fullsize = 1
		resizefull() 
	} else { 
		fullsize = 0
		resize() 
	}
}


function updateDownloadProgress(s,e) {

	bgBar=s.findName("ToBeLoadedPath")
	progressBar=s.findName("LoadedPath")
	//window.status=s.downloadProgress
	progressBar.width = bgBar.width * s.downloadProgress
}



function handleBufferProgressChanged (s,e) {

	s.findName("bufferMsgText").Text="Buffering Video: "+Math.floor(s.bufferingProgress*100)+"%"
		
	if(s.bufferingProgress >0 && s.bufferingProgress <1) {
		s.findName("bufferMsg").opacity=0.8
	}
	else {
		s.findName("bufferMsg").opacity=0
	}
}


function mediaLoaded(s){ 

	//alert("mediaLoaded")	
	
	vid=s.findName("videoElement")
	resize()
	
	updateTimeCodesInt=setInterval("updateTimeCodes()", 100)
}


function mediaEnd(s){ 
	s.stop()
	togglePlayPauseBtn(s.findName("thePlayBtn"))
}


function mainCanvasMouseLeave(s) {

	objsArr["Playhead"].dragging=false
	clearInterval(objsArr["Playhead"].playHeadInt)
	clearInterval(mouseCheckerVolumeInt)
	s.releaseMouseCapture()
}


function whenMouseMoves(s,e) {

	var pt = e.getPosition(null);
	_root_xmouse = pt.x
	_root_ymouse = pt.y	
	
	s.findName("PlayControls").opacity = 1
	//clearTimeout ( controlsTimer );
	//controlsTimer = setTimeout("setControlsInvisible()",1000)
}


function setControlsInvisible() {
	//clearTimeout ( controlsTimer );
	//alert(plugin.content.actualWidth);
	//if(_root_ymouse<plugin.content.actualHeight || _root_ymouse<plugin.content.actualWidth) {
		//main.findName("PlayControls").opacity = 0
	//}
}


