﻿// ***********************************************************************************************************
// Name: JavaScript Events
// Type: Library
// Author: Cliff Gower
//************************************************************************************************************


var Framework = Framework || {};
Framework.Events = Framework.Events || {};


Framework.Events.JavaScriptEvents = {
    CLICK: "click",
    MOUSE_DOWN: "mousedown",
    MOUSE_UP: "mouseup",
    MOUSE_OVER: "mouseover",
    MOUSE_OUT: "mouseout",
    KEY_UP: "keyup",
    KEY_DOWN: "keydown",
    KEY_PRESS: "keypress",
    FOCUS: "focus",
    BLUR: "blur",
    SUBMIT: "submit",
    ROW_ENTER: "rowenter",
    ROW_EXIT: "rowexit",
    AFTER_UPDATE: 'afterupdate',
    BEFORE_UNLOAD: 'beforeunload',
    BEFORE_UPDATE: 'beforeupdate',
    ERROR: 'error',
    ERROR_UPDATE: 'errorupdate',
    LOAD: 'load',
    READY_STATE_CHANGE: 'readystatechange',
    RESIZE: 'resize',
    SCROLL: 'scroll',
    SELECT_START: 'selectstart',
    UNLOAD: 'unload'
};

Framework.Events.MouseEvents = {
    CLICK: "click",
    MOUSE_DOWN: "mousedown",
    MOUSE_UP: "mouseup",
    MOUSE_OVER: "mouseover",
    MOUSE_OUT: "mouseout"
};

Framework.Events.FormElementEvents = {
    FOCUS: "focus",
    BLUR: "blur",
    SUBMIT: "submit"
};

Framework.Events.TableEvents = {
    ROW_ENTER: "rowenter",
    ROW_EXIT: "rowexit"
};

Framework.Events.WindowEvents = {
    AFTER_UPDATE: 'afterupdate',
    BEFORE_UNLOAD: 'beforeunload',
    BEFORE_UPDATE: 'beforeupdate',
    DRAG_DROP: 'dragdrop',
    ERROR: 'error',
    ERROR_UPDATE: 'errorupdate',
    LOAD: 'load',
    MOVE: 'move',
    READY_STATE_CHANGE: 'readystatechange',
    RESIZE: 'resize',
    SCROLL: 'scroll',
    SELECT_START: 'selectstart',
    UNLOAD: 'unload'
}

Framework.Events.KeyEvents = {
    KEY_UP: "keyup",
    KEY_DOWN: "keydown",
    KEY_PRESS: "keypress"
};

Framework.Events.KeyCodes = {
    ENTER: 13,
    LEFT_ARROW: 37,
    UP_ARROW: 38,
    RIGHT_ARROW: 39,
    DOWN_ARROW: 40,
    OPEN_BRACKET: 91,
    CLOSE_BRACKET: 93,
    OPEN_PARENTHESES: 40,
    CLOSE_PARENTHESES: 41
};



var Framework = Framework || {};

//*********************** Event Handler Creation ***************************
Framework.AddHandler = function (object, eventName, handler) {
    if (object.addEventListener) { object.addEventListener(eventName, handler, false); }
    else { object.attachEvent("on" + eventName, handler); }
};

Framework.RemoveHandler = function (object, eventName, handler) {
    if (object.removeEventListener) { object.removeEventListener(eventName, handler, false); }
    else { object.detachEvent("on" + eventName, handler); }
};

Framework.AddWheelHandler = function (handler) {
    if (document.addEventListener) {
        document.addEventListener('DOMMouseScroll', handler, false);
        document.addEventListener('mousewheel', handler, false);
    }
    else {
        document.attachEvent("onmousewheel", handler);
    }
};

Framework.RemoveWheelHandler = function (handler) {
    if (document.removeEventListener) {
        document.removeEventListener('DOMMouseScroll', handler, false);
        document.removeEventListener('mousewheel', handler, false);
    }
    else {
        document.detachEvent("onmousewheel", handler);
    }
};

Framework.CreateDelegate = function (object, method) {
    return (function () { return method.apply(object, arguments); })
};



// ***********************************************************************************************************
// Name: CSS 
// Type: Library
// Author: Cliff Gower
//************************************************************************************************************


var Framework = Framework || {};
Framework.CSS = Framework.CSS || {};


Framework.CSS.Display = {
    BLOCK: 'block',
    NONE: 'none'
};


//*********************** Browser and Device Detection ***************************
Framework.IsIE6 = function () {
    return /MSIE 6/.test(navigator.userAgent) ? true : false;
};

Framework.IsIE7 = function () {
    return /MSIE 7/.test(navigator.userAgent) ? true : false;
};

Framework.IsIE8 = function () {
    return /MSIE 8/.test(navigator.userAgent) ? true : false;
};

Framework.IsSafari = function () {
    return /Safari/.test(navigator.userAgent) ? true : false;
};

Framework.IsiPad = function () {
    return (/iPad/.test(navigator.userAgent) || navigator.platform == "iPad");
};


// ***********************************************************************************************************
// Name: Named List
// Type: Object
// Author: Cliff Gower
//************************************************************************************************************

var Framework = Framework || {};
Framework.Collections = Framework.Collections || {};

Framework.Collections.NamedList = function () {
    this.KeyValuePairs = new Object();
    this.KeyValuePairIterator = new Array();
}

