﻿//----- Class Definition ------------------------------

var VideoInformation = Class.create({

    initialize: function() {
    },

    getByURL: function(videoURL) {
        return this.setVideoInformation('/Embed/videoinformation.htm?PageUrl=' + escape(videoURL));
    },

    getById: function(Id) {
        return this.setVideoInformation('/Embed/VideoInformationById.htm?oid=' + Id);
    },

    GetWikiVCard: function(title) {
        return this.setVideoInformation('/Info/Wiki/' + title);
    },

    /*GetAutoTranslation: function(url, language) {
        return this.setVideoInformation('/API/Translate?language=' + language + '&url=' + url);
    },

    GetSubtitles: function(url, language, source) {
        return this.setVideoInformation('/API/Subtitles?language=' + language + '&source=' + source + '&url=' + url);
    },*/

    GetGoogleLanguages: function(url, language, source) {
        return this.setVideoInformation('/API/GoogleLanguages');
    },

    setVideoInformation: function(url) {
        var objVideoInfo;
        new Ajax.Request(url, {
            method: 'post',
            asynchronous: false,
            onSuccess: function(transport) {
                objVideoInfo = transport.responseText.evalJSON();
            },
            onFailure: function(transport) {
                objVideoInfo = null;
            }
        });
        return objVideoInfo;
    }
});
        
        var EmbedManager = Class.create({
            
            initialize: function(container, pageDirectLinkUrl) {
                this._embedCodeTemplate = new Template('<object width="#{Width}" height="#{Height}" ><param name="movie" value="#{playerUrl}"></param><param name="allowFullScreen" value="true"></param><embed src="#{playerUrl}" type="application/x-shockwave-flash" width="#{Width}" height="#{Height}" allowfullscreen="true"></embed></object>');
                this._embedParams = new Object();
                this._container = container;
                this._embedParams.Height = '341';
                this._embedParams.Width = '425';
                this._embedParams.pageDirectLinkUrl = (pageDirectLinkUrl) ? pageDirectLinkUrl : '';
                this._embedParams.playerUrl = '';
            }, 
            
            setPlayerUrl: function(playerUrl) {
                this._embedParams.playerUrl = playerUrl;
            }, 
            
            setEmbedSize:function (embedDimentions) { //embedDimentions is in the format of widthXheight
                arrTemp = embedDimentions.toLowerCase().split("x");
                this._embedParams.Width = arrTemp[0];
                this._embedParams.Height = arrTemp[1];
                
                embed = this._container.down('embed');
                object = this._container.down('object');
                
                if(embed) {
                    embed.width = this._embedParams.Width;
                    embed.height = this._embedParams.Height;
                }
                if (object) {
                    object.width = this._embedParams.Width;
                    object.height = this._embedParams.Height;
                }
            },
            
            getEmbedCode: function() {
                return this._embedCodeTemplate.evaluate(this._embedParams);
            },
            
            getPageDirectLink: function(Id) {
                return this._embedParams.pageDirectLinkUrl + "?embedid=" + Id;
            },
            
            getPageDirectLinkByVid: function(id)
            {
                    return this._embedParams.pageDirectLinkUrl + "?vid=" + id;
            }
        }); 
                   
//----- End Class Definition ------------------------------
