﻿if (!window.LivePlayer)
    window.LivePlayer = {};

LivePlayer.Stream = null;

LivePlayer.embedFlash = function(id, thumbnail) {
    this.id = id;
    if (id != null) { this.Stream = getStreaming(id, this); }
    this.thumbnail = thumbnail;
    this.copyright = "../ClientBin/no_disponible_"+id+".jpg";
    this.width = "100%";
    this.height = "100%";

    var config = {
        key: "#@9b30f1b424a4496850e",
        version: [9, 115],
        canvas: {
            backgroundColor: '#000000',
            backgroundGradient: [0, 0]
        },
        clip: {
		},
		plugins: {
			content: {
				url: "flowplayer.content-3.1.0.swf",
				closeButton: true,
				height: 30,
				top: 310,
				padding: 5,
				color: '#ffffff',
				backgroundColor: '#000000',
				opacity: 0.9,
				html: '',
				style: { p: { fontSize: 14} },
				display: 'block',
				onClick: function() {
					pageTracker._trackEvent($("#hidden_campaign").val(), 'Clic', $("#hidden_spotname").val());
				}
			},
			controls: {
				display: 'none'
			},
			rtmp: {
				url: 'flowplayer.rtmp-3.1.3.swf',
				onBeforePause: function() {
					return false;
				}
			}
		},
		playlist: [
				{
					url: '',
					autoPlay: false,
					onStart: function() {
						pageTracker._trackEvent($("#hidden_campaign").val(), 'Reproduccion', $("#hidden_spotname").val());
					}
				},
				{
					provider: 'rmtp',
					netConnectionUrl: '',
					url: '',
					scaling: "fit",
					autoPlay: true,
					live: true,
					onStart: function() {
						this.getControls().show();
						this.getPlugin('content').hide();
						pageTracker._trackEvent('Directo', 'Reproduccion', id);
					},
					onFinish: function() {
						this.unload();
					}
				}
			]
		};

if (this.Stream) {
    config.playlist[1].provider = 'rtmp';
    config.playlist[1].netConnectionUrl = this.Stream[0];
    config.playlist[1].url = this.Stream[1];

    if ($("#hidden_spot").val())
        config.playlist[0].url = $("#hidden_spot").val();
    else {
        config.playlist.shift();
        config.plugins.content.display = 'none';
        config.playlist[0].autoPlay = false;
    }

    config.canvas.backgroundColor = null;
    config.plugins.content.html = '<p align="center"><a href="' + $("#hidden_spoturl").val() + '" target="_blank">' + $("#hidden_spottext").val() + '</a>'
    if (this.Stream[2]) {
        $("#reproductor").css("background-image", "url(" + this.Stream[2] + ")");
        config.clip.image = true;
    }
    else {
        $("#reproductor").css('background-image', '');
        config.clip.image = false;
    }
} else {
    config.plugins.content.display = 'none';
    config.playlist.shift();
    config.playlist.shift();
    config.clip.url = this.copyright;
    config.play = null;
}

flowplayer("reproductor", { src: "../swf/flowplayer.commercial-3.1.5.swf", wmode: "transparent" }, config);
}

LivePlayer.Zapping = function(id, thumbnail) {
    LivePlayer.Zapping(id, thumbnail, null);
}

LivePlayer.Zapping = function(id, thumbnail) {
    try {
        $("#hidden_canal").val(id);
        LivePlayer.embedFlash(id, thumbnail);
    }
    catch (msg) { }
}

LivePlayer.Play = function(clip) {
    try {
        var player = flowplayer();
        player.stop();
        player.setClip(clip);
        player.play();
    }
    catch (msg) { }
}

function getStreaming(id, control) {
    var _streaming = null;
    var _showPlayer = $("#showPlayer").val();

    // 0: no play ideo;
    // 1: everybody play video;
    // 2: somebody play video, only in white list ip's;
    _showPlayer = parseInt(_showPlayer);
    var img = $("#imgSelected").val();
    
    if (_showPlayer > 0) {
    
        switch (id) {
            case "tv":
				_streaming = ["rtmp://streamrtvc.mad.idec.net/rtvc1", "rtvc_1.sdp", img];
                break;
            case "rtvc2":
				_streaming = ["rtmp://streamrtvc.mad.idec.net/rtvc2", "rtvc_2.sdp", img];
                break;
            case "sat":
				_streaming = ["rtmp://streamrtvc.mad.idec.net/rtvcnet", "rtvc_net.sdp", img];
                break;
            case "radio":
                _streaming = ["rtmp://streamrtvc.mad.idec.net/rtvcradio", "rtvc_radio.sdp", img];
                break;
            case "volcan":
                _streaming = ["rtmp://streaming.mad.idec.net/30986.1321612191", "volcan.sdp", img];
                break;
            default:
                _streaming = [];
                break;
        }
        
        
    }

    return _streaming;
}
