var playing = false;

function showPlayer(id, video, image, fuente, zonevideo, zoneoverlay, pinta_content, embedId){
    $("#" + id).html("");
    flowplayer(id, "http://media.vtelevision.es/video/flowplayer.commercial-3.1.5.swf",{
        key: '#$65f19e0dd8ab233181e',

        canvas: {
            backgroundColor: "#000000",
            backgroundGradient: "none"
        },
        
        /*logo: {
            url: "http://media.vtelevision.es/video/fuentes/" + fuente + ".png",
            fullscreenOnly: false, 
            displayTime: 0, 
            opacity: 0.8 
        },*/

        play: {
            // Texto que aparece al final de la reproduccion
            replayLabel: 'Ver otra vez',
            opacity: 1 
        },

        playlist: [
            {
                url: image
            },
            {
                url: video
            }
        ],

        clip: {
            fadeInSpeed: 500,
            fadeOutSpeed: 0,
            scaling: "fit",
            onStart: function(clip) {
                //Controlamos las veces que se ha visto, al llevar publi contaba varias veces el visionado.
                //if (clip.index>0){
                  if (clip.url.indexOf("vtelevision.es")!=-1 && (clip.url.indexOf(".flv")!=-1 || clip.url.indexOf(".mp4")!=-1)){
                    playing = true;
                    var idVideo = id;
                    if (id.search(/^0031/)==-1){
                        idVideo = id.substring(id.indexOf("_")+1);
                    }
                    visualizar(idVideo, '1265627739079244294', id);
                    this.getPlugin("content").hide();
                }
            },
            onFinish: function(clip) {
                playing = false;
                if (pinta_content == "true" && this.getPlugin("content").getHtml() != ""){
                    this.getPlugin("content").show();
                }else{
                    this.getPlugin("content").hide();
                }
            }
        },

        plugins: {

            controls: {
                "url": "http://media.vtelevision.es/video/flowplayer.controls-3.1.5.swf",
                "autoHide": "always",
                //Estilos del controlbar
                "backgroundColor": "transparent",
                "backgroundGradient": "none",
                "sliderColor": '#ffffff',
                "sliderBorder": '1.5px solid rgba(160,160,160,0.7)',
                "volumeSliderColor": '#ffffff',
                "volumeBorder": '1.5px solid rgba(160,160,160,0.7)',
                "bufferColor":"#cccccc",
                "progressColor":"#AE101A",
                "buttonOverColor":"#AE101A",
                "buttonColor":"#AE101A",
                "timeBgColor":"#AE101A",
                "timeColor": '#ffffff',
                "durationColor": '#cccccc',

                "tooltipColor": 'rgba(255, 255, 255, 0.7)',
                "tooltipTextColor": '#AE101A'
            },

            content: {
                "url": "http://media.vtelevision.es/video/flowplayer.content-3.1.0.swf",
                "height": 40, 
                "width": "100%",
                "top": 0,
                "backgroundColor": '#000000', 
                "border": "none",
                "borderRadius": 0,
                "style": {
                    "a":{
                        "color": "#ffffff",
                        "fontSize": 20,
                        "fontWeight": "bold",
                        "marginLeft": 20
                    }
                },
                "opacity": 0.9,
                "html": $("#titulo" + id).html(),
                "display": pinta_content=="true"?"block":"none"
            },

            openAdStreamer: {
                "url": "http://media.vtelevision.es/video/OpenAdStreamer.swf",
                "autoPlay": false,
                
                "player": {
                    "metaData": false,
                    "scaling": "fit"
                },
				"ads": {
                             "notice": {
						"type": "countdown",
						"textStyle": "smalltext",
						"message": "La publicidad finaliza en _countdown_ sg."
					},
                             "disableControls": false,
					"servers": [
						{
						"type": "direct",
						"tag": "http://reachandrich.antevenio.com/call/pubj/18844/135289/4332/M/%5Btimestamp%5D/%5Btarget%5D?[countgo]"
/*"http://publicidadinternet.lavozdegalicia.es"*/
						}
					],
					"schedule": [
						{
						"position": "pre-roll"
						}
					]
				}            
            }
        },

        onLoad: function(){
            if (pinta_content == "true" && this.getPlugin("content").getHtml() != ""){
                this.getPlugin("content").show();
            }else{
                this.getPlugin("content").hide();
            }
        },

        onMouseOver: function() {
            if (pinta_content == "true"){
                this.getPlugin("content").show();
            }
        },

        onMouseOut: function() {
            if (playing == true){
                this.getPlugin("content").hide();
            }
        }

    });
    if (embedId){
        //var code = $("#"+id).html();
        var code = flowplayer().embed().getEmbedCode(true);
        getObject(embedId).value = code;
    }
}