Framework.Collections.NamedList.prototype.Add = function (key, value) {
    this.KeyValuePairs[key] = value;
    this.KeyValuePairIterator.push(key);
};

Framework.Collections.NamedList.prototype.Remove = function (key) {
    var index = this.FindItemIndex(key);
    this.RemoveItemAt(index);
};

Framework.Collections.NamedList.prototype.RemoveItemAt = function (index) {
    if (this.KeyValuePairIterator[index] != null
    && this.KeyValuePairIterator[index] != undefined) {
        var key = this.KeyValuePairIterator[index];
        delete this.KeyValuePairs[key];
        this.KeyValuePairIterator.splice(index, 1);
    }
};

Framework.Collections.NamedList.prototype.Clear = function () {
    var listSize = this.KeyValuePairIterator.length;
    this.KeyValuePairs.splice(0, listSize);
    this.KeyValuePairIterator.splice(0, listSize);
};

Framework.Collections.NamedList.prototype.Item = function (key) {
    if (this.KeyValuePairs[key] != null
    && this.KeyValuePairs[key] != undefined) {
        return this.KeyValuePairs[key];
    }
};

Framework.Collections.NamedList.prototype.ItemAt = function (index) {
    if (this.KeyValuePairIterator[index] != null
    && this.KeyValuePairIterator[index] != undefined) {
        var key = this.KeyValuePairIterator[index];
        return this.KeyValuePairs[key];
    }
};

Framework.Collections.NamedList.prototype.Count = function () {
    return this.KeyValuePairIterator.length;
};

Framework.Collections.NamedList.prototype.FindItemIndex = function (key) {
    for (index = 0; index < this.KeyValuePairIterator.length; index++) {
        if (this.KeyValuePairIterator[index] == key) {
            return index;
        }
    }

    return -1;
};





// ***********************************************************************************************************
// Name: Custom Event Handling Base Class
// Type: Base Class
// Author: Cliff Gower
//************************************************************************************************************

//dependencies
//Framework.Collections.NamedList.js

var Framework = Framework || {};

Framework.CustomEventHandlingBase = function () {
    this.Events = new Framework.Collections.NamedList();
}

Framework.CustomEventHandlingBase.prototype.AddEvent = function (event) {
    var eventHandlerList = new Framework.Collections.NamedList();
    this.Events.Add(event, eventHandlerList);
};

Framework.CustomEventHandlingBase.prototype.RemoveEvent = function (event) {
    this.Events.Remove(event);
};

Framework.CustomEventHandlingBase.prototype.RegisterEventHandler = function (eventHandler) {
    if (this.Events.Item(eventHandler.Event) == null || this.Events.Item(eventHandler.Event) == undefined) {
        this.AddEvent(eventHandler.Event);
    }

    this.Events.Item(eventHandler.Event).Add(eventHandler.Name, eventHandler);
};

Framework.CustomEventHandlingBase.prototype.UnregisterEventHandler = function (eventHandlerName, event) {
    this.Events.Item(event).Remove(eventHandlerName);
};

Framework.CustomEventHandlingBase.prototype.FireEvent = function (event, eventArgs) {
    var eventToFire = this.Events.Item(event);
    for (var index = 0; index < eventToFire.Count(); index++) {
        eventToFire.ItemAt(index).Delegate(eventArgs);
    }
};


Framework.CustomEventHandler = function (name, event, delegate) {
    this.Name = null;
    this.Event = null;
    this.Delegate = null;

    if (name != null && name != undefined) {
        this.Name = name;
    }

    if (event != null && event != undefined) {
        this.Event = event;
    }

    if (delegate != null && delegate != undefined) {
        this.Delegate = delegate;
    }
}


// ***********************************************************************************************************
// Name: Drawing Library
// Type: Library
// Author: Cliff Gower
//************************************************************************************************************

var Framework = Framework || {};
Framework.Drawing = Framework.Drawing || {};

Framework.Drawing.Dimension = function (width, height) {
    this.Width = null;
    this.Height = null;

    if (width != null && width != undefined) { this.Width = width; }
    if (height != null && height != undefined) { this.Height = height; }
}


Framework.Drawing.Coordinate = function (posX, posY) {
    this.PositionX = null;
    this.PositionY = null;

    if (posX != null && posX != undefined) { this.PositionX = posX; }
    if (posY != null && posY != undefined) { this.PositionY = posY; }
}



// ***********************************************************************************************************
// Name: Resizing Background Control
// Type: User Control
// Author: Cliff Gower
//************************************************************************************************************


//dependencies
//Framework.EventHandling.js


var Framework = Framework || {};
Framework.Controls = Framework.Controls || {};


Framework.Controls.ResizingBackground = function (backgroundElement, aspectRatio) {
    this.BackgroundElement = backgroundElement;
    this.AspectRatio = aspectRatio;
    this.MinimumWidth = null;
    this.MinimumHeight = null;

    this.OnResize = null;

    Framework.AddHandler(window, Framework.Events.WindowEvents.LOAD,
    Framework.CreateDelegate(this, this.PageLoadHandler));

    Framework.AddHandler(window, Framework.Events.WindowEvents.RESIZE,
    Framework.CreateDelegate(this, this.PageResizeHandler));

    if (Framework.IsiPad()) {
        Framework.AddHandler(window, 'orientationchange',
        Framework.CreateDelegate(this, this.PageResizeHandler));
    }
};


