﻿var currentState = "NONE"; 
var previousState = "NONE"; 
var videosCarregados = 0; 
var videoInicial = ""; 
 
var player = null;
function playerReady(thePlayer) {
	player = document.getElementById(thePlayer.id);
	addListeners();
} 
 
function addListeners() {
	if (player) { 
		player.addModelListener("STATE", "stateListener");
	} else {
		setTimeout("addListeners()",100);
	}
} 
 
function stateListener(obj) { //IDLE, BUFFERING, PLAYING, PAUSED, COMPLETED
	currentState = obj.newstate; 
	previousState = obj.oldstate; 
 	
 	if ((currentState == "COMPLETED")&&(previousState == "PLAYING")) 
 	{
        if(videosCarregados <= 0)
		    completo();
	}
} 

function completo(){
     videosCarregados ++;
     Carregar.Video.createPlayer(videoInicial);
}

/************************************[ BOX VIDEO ]************************************/   
Carregar = {};

Carregar.Video = {    

    carregaVideo : function(caminho){
        videoInicial = caminho;
        var version = parseFloat(navigator.appVersion.split("MSIE")[1]);
        var mp4 = caminho.indexOf('mp4');
        if (version != 6 )
        {
            var isIPhone = navigator.userAgent.toLowerCase().indexOf('iphone') != -1;            
            if (!isIPhone)
            {
                jQuery('#divCaixaTelevisao').show();
                jQuery('#btnIphone').hide();
            
                Carregar.Video.createPlayer("http://www.tvnewtonpaiva.com.br/ArquivosWebTV/Videos/vinheta_webtv.mp4");		
            }
            else
            {
                jQuery('#divCaixaTelevisao').hide();
                jQuery('#btnIphone').show();
                
                Carregar.Video.createIphoneAcess(caminho);	
            }
        }
        else
            jQuery('#bsAntigo').show();
         
    },
    
    createIphoneAcess : function(caminhoVideo)
    {
      /*Para que o vídeo possa ser exibido no IPhone, ele deve ser mp4.*/            
        var link = document.createElement('a');                        
        link.href = caminhoVideo;
        link.innerHTML = '<br/> <img class="nv" src="App_Themes/Default/imagens/btn/btnVerVideo_off.gif" onmouseover="this.src = \'App_Themes/Default/imagens/btn/btnVerVideo_on.gif\';"  onmouseout="this.src = \'App_Themes/Default/imagens/btn/btnVerVideo_off.gif\';"  /> <br/><br/>';
        jQuery('#btnIphone')[0].appendChild(link);
    },
        
    createPlayer : function(caminhoVideo)
    {        
        var swf = new SWFObject("player-licensed-viral.swf",'video',"444","279","9","#FFFFFF");
	    swf.addParam("allowfullscreen","true");
	    swf.addParam("allownetworking","all");
	    swf.addParam("allowscriptaccess","always");
	    swf.addParam("flashvars","autostart=true&file=" + caminhoVideo);
	    swf.write(jQuery('#playerContainer')[0]);
		
	    video = document.getElementById('video');
    }
};
/************************************[ BOX VIDEO ]************************************/       
    
