//----------------------------------------------------------
// Copyright (C) Microsoft Corporation. All rights reserved.
//----------------------------------------------------------
// PreviewMedia.js
Type.registerNamespace("Sys.Preview.UI.Xaml");Sys.Preview.UI.Xaml.scriptVersion="0.1.070416.1";Sys.Preview.UI.Xaml.PlayerElementName={videoWindow:"VideoWindow",playerControls:"PlayerControls",playButton:"PlayButton",playPauseButton:"PlayPauseButton",playSymbol:"PlaySymbol",pauseSymbol:"PauseSymbol",stopButton:"StopButton",pauseButton:"PauseButton",nextButton:"NextButton",previousButton:"PreviousButton",muteButton:"MuteButton",muteOnSymbol:"MuteOnSymbol",muteOffSymbol:"MuteOffSymbol",timeSlider:"TimeSlider",timeThumb:"TimeThumb",timeCompleted:"TimeCompleted",volumeSlider:"VolumeSlider",volumeThumb:"VolumeThumb",volumeLevel:"VolumeLevel",volumeUpButton:"VolumeUpButton",volumeDownButton:"VolumeDownButton",totalTimeText:"TotalTimeText",currentTimeText:"CurrentTimeText",downloadSlider:"DownloadProgressSlider",downloadText:"DownloadProgressText",fullScreenButton:"FullScreenButton",chapterArea:"ChapterArea",chapterScroll:"ChapterScroll",chapterPrev:"ChapterScrollPrevious",chapterNext:"ChapterScrollNext",chapterItem:"ChapterScrollItem",captionText:"CaptionText",captionArea:"CaptionArea"};Sys.Preview.UI.Xaml.Visibility=function(){throw Error.notImplemented()};Sys.Preview.UI.Xaml.Visibility.prototype={visible:0,collapsed:1};Sys.Preview.UI.Xaml.Visibility.registerEnum("Sys.Preview.UI.Xaml.Visibility");Sys.Preview.UI.Xaml.Control=function(a){Sys.Preview.UI.Xaml.Control.initializeBase(this,[a])};Sys.Preview.UI.Xaml.Control.prototype={add_xamlError:function(a){this.get_events().addHandler("xamlError",a)},remove_xamlError:function(a){this.get_events().removeHandler("xamlError",a)},add_xamlInitialized:function(a){this.get_events().addHandler("xamlInitialized",a)},remove_xamlInitialized:function(a){this.get_events().removeHandler("xamlInitialized",a)},get_actualHeight:function(){var a=this.get_element();return a&&a.content?a.content.ActualHeight:0},get_actualWidth:function(){var a=this.get_element();return a&&a.content?a.content.ActualWidth:0},get_isFullScreen:function(){var a=this.get_element();return a&&a.content?a.content.FullScreen:false},set_isFullScreen:function(b){var a=this.get_element();if(a&&a.content)a.content.FullScreen=b},get_minimumSilverlightVersion:function(){return this._minimumVersion||"0.9"},set_minimumSilverlightVersion:function(a){if(!a.match(/^\d+\.\d+$/))throw Error.argument("minimumSilverlightVersion",Sys.Preview.XamlRes.Xaml_SilverlightVersionFormat);this._minimumVersion=a},get_rootElement:function(){return this._rootElement||null},set_rootElement:function(a){this._rootElement=a},get_xamlSource:function(){return this._xamlSource||""},set_xamlSource:function(a){this._xamlSource=a},initialize:function(){Sys.Preview.UI.Xaml.Control.callBaseMethod(this,"initialize");if(this._ensureVersion()){var e=this.get_element(),d="Sys$Preview$UI$Xaml$Control$GlobalXamlError_"+this.get_id();window[d]=Function.createDelegate(this,this._xamlError);var b=Sys.UI.DomElement.getElementById(this.get_id()+"_source",this.get_element()),a=this.get_xamlSource();if(a&&b&&a!==b.value){var c="Sys$Preview$UI$Xaml$Control$GlobalXamlLoaded_"+this.get_id();window[c]=Function.createDelegate(this,this._xamlLoaded);e.Source=a}else this._raiseXamlInitialize()}},onXamlError:function(){},toggleFullScreen:function(){this.set_isFullScreen(!this.get_isFullScreen());return this.get_isFullScreen()},xamlInitialize:function(){},_ensureVersion:function(){if(!this._isMinimumVersion()){this._needToUpgrade(this.get_minimumSilverlightVersion());return false}else return true},_getInlineInstall:function(b){var a=document.createElement("div");a.innerHTML=String.format(Sys.Preview.XamlRes.Xaml_InlineInstallHtml,b);return a},_getLinkedInstall:function(d){var c=document.createElement("div"),b,a;if(d){b="http://go.microsoft.com/fwlink/?LinkID=88363";a="http://go.microsoft.com/fwlink/?LinkID=88365"}else{b="http://go.microsoft.com/fwlink/?LinkID=86009";a="http://go.microsoft.com/fwlink/?LinkID=87023"}c.innerHTML=String.format(Sys.Preview.XamlRes.Xaml_LinkedInstallHtml,b,a);return c},_isMinimumVersion:function(){var e=this.get_element().settings,f=e?e.version||"":"",d=this.get_minimumSilverlightVersion();if(!d)return true;if(!f)return false;var b=d.split("."),c=f.split(".");if(c.length<b.length)return false;for(var a=0,i=b.length;a<i;a++){var h=parseInt(c[a]),g=parseInt(b[a]);if(h>g)return true;else if(h<g)return false}return true},_needToUpgrade:function(e){var c=this.get_element(),a,d=e==="0.95";if(d||!Sys.Browser.supportsSilverlight)a=this._getLinkedInstall(d);else{var f,b=navigator.userAgent;if(b.indexOf("Windows")!==-1)a=this._getInlineInstall("http://go.microsoft.com/fwlink/?LinkID=86008");else if(b.indexOf("PPC Mac OS X")!==-1)replacemenetElement=this._getInlineInstall("http://go.microsoft.com/fwlink/?LinkID=87380");else if(b.indexOf("Intel Mac OS X")!==-1)replacemenetElement=this._getInlineInstall("http://go.microsoft.com/fwlink/?LinkID=87384");else a=this._getLinkedInstall(false)}a.id=c.id;this._replacePlugin(c,a)},_raiseXamlError:function(b){this.onXamlError(b);if(!b.get_cancel()){var i=this.get_events().getHandler("xamlError");if(i)i(this,b);if(!b.get_cancel()){var a=b.get_error(),g=a.errorType,k=a.errorCode,j=a.errorMessage,l=this.get_id(),e="",d="",h="",f="",c=Sys.Preview.XamlRes.Xaml_OtherError;if(g==="ParserError"){c=Sys.Preview.XamlRes.Xaml_ParserError;e=a.lineNumber;d=a.charPosition;h=a.xamlFile}else if(g==="RuntimeError")if(a.lineNumber){c=Sys.Preview.XamlRes.Xaml_RuntimeErrorWithPosition;e=a.lineNumber;d=a.charPosition;f=a.methodName}else{c=Sys.Preview.XamlRes.Xaml_RuntimeErrorWithoutPosition;f=a.methodName}throw Error.invalidOperation(String.format(c,l,g,k,j,e,d,f,h))}}},_raiseXamlInitialize:function(){if(!this.get_rootElement())throw Error.invalidOperation(Sys.Preview.XamlRes.Xaml_RequiresRootElement);this.xamlInitialize();var a=this.get_events().getHandler("xamlInitialized");if(a)a(this,Sys.EventArgs.Empty)},_replacePlugin:function(b,a){var c=Sys.UI.DomElement._getCurrentStyle(b);a.style.width=c.width;a.style.height=c.height;a.style.display="";var d=b.parentNode;d.insertBefore(a,b);d.removeChild(b);this._element=a},_xamlError:function(b,a){if(this._disposed)return;this._raiseXamlError(new Sys.Preview.UI.Xaml.ErrorEventArgs(a))},_xamlLoaded:function(a){if(this._isXamlLoaded||this._disposed)return;this._isXamlLoaded=true;this._rootElement=a;this._raiseXamlInitialize()},dispose:function(){this._disposed=true;delete this._designer;this._rootElement=null;Sys.Preview.UI.Xaml.Control.callBaseMethod(this,"dispose")}};Sys.Preview.UI.Xaml.Control.registerClass("Sys.Preview.UI.Xaml.Control",Sys.UI.Control);if(Sys.Browser.agent===Sys.Browser.InternetExplorer)Sys.Browser.supportsSilverlight=Sys.Browser.version>=6&&navigator.userAgent.indexOf("Win64")===-1;else if(Sys.Browser.agent===Sys.Browser.Firefox)Sys.Browser.supportsSilverlight=Sys.Browser.version>=1.5;else if(Sys.Browser.agent===Sys.Browser.Safari)Sys.Browser.supportsSilverlight=true;else Sys.Browser.supportsSilverlight=false;Sys.Preview.UI.Xaml.Point=function(a,b){this.x=a;this.y=b};Sys.Preview.UI.Xaml.Point.registerClass("Sys.Preview.UI.Xaml.Point");Sys.Preview.UI.Xaml.Bounds=function(c,d,b,a){this.x=c;this.y=d;this.height=a;this.width=b};Sys.Preview.UI.Xaml.Bounds.registerClass("Sys.Preview.UI.Xaml.Bounds");Sys.Preview.UI.Xaml.Scale=function(a,b){this.horizontal=a||1;this.vertical=b||1};Sys.Preview.UI.Xaml.Scale.registerClass("Sys.Preview.UI.Xaml.Scale");Sys.Preview.UI.Xaml.DomElement=function(b,a,d,c){this._host=b;this._control=b.content.findName(a);this._nameElement=a;if(this._control){Sys.Preview.UI.Xaml.DomElement.addHandlers(this._control,{"mouseEnter":this._domElementMouseEnter,"mouseLeave":this._domElementMouseLeave},this);this._animFocusIn=b.content.findName(a+"_FocusInAnimation");this._animFocusOut=b.content.findName(a+"_FocusOutAnimation");if(!this._animFocusIn&&!this._animFocusOut&&typeof d==="number"&&typeof c==="number"){this._animFocusIn=Sys.Preview.UI.Xaml.DomElement.createDoubleAnimation(b,a,"Storyboard.TargetProperty='opacity' From='"+c+"' To='"+d+"' Duration='0:0:0.4'");this._animFocusOut=Sys.Preview.UI.Xaml.DomElement.createDoubleAnimation(b,a,"Storyboard.TargetProperty='opacity' From='"+d+"' To='"+c+"' Duration='0:0:0.4'");this._control.opacity=c}if(this._animFocusOut)this._animFocusOut.begin();this._timeLastLeftButtonUp=(new Date).getTime()}};Sys.Preview.UI.Xaml.DomElement.prototype={add_disposing:function(a){this.get_events().addHandler("disposing",a)},remove_disposing:function(a){this.get_events().removeHandler("disposing",a)},get_bounds:function(){return new Sys.Preview.UI.Xaml.Bounds(this.get_left(),this.get_top(),this.get_width(),this.get_height())},set_bounds:function(a){if(this._control){this._control["Canvas.Left"]=a.x;this._control["Canvas.Top"]=a.y;this._control.width=a.width;this._control.height=a.height}},get_control:function(){return this._control},get_events:function(){if(!this._events)this._events=new Sys.EventHandlerList;return this._events},get_height:function(){return this._control?this._control.height:0},set_height:function(a){if(this._control)this._control.height=a},get_left:function(){return this._control?this._control["Canvas.Left"]:0},set_left:function(a){if(this._control)this._control["Canvas.Left"]=a},get_opacity:function(){return this._control?this._control.opacity:0},set_opacity:function(a){if(this._control)this._control.opacity=a},get_top:function(){return this._control?this._control["Canvas.Top"]:0},set_top:function(a){if(this._control)this._control["Canvas.Top"]=a},get_visibility:function(){if(!this._control)return Sys.Preview.UI.Xaml.Visibility.collapsed;return this._control.Visibility===0?Sys.Preview.UI.Xaml.Visibility.visible:Sys.Preview.UI.Xaml.Visibility.collapsed},set_visibility:function(a){if(this._control)this._control.Visibility=a},get_width:function(){return this._control?this._control.width:0},set_width:function(a){if(this._control)this._control.width=a},get_host:function(){return this._host},_domElementMouseEnter:function(){if(this._animFocusIn)this._animFocusIn.begin()},_domElementMouseLeave:function(){if(this._animFocusOut)this._animFocusOut.begin()},dispose:function(){if(this._events){var a=this._events.getHandler("disposing");if(a)a(this,Sys.EventArgs.Empty)}if(this._control){delete this._events;Sys.Preview.UI.Xaml.DomElement.clearHandlers(this._control);this._control=null;this._host=null;this._animFocusIn=null;this._animFocusOut=null}}};Sys.Preview.UI.Xaml.DomElement.registerClass("Sys.Preview.UI.Xaml.DomElement",null,Sys.IDisposable);Sys.Preview.UI.Xaml.DomElement.getLocation=function(a){var d=a["Canvas.Left"],e=a["Canvas.Top"],c=a.getParent();if(c){var b=Sys.Preview.UI.Xaml.DomElement.getLocation(c);return new Sys.Preview.UI.Xaml.Point(b.x+d,b.y+e)}return new Sys.Preview.UI.Xaml.Point(d,e)};Sys.Preview.UI.Xaml.DomElement._uniqueElementNameIndex=0;Sys.Preview.UI.Xaml.DomElement.getUniqueName=function(a){return a+Sys.Preview.UI.Xaml.DomElement._uniqueElementNameIndex++};Sys.Preview.UI.Xaml.DomElement.computeScale=function(a){var c=a.width,b=a.height;if(!c||!b)return new Sys.Preview.UI.Xaml.Scale(1,1);var d=a.getHost(),e=d.content.ActualWidth/c,f=d.content.ActualHeight/b;return new Sys.Preview.UI.Xaml.Scale(e,f)};Sys.Preview.UI.Xaml.DomElement.createDoubleAnimation=function(d,a,e){var c=d.content.findName(a);if(!c)throw Error.invalidOperation("Could not find an element with the name '"+a+"'.");var f="<Storyboard xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'><DoubleAnimation Storyboard.TargetName='"+a+"' "+e+" /></Storyboard>",b=d.content.createFromXaml(f);c.Resources.add(b);return b};Sys.Preview.UI.Xaml.DomElement._hostStorage=[];Sys.Preview.UI.Xaml.DomElement._hostStorageIndex=0;Sys.Preview.UI.Xaml.DomElement._getHostStorage=function(d,f){var a=Sys.Preview.UI.Xaml.DomElement._hostStorage;for(var b=0,g=a.length;b<g;b++){var e=a[b];if(d===e.host)return e}if(!f)return null;var c={host:d,hostNumber:Sys.Preview.UI.Xaml.DomElement._hostStorageIndex++,elementStorageCount:0};a[a.length]=c;return c};Sys.Preview.UI.Xaml.DomElement._getElementStorage=function(e,c){var f=e.getHost(),d=e.name,a=Sys.Preview.UI.Xaml.DomElement._getHostStorage(f,c);if(!a)return null;if(!a.elementStorageDictionary){if(!c)return null;a.elementStorageDictionary={}}var b=a.elementStorageDictionary[d];if(!b){if(!c)return null;b=a.elementStorageDictionary[d]={hostStorage:a,elementName:d,eventCount:0,eventCacheDictionary:{}};a.elementStorageCount++}return b};var $xamlAddHandler=Sys.Preview.UI.Xaml.DomElement.addHandler=function(d,b,f){var c=Sys.Preview.UI.Xaml.DomElement._getElementStorage(d,true),e=c.eventCacheDictionary,a=e[b];if(!a){a=e[b]=[];c.eventCount++}a[a.length]=f;d.addEventListener(b,f)},$xamlRemoveHandler=Sys.Preview.UI.Xaml.DomElement.removeHandler=function(e,d,g){var a=Sys.Preview.UI.Xaml.DomElement._getElementStorage(e,false);if(!a)throw Error.invalidOperation(Sys.Res.eventHandlerInvalid);var f=a.eventCacheDictionary,c=f[d];if(!c)throw Error.invalidOperation(Sys.Res.eventHandlerInvalid);Array.remove(c,g);e.removeEventListener(d,g);if(c.length===0){delete f[d];a.eventCount--;if(a.eventCount<=0){var b=a.hostStorage;delete a.hostStorage;delete a.eventCache;delete b.elementStorageDictionary[a.elementName];b.elementStorageCount--;if(b.elementStorageCount===0)Array.remove(Sys.Preview.UI.Xaml.DomElement._hostStorage,b)}}},$xamlAddHandlers=Sys.Preview.UI.Xaml.DomElement.addHandlers=function(e,d,c){for(var b in d){var a=d[b];if(c)a=Function.createDelegate(c,a);Sys.Preview.UI.Xaml.DomElement.addHandler(e,b,a)}},$xamlClearHandlers=Sys.Preview.UI.Xaml.DomElement.clearHandlers=function(e){var d=Sys.Preview.UI.Xaml.DomElement._getElementStorage(e,false);if(!d)return;var f=d.eventCacheDictionary;for(var a in f){var g=f[a],c=Array.clone(g);for(var b=0,h=c.length;b<h;b++)Sys.Preview.UI.Xaml.DomElement.removeHandler(e,a,c[b])}};Sys.Preview.UI.Xaml._Button=function(c,a,g,f,h,e){Sys.Preview.UI.Xaml._Button.initializeBase(this,[c,a,g,f]);var b=this.get_control();if(b){Sys.Preview.UI.Xaml.DomElement.addHandlers(b,{"mouseLeave":this._buttonMouseLeave,"mouseLeftButtonDown":this._buttonLeftButtonDown,"mouseLeftButtonUp":this._buttonLeftButtonUp},this);this._depress=!!h;this._repeatInterval=e||0;b.cursor="Hand";this._animPress=c.content.findName(a+"_PressAnimation");this._animDepress=c.content.findName(a+"_DepressAnimation");if(this._depress){if(!this._animPress){this._ensureTransform();var d="<Storyboard>"+"<DoubleAnimationUsingKeyFrames Storyboard.TargetName='"+a+"' Storyboard.TargetProperty='(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)'>"+"<SplineDoubleKeyFrame KeyTime='00:00:00.1000000' Value='1'/>"+"</DoubleAnimationUsingKeyFrames>"+"<DoubleAnimationUsingKeyFrames Storyboard.TargetName='"+a+"' Storyboard.TargetProperty='(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.Y)'>"+"<SplineDoubleKeyFrame KeyTime='00:00:00.1000000' Value='1'/>"+"</DoubleAnimationUsingKeyFrames>"+"</Storyboard>";this._animPress=c.content.createFromXaml(d);b.Resources.add(this._animPress)}if(!this._animDepress){this._ensureTransform();var d="<Storyboard>"+"<DoubleAnimationUsingKeyFrames Storyboard.TargetName='"+a+"' Storyboard.TargetProperty='(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)'>"+"<SplineDoubleKeyFrame KeyTime='00:00:00.1000000' Value='0'/>"+"</DoubleAnimationUsingKeyFrames>"+"<DoubleAnimationUsingKeyFrames Storyboard.TargetName='"+a+"' Storyboard.TargetProperty='(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.Y)'>"+"<SplineDoubleKeyFrame KeyTime='00:00:00.1000000' Value='0'/>"+"</DoubleAnimationUsingKeyFrames>"+"</Storyboard>";this._animDepress=c.content.createFromXaml(d);b.Resources.add(this._animDepress)}}}};Sys.Preview.UI.Xaml._Button.prototype={add_click:function(a){this.get_events().addHandler("click",a)},remove_click:function(a){this.get_events().removeHandler("click",a)},add_doubleClick:function(a){this.get_events().addHandler("doubleClick",a)},remove_doubleClick:function(a){this.get_events().removeHandler("doubleClick",a)},_buttonMouseLeave:function(){if(this._down){this._down=false;this._playDepress()}if(this._idTimer){window.clearTimeout(this._idTimer);delete this._idTimer}},_buttonLeftButtonDown:function(){this._down=true;this._playPress();if(this._repeatInterval){var c=this;if(!this._idTimer){this._raiseClick(Sys.EventArgs.Empty);this._repeatClickDelegate=Function.createDelegate(this,this._repeatClick);this._idTimer=window.setTimeout(this._repeatClickDelegate,this._repeatInterval)}}},_buttonLeftButtonUp:function(){this._down=false;this._playDepress();var b=(new Date).getTime(),a=false;if(this._timeLastLeftButtonUp){a=b-this._timeLastLeftButtonUp<300;this._timeLastLeftButtonUp=0}else this._timeLastLeftButtonUp=b;if(this._idTimer){window.clearTimeout(this._idTimer);delete this._idTimer;delete this._repeatClickDelegate}else if(a)this._raiseDoubleClick(Sys.EventArgs.Empty);else this._raiseClick(Sys.EventArgs.Empty)},_ensureTransform:function(){var a=this.get_control();if(!a.RenderTransform){var b="<Canvas.RenderTransform>"+"<TransformGroup>"+"<ScaleTransform ScaleX='1' ScaleY='1' CenterX='"+a.width/2+"' CenterY='"+a.height/2+"'/>"+"<SkewTransform AngleX='0' AngleY='0'/>"+"<RotateTransform Angle='0' CenterX='"+a.width/2+"' CenterY='"+a.height/2+"'/>"+"<TranslateTransform X='0' Y='0'/>"+"</TransformGroup>"+"</Canvas.RenderTransform>";a.RenderTransform=this.get_host().content.createFromXaml(b)}},onClick:function(){},onDoubleClick:function(){},_raiseClick:function(b){this.onClick(b);var a=this.get_events().getHandler("click");if(a)a(this,b)},_raiseDoubleClick:function(b){this.onDoubleClick(b);var a=this.get_events().getHandler("doubleClick");if(a)a(this,b)},_playPress:function(){if(this._animPress)this._animPress.begin()},_playDepress:function(){if(this._animDepress)this._animDepress.begin()},_repeatClick:function(){this._idTimer=window.setTimeout(this._repeatClickDelegate,this._repeatInterval);this._raiseClick(Sys.EventArgs.Empty)},dispose:function(){if(this._idTimer){window.clearTimeout(this._idTimer);delete this._idTimer}this._animPress=null;this._animDepress=null;var a=this.get_control();if(a)Sys.Preview.UI.Xaml.DomElement.clearHandlers(a);Sys.Preview.UI.Xaml._Button.callBaseMethod(this,"dispose")}};Sys.Preview.UI.Xaml._Button.registerClass("Sys.Preview.UI.Xaml._Button",Sys.Preview.UI.Xaml.DomElement);Sys.Preview.UI.Xaml._MediaElement=function(c,d,b,f,e){Sys.Preview.UI.Xaml._MediaElement.initializeBase(this,[c,d,f,e]);var a=this.get_control();if(!a)return;a.AutoPlay=false;Sys.Preview.UI.Xaml.DomElement.addHandlers(a,{"mouseLeftButtonUp":this._veLeftButtonUp,"mediaOpened":this._mediaOpened,"mediaFailed":this._mediaFailed,"mediaEnded":this._mediaEnded,"downloadProgressChanged":this._downloadProgress,"markerReached":this._markerReached},this);if(b){this._namePlaceholder=Sys.Preview.UI.Xaml.DomElement.getUniqueName("PlaceholderImage");var g="<Image xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' IsHitTestVisible='false' x:Name='"+this._namePlaceholder+"' Source='"+encodeURI(b)+"' Canvas.Left='"+this.get_left()+"' Canvas.Top='"+this.get_top()+"' Width='"+this.get_width()+"' Height='"+this.get_height()+"'/>";a.getParent().children.add(c.content.createFromXaml(g))}};Sys.Preview.UI.Xaml._MediaElement.prototype={add_click:function(a){this.get_events().addHandler("click",a)},remove_click:function(a){this.get_events().removeHandler("click",a)},add_doubleClick:function(a){this.get_events().addHandler("doubleClick",a)},remove_doubleClick:function(a){this.get_events().removeHandler("doubleClick",a)},add_downloadProgress:function(a){this.get_events().addHandler("downloadProgress",a)},remove_downloadProgress:function(a){this.get_events().removeHandler("downloadProgress",a)},add_markerReached:function(a){this.get_events().addHandler("markerReached",a)},remove_markerReached:function(a){this.get_events().removeHandler("markerReached",a)},add_mediaEnded:function(a){this.get_events().addHandler("mediaEnded",a)},remove_mediaEnded:function(a){this.get_events().removeHandler("mediaEnded",a)},add_mediaFailed:function(a){this.get_events().addHandler("mediaFailed",a)},remove_mediaFailed:function(a){this.get_events().removeHandler("mediaFailed",a)},add_mediaOpened:function(a){this.get_events().addHandler("mediaOpened",a)},remove_mediaOpened:function(a){this.get_events().removeHandler("mediaOpened",a)},get_downloadProgress:function(){return this._downloadProgress||0},get_mediaMarkers:function(){if(!this._markers){this._markers=[];var a=this.get_control();if(a)for(var b=0,c=a.Markers.Count;b<c;b++)Array.add(this._markers,new Sys.Preview.UI.Xaml.MediaMarker(a.Markers.getItem(b)))}return this._markers},get_mediaUrl:function(){return this.get_control().Source},set_mediaUrl:function(a){this.get_control().Source=a},get_muted:function(){return !!this.get_control().IsMuted},set_muted:function(a){this.get_control().IsMuted=a?1:0},get_naturalDuration:function(){try{return this.get_control().naturalduration.seconds}catch(a){return 0}},get_playState:function(){return this.get_control().CurrentState},get_timeIndex:function(){return this.get_control().position.seconds},set_timeIndex:function(b){var a=this.get_control().position;a.seconds=b;this.get_control().position=a},get_volume:function(){return this.get_control().volume},set_volume:function(a){vol=Math.min(1,Math.max(0,a));this.get_control().volume=a},pause:function(){this.get_control().pause()},play:function(){this.get_control().play()},stop:function(){this.get_control().stop()},_downloadProgress:function(){this._downloadProgress=this.get_control().downloadProgress;this._raiseEvent("downloadProgress",Sys.EventArgs.Empty)},_markerReached:function(b,a){this._raiseEvent("markerReached",new Sys.Preview.UI.Xaml.MarkerEventArgs(new Sys.Preview.UI.Xaml.MediaMarker(a.marker)))},_mediaEnded:function(){this._raiseEvent("mediaEnded",Sys.EventArgs.Empty)},_mediaFailed:function(){this._raiseEvent("mediaFailed",Sys.EventArgs.Empty)},_mediaOpened:function(){this._markers=null;if(this._namePlaceholder){var a=Sys.Preview.UI.Xaml.DomElement.createDoubleAnimation(this.get_host(),this._namePlaceholder,"Storyboard.TargetProperty='opacity' To='0.0' From='1.0' Duration='0:0:0.5'");a.begin();delete this._namePlaceholder}this._raiseEvent("mediaOpened",Sys.EventArgs.Empty)},_raiseEvent:function(c,b){var a=this.get_events().getHandler(c);if(a)a(this,b)},_veLeftButtonUp:function(){var b=(new Date).getTime(),a=false;if(this._timeLastLeftButtonUp)a=b-this._timeLastLeftButtonUp<300;this._timeLastLeftButtonUp=b;if(a)this._raiseEvent("doubleClick",Sys.EventArgs.Empty);else this._raiseEvent("click",Sys.EventArgs.Empty)},dispose:function(){var a=this.get_control();if(a)Sys.Preview.UI.Xaml.DomElement.clearHandlers(a);Sys.Preview.UI.Xaml._MediaElement.callBaseMethod(this,"dispose")}};Sys.Preview.UI.Xaml._MediaElement.registerClass("Sys.Preview.UI.Xaml._MediaElement",Sys.Preview.UI.Xaml.DomElement);Sys.Preview.UI.Xaml.MediaMarker=function(a){this._type=a.type;this._text=a.text;this._timeIndex=a.time.seconds};Sys.Preview.UI.Xaml.MediaMarker.prototype={get_type:function(){return this._type||""},get_text:function(){return this._text||""},get_timeIndex:function(){return this._timeIndex||0}};Sys.Preview.UI.Xaml.MediaMarker.registerClass("Sys.Preview.UI.Xaml.MediaMarker",null);Sys.Preview.UI.Xaml.BasePlayer=function(a){Sys.Preview.UI.Xaml.BasePlayer.initializeBase(this,[a])};Sys.Preview.UI.Xaml.BasePlayer.prototype={_chapters:null,_autoPlay:false,_enableChapters:true,_chaptersActive:false,_duration:0,_loopCount:1,_start:0,_autoScale:true,_placeholderImage:null,_dirtyChapterCache:true,_lastChapterStarted:-1,add_chapterStarted:function(a){this.get_events().addHandler("chapterStarted",a)},remove_chapterStarted:function(a){this.get_events().removeHandler("chapterStarted",a)},add_markerReached:function(a){this.get_events().addHandler("markerReached",a)},remove_markerReached:function(a){this.get_events().removeHandler("markerReached",a)},add_mediaEnded:function(a){this.get_events().addHandler("mediaEnded",a)},remove_mediaEnded:function(a){this.get_events().removeHandler("mediaEnded",a)},add_mediaFailed:function(a){this.get_events().addHandler("mediaFailed",a)},remove_mediaFailed:function(a){this.get_events().removeHandler("mediaFailed",a)},add_mediaOpened:function(a){this.get_events().addHandler("mediaOpened",a)},remove_mediaOpened:function(a){this.get_events().removeHandler("mediaOpened",a)},add_sizeChanged:function(a){this.get_events().addHandler("sizeChanged",a)},remove_sizeChanged:function(a){this.get_events().removeHandler("sizeChanged",a)},add_stateChanged:function(a){this.get_events().addHandler("stateChanged",a)},remove_stateChanged:function(a){this.get_events().removeHandler("stateChanged",a)},add_volumeChanged:function(a){this.get_events().addHandler("volumeChanged",a)},remove_volumeChanged:function(a){this.get_events().removeHandler("volumeChanged",a)},get_autoPlay:function(){return this._autoPlay},set_autoPlay:function(a){this._autoPlay=a},get_autoScale:function(){return this._autoScale},set_autoScale:function(a){this._autoScale=a},get_caption:function(){if(this.captionArea&&this.captionArea.get_visibility()!==Sys.Preview.UI.Xaml.Visibility.collapsed)return this.captionArea.get_text();return ""},set_caption:function(a){if(this.captionArea){a=a.trim();if(a)this.captionArea.set_visibility(Sys.Preview.UI.Xaml.Visibility.visible);else this.captionArea.set_visibility(Sys.Preview.UI.Xaml.Visibility.collapsed);this.captionArea.set_text(a)}},get_chapterAreaOpacityOn:function(){return 0.8},get_chapterAreaOpacityOff:function(){return 0},get_chapterItemOpacityOn:function(){return 1},get_chapterItemOpacityOff:function(){return 0.7},get_chapters:function(){return this._chapters},set_chapters:function(a){this._chapters=a;if(this.chapterArea){this._ensureChapterArea();this.chapterArea.setChapters(a)}},get_currentChapter:function(){if(this._dirtyChapterCache){this._calculateCurrentChapter();this._detectChapterChanged(this.get_timeIndex())}return this._currentChapterIndex},set_currentChapter:function(a){var b=this.get_chapters();if(!b||a<0||a>=b.length)throw Error.argumentOutOfRange("currentChapter",a,Sys.Preview.MediaRes.Media_InvalidChapterIndex);var c=b[a].time;if(c!==-1){this.set_timeIndex(c);this._dirtyChapterCache=true;this._detectChapterChanged(c)}},get_duration:function(){return this._duration},set_duration:function(a){this._duration=a;this._timeEnd=a===0?0:this.get_startTime()+a},get_enableCaptions:function(){return this._enableCaptions||true},set_enableCaptions:function(a){this._enableCaptions=a},get_enableChapters:function(){return this._enableChapters},set_enableChapters:function(a){this._enableChapters=a;if(this.chapterArea)this._ensureChapterArea()},get_loopCount:function(){return this._loopCount},set_loopCount:function(a){this._loopCount=a},get_mediaMarkers:function(){return this.videoWindow?this.videoWindow.get_mediaMarkers():[]},get_mediaUrl:function(){if(this.videoWindow)return this.videoWindow.get_mediaUrl();else return this._mediaUrl||""},set_mediaUrl:function(a){if(this.videoWindow){this.videoWindow.set_mediaUrl(a);this._dirtyChapterCache=true;this._calculateCurrentChapter();this._detectChapterChanged(this.get_timeIndex())}else this._mediaUrl=a},get_muted:function(){if(this.videoWindow)return this.videoWindow.get_muted();else return !!this._muted},set_muted:function(a){if(a!==this.get_muted()){if(this.videoWindow)this.videoWindow.set_muted(a);else this._muted=a;if(this.muteButton)this.muteButton.set_state(a?1:0);this._raiseVolumeChanged(Sys.EventArgs.Empty)}},get_placeholderImage:function(){return this._placeholderImage||""},set_placeholderImage:function(a){this._placeholderImage=a},get_playState:function(){return this.videoWindow?this.videoWindow.get_playState():"Stopped"},get_startTime:function(){return this._start},set_startTime:function(b){this._start=b;var a=this.get_duration();this._timeEnd=a===0?0:b+a},get_timeIndex:function(){return this.videoWindow?this.videoWindow.get_timeIndex():0},set_timeIndex:function(a){if(this.videoWindow){this.set_caption("");this.videoWindow.set_timeIndex(a);this._updateTime(a);this._dirtyChapterCache=true;this._calculateCurrentChapter();this._detectChapterChanged(a)}},get_volume:function(){if(this.videoWindow)return this.videoWindow.get_volume();else return this._volume||1},set_volume:function(a){a=Math.min(1,Math.max(0,a));if(a!==this.get_volume()){if(this.videoWindow)this.videoWindow.set_volume(a);else this._volume=a;if(this.dragVolume)this.dragVolume.set_value(a);this._raiseVolumeChanged(Sys.EventArgs.Empty)}},activateChapterArea:function(){this.chapterArea.set_visibility(Sys.Preview.UI.Xaml.Visibility.visible)},deactivateChapterArea:function(){this.chapterArea.set_visibility(Sys.Preview.UI.Xaml.Visibility.collapsed)},formatTime:function(d){var a="",c=Math.floor(d/(1000*60*60));if(c>0){a=c<10?"0"+c:""+c;a+=":"}d-=c*1000*60*60;var b=Math.floor(d/(1000*60));if(b===0)a+="00";else a+=b<10?"0"+b:""+b;a+=":";d-=b*1000*60;var e=Math.floor(d/1000);if(e===0)a+="00";else a+=e<10?"0"+e:""+e;return a},initialize:function(){this._onResizeHandler=Function.createDelegate(this,this._onWindowResize);Sys.UI.DomEvent.addHandler(window,"resize",this._onResizeHandler);Sys.Preview.UI.Xaml.BasePlayer.callBaseMethod(this,"initialize")},nextChapter:function(){var a=this.get_chapters();if(a){var b=this.get_currentChapter();if(++b<a.length){this.set_currentChapter(b);return true}}return false},onChapterStarted:function(){},onMarkerReached:function(){},onPlayStateChanged:function(){},onSizeChanged:function(){},onVolumeChanged:function(){},pause:function(){if(!this.videoWindow)throw Error.invalidOperation(Sys.Preview.MediaRes.Media_NoMediaElement);this.videoWindow.pause()},play:function(){if(!this.videoWindow)throw Error.invalidOperation(Sys.Preview.MediaRes.Media_NoMediaElement);this._dirtyChapterCache=true;this.set_caption("");if(this._mediaUrl){delete this._mediaUrl;this.videoWindow.set_mediaUrl(this._mediaUrl);this._forcePlay=true}else this.videoWindow.play()},previousChapter:function(){var b=this.get_chapters();if(b){var a=this.get_currentChapter();if(--a>=0){this.set_currentChapter(a);return true}}return false},restore:function(b,a){var e=b.name;if(!e)throw Error.argument("xamlElement",Sys.Preview.MediaRes.Xaml_MustHaveName);if(!this._tag)return;var c=this._tag[e];if(!c)return;var d=c[a];if(typeof d!=="undefined")b[a]=d},stop:function(){if(!this.videoWindow)throw Error.invalidOperation(Sys.Preview.MediaRes.Media_NoMediaElement);this._dirtyChapterCache=true;this.videoWindow.stop();this.set_caption("")},store:function(d,c){var b=d.name;if(!b)throw Error.argument("xamlElement",Sys.Preview.MediaRes.Xaml_MustHaveName);if(!this._tag)this._tag={};var a=this._tag[b];if(!a)this._tag[b]=a={};a[c]=d[c]},toggleMuted:function(){var a=!this.get_muted();this.set_muted(a);return a},togglePlayPause:function(){if(this.get_playState()==="Playing")this.pause();else this.play();return this.get_playState()},xamlInitialize:function(){this._bindChildControls();this._resizePlayer(false);Sys.Preview.UI.Xaml.BasePlayer.callBaseMethod(this,"xamlInitialize");if(typeof this._muted!=="undefined"){this.set_muted(this._muted);delete this._muted}if(typeof this._volume!=="undefined"){this.set_volume(this._volume);delete this._volume}var a=this.get_chapters();if(a)this.set_chapters(a);var b=this.get_rootElement();if(b.opacity===0)b.opacity=1;if(this._mediaUrl){this.set_mediaUrl(this._mediaUrl);delete this._mediaUrl}},_bindChildControls:function(){var a=Sys.Preview.UI.Xaml.PlayerElementName,b=this.get_element(),c=this.get_rootElement();this._scaleTransform=c.RenderTransform;if(!this._scaleTransform){this._scaleTransform=b.content.createFromXaml('<ScaleTransform ScaleX="1" ScaleY="1"/>');c.RenderTransform=this._scaleTransform}else if(this._scaleTransform.toString()!=="ScaleTransform")this._scaleTransform=null;this.videoWindow=new Sys.Preview.UI.Xaml._MediaElement(b,a.videoWindow,this.get_placeholderImage());if(!this.videoWindow.get_control())throw Error.invalidOperation("You must have a MediaElement in your XAML called '"+a.videoWindow+"' to use the BasePlayer class");this.videoWindow.add_mediaOpened(Function.createDelegate(this,this._mediaOpened));this.videoWindow.add_mediaFailed(Function.createDelegate(this,this._mediaFailed));this.videoWindow.add_mediaEnded(Function.createDelegate(this,this._mediaEnded));this.videoWindow.add_markerReached(Function.createDelegate(this,this._markerReached));this.videoWindow.add_click(Function.createDelegate(this,this._onPlayPause));this.videoWindow.add_doubleClick(Function.createDelegate(this,this._onFullScreen));this.videoWindow.add_downloadProgress(Function.createDelegate(this,this._onDownloadProgress));this.playerControls=new Sys.Preview.UI.Xaml.DomElement(b,a.playerControls,1,0);this.playButton=new Sys.Preview.UI.Xaml._Button(b,a.playButton);this.playButton.add_click(Function.createDelegate(this,this._onPlay));this.stopButton=new Sys.Preview.UI.Xaml._Button(b,a.stopButton);this.stopButton.add_click(Function.createDelegate(this,this._onStop));this.pauseButton=new Sys.Preview.UI.Xaml._Button(b,a.pauseButton);this.pauseButton.add_click(Function.createDelegate(this,this._onPause));this.volumeUpButton=new Sys.Preview.UI.Xaml._Button(b,a.volumeUpButton,null,null,false,20);this.volumeUpButton.add_click(Function.createDelegate(this,this._onVolumeUp));this.volumeDownButton=new Sys.Preview.UI.Xaml._Button(b,a.volumeDownButton,null,null,false,20);this.volumeDownButton.add_click(Function.createDelegate(this,this._onVolumeDown));this.fullscreenButton=new Sys.Preview.UI.Xaml._Button(b,a.fullScreenButton);this.fullscreenButton.add_click(Function.createDelegate(this,this._onFullScreen));this.dragTime=new Sys.Preview.UI.Xaml._Slider(b,a.timeThumb,a.timeSlider);this.dragTime.add_valueChanged(Function.createDelegate(this,this._onTimeSliderChanged));this.dragTime.set_value(this.get_startTime());this.dragVolume=new Sys.Preview.UI.Xaml._Slider(b,a.volumeThumb,a.volumeSlider);this.dragVolume.add_valueChanged(Function.createDelegate(this,this._onVolumeSliderChanged));this.dragVolume.set_value(this.get_volume());this.previousButton=new Sys.Preview.UI.Xaml._Button(b,a.previousButton);this.previousButton.add_click(Function.createDelegate(this,this._chapterPrevious));this.nextButton=new Sys.Preview.UI.Xaml._Button(b,a.nextButton);this.nextButton.add_click(Function.createDelegate(this,this._chapterNext));this.playPauseButton=new Sys.Preview.UI.Xaml._MultiStateButton(b,a.playPauseButton,null,null,false,null,a.playSymbol,a.pauseSymbol);this.playPauseButton.add_click(Function.createDelegate(this,this._onPlayPause));this.muteButton=new Sys.Preview.UI.Xaml._MultiStateButton(b,a.muteButton,null,null,false,null,a.muteOffSymbol,a.muteOnSymbol);this.muteButton.add_click(Function.createDelegate(this,this._onMute));this.totalTimeText=b.content.findName(a.totalTimeText);this.currentTimeText=b.content.findName(a.currentTimeText);this.downloadProgress=new Sys.Preview.UI.Xaml._ProgressBar(b,a.downloadSlider,a.downloadText);this.chapterArea=new Sys.Preview.UI.Xaml._ChapterArea(this,this.get_chapterAreaOpacityOn(),this.get_chapterAreaOpacityOff());this.chapterArea.set_itemOpacityOn(this.get_chapterItemOpacityOn());this.chapterArea.set_itemOpacityOff(this.get_chapterItemOpacityOff());this.captionArea=new Sys.Preview.UI.Xaml._TextBlock(b,a.captionText,a.captionArea);this.deactivateChapterArea();this.captionArea.set_visibility(Sys.Preview.UI.Xaml.Visibility.collapsed);this._fullScreenHandlerName=Sys.Preview.UI.Xaml.DomElement.getUniqueName("onFullScreen");window[this._fullScreenHandlerName]=Function.createDelegate(this,this._fullScreenChanged);b.content.onFullScreenChange="javascript:"+this._fullScreenHandlerName;this._resizeHandlerName=Sys.Preview.UI.Xaml.DomElement.getUniqueName("onResize");window[this._resizeHandlerName]=Function.createDelegate(this,this._resized);b.content.onResize="javascript:"+this._resizeHandlerName;$xamlAddHandlers(this.videoWindow.get_control(),{"CurrentStateChanged":this._stateChanged},this)},_calculateCurrentChapter:function(){this._currentChapterIndex=-1;this._nextChapterTime=-1;var a=this.get_chapters();if(!a||!a.length){this._dirtyChapterCache=false;return}var e=this.get_timeIndex();for(var b=0,f=a.length;b<f;b++){var c=a[b],d=c.time-e;if(d>0.001){this._nextChapterTime=c.time;break}else this._currentChapterIndex=b}this._dirtyChapterCache=false},_chapterNext:function(){this.nextChapter()},_chapterPrevious:function(){var b=this.get_chapters(),a=this.get_currentChapter();if(b&&a!==-1)if(a>0){var c=this.get_timeIndex(),d=b[a];if(d.time+1>=c)this.set_currentChapter(a-1);else this.set_currentChapter(a)}else this.set_timeIndex(0)},_ensureChapterArea:function(){var b=this.get_enableChapters();if(b&&!this._chaptersActive){var a=this.get_chapters();if(a&&a.length){this.activateChapterArea();this._chaptersActive=true}}else if(this._chaptersActive){this.deactivateChapterArea();this._chaptersActive=false}},_detectChapterChanged:function(a){if(this._dirtyChapterCache)this._calculateCurrentChapter();if(this._lastChapterStarted!==this._currentChapterIndex){this._lastChapterStarted=this._currentChapterIndex;this._raiseChapterStarted(new Sys.Preview.UI.Xaml.ChapterEventArgs(this._currentChapterIndex))}else if(this._nextChapterTime!==-1&&a>=this._nextChapterTime){this._calculateCurrentChapter();this._lastChapterStarted=this._currentChapterIndex;this._raiseChapterStarted(new Sys.Preview.UI.Xaml.ChapterEventArgs(this._currentChapterIndex))}},_fullScreenChanged:function(){if(this._disposed)return;this._resizePlayer(true);var a=this.videoWindow.get_control(),c=this.captionArea.get_control(),b=this.captionArea.get_backgroundControl();if(this.get_isFullScreen()){var e=Sys.Preview.UI.Xaml.DomElement.computeScale(this.get_rootElement()),f=Math.min(e.horizontal,e.vertical),d=new Sys.Preview.UI.Xaml.Bounds(0,0,this.get_element().content.ActualWidth/f,this.get_element().content.ActualHeight/f);this.store(a,"Canvas.ZIndex");this.store(a,"Opacity");if(c){this.store(c,"Canvas.ZIndex");c["Canvas.ZIndex"]=1000}if(b){this.store(b,"Canvas.ZIndex");b["Canvas.ZIndex"]=999}a["Canvas.ZIndex"]=998;a.opacity=1;var g='<Rectangle Canvas.ZIndex="997" Fill="#FF000000" Canvas.Top="0" Canvas.Left="0" Width="'+d.width+'" Height="'+d.height+'" />';this._fullScreenRectangle=this.get_element().content.createFromXaml(g);a.getParent().children.add(this._fullScreenRectangle);this._boundsVideoOrig=this.videoWindow.get_bounds();this.videoWindow.set_bounds(d)}else{this.restore(a,"Canvas.ZIndex");this.restore(a,"Opacity");if(c)this.restore(c,"Canvas.ZIndex");if(b)this.restore(b,"Canvas.ZIndex");if(this._boundsVideoOrig)this.videoWindow.set_bounds(this._boundsVideoOrig);if(this._fullScreenRectangle){this._fullScreenRectangle.getParent().children.remove(this._fullScreenRectangle);this._fullScreenRectangle=null}}},_onDownloadProgress:function(a){this.downloadProgress.set_value(a.get_downloadProgress())},_onFullScreen:function(){this.toggleFullScreen()},_onMute:function(){this.toggleMuted()},_onPause:function(){this.pause()},_onPlay:function(){this.play()},_onPlayPause:function(){this.togglePlayPause()},_onStop:function(){this.stop()},_onTimeSliderChanged:function(a){this.set_timeIndex(a.get_value()*this.videoWindow.get_naturalDuration())},_onVolumeDown:function(){this.set_volume(this.get_volume()-0.02)},_onVolumeSliderChanged:function(a){this.set_volume(a.get_value())},_onVolumeUp:function(){this.set_volume(this.get_volume()+0.02)},_onWindowResize:function(){this._resizePlayer(false)},_markerReached:function(b,a){this._raiseMarkerReached(a)},_mediaEnded:function(){if(!this._loopVideo()){var a=this.get_events().getHandler("mediaEnded");if(a)a(this,Sys.EventArgs.Empty)}},_mediaFailed:function(){var a=this.get_events().getHandler("mediaFailed"),b=false;if(a){var c=new Sys.CancelEventArgs;a(this,c);b=c.get_cancel()}if(!b)throw Error.invalidOperation('Unable to load media "'+this.get_mediaUrl()+'"')},_mediaOpened:function(){if(this.get_startTime()>0&&this.get_startTime()<this.videoWindow.get_naturalDuration())this.set_timeIndex(this.get_startTime());if(this._forcePlay||this.get_autoPlay()){delete this._forcePlay;this.play()}if(this.totalTimeText)this.totalTimeText.Text=this.formatTime(this.videoWindow.get_naturalDuration()*1000);if(this.currentTimeText)this.currentTimeText.Text=this.formatTime(this.get_timeIndex()*1000);this._tickTimerDelegate=Function.createDelegate(this,this._tickTimer);this._timerCookie=window.setTimeout(this._tickTimerDelegate,100);var a=this.get_events().getHandler("mediaOpened");if(a)a(this,Sys.EventArgs.Empty)},_loopVideo:function(){if(typeof this._loopsRemaining==="undefined")this._loopsRemaining=this.get_loopCount()-1;else if(this._loopsRemaining>0)this._loopsRemaining--;if(this._loopsRemaining===-1||this._loopsRemaining>0){this._queuedLoop=this.get_timeIndex();this.set_timeIndex(this.get_startTime());this.play();return true}else{this.stop();return false}},_raiseChapterStarted:function(a){this.onChapterStarted(a);var b=this.get_events().getHandler("chapterStarted");if(b)b(this,a);this.raisePropertyChanged("currentChapter")},_raiseMarkerReached:function(a){this.onMarkerReached(a);if(this.get_enableCaptions()){var c=a.get_marker();if(c.get_type().toLowerCase()==="caption")this.set_caption(c.get_text())}var b=this.get_events().getHandler("markerReached");if(b)b(this,a);this.raisePropertyChanged("caption")},_raisePlayStateChanged:function(b){this.playPauseButton.set_state(b.get_currentState()==="Playing"?1:0);this.onPlayStateChanged(b);var a=this.get_events().getHandler("stateChanged");if(a)a(this,b);var a=this.get_events().getHandler("propertyChanged");if(a)a(this,b)},_raiseSizeChanged:function(b){this.onSizeChanged(b);var a=this.get_events().getHandler("sizeChanged");if(a)a(this,b);this.raisePropertyChanged("bounds")},_raiseVolumeChanged:function(b){this.onVolumeChanged(b);var a=this.get_events().getHandler("volumeChanged");if(a)a(this,b);this.raisePropertyChanged("volume")},_resized:function(){if(this._disposed)return;this._resizePlayer(false);this._raiseSizeChanged(Sys.EventArgs.Empty)},_resizePlayer:function(c){if(this._scaleTransform&&(c||this.get_autoScale())){var a=Sys.Preview.UI.Xaml.DomElement.computeScale(this.get_rootElement()),b=Math.min(a.horizontal,a.vertical);this._scaleTransform.ScaleX=b;this._scaleTransform.ScaleY=b}},_stateChanged:function(){var a=this.get_playState(),b=this._oldState;this._raisePlayStateChanged(new Sys.Preview.UI.Xaml.StateChangedEventArgs("playState",b||"",a||""));this._oldState=a},_tickTimer:function(){this._timerCookie=window.setTimeout(this._tickTimerDelegate,100);var a=this.get_timeIndex();if(this.dragTime&&!this.dragTime.get_isDragging()){var b=this.videoWindow.get_naturalDuration();if(b)this.dragTime.set_value(a/b)}this._updateTime(a);this._detectChapterChanged(a);if(this._timeEnd>0)if(this._queuedLoop){if(a<this._queuedLoop)this._queuedLoop=null}else if(a>this._timeEnd)this._loopVideo()},_updateTime:function(a){if(this.currentTimeText)this.currentTimeText.Text=this.formatTime(a*1000)},dispose:function(){this._disposed=true;if(this._timerCookie){window.clearTimeout(this._timerCookie);delete this._timerCookie}if(this._tickTimerDelegate)delete this._tickTimerDelegate;if(this._tag)delete this._tag;if(this._fullScreenHandlerName)delete this._fullScreenHandlerName;if(this._resizeHandlerName)delete this._resizeHandlerName;var a=this.get_rootElement();if(a){Sys.Preview.UI.Xaml.DomElement.clearHandlers(this.videoWindow.get_control());this._scaleTransform=null;this.totalTimeText=null;this.currentTimeText=null;this._fullScreenRectangle=null;this.videoWindow.dispose();this.playerControls.dispose();this.playButton.dispose();this.stopButton.dispose();this.pauseButton.dispose();this.volumeUpButton.dispose();this.volumeDownButton.dispose();this.fullscreenButton.dispose();this.playPauseButton.dispose();this.previousButton.dispose();this.nextButton.dispose();this.muteButton.dispose();this.downloadProgress.dispose();this.dragTime.dispose();this.dragVolume.dispose();this.chapterArea.dispose();this.captionArea.dispose();delete this.videoWindow;delete this.playerControls;delete this.playButton;delete this.stopButton;delete this.pauseButton;delete this.volumeUpButton;delete this.volumeDownButton;delete this.fullscreenButton;delete this.playPauseButton;delete this.previousButton;delete this.nextButton;delete this.muteButtonull;delete this.downloadProgress;delete this.dragTime;delete this.dragVolume;delete this.chapterArea;delete this.captionArea;if(this._chapters)delete this._chapters}if(this._onResizeHandler){Sys.UI.DomEvent.removeHandler(window,"resize",this._onResizeHandler);delete this._onResizeHandler}Sys.Preview.UI.Xaml.BasePlayer.callBaseMethod(this,"dispose")}};Sys.Preview.UI.Xaml.BasePlayer.registerClass("Sys.Preview.UI.Xaml.BasePlayer",Sys.Preview.UI.Xaml.Control);Sys.Preview.UI.Xaml.StateChangedEventArgs=function(b,c,a){this._currentState=a;Sys.Preview.UI.Xaml.StateChangedEventArgs.initializeBase(this,[b])};Sys.Preview.UI.Xaml.StateChangedEventArgs.prototype={get_currentState:function(){return this._currentState||null},get_previousState:function(){return this._previousState||null}};Sys.Preview.UI.Xaml.StateChangedEventArgs.registerClass("Sys.Preview.UI.Xaml.StateChangedEventArgs",Sys.PropertyChangedEventArgs);Sys.Preview.UI.Xaml.ChapterEventArgs=function(a){this._chapterIndex=a;Sys.Preview.UI.Xaml.ChapterEventArgs.initializeBase(this)};Sys.Preview.UI.Xaml.ChapterEventArgs.prototype={get_chapterIndex:function(){return this._chapterIndex}};Sys.Preview.UI.Xaml.ChapterEventArgs.registerClass("Sys.Preview.UI.Xaml.ChapterEventArgs",Sys.EventArgs);Sys.Preview.UI.Xaml.MarkerEventArgs=function(a){this._marker=a;Sys.Preview.UI.Xaml.MarkerEventArgs.initializeBase(this)};Sys.Preview.UI.Xaml.MarkerEventArgs.prototype={get_marker:function(){return this._marker}};Sys.Preview.UI.Xaml.MarkerEventArgs.registerClass("Sys.Preview.UI.Xaml.MarkerEventArgs",Sys.EventArgs);Sys.Preview.UI.Xaml.ErrorEventArgs=function(a){this._xamlError=a;Sys.Preview.UI.Xaml.ErrorEventArgs.initializeBase(this)};Sys.Preview.UI.Xaml.ErrorEventArgs.prototype={get_error:function(){return this._xamlError}};Sys.Preview.UI.Xaml.ErrorEventArgs.registerClass("Sys.Preview.UI.Xaml.ErrorEventArgs",Sys.CancelEventArgs);Sys.Preview.UI.Xaml._TextBlock=function(b,c,a,e,d){Sys.Preview.UI.Xaml._TextBlock.initializeBase(this,[b,c,e,d]);if(this.get_control()&&a)this.set_backgroundControl(b.content.findName(a))};Sys.Preview.UI.Xaml._TextBlock.prototype={get_backgroundControl:function(){return this._background||null},set_backgroundControl:function(a){this._background=a;if(a){this._centerX=a["Canvas.Left"]+a.width/2;this._bottomY=a["Canvas.Top"]+a.height}},get_text:function(){var a=this.get_control();return a?a.Text||"":""},set_text:function(e){var b=this.get_control();if(b){b.Text=e||"";var a=this.get_backgroundControl();if(a){var c=b.ActualWidth,d=b.ActualHeight;a["Canvas.Left"]=this._centerX-c/2;a["Canvas.Top"]=this._bottomY-d;a.width=c;a.height=d;var f='<RectangleGeometry Rect="0,0,'+c+","+d+'"/>';a.clip=this.get_host().content.createFromXaml(f)}}},set_opacity:function(a){Sys.Preview.UI.Xaml._TextBlock.callBaseMethod(this,"set_opacity",[a]);var b=this.get_backgroundControl();if(b)b.opacity=a},set_visibility:function(a){Sys.Preview.UI.Xaml._TextBlock.callBaseMethod(this,"set_visibility",[a]);var b=this.get_backgroundControl();if(b)b.visibility=a},dispose:function(){Sys.Preview.UI.Xaml._TextBlock.callBaseMethod(this,"dispose");this._background=null}};Sys.Preview.UI.Xaml._TextBlock.registerClass("Sys.Preview.UI.Xaml._TextBlock",Sys.Preview.UI.Xaml.DomElement);Sys.Preview.UI.Xaml._MultiStateButton=function(b,f,h,g,i,e){Sys.Preview.UI.Xaml._MultiStateButton.initializeBase(this,[b,f,h,g,i,e]);this._stateAnimationsOn=[];this._stateAnimationsOff=[];this._stateCount=arguments.length-6;for(var a=0,j=this._stateCount;a<j;a++){var c=arguments[a+6],d=b.content.findName(c);if(!d)continue;this._stateAnimationsOn[a]=b.content.findName(c+"_ShowAnimation");this._stateAnimationsOff[a]=b.content.findName(c+"_HideAnimation");if(!this._stateAnimationsOn[a])this._stateAnimationsOn[a]=Sys.Preview.UI.Xaml.DomElement.createDoubleAnimation(b,c,"Storyboard.TargetProperty='opacity' To='1.0' Duration='0:0:0.3'");if(!this._stateAnimationsOff[a]){this._stateAnimationsOff[a]=Sys.Preview.UI.Xaml.DomElement.createDoubleAnimation(b,c,"Storyboard.TargetProperty='opacity' To='0.0' Duration='0:0:0.3'");d.opacity=0}}this._iState=-1;this.set_state(0)};Sys.Preview.UI.Xaml._MultiStateButton.prototype={get_state:function(){return this._iState},set_state:function(a){if(a!==this._iState){if(this._iState!==-1&&this._stateAnimationsOff[this._iState])this._stateAnimationsOff[this._iState].begin();this._iState=a;if(this._stateAnimationsOn[this._iState])this._stateAnimationsOn[this._iState].begin()}},dispose:function(){Sys.Preview.UI.Xaml._MultiStateButton.callBaseMethod(this,"dispose");delete this._stateAnimationsOn;delete this._stateAnimationsOff}};Sys.Preview.UI.Xaml._MultiStateButton.registerClass("Sys.Preview.UI.Xaml._MultiStateButton",Sys.Preview.UI.Xaml._Button);Sys.Preview.UI.Xaml._ImageList=function(a,f,b,e,d,c,h,g){Sys.Preview.UI.Xaml._ImageList.initializeBase(this,[a,f,h,g]);if(!this.get_control())return;this.get_control().cursor="Arrow";if(!a.content.findName(c))throw Error.invalidOperation("ImageList needs a scroll next button");if(!a.content.findName(d))throw Error.invalidOperation("ImageList needs a scroll previous button");if(!a.content.findName(b))throw Error.invalidOperation("ImageList needs a scroll container");if(!a.content.findName(e))throw Error.invalidOperation("ImageList needs a single defined item");this._scrollNext=new Sys.Preview.UI.Xaml._Button(a,c,null,null,false,200);this._scrollNext.add_click(Function.createDelegate(this,this._scrollNextClick));this._scrollPrev=new Sys.Preview.UI.Xaml._Button(a,d,null,null,false,200);this._scrollPrev.add_click(Function.createDelegate(this,this._scrollPrevClick));this._item=new Sys.Preview.UI.Xaml.DomElement(a,e);this._item.set_visibility(Sys.Preview.UI.Xaml.Visibility.collapsed);scrollContainer=a.content.findName(b);widthContainer=scrollContainer.width;heightContainer=scrollContainer.height;this._isVerticalScroll=heightContainer>widthContainer;nameInnerContainer=Sys.Preview.UI.Xaml.DomElement.getUniqueName("__innerContainer");var i='<Canvas xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Canvas.Top="0" Canvas.Left="0" Width="'+widthContainer+'" Height="'+heightContainer+'">'+"<Canvas.Clip>"+'<RectangleGeometry Rect="0,0,'+widthContainer+","+heightContainer+'" />'+"</Canvas.Clip>"+'<Canvas x:Name="'+nameInnerContainer+'" Canvas.Top="0" Canvas.Left="0" Height="'+heightContainer+'" Width="'+widthContainer+'"/>'+"</Canvas>";outerContainerControl=a.content.createFromXaml(i);scrollContainer.children.add(outerContainerControl);nameScrollAnimation=Sys.Preview.UI.Xaml.DomElement.getUniqueName("__scrollAnimation");if(this._isVerticalScroll){this._itemStep=this._item.get_height()+this._item.get_top();this._cItemsDisplay=heightContainer/this._itemStep+1;this._animScroll=Sys.Preview.UI.Xaml.DomElement.createDoubleAnimation(a,nameInnerContainer,"x:Name='"+nameScrollAnimation+"' Storyboard.TargetProperty='(Canvas.Top)' Duration='0:0:0.3'")}else{this._itemStep=this._item.get_width()+this._item.get_left();this._cItemsDisplay=widthContainer/this._itemStep+1;this._animScroll=Sys.Preview.UI.Xaml.DomElement.createDoubleAnimation(a,nameInnerContainer,"x:Name='"+nameScrollAnimation+"' Storyboard.TargetProperty='(Canvas.Left)' Duration='0:0:0.3'")}this._animScrollParams=a.content.findName(nameScrollAnimation);this._containerControl=a.content.findName(nameInnerContainer);Sys.Debug.assert(!!this._containerControl);this._iItemTopLeft=0;this._imageArray=[]};Sys.Preview.UI.Xaml._ImageList.prototype={_itemOpacityOn:1,_itemOpacityOff:0.7,get_itemOpacityOff:function(){return this._itemOpacityOff},set_itemOpacityOff:function(a){this._itemOpacityOff=a},get_itemOpacityOn:function(){return this._itemOpacityOn},set_itemOpacityOn:function(a){this._itemOpacityOn=a},get_itemCount:function(){return this._itemButtons?this._itemButtons.length:0},getBoundsForItem:function(b){if(b<0)throw new Error.invalidOperation("index must be greater than or equal to zero.");var a=this._item.get_bounds();if(this._isVerticalScroll)a.y+=b*this._itemStep;else a.x+=b*this._itemStep;return a},getItemAtPosition:function(a,b){if(this._isVerticalScroll)return Math.floor((b-this._item.get_top())/this._item.get_height());return Math.floor((a-this._item.get_left())/this._item.get_width())},itemClicked:function(){},setImages:function(b){if(this._itemButtons)for(var a=0,d=this._itemButtons.length;a<d;a++){var c=this._itemButtons[a];this._remove(c)}this._itemButtons=[];this._itemIndex=null;this._imageArray=b;this._ensureVisible()},_addItem:function(b){var c=Sys.Preview.UI.Xaml.DomElement.getUniqueName("__imageListBtn"),a=this.getBoundsForItem(b),f='<Image xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Name="'+c+'" Canvas.Top="'+a.y+'" Canvas.Left="'+a.x+'" Height="'+a.height+'" Width="'+a.width+'" Source="'+this._imageArray[b]+'" />',e=this.get_host().content.createFromXaml(f);this._containerControl.children.add(e);var d=new Sys.Preview.UI.Xaml._Button(this.get_host(),c,this.get_itemOpacityOn(),this.get_itemOpacityOff(),true);d.add_click(Function.createDelegate(this,this._itemClick));this._itemButtons[b]=d;if(!this._itemIndex)this._itemIndex={};this._itemIndex[c]=b},_ensureVisible:function(){if(this._itemButtons){var b=this._imageArray.length;for(var a=this._iItemTopLeft,c=this._iItemTopLeft+this._cItemsDisplay;a<c;a++)if(a>=0&&a<b&&!this._itemButtons[a])this._addItem(a)}},_itemClick:function(b){var c=b.get_control().name,a=this._itemIndex[c];this.itemClicked(a)},_remove:function(b){var a=b.get_control();if(!a)return;var c=a.getParent();if(c)c.children.remove(a);b.dispose()},_scroll:function(a){if(a!==1&&a!==-1)throw Error.argumentOutOfRange("direction",a,"Must be -1 for right/down or +1 for left/up.");if(a===-1&&this._iItemTopLeft<0||a===1&&this._iItemTopLeft>this._imageArray.length-this._cItemsDisplay+1)return;this._animScrollParams.From="-"+this._iItemTopLeft*this._itemStep;this._iItemTopLeft+=a;this._animScrollParams.To="-"+this._iItemTopLeft*this._itemStep;this._animScroll.begin();this._ensureVisible()},_scrollNextClick:function(){this._scroll(1)},_scrollPrevClick:function(){this._scroll(-1)},dispose:function(){if(this._item){this._item.dispose();delete this._item}if(this._scrollNext){this._scrollNext.dispose();delete this._scrollNext}if(this._scrollPrev){this._scrollPrev.dispose();delete this._scrollPrev}if(this._itemButtons){for(var a=0,c=this._itemButtons.length;a<c;a++){var b=this._itemButtons[a];this._remove(b)}delete this._itemButtons}delete this._imageArray;this._animScroll=null;this._containerControl=null;this._animScrollParams=null;Sys.Preview.UI.Xaml._ImageList.callBaseMethod(this,"dispose")}};Sys.Preview.UI.Xaml._ImageList.registerClass("Sys.Preview.UI.Xaml._ImageList",Sys.Preview.UI.Xaml.DomElement);Sys.Preview.UI.Xaml._ChapterArea=function(b,d,c){this._player=b;var a=Sys.Preview.UI.Xaml.PlayerElementName;Sys.Preview.UI.Xaml._ChapterArea.initializeBase(this,[b.get_element(),a.chapterArea,a.chapterScroll,a.chapterItem,a.chapterPrev,a.chapterNext,d,c])};Sys.Preview.UI.Xaml._ChapterArea.prototype={setChapters:function(b){if(!this.get_control())return;imageArray=[];if(b){this._imageChapters=[];for(var a=0,d=b.length;a<d;a++){var c=b[a];if(c.imageUrl){this._imageChapters[this._imageChapters.length]=a;imageArray[imageArray.length]=c.imageUrl}}}this.setImages(imageArray)},itemClicked:function(a){if(a<0||a>this.get_itemCount())throw Error.argumentOutOfRange("index",a,"Must be greater than or equal to 0 and less than the size of the image list.");this._player.set_currentChapter(this._imageChapters[a])},dispose:function(){Sys.Preview.UI.Xaml._ChapterArea.callBaseMethod(this,"dispose");delete this._player}};Sys.Preview.UI.Xaml._ChapterArea.registerClass("Sys.Preview.UI.Xaml._ChapterArea",Sys.Preview.UI.Xaml._ImageList);Sys.Preview.UI.Xaml._Slider=function(b,h,c,i,g){Sys.Preview.UI.Xaml._Slider.initializeBase(this,[b,c,i,g]);this._xamlThumbControl=b.content.findName(h);this._xamlSliderControl=b.content.findName(c);if(!this._xamlThumbControl||!this._xamlSliderControl)return;this._xamlHighlightControl=b.content.findName(c+"_Highlight");var a;for(a=this.get_control();a.getParent();a=a.getParent());this._rootCanvas=a;this._xamlThumbControl.cursor="Hand";this._xamlSliderControl.cursor="Hand";this._transform=a.RenderTransform;Sys.Preview.UI.Xaml.DomElement.addHandlers(this._xamlThumbControl,{"mouseLeftButtonDown":this._thumbMouseLeftButtonDown,"mouseLeftButtonUp":this._thumbMouseLeftButtonUp,"mouseMove":this._thumbMouseMove},this);Sys.Preview.UI.Xaml.DomElement.addHandlers(this._xamlSliderControl,{"mouseLeftButtonDown":this._sliderLeftButtonDown},this);Sys.Preview.UI.Xaml.DomElement.addHandlers(a,{"mouseLeave":this._rootMouseLeave},this);var f=Sys.Preview.UI.Xaml.DomElement.getLocation(this._xamlSliderControl.getParent());this._leftContainer=f.x;this._topContainer=f.y;this._leftSlider=this._xamlSliderControl["Canvas.Left"]+this._leftContainer;this._topSlider=this._xamlSliderControl["Canvas.Top"]+this._topContainer;this._widthThumb=this._xamlThumbControl.width;this._heightThumb=this._xamlThumbControl.height;var e=this._xamlSliderControl.width,d=this._xamlSliderControl.height;this._isHorizontal=e>d;if(this._isHorizontal){this._lowerLimit=this._leftSlider;this._upperLimit=this._leftSlider+e-this._widthThumb;if(this._xamlHighlightControl)this._xamlHighlightControl.width=0}else{this._lowerLimit=this._topSlider;this._upperLimit=this._topSlider+d-this._heightThumb;if(this._xamlHighlightControl)this._xamlHighlightControl.height=0}this._range=this._upperLimit-this._lowerLimit;this._isDragging=false};Sys.Preview.UI.Xaml._Slider.prototype={add_valueChanged:function(a){this.get_events().addHandler("valueChanged",a)},remove_valueChanged:function(a){this.get_events().removeHandler("valueChanged",a)},get_isDragging:function(){return this._isDragging},get_isHorizontal:function(){return this._isHorizontal},get_value:function(){var a=0;if(!this._xamlThumbControl)return 0;if(this._isHorizontal)a=(this._xamlThumbControl["Canvas.Left"]-(this._leftSlider-this._leftContainer))/this._range;else a=(this._xamlThumbControl["Canvas.Top"]-(this._topSlider-this._topContainer))/this._range;if(!this.get_isHorizontal())a=1-a;return a},set_value:function(a){var a=Math.min(1,Math.max(0,a));if(this._isHorizontal)pos=this._leftSlider+this._range*a;else pos=this._topSlider+this._range*(1-a);this._setThumbPosition(pos);this._setHighlight(a)},onValueChanged:function(){},_raiseValueChanged:function(b){this.onValueChanged(b);var a=this.get_events().getHandler("valueChanged");if(a)a(this,b)},_rootMouseLeave:function(){if(this._xamlThumbControl){this._isDragging=false;this._xamlThumbControl.ReleaseMouseCapture()}},_setThumbPosition:function(a){if(this._xamlThumbControl){var a=Math.max(this._lowerLimit,Math.min(this._upperLimit,a));if(this.get_isHorizontal())this._xamlThumbControl["Canvas.Left"]=a-this._leftContainer;else{this._xamlThumbControl["Canvas.Top"]=a-this._topContainer;if(this._xamlHighlightControl)this._xamlHighlightControl.height=this.get_height()*a}}},_setHighlight:function(a){if(this._xamlHighlightControl)if(this.get_isHorizontal())this._xamlHighlightControl.width=this.get_width()*a;else this._xamlHighlightControl.height=this.get_height()*a},_sliderLeftButtonDown:function(b,a){this._thumbMove(a.getPosition(null));this._isDragging=true;this._raiseValueChanged(Sys.EventArgs.Empty);this._xamlThumbControl.CaptureMouse()},_thumbMove:function(c){var a=c.X,b=c.Y;if(this._transform){a=a/this._transform.ScaleX;b=b/this._transform.ScaleY}if(this.get_isHorizontal())this._setThumbPosition(a-this._widthThumb/2);else this._setThumbPosition(b-this._heightThumb/2);this._setHighlight(this.get_value())},_thumbMouseLeftButtonDown:function(){this._isDragging=true;this._xamlThumbControl.CaptureMouse()},_thumbMouseLeftButtonUp:function(){this._isDragging=false;this._xamlThumbControl.ReleaseMouseCapture()},_thumbMouseMove:function(b,a){if(this._isDragging){this._thumbMove(a.getPosition(null));this._raiseValueChanged(Sys.EventArgs.Empty)}},dispose:function(){this._transform=null;this._xamlHighlightControl=null;if(this._xamlThumbControl){Sys.Preview.UI.Xaml.DomElement.clearHandlers(this._xamlThumbControl);this._xamlThumbControl=null}if(this._xamlSliderControl){Sys.Preview.UI.Xaml.DomElement.clearHandlers(this._xamlSliderControl);this._xamlSliderControl=null}if(this._rootCanvas){Sys.Preview.UI.Xaml.DomElement.clearHandlers(this._rootCanvas);this._rootCanvas=null}Sys.Preview.UI.Xaml._Slider.callBaseMethod(this,"dispose")}};Sys.Preview.UI.Xaml._Slider.registerClass("Sys.Preview.UI.Xaml._Slider",Sys.Preview.UI.Xaml.DomElement);Sys.Preview.UI.Xaml._ProgressBar=function(b,c,a,e,d){Sys.Preview.UI.Xaml._ProgressBar.initializeBase(this,[b,c,e,d]);if(this.get_control()){this._originalWidth=this.get_width();this.set_width(0)}if(a){this._xamlText=new Sys.Preview.UI.Xaml._TextBlock(b,a);this._xamlText.set_text("")}};Sys.Preview.UI.Xaml._ProgressBar.prototype={get_value:function(){return this.get_width()/this._originalWidth},set_value:function(a){this.set_width(this._originalWidth*a);this._xamlText.set_text(""+Math.floor(a*100))},dispose:function(){Sys.Preview.UI.Xaml._ProgressBar.callBaseMethod(this,"dispose");if(this._xamlText){this._xamlText.dispose();delete this._xamlText}}};Sys.Preview.UI.Xaml._ProgressBar.registerClass("Sys.Preview.UI.Xaml._ProgressBar",Sys.Preview.UI.Xaml.DomElement)