﻿//=================================================
// Classe que adiciona o voxelPlayer na página
//=================================================

function VoxelPlayerV2(SWFFilePath, divToWriteObject, width, height, hideOnInit, flashVars)
{
    //===============================================
    // Fields
    var _width = width;
    var _height = height;
    
    this.IsVisible = !hideOnInit;
    //===============================================

    //===============================================
    //Cosntructor Logic
    
    //instanciando o script para embed flash
    var swfUtil = new SWFUtil();
    
    var flashParams = {
        menu: "false"   
        ,allowFullScreen: "true"
        ,allowscriptaccess: "sameDomain"
        ,scaleMode: "noScale"
        //,quality: "high"
        //,wmode: "opaque"
    };
    
    //escrevendo o embed
    swfUtil.Embed(  SWFFilePath,
                    hideOnInit ? 0 : width,
                    hideOnInit ? 0 : height,
                    divToWriteObject,
                    "9.0.115.0", 
                    "VMP", 
                    "VMP", 
                    flashVars, 
                    flashParams);
                    
    //===============================================
    //===============================================
    
    this.ShowPlayer = function()
    {
        document.VMP.width = _width;
        document.VMP.height = _height;
        
        this.IsVisible = true;
    };
    
    this.AddMediaInPlaylist = function(codMedia,type,videoURL,thumbPath,addPlaying)
    {
        //mostra o player caso não esteja visível
        if(!this.IsVisible) this.ShowPlayer();
        
        document.VMP.AddMediaInPlaylist(codMedia,type,videoURL,thumbPath,addPlaying);
    };
    
    this.AddMediaWithCut = function(codMedia,type,initialTime,finalTime,videoURL,thumbPath,addPlaying)
    {
        //mostra o player caso não esteja visível
        if(!this.IsVisible) this.ShowPlayer();
        
        document.VMP.AddMediaWithCut(codMedia,type,initialTime,finalTime,videoURL,thumbPath,addPlaying);
    };
    
    this.AddVignette = function(codMedia,type,videoURL)
    {
        document.VMP.AddVignette(codMedia,type,videoURL);
    };
    
    this.PlayMediaToPlaylist = function(codMedia,type,videoURL,thumbPath,isCommercial)
    {
        //mostra o player caso não esteja visível
        if(!this.IsVisible) this.ShowPlayer();
        
        document.VMP.PlayMediaToPlaylist(codMedia,type,videoURL, thumbPath,isCommercial);
    };
    
    this.PlayMediaToPlaylistWithCut = function(codMedia,type,initialTime,finalTime,videoURL,thumbPath,isCommercial)
    {
        //mostra o player caso não esteja visível
        if(!this.IsVisible) this.ShowPlayer();
        
        document.VMP.PlayMediaToPlaylistWithCut(codMedia,type,initialTime,finalTime,videoURL, thumbPath,isCommercial);
        
    };
    
    this.PlayMedia = function(codMedia,type,videoURL,isCommercial)
    {
        //mostra o player caso não esteja visível
        if(!this.IsVisible) this.ShowPlayer();
        
        document.VMP.PlayMedia(codMedia, type, videoURL, isCommercial);
    };  
};

//Captura a Largura e altura do client
//TODO: buscar solução para variável estática em js OO

function VoxelPlayer_GetClientWidth()
{
    return screen.width;
};

function VoxelPlayer_GetClientHeight()
{
    return screen.height;
};

function VoxelPlayer_OnLoadMediaError()
{
    var confirmResult = confirm("Ocorreu um erro ao carregar este vídeo. Deseja Excluí-lo da playlist?");
    
    return confirmResult;
};

function VoxelPlayer_OnLoadProtectedMedia()
{
    return "http://www.helpexamples.com/flash/video/caption_video.flv";
};