Framework.Controls.ResizingBackground.prototype.ResizeBackground = function () {
    var pageDimensions = this.GetPageDimensions();
    if (this.IsMinimumSize(pageDimensions)) { return; }

    var adjustedDimensions = this.AdjustToApsectRatio(pageDimensions);
    this.BackgroundElement.width = adjustedDimensions.Width;
    this.BackgroundElement.height = adjustedDimensions.Height;

    if (this.OnResize != null && this.OnResize != undefined) {
        this.OnResize();
    }
};

Framework.Controls.ResizingBackground.prototype.GetPageDimensions = function () {
    var pageDimensions = new Framework.Drawing.Dimension();

    if (Framework.IsiPad()) {
        if (window.orientation == 0) {
            pageDimensions.Width = 768;
            pageDimensions.Height = 1024;
        }
        else {
            pageDimensions.Width = 1024;
            pageDimensions.Height = 768;
        }
    } else if (typeof (window.innerWidth) == 'number') {
        pageDimensions.Width = window.innerWidth;
        pageDimensions.Height = window.innerHeight;
    } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
        pageDimensions.Width = document.documentElement.clientWidth;
        pageDimensions.Height = document.documentElement.clientHeight;
    } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
        pageDimensions.Width = document.body.clientWidth;
        pageDimensions.Height = document.body.clientHeight;
    } else if (screen.width) {
        pageDimensions.Width = screen.width;
        pageDimensions.Height = screen.height;
    }

    return pageDimensions;
};

Framework.Controls.ResizingBackground.prototype.AdjustToApsectRatio = function (pageDimensions) {
    var newPageDimensions = new Framework.Drawing.Dimension();

    if ((Framework.IsiPad() && window.orientation == 0) || (Framework.IsiPad() && window.orientation == 180)) {
        newPageDimensions.Width = (pageDimensions.Height / this.AspectRatio.Height) * this.AspectRatio.Width;
        newPageDimensions.Height = pageDimensions.Height;
    } else if ((pageDimensions.Width / pageDimensions.Height) >= (this.AspectRatio.Width / this.AspectRatio.Height)) {
        newPageDimensions.Width = pageDimensions.Width;
        newPageDimensions.Height = (pageDimensions.Width / this.AspectRatio.Width) * this.AspectRatio.Height;
    }
    else {
        newPageDimensions.Width = (pageDimensions.Height / this.AspectRatio.Height) * this.AspectRatio.Width;
        newPageDimensions.Height = pageDimensions.Height;
    }

    return newPageDimensions;
};

Framework.Controls.ResizingBackground.prototype.IsMinimumSize = function (pageDimensions) {
    if ((pageDimensions.Width / pageDimensions.Height) >= (this.AspectRatio.Width / this.AspectRatio.Height)) {
        if (pageDimensions.Width < this.MinimumWidth) {
            return true;
        }
        else {
            return false;
        }
    }
    else {
        if (pageDimensions.Height < this.MinimumHeight) {
            return true;
        }
        else {
            return false;
        }
    }
}


Framework.Controls.ResizingBackground.prototype.PageLoadHandler = function () {
    this.ResizeBackground();
};

Framework.Controls.ResizingBackground.prototype.PageResizeHandler = function () {
    this.ResizeBackground();
};






// ***********************************************************************************************************
// Name:HTML5Video Player Types
// Type:User Control Library
// Author: Cliff Gower
//************************************************************************************************************


//Dependencies
//Framework.EventHandling.js


var Framework = Framework || {};
Framework.Video = Framework.Video || {};


Framework.Video.HTML5VideoMuteState = {
    AUDIBLE: false,
    MUTED: true
};

Framework.Video.HTML5VideoLoop = {
    YES: false,
    NO: true
};

Framework.Video.HTML5VideoPlaybackRate = {
    FORWARD: 1,
    FAST_FORWARD: 3,
    REVERSE: -1,
    FAST_REVERSE: -3
};

Framework.Video.HTML5VideoEvent = {
    LOAD_START: 'loadstart',
    PROGRESS: 'progress',
    SUSPEND: 'suspend',
    ABORT: 'abort',
    ERROR: 'error',
    EMPTIED: 'emptied',
    STALLED: 'stalled',
    LOADED_METADATA: 'loadedmetadata',
    LOADED_DATA: 'loadeddata',
    CAN_PLAY: 'canplay',
    CAN_PLAY_THROUGH: 'canplaythrough',
    PLAYING: 'playing',
    WAITING: 'waiting',
    SEEKING: 'seeking',
    SEEKED: 'seeked',
    ENDED: 'ended',
    DURATION_CHANGE: 'durationchange',
    TIME_UPDATE: 'timeupdate',
    PLAY: 'play',
    PAUSE: 'pause',
    RATE_CHANGE: 'ratechange',
    VOLUME_CHANGE: 'volumechange'
};

