var flowplayer_key="#@e425446c11b3dddfc10";

$(document).ready(
    function()
    {
        // Establecemos el click para todos los reproductores de vídeo de la página
        $("a.videoplayer").click(function() {
           $(this).flowplayer("/swf/flowplayer.swf",{ key: flowplayer_key });
           return false;
        });
        $("a.videoplayer_playlist").each(function() {
            $.ajax({
                async:true,
                dataType:'script',
                url: "/videos/load_playlist/" + $(this).attr("id").split("_")[1]
            });

        });
        // Cargamos todos los flash de la página
        $("div.flash_container").each(function() {
            var flashvars = {};
            var params = {
                wmode: "transparent"
            };
            var attributes = {
                wmode: "transparent"
            };
            id = $(this).attr("id").split("_")[1];
            width = $(this).attr("width");
            height = $(this).attr("height");
            file = $(this).attr("file");
            div_id = "flash_replace_" + id;
            swfobject.embedSWF(file, div_id, width, height, "8.0.0","",flashvars,params,attributes);

        });
        // Todos los enlaces de tipo nicedit_external_link han de abrirse en una ventana nueva
        $("a[rel='external']").click(function() {
            window.open($(this).attr("href"));
            return false;
        });
                //Ocultamos los divs vacíos
        $(".botones-cms").each(function() {
            if ($(this).children().length==0) {
                $(this).hide();
            }
        });
        $(".gmap").each(function() {
            if ($(this).children().length==0) {
                $(this).hide();
            }
        });
        $(".galeria").each(function() {
            if ($(this).children().length==0) {
                $(this).hide();
            }
        });

    }
    );

function load_videos_from_folder(folder,videos) {
    var pl = [];
    for(var i=0;i<videos.length;i++) {
       pl.push({url: videos[i]});
    }
    $("a.videoplayer_playlist[id=videos_" + folder + "]").click(function() {
        $(this).flowplayer("/swf/flowplayer.swf",{ key: flowplayer_key,  playlist: pl, plugins: {controls: {playlist: true }} });
        return false;
    });
}

function load_videos_from_folder_and_start(folder,videos) {
    var pl = [];
    for(var i=0;i<videos.length;i++) {
       pl.push({url: videos[i]});
    }
    $("a.videoplayer_playlist[id=videos_" + folder + "]").flowplayer("/swf/flowplayer.swf",{ key: flowplayer_key, playlist: pl, plugins: {controls: {playlist: true }} });
}
