﻿if (!window.miniplayer)
    miniplayer = {};

miniplayer.Page = function() {
}

miniplayer.Page.prototype =
{
    handleLoad: function(control, userContext, rootElement) {
        this.control = control;
        this.vidId = this.control.initParams;
        this.tmpVidId = this.vidId.sub('vid', '');
        this.tmpVidBgUrl;
        this.callFadeInOnce = 0;
        rootElement.addEventListener("MouseLeftButtonDown", Silverlight.createDelegate(this, this.handleClick));
        rootElement.addEventListener("MouseEnter", Silverlight.createDelegate(this, this.handlevidMouseEnter));
        rootElement.addEventListener("MouseLeave", Silverlight.createDelegate(this, this.handlevidMouseLeave));
        rootElement.findName("Vid").addEventListener("BufferingProgressChanged", Silverlight.createDelegate(this, this.handleBufferingProgressChanged));

        //Set Vid Properties
        rootElement.findName("Vid").Volume = 0;
        rootElement.findName("Vid").Source = globalVars.get(this.vidId + "UrlThumb");
        rootElement.findName("VidTitle").Text = globalVars.get(this.vidId + "Title");

        rootElement.findName("copyVid").Source = globalVars.get(this.vidId + "Copy");

        rootElement.findName("VidTitle").Foreground = "#FFFFFFFF";

        //Text align Center
        this.maxVidTitleWidth = 180;
        rootElement.findName("VidTitle")["Canvas.Left"] = (rootElement.findName("Page").Width / 2) - (rootElement.findName("VidTitle").ActualWidth / 2);
    },
    handleClick: function(sender, eventArgs) {
        $("mediaPlayerContainer").setStyle({ display: "none" });
        globalVars.set("activeVidId", this.vidId);
        globalVars.get("createHtmlOverlay").show();
        globalVars.set("tmpOverlayVidSource", globalVars.get(this.vidId + "UrlSl"));
        $("SilverlightControlOverlay").content.findName("vidMedia").Source = globalVars.get(this.vidId + "UrlSl");
        globalVars.get("callOverlayVidPlay")();
        $("overlayMoreLink").writeAttribute("href", globalVars.get(this.vidId + "MoreBtnTopic"));
        sender.findName("Vid").Stop();
        new wtTrack(globalVars.get(this.vidId + "UrlSl") + globalVars.get("slVideoUrlSuffix0"), globalVars.get("slVideoStartedWtTitlePrefix") + globalVars.get(this.vidId + "Title"), globalVars.get("WebtrendsChannel"), 7);
    },
    handlevidMouseEnter: function(sender, eventArgs) {
        sender.findName("Vid").Play();
        this.tmpVidBgUrl = $("navi-" + this.tmpVidId).getStyle("background-image");
        $("navi-" + this.tmpVidId).setStyle({ backgroundImage: "url(" + globalVars.get("globalRelativeUrl") + "_sub/img/navi" + globalVars.get("NumberOfVideos") + "/navi-" + this.tmpVidId + "-hvr2.jpg)" });
    },
    handlevidMouseLeave: function(sender, eventArgs) {
        globalVars.get("navi").setNavi();
        this.control.content.findName("Vid").Stop();
    },
    handleBufferingProgressChanged: function(sender, eventArgs) {
        if (sender.BufferingProgress == 1 && this.callFadeInOnce == 0) {
            this.control.content.findName("vidfadein").begin();
            this.callFadeInOnce++;
        }
    }
}