Framework.Video.HTML5VideoControllerEvent = {
    EMPTIED: 'emptied',
    LOADED_METADATA: 'loadedmetadata',
    LOADED_DATA: 'loadeddata',
    CAN_PLAY: 'canplay',
    CAN_PLAY_THROUGH: 'canplaythrough',
    PLAYING: 'playing',
    WAITING: 'waiting',
    ENDED: 'ended',
    DURATION_CHANGE: 'durationchange',
    TIME_UPDATE: 'timeupdate',
    PLAY: 'play',
    PAUSE: 'pause',
    RATE_CHANGE: 'ratechange',
    VOLUME_CHANGE: 'volumechange'
};

Framework.Video.HTML5VideoReadyState = {
    HAVE_NOTHING: 0,
    HAVE_METADATA: 1,
    HAVE_CURRENT_DATA: 2,
    HAVE_FUTURE_DATA: 3,
    HAVE_ENOUGH_DATA: 4
};

Framework.Video.HTML5VideoNetworkState = {
    NETWORK_EMPTY: 0,
    NETWORK_IDLE: 1,
    NETWORK_LOADING: 2,
    NETWORK_NO_SOURCE: 3
};

Framework.Video.HTML5VideoError = {
    MEDIA_ERR_ABORTED: 1,
    MEDIA_ERR_NETWORK: 2,
    MEDIA_ERR_DECODE: 3,
    MEDIA_ERR_SRC_NOT_SUPPORTED: 4
};


Framework.Video.HTML5Video = {
    YES: true,
    NO: false
};



Framework.Video.TextTrack = function () {
};



Framework.Video.MutableTextTrack = function () {
};

Framework.Video.MutableTextTrack.prototype = new Framework.Video.TextTrack();



// ***********************************************************************************************************
// Name:HTML5Video Player
// Type:User Control Library
// Author: Cliff Gower
//************************************************************************************************************


//Dependencies
//Framework.EventHandling.js
//Framework.Collections.NamedList.js
//Framework.CustomEventHandling.js
//Framework.Video.js


var Framework = Framework || {};
Framework.Controls = Framework.Controls || {};


//*********************** Video Player Control Base Class  ***************************
Framework.Controls.HTML5VideoPlayer = function (videoElement) {
    this.VideoElement = videoElement;

    Framework.AddHandler(this.VideoElement, Framework.Video.HTML5VideoEvent.LOAD_START, Framework.CreateDelegate(this, this.LoadStartHandler));
    Framework.AddHandler(this.VideoElement, Framework.Video.HTML5VideoEvent.PROGRESS, Framework.CreateDelegate(this, this.ProgressHandler));
    Framework.AddHandler(this.VideoElement, Framework.Video.HTML5VideoEvent.SUSPEND, Framework.CreateDelegate(this, this.SuspendHandler));
    Framework.AddHandler(this.VideoElement, Framework.Video.HTML5VideoEvent.ABORT, Framework.CreateDelegate(this, this.AbortHandler));
    Framework.AddHandler(this.VideoElement, Framework.Video.HTML5VideoEvent.ERROR, Framework.CreateDelegate(this, this.ErrorHandler));
    Framework.AddHandler(this.VideoElement, Framework.Video.HTML5VideoEvent.EMPTIED, Framework.CreateDelegate(this, this.EmptiedHandler));
    Framework.AddHandler(this.VideoElement, Framework.Video.HTML5VideoEvent.STALLED, Framework.CreateDelegate(this, this.StalledHandler));
    Framework.AddHandler(this.VideoElement, Framework.Video.HTML5VideoEvent.LOADED_METADATA, Framework.CreateDelegate(this, this.LoadedMetadataHandler));
    Framework.AddHandler(this.VideoElement, Framework.Video.HTML5VideoEvent.LOADED_DATA, Framework.CreateDelegate(this, this.LoadedDataHandler));
    Framework.AddHandler(this.VideoElement, Framework.Video.HTML5VideoEvent.CAN_PLAY, Framework.CreateDelegate(this, this.CanPlayHandler));
    Framework.AddHandler(this.VideoElement, Framework.Video.HTML5VideoEvent.CAN_PLAY_THROUGH, Framework.CreateDelegate(this, this.CanPlayThroughHandler));
    Framework.AddHandler(this.VideoElement, Framework.Video.HTML5VideoEvent.PLAYING, Framework.CreateDelegate(this, this.PlayingHandler));
    Framework.AddHandler(this.VideoElement, Framework.Video.HTML5VideoEvent.WAITING, Framework.CreateDelegate(this, this.WaitingHandler));
    Framework.AddHandler(this.VideoElement, Framework.Video.HTML5VideoEvent.SEEKING, Framework.CreateDelegate(this, this.SeekingHandler));
    Framework.AddHandler(this.VideoElement, Framework.Video.HTML5VideoEvent.SEEKED, Framework.CreateDelegate(this, this.SeekedHandler));
    Framework.AddHandler(this.VideoElement, Framework.Video.HTML5VideoEvent.ENDED, Framework.CreateDelegate(this, this.EndedHandler));
    Framework.AddHandler(this.VideoElement, Framework.Video.HTML5VideoEvent.DURATION_CHANGE, Framework.CreateDelegate(this, this.DurationChangeHandler));
    Framework.AddHandler(this.VideoElement, Framework.Video.HTML5VideoEvent.TIME_UPDATE, Framework.CreateDelegate(this, this.TimeUpdateHandler));
    Framework.AddHandler(this.VideoElement, Framework.Video.HTML5VideoEvent.PLAY, Framework.CreateDelegate(this, this.PlayHandler));
    Framework.AddHandler(this.VideoElement, Framework.Video.HTML5VideoEvent.PAUSE, Framework.CreateDelegate(this, this.PauseHandler));
    Framework.AddHandler(this.VideoElement, Framework.Video.HTML5VideoEvent.VOLUME_CHANGE, Framework.CreateDelegate(this, this.VolumeChangeHandler));
    Framework.AddHandler(this.VideoElement, Framework.Video.HTML5VideoEvent.RATE_CHANGE, Framework.CreateDelegate(this, this.RateChangeHandler));

    this.AddEvent(Framework.Video.HTML5VideoEvent.LOAD_START);
    this.AddEvent(Framework.Video.HTML5VideoEvent.PROGRESS);
    this.AddEvent(Framework.Video.HTML5VideoEvent.SUSPEND);
    this.AddEvent(Framework.Video.HTML5VideoEvent.ABORT);
    this.AddEvent(Framework.Video.HTML5VideoEvent.ERROR);
    this.AddEvent(Framework.Video.HTML5VideoEvent.EMPTIED);
    this.AddEvent(Framework.Video.HTML5VideoEvent.STALLED);
    this.AddEvent(Framework.Video.HTML5VideoEvent.LOADED_METADATA);
    this.AddEvent(Framework.Video.HTML5VideoEvent.LOADED_DATA);
    this.AddEvent(Framework.Video.HTML5VideoEvent.CAN_PLAY);
    this.AddEvent(Framework.Video.HTML5VideoEvent.CAN_PLAY_THROUGH);
    this.AddEvent(Framework.Video.HTML5VideoEvent.PLAYING);
    this.AddEvent(Framework.Video.HTML5VideoEvent.WAITING);
    this.AddEvent(Framework.Video.HTML5VideoEvent.SEEKING);
    this.AddEvent(Framework.Video.HTML5VideoEvent.SEEKED);
    this.AddEvent(Framework.Video.HTML5VideoEvent.ENDED);
    this.AddEvent(Framework.Video.HTML5VideoEvent.DURATION_CHANGE);
    this.AddEvent(Framework.Video.HTML5VideoEvent.TIME_UPDATE);
    this.AddEvent(Framework.Video.HTML5VideoEvent.PLAY);
    this.AddEvent(Framework.Video.HTML5VideoEvent.PAUSE);
    this.AddEvent(Framework.Video.HTML5VideoEvent.VOLUME_CHANGE);
    this.AddEvent(Framework.Video.HTML5VideoEvent.RATE_CHANGE);
};

