var player = null;

function startVideo(arquivo, play){
	if ($('#in_live').length >= 1){
		$('#in_live').remove();
	}
	
	var so = new SWFObject('http://www.tvcntur.com.br/libs/player/player.swf','mpl','470','290','9');
	so.addParam('allowfullscreen','true');
	so.addParam('allowscriptaccess','always');
	so.addParam('wmode','opaque');

	if (strstr(arquivo, 'http://'))
    	so.addVariable('file', arquivo);
    else
    	so.addVariable('file', 'http://www.tvcntur.com.br/application/tv_cntur/media/' + arquivo);
        
	so.addVariable('backcolor', '57565e');
	so.addVariable('frontcolor', '11f505');
    so.addVariable('skin', 'http://www.tvcntur.com.br/libs/player/skin/beelden.zip');
	so.addVariable('bufferlength','2');

	if (play)
		so.addVariable('autostart','true');

	so.write('mediaspace');
	
	$('#tv_content').css({'background': '#ffffff'});
    
    getVideoInfos(arquivo);
}

function getVideoInfos(video_file){
	if ($('#video_information').length == 0){
    	return false;
    }

	$.post("includes/getVideoInfo.php",
    	{file: video_file},
        function(data){
        	if (data != null){
                $('#titulo').html("<b>Título:</b> " + data.titulo);
                $('#descricao').html("<b>Descrição:</b> " + data.descricao);
                $('#keywords').html("<b>Keywords:</b> " + data.keywords);
                $('#tempo').html("<b>Tempo de vídeo:</b> " + data.tempo);
                $('#qualidade').html("<b>Qualidade:</b> " + data.velocidade);
                $('#produtor').html("<b>Produtor:</b> " + data.produtor);
            }
        }
    );
}

function playerReady(obj){
	player = document.getElementById(obj.id);
	player.addModelListener('STATE', 'stateHandler');
}

function playerReady(thePlayer){
	player = document.getElementById(thePlayer.id);
	player.addModelListener('STATE', 'stateMonitor');
}

function stateMonitor(obj) {
	if (obj.newstate == 'COMPLETED'){
    	if (playlist_pos >= 0){
    		startVideo(playlist_list[playlist_pos]['url'], true);
            $('#live_in').html(playlist_list[playlist_pos]['title']);
        	playlist_pos++;
        }
    }
}

function playlistControl(url, current){
	startVideo(url, true);
    $('#live_in').html(playlist_list[current]['title']);
    playlist_pos = current+1;
}

function startLive(){
	var so = new SWFObject('http://www.tvcntur.com.br/libs/player/player.swf','mpl','988','290','9');
	so.addParam('allowfullscreen','true');
	so.addParam('allowscriptaccess','always');
	so.addParam('wmode','opaque');
    
    so.addVariable('file', 'tv_cntur');
    so.addVariable('streamer', 'rtmp://videocasting.com.br/oflaDemo');
	so.addVariable('backcolor', '57565e');
	so.addVariable('frontcolor', '11f505');
    so.addVariable('skin', 'http://www.tvcntur.com.br/libs/player/skin/beelden.zip');
	so.addVariable('bufferlength','2');
	so.addVariable('autostart','true');
	so.write('mediaspace');
	
	$('#tv_content').css({'background': '#ffffff'});
}

function clearChannelVideoInfo(){
    $('#titulo').html("<img src=\"../../core/images/outros/ajax-loader.gif\" />");
    $('#descricao').html("");
    $('#keywords').html("");
    $('#tempo').html("");
    $('#qualidade').html("");
    $('#produtor').html("");
}
