var l;
function getL() {
    return l;
}
function fd() {
    var v = $();
}


function _smFlowPlayerLogoControls () { }

_smFlowPlayerLogoControls.prototype = {

    //configuration variables and default values
    flowPlayerComponent     : null,
    flowPlayerLogo          : null,
    animationSpeed          : 1000,
    flowPlayerConfiguration : null,

    logoOffset:  {
        top     : 15,
        right   : 15,
        bottom  : 25,
        left    : 15,
        playlistWidth: 208
    },

    initialize:  function (flowPlayerComponent) {
        l = this;
        this.flowPlayerComponent = flowPlayerComponent;
        this.flowPlayerConfiguration = this.flowPlayerComponent.configuration;

        if (!('width' in this.flowPlayerConfiguration.logo))

        if (typeof this.flowPlayerConfiguration.logo == 'undefined')
            this.flowPlayerConfiguration.logo = {};

        if (typeof this.flowPlayerConfiguration.logo.displayTime == 'undefined')
            this.flowPlayerConfiguration.logo.displayTime = 0;

        if (typeof this.flowPlayerConfiguration.logo.opacity == 'undefined')
            this.flowPlayerConfiguration.logo.opacity = 1;

        if (typeof this.flowPlayerConfiguration.logo.linkUrl == 'undefined')
            this.flowPlayerConfiguration.logo.linkUrl = "";

        if (typeof this.flowPlayerConfiguration.logo.top == 'undefined' && typeof this.flowPlayerConfiguration.logo.left == 'undefined' &&
            typeof this.flowPlayerConfiguration.logo.right == 'undefined' && typeof this.flowPlayerConfiguration.logo.right == 'undefined') {
            this.flowPlayerConfiguration.logo.bottom = this.logoOffset.bottom;// + (this.flowPlayerConfiguration.logo.logoHeight || 0);
            this.flowPlayerConfiguration.logo.right = this.logoOffset.right;// + (this.flowPlayerConfiguration.logo.logoWidth || 0);
        }
        
        this.logoBottomMargin = 0
        this.logoTopMargin = 0
        this.logoRightMargin = 0
        this.logoLeftMargin = 0
    },

    getLogoPosition:  function(camelCase) {
        if (this.flowPlayerConfiguration.logo.top && this.flowPlayerConfiguration.logo.left)
            position = "Top Left";
        else if (this.flowPlayerConfiguration.logo.top && this.flowPlayerConfiguration.logo.right)
            position = "Top Right";
        else if (this.flowPlayerConfiguration.logo.bottom && this.flowPlayerConfiguration.logo.left)
            position = "Bottom Left";
        else
            position = "Bottom Right";

        if (camelCase == true) {
            words = position.split(' ');
            position = words[0].toLowerCase() + words[1];
        }

        return position;
    },

    getLogoOpacity:  function() {
        return this.flowPlayerConfiguration.logo.opacity;
    },

    getLogoDuration:  function() {
        return this.flowPlayerConfiguration.logo.displayTime;
    },

    setLogoBottomMargin: function(margin) {
        if (this.logoBottomMargin == margin)
            return;
        this.logoBottomMargin = margin;
        this.changeLogoPosition(this.getLogoPosition(false), 0);
    },
    
    changeLogoPosition:  function (position, speed) {
        var pluginExists = this.getLogoPlugin();

        delete this.flowPlayerConfiguration.logo.top;
        delete this.flowPlayerConfiguration.logo.left;
        delete this.flowPlayerConfiguration.logo.bottom;
        delete this.flowPlayerConfiguration.logo.right;

        if (speed == null) {
            speed = this.animationSpeed
        }

        var newPosition = {};
        switch (position)
        {
            case 'Top Left':
                newPosition = { top: this.logoOffset.top, left: this.logoOffset.left };
                break;
            case 'Top Right':
                newPosition = { top: this.logoOffset.top, right: this.logoOffset.right };
                break;
            case 'Bottom Left':
                newPosition = { bottom: this.logoOffset.bottom, left: this.logoOffset.left };
                break;
            case 'Bottom Right':
                newPosition = { bottom: this.logoOffset.bottom, right: this.logoOffset.right };
                break;
        }

        // fix logo position if logo size is set
        /*
        if ('right' in newPosition && 'logoWidth' in this.flowPlayerConfiguration.logo)
            newPosition.right += this.flowPlayerConfiguration.logo.logoWidth;
        if ('bottom' in newPosition && 'logoHeight' in this.flowPlayerConfiguration.logo)
            newPosition.bottom += this.flowPlayerConfiguration.logo.logoHeight;
        */


        // adjust as necessary for if in playlist mode - kinda hacky: this shouldnt know about playlists or not; instead a
        // caller should be able to set margins that affect the logo placement...
        if ('left' in newPosition && 'playListView' in this.flowPlayerConfiguration.plugins && this.flowPlayerConfiguration.plugins.playListView != null)
            newPosition.left += this.logoOffset.playlistWidth;

        // adjust for the generic margins
        if ('top' in newPosition)
            newPosition.top += this.logoTopMargin
        
        if ('bottom' in newPosition)
            newPosition.bottom += this.logoBottomMargin

        if ('right' in newPosition)
            newPosition.right += this.logoRightMargin

        if ('left' in newPosition)
            newPosition.left += this.logoLeftMargin
        
        if (pluginExists) 
            this.flowPlayerLogo.animate(newPosition, speed);
            
        for (var prop in newPosition) {
            this.flowPlayerConfiguration.logo[prop] = newPosition[prop];
        }

    },

    // uncomment logoWidth/logoHeight if/when we want to specify logo dimensions to fix logo positioning bug (DE495)
    changeLogo:  function (logoUrl/*, logoWidth, logoHeight*/) {
        this.flowPlayerComponent.logoUrl = logoUrl;
        this.flowPlayerConfiguration.logo.url = logoUrl;
            //this.updateLogoSize(logoWidth, logoHeight);
            if (this.getLogoPlugin() == false)
           return;
        this.displayFlowPlayer(true);
    },

    getLogoLink:  function () {
        return this.flowPlayerConfiguration.logo.linkUrl;
    },

    changeLogoLink:  function (linkUrl) {
        if (linkUrl.length > 0 && linkUrl.substring(0, 7) != "http://")
            linkUrl = "http://" + linkUrl

        this.flowPlayerComponent.logoLink = linkUrl;
        this.flowPlayerConfiguration.logo.linkUrl = linkUrl;

        if (this.getLogoPlugin() == false)
           return;

        this.displayFlowPlayer();
    },

    changeLogoFullscreen:  function (onlyFullScreen) {
        this.flowPlayerComponent.logoFullScreen = onlyFullScreen;
        this.flowPlayerConfiguration.logo.fullscreenOnly = onlyFullScreen;
        if (this.getLogoPlugin() == false)
           return;
        this.displayFlowPlayer();
    },

    changeLogoDuration:  function (duration) {
        this.flowPlayerConfiguration.logo.displayTime = duration;
        if (this.getLogoPlugin() == false)
           return;
        this.displayFlowPlayer();
    },

    changeLogoOpacity:  function (newOpacity) {
        this.flowPlayerConfiguration.logo.opacity = newOpacity;
        this.flowPlayerLogo = this.flowPlayerComponent.fp.getPlugin("logo");
        if (this.getLogoPlugin() == false)
           return;
        this.flowPlayerLogo.animate({opacity: newOpacity}, this.animationSpeed);
    },

    getLogoPlugin:  function() {
        this.flowPlayerLogo = this.flowPlayerComponent.fp.getPlugin("logo");
        if (this.flowPlayerLogo == null) {
            return false;
        }
        return true;
    },

    displayFlowPlayer:  function(forceDisplay) {
        if (forceDisplay == true || (this.flowPlayerConfiguration.logo.url != null && this.flowPlayerConfiguration.logo.url != "")) {
           this.flowPlayerComponent.displayFlowPlayer();
        }
    }

//  updateLogoSize: function (width, height) {

//      width = width || 0;
//      height = height || 0;

//      this.flowPlayerConfiguration.logo.width = width;
//      this.flowPlayerConfiguration.logo.height = height;

//      // first, reset logo size
//      //this.logoSize.width = width || 0;
//      //this.logoSize.height = height || 0;
//      if ('right' in this.flowPlayerConfiguration.logo)
//          this.flowPlayerConfiguration.logo.right = this.logoOffset.right;// + width;
//      if ('bottom' in this.flowPlayerConfiguration.logo)
//          this.flowPlayerConfiguration.logo.bottom = this.logoOffset.bottom;// + height;

//      /*
//      var url = this.flowPlayerConfiguration.logo.url;

//      console.log(url.substr(-3));

//      // determine if logo is a swf
//      if (url.substr(-3) != 'swf')
//          return;

//      // determine logo size
//      var $swfDetect = $('<object id="detectSwfSize" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0"><param name="movie" value="' + url + '"><param name="quality" value="high"><param name="allowscriptaccess" value="sameDomain"><embed src="' + url + '" name="detectSwfSize" swliveconnect="true" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"></embed></object>');

//      $swfDetect
//          .css({
//              opacity: 0.5,
//              position: 'absolute',
//              top: 0,
//              left: 0
//          })
//          .appendTo('body');

//      var swfDetect = $swfDetect[0];
//      this.logoSize = {
//          width: $swfDetect.width(),
//          height: $swfDetect.height()
//      };

//      console.log('width: ' + this.logoSize.width + ', height: ' + this.logoSize.height);

//      this.flowPlayerConfiguration.logo.bottom += this.logoSize.height;
//      this.flowPlayerConfiguration.logo.right += this.logoSize.width / 2;
//      */

//  }

};