Framework.Controls.HTML5VideoPlayer.prototype = new Framework.CustomEventHandlingBase();


// Readonly Properties
Framework.Controls.HTML5VideoPlayer.prototype.Error = function () { return this.VideoElement.error; };
Framework.Controls.HTML5VideoPlayer.prototype.CurrentSource = function () { return this.VideoElement.currentSrc; };
Framework.Controls.HTML5VideoPlayer.prototype.NetworkState = function () { return this.VideoElement.networkState; };
Framework.Controls.HTML5VideoPlayer.prototype.Buffered = function () { return this.VideoElement.Buffered; };
Framework.Controls.HTML5VideoPlayer.prototype.ReadyState = function () { return this.VideoElement.readyState; };
Framework.Controls.HTML5VideoPlayer.prototype.Seeking = function () { return this.VideoElement.seeking; };
Framework.Controls.HTML5VideoPlayer.prototype.InitialTime = function () { return this.VideoElement.intialTime; };
Framework.Controls.HTML5VideoPlayer.prototype.Duration = function () { return this.VideoElement.duration; };
Framework.Controls.HTML5VideoPlayer.prototype.StartOffsetTime = function () { return this.VideoElement.startOffsetTime; };
Framework.Controls.HTML5VideoPlayer.prototype.Paused = function () { return this.VideoElement.paused; };
Framework.Controls.HTML5VideoPlayer.prototype.Played = function () { return this.VideoElement.played; };
Framework.Controls.HTML5VideoPlayer.prototype.Seekable = function () { return this.VideoElement.seekable; };
Framework.Controls.HTML5VideoPlayer.prototype.Ended = function () { return this.VideoElement.ended; };
Framework.Controls.HTML5VideoPlayer.prototype.AudioTracks = function () { return this.VideoElement.audioTracks; };
Framework.Controls.HTML5VideoPlayer.prototype.ExclusiveTrackList = function () { return this.VideoElement.videoTracks; };
Framework.Controls.HTML5VideoPlayer.prototype.TextTracks = function () { return this.VideoElement.textTracks; };



// Read/Write Properties
Framework.Controls.HTML5VideoPlayer.prototype.Source = function (source) {
    if (source == null || source == undefined) {
        return this.VideoElement.src;
    }
    else {
        this.VideoElement.src = source;
    }
};

Framework.Controls.HTML5VideoPlayer.prototype.CurrentTime = function (time) {
    if (time == null || time == undefined) {
        return this.VideoElement.currentTime;
    }
    else {
        this.VideoElement.currentTime = time;
    }
};

Framework.Controls.HTML5VideoPlayer.prototype.DefaultPlaybackRate = function (rate) {
    if (rate == null || rate == undefined) {
        return this.VideoElement.defaultPlaybackRate;
    }
    else {
        this.VideoElement.defaultPlaybackRate = rate;
    }
};

Framework.Controls.HTML5VideoPlayer.prototype.PlaybackRate = function (rate) {
    if (rate == null || rate == undefined) {
        return this.VideoElement.playbackRate;
    }
    else {
        this.VideoElement.playbackRate = rate;
    }
};

Framework.Controls.HTML5VideoPlayer.prototype.Autoplay = function (setting) {
    if (setting == null || setting == undefined) {
        return this.VideoElement.autoplay;
    }
    else {
        this.VideoElement.autoplay = setting;
    }
};

Framework.Controls.HTML5VideoPlayer.prototype.Loop = function (setting) {
    if (setting == null || setting == undefined) {
        return this.VideoElement.loop;
    }
    else {
        this.VideoElement.loop = setting;
    }
};

Framework.Controls.HTML5VideoPlayer.prototype.MediaGroup = function (group) {
    if (group == null || group == undefined) {
        return this.VideoElement.mediaGroup;
    }
    else {
        this.VideoElement.mediaGroup = group;
    }
};

Framework.Controls.HTML5VideoPlayer.prototype.MediaController = function (controller) {
    if (controller == null || controller == undefined) {
        return this.VideoElement.controller;
    }
    else {
        this.VideoElement.controller = controller;
    }
};

Framework.Controls.HTML5VideoPlayer.prototype.Controls = function (setting) {
    if (setting == null || setting == undefined) {
        return this.VideoElement.controls;
    }
    else {
        this.VideoElement.controls = setting;
    }
};

Framework.Controls.HTML5VideoPlayer.prototype.Volume = function (volume) {
    if (volume == null || volume == undefined) {
        return this.VideoElement.volume;
    }
    else {
        this.VideoElement.volume = volume;
    }
};

Framework.Controls.HTML5VideoPlayer.prototype.Muted = function (muteState) {
    if (muteState == null || muteState == undefined) {
        return this.VideoElement.muted;
    }
    else {
        this.VideoElement.muted = muteState;
    }
};

Framework.Controls.HTML5VideoPlayer.prototype.DefaultMuted = function (muteState) {
    if (muteState == null || muteState == undefined) {
        return this.VideoElement.defaultMuted;
    }
    else {
        this.VideoElement.defaultMuted = muteState;
    }
};



// Methods
Framework.Controls.HTML5VideoPlayer.prototype.Pause = function () {
    this.PlaybackRate(Framework.Video.HTML5VideoPlaybackRate.FORWARD);
    this.VideoElement.pause();
};

Framework.Controls.HTML5VideoPlayer.prototype.Play = function () {
    this.PlaybackRate(Framework.Video.HTML5VideoPlaybackRate.FORWARD);
    this.VideoElement.play();
};

Framework.Controls.HTML5VideoPlayer.prototype.Replay = function () {
    this.ResetMedia();
    this.Play();
};

Framework.Controls.HTML5VideoPlayer.prototype.FastForward = function () {
    this.VideoElement.play();
    this.PlaybackRate(Framework.Video.HTML5VideoPlaybackRate.FAST_FORWARD);
};

Framework.Controls.HTML5VideoPlayer.prototype.Reverse = function () {
    this.VideoElement.play();
    this.PlaybackRate(Framework.Video.HTML5VideoPlaybackRate.REVERSE);
};

Framework.Controls.HTML5VideoPlayer.prototype.FastReverse = function () {
    this.VideoElement.play();
    this.PlaybackRate(Framework.Video.HTML5VideoPlaybackRate.FAST_REVERSE);
};

Framework.Controls.HTML5VideoPlayer.prototype.ResetMedia = function () {
    if (this.CurrentTime() > 0) {
        this.CurrentTime(0);
    }
};

Framework.Controls.HTML5VideoPlayer.prototype.ChangeMediaSource = function (media) {
    this.VideoElement.src = media;
    this.VideoElement.load();
};

Framework.Controls.HTML5VideoPlayer.prototype.ChangeMediaSources = function (mediaList) {
    var sources = this.VideoElement.getElementsByTagName('source');
    sources[0].src = mediaList[0];
    sources[1].src = mediaList[1];

    this.VideoElement.load();
};

Framework.Controls.HTML5VideoPlayer.prototype.CanPlayType = function (type) {
    return this.VideoElement.canPlayType(type);
};

Framework.Controls.HTML5VideoPlayer.prototype.AddTextTrack = function (kind, label, language) {
    if (label != undefined && language != undefined) {
        return this.VideoElement.addTextTrack(kind, label, language);
    }
    else if (label != undefined && language == undefined) {
        return this.VideoElement.addTextTrack(kind, label);
    }
    else {
        return this.VideoElement.addTextTrack(kind);
    }
};



// Event Handlers
Framework.Controls.HTML5VideoPlayer.prototype.LoadStartHandler = function () {
    this.FireEvent(Framework.Video.HTML5VideoEvent.LOAD_START);
};

Framework.Controls.HTML5VideoPlayer.prototype.ProgressHandler = function () {
    this.FireEvent(Framework.Video.HTML5VideoEvent.PROGRESS);
};

Framework.Controls.HTML5VideoPlayer.prototype.SuspendHandler = function () {
    this.FireEvent(Framework.Video.HTML5VideoEvent.SUSPEND);
};

Framework.Controls.HTML5VideoPlayer.prototype.AbortHandler = function () {
    this.FireEvent(Framework.Video.HTML5VideoEvent.ABORT);
};

Framework.Controls.HTML5VideoPlayer.prototype.ErrorHandler = function () {
    this.FireEvent(Framework.Video.HTML5VideoEvent.ERROR);
};

Framework.Controls.HTML5VideoPlayer.prototype.EmptiedHandler = function () {
    this.FireEvent(Framework.Video.HTML5VideoEvent.EMPTIED);
};

Framework.Controls.HTML5VideoPlayer.prototype.StalledHandler = function () {
    this.FireEvent(Framework.Video.HTML5VideoEvent.STALLED);
};

Framework.Controls.HTML5VideoPlayer.prototype.LoadedMetadataHandler = function () {
    this.FireEvent(Framework.Video.HTML5VideoEvent.LOADED_METADATA);
};

Framework.Controls.HTML5VideoPlayer.prototype.LoadedDataHandler = function () {
    this.FireEvent(Framework.Video.HTML5VideoEvent.LOADED_DATA);
};

Framework.Controls.HTML5VideoPlayer.prototype.CanPlayHandler = function () {
    this.FireEvent(Framework.Video.HTML5VideoEvent.CAN_PLAY);
};

Framework.Controls.HTML5VideoPlayer.prototype.CanPlayThroughHandler = function () {
    this.FireEvent(Framework.Video.HTML5VideoEvent.CAN_PLAY_THROUGH);
};

Framework.Controls.HTML5VideoPlayer.prototype.PlayingHandler = function () {
    this.FireEvent(Framework.Video.HTML5VideoEvent.PLAYING);
};

Framework.Controls.HTML5VideoPlayer.prototype.WaitingHandler = function () {
    this.FireEvent(Framework.Video.HTML5VideoEvent.WAITING);
};

Framework.Controls.HTML5VideoPlayer.prototype.SeekingHandler = function () {
    this.FireEvent(Framework.Video.HTML5VideoEvent.SEEKING);
};

Framework.Controls.HTML5VideoPlayer.prototype.SeekedHandler = function () {
    this.FireEvent(Framework.Video.HTML5VideoEvent.SEEKED);
};

Framework.Controls.HTML5VideoPlayer.prototype.EndedHandler = function () {
    this.FireEvent(Framework.Video.HTML5VideoEvent.ENDED);
};

Framework.Controls.HTML5VideoPlayer.prototype.DurationChangeHandler = function () {
    this.FireEvent(Framework.Video.HTML5VideoEvent.DURATION_CHANGE);
};

Framework.Controls.HTML5VideoPlayer.prototype.TimeUpdateHandler = function () {
    this.FireEvent(Framework.Video.HTML5VideoEvent.TIME_UPDATE);
};

Framework.Controls.HTML5VideoPlayer.prototype.PlayHandler = function () {
    this.FireEvent(Framework.Video.HTML5VideoEvent.PLAY);
};

Framework.Controls.HTML5VideoPlayer.prototype.PauseHandler = function () {
    this.FireEvent(Framework.Video.HTML5VideoEvent.PAUSE);
};

Framework.Controls.HTML5VideoPlayer.prototype.VolumeChangeHandler = function () {
    this.FireEvent(Framework.Video.HTML5VideoEvent.VOLUME_CHANGE);
};

Framework.Controls.HTML5VideoPlayer.prototype.RateChangeHandler = function () {
    this.FireEvent(Framework.Video.HTML5VideoEvent.RATE_CHANGE);
};




// ***********************************************************************************************************
// Name:HTML5 Video Playback Controls
// Type:User Control Library
// Author: Cliff Gower
//************************************************************************************************************


//Dependencies
//Framework.EventHandling.js
//Framework.Controls.VideoPlayer.js
//Framework.Video.js


var Framework = Framework || {};
Framework.Controls = Framework.Controls || {};


//*********************** Video Player Play Button  ***************************
Framework.Controls.HTML5VideoPlayButton = function (playButtonElement, videoPlayer, hideOnPlay) {
    this.PlayButtonElement = playButtonElement;
    this.VideoPlayer = videoPlayer;
    this.HideOnPlay = hideOnPlay;
    this.UniqueID = new Date().getMilliseconds();

    Framework.AddHandler(this.PlayButtonElement, Framework.Events.MouseEvents.CLICK, Framework.CreateDelegate(this, this.ClickHandler));

    this.VideoPlayer.RegisterEventHandler(new Framework.CustomEventHandler('PlayButtonPlayEventHandler' + this.UniqueID,
    Framework.Video.HTML5VideoEvent.PLAY, Framework.CreateDelegate(this, this.VideoPlayHandler)));

    this.VideoPlayer.RegisterEventHandler(new Framework.CustomEventHandler('PlayButtonPauseEventHandler' + this.UniqueID,
    Framework.Video.HTML5VideoEvent.PAUSE, Framework.CreateDelegate(this, this.VideoPauseHandler)));
};

Framework.Controls.HTML5VideoPlayButton.prototype.ClickHandler = function () {
    this.VideoPlayer.Play();
}

Framework.Controls.HTML5VideoPlayButton.prototype.VideoPlayHandler = function () {
    if (this.HideOnPlay) {
        this.PlayButtonElement.style.display = Framework.CSS.Display.NONE;
    }
}

Framework.Controls.HTML5VideoPlayButton.prototype.VideoPauseHandler = function () {
    if (this.HideOnPlay) {
        this.PlayButtonElement.style.display = Framework.CSS.Display.BLOCK;
    }
}




//*********************** Video Player Pause Button  ***************************
Framework.Controls.HTML5VideoPauseButton = function (pauseButtonelement, videoPlayer, hideOnPause) {
    this.PauseButtonElement = pauseButtonelement;
    this.VideoPlayer = videoPlayer;
    this.HideOnPause = hideOnPause;
    this.UniqueID = new Date().getMilliseconds();

    Framework.AddHandler(this.PauseButtonElement, Framework.Events.MouseEvents.CLICK, Framework.CreateDelegate(this, this.ClickHandler));

    this.VideoPlayer.RegisterEventHandler(new Framework.CustomEventHandler('PauseButtonPlayEventHandler' + this.UniqueID,
    Framework.Video.HTML5VideoEvent.PLAY, Framework.CreateDelegate(this, this.VideoPlayHandler)));

    this.VideoPlayer.RegisterEventHandler(new Framework.CustomEventHandler('PauseButtonPauseEventHandler' + this.UniqueID,
    Framework.Video.HTML5VideoEvent.PAUSE, Framework.CreateDelegate(this, this.VideoPauseHandler)));
};

Framework.Controls.HTML5VideoPauseButton.prototype.ClickHandler = function () {
    this.VideoPlayer.Pause();
}

Framework.Controls.HTML5VideoPauseButton.prototype.VideoPlayHandler = function () {
    if (this.HideOnPause) {
        this.PauseButtonElement.style.display = Framework.CSS.Display.BLOCK;
    }
}

Framework.Controls.HTML5VideoPauseButton.prototype.VideoPauseHandler = function () {
    if (this.HideOnPause) {
        this.PauseButtonElement.style.display = Framework.CSS.Display.NONE;
    }
}




//*********************** Video Player Mute Button  ***************************
Framework.Controls.HTML5VideoMuteButton = function (muteButtonElement, videoPlayer, hideOnMute) {
    this.MuteButtonElement = muteButtonElement;
    this.VideoPlayer = videoPlayer;
    this.HideOnMute = hideOnMute;
    this.UniqueID = new Date().getMilliseconds();

    Framework.AddHandler(this.MuteButtonElement, Framework.Events.MouseEvents.CLICK, Framework.CreateDelegate(this, this.ClickHandler));

    this.VideoPlayer.RegisterEventHandler(new Framework.CustomEventHandler('MuteButtonVolumeChangeEventHandler' + this.UniqueID,
    Framework.Video.HTML5VideoEvent.VOLUME_CHANGE, Framework.CreateDelegate(this, this.VolumeChangeHandler)));
};

Framework.Controls.HTML5VideoMuteButton.prototype.ClickHandler = function () {
    this.VideoPlayer.Muted(Framework.Video.HTML5VideoMuteState.MUTED);
}

Framework.Controls.HTML5VideoMuteButton.prototype.VolumeChangeHandler = function () {
    if (this.VideoPlayer.Muted() == Framework.Video.HTML5VideoMuteState.MUTED) {
        if (this.HideOnMute) {
            this.MuteButtonElement.style.display = Framework.CSS.Display.NONE;
        }
    }
    else {
        if (this.HideOnMute) {
            this.MuteButtonElement.style.display = Framework.CSS.Display.BLOCK;
        }
    }
}




//*********************** Video Player Unmute Button  ***************************
Framework.Controls.HTML5VideoUnMuteButton = function (unmuteButtonElement, videoPlayer, hideOnUnmute) {
    this.UnmuteButtonElement = unmuteButtonElement;
    this.VideoPlayer = videoPlayer;
    this.HideOnUnmute = hideOnUnmute;
    this.UniqueID = new Date().getMilliseconds();

    Framework.AddHandler(this.UnmuteButtonElement, Framework.Events.MouseEvents.CLICK, Framework.CreateDelegate(this, this.ClickHandler));

    this.VideoPlayer.RegisterEventHandler(new Framework.CustomEventHandler('UnmuteButtonVolumeChangeEventHandler' + this.UniqueID,
    Framework.Video.HTML5VideoEvent.VOLUME_CHANGE, Framework.CreateDelegate(this, this.VolumeChangeHandler)));
};

Framework.Controls.HTML5VideoUnMuteButton.prototype.ClickHandler = function () {
    this.VideoPlayer.Muted(Framework.Video.HTML5VideoMuteState.AUDIBLE);
}

Framework.Controls.HTML5VideoUnMuteButton.prototype.VolumeChangeHandler = function () {
    if (this.VideoPlayer.Muted() == Framework.Video.HTML5VideoMuteState.MUTED) {
        if (this.HideOnUnmute) {
            this.UnmuteButtonElement.style.display = Framework.CSS.Display.BLOCK;
        }
    }
    else {
        if (this.HideOnUnmute) {
            this.UnmuteButtonElement.style.display = Framework.CSS.Display.NONE;
        }
    }
}
