///mostrar capas video

function getFlashMovie(movieName) {
    if (window.document[movieName]) {
        return window.document[movieName];
    }
    if (navigator.appName.indexOf("Microsoft Internet") == -1) {
        if (document.embeds && document.embeds[movieName]) {
            return document.embeds[movieName];
        }
    }
    else // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
    {
        return document.getElementByName(movieName);
    }
}

function showVideoOptions(idVideo) {
    idVideo = idVideo.replace(".swf", "");

    if ($("#bot" + idVideo).is(":hidden")) {
        $("#inf" + idVideo).slideUp("slow");
        $("#bot" + idVideo).slideDown("slow");
    }
    else {
        $("#bot" + idVideo).slideUp("slow");
    }
}

function showInfo(idVideo) {
    idVideo = idVideo.replace(".swf", "");

    if ($("#inf" + idVideo).is(":hidden")) {
        $("#bot" + idVideo).slideUp("slow");
        $("#inf" + idVideo).slideDown("slow");
    } else {
        $("#inf" + idVideo).slideUp("slow");
    }
}

function cerrarcapa(idVideo) {
    $("#inf" + idVideo).slideUp("slow");
}

$(document).ready(function () {
    //    $(".item").each(function() {
    //    if ($(this).children().get(1).name != null && $(this).children().get(1).name!="") {
    //            alert($(this).children().get(1).name);
    //        }
    //    })

    if (document.getElementById("logotIber") != null) {
        document.getElementById("logotIber").oncontextmenu = function () {
            return false;
        }
        document.getElementById("logotIber").onselectstart = function () {
            return false;
        }
        document.getElementById("logotIber").ondragstart = function () {
            return false;
        }
    }

    $("#iberdrola24").click(function () { window.open('http://www.iberdrola.es/webibd/gc/prod/es/clientes/iberdrola_24h.html', 'popup', 'width= 682 ,height= 700,scrollbars=yes '); return false; });
    $("#pie24").click(function () { window.open('http://www.iberdrola.es/webibd/gc/prod/es/clientes/iberdrola_24h.html', 'popup', 'width= 682 ,height= 700,scrollbars=yes '); return false; });
    $("#print").click(function () { print(); return false; });
    /*$("#enviar").click(function() {openenviar(); return false;});	*/

    $(".txt").click(function () { this.value = ""; return false; });
    $(".cajabuscador").click(function () { this.value = ""; return false; });

    $("#acceso-pro .head").click(function () {
        if ($(".login").is(":hidden")) {
            $(".login").slideDown("slow");
        } else {
            $(".login").slideUp("slow");
        }
    });

    //acceso ingles
    $("#acceso-pro .headen").click(function () {
        if ($(".loginen").is(":hidden")) {
            $(".loginen").slideDown("slow");
        } else {
            $(".loginen").slideUp("slow");
        }
    });

    //ordenar

    $("#ordena-noticias .head").click(function () {
        if ($(".ordena-options").is(":hidden")) {
            $(".ordena-options").slideDown("slow");
            $("#txtFilter").addClass('txtOrdena-active');
        } else {
            $(".ordena-options").slideUp("slow");
            $("#txtFilter").removeClass('txtOrdena-active');
        }
    });

    //ordenar en ingles
    $("#ordena-noticias .headen").click(function () {
        if ($(".ordena-options").is(":hidden")) {
            $(".ordena-options").slideDown("slow");
            $("#txtFilter").addClass('txtOrdena-active');
        } else {
            $(".ordena-options").slideUp("slow");
            $("#txtFilter").removeClass('txtOrdena-active');
        }
    });

    //BUCADOR
    $("#avanzado").click(function () {
        if ($(".avanzado").is(":hidden")) {
            $(".avanzado").slideDown("slow");
            $("#buscador-web").css('backgroundImage', 'url(/images/fondo-buscador-avanzado.png)');
            $("#avanzado").addClass('verde-claro-active');
            $("#avanzado").css('backgroundImage', 'url(/images/arrow-green-down.png)');
        } else {
            $(".avanzado").hide();
            $("#buscador-web").css('backgroundImage', 'url(/images/fondo-buscador.png)');
            $("#avanzado").removeClass('verde-claro-active');
            $("#avanzado").css('backgroundImage', 'url(/images/arrow-green-right.png)');
        }

        ;
    });

    //BUCADOR ESPAŅOL
    $("#avanzado2").click(function () {
        if ($(".avanzado2").is(":hidden")) {
            $(".avanzado2").slideDown("slow");
            $("#buscador-weben").css('backgroundImage', 'url(/images/fondo-buscador-avanzado-en.png)');
            $("#avanzado2").addClass('verde-claro-active');
            $("#avanzado2").css('backgroundImage', 'url(/images/arrow-green-down.png)');
        } else {
            $(".avanzado2").hide();
            $("#buscador-weben").css('backgroundImage', 'url(/images/fondo-buscador.png)');
            $("#avanzado2").removeClass('verde-claro-active');
            $("#avanzado2").css('backgroundImage', 'url(/images/arrow-green-right.png)');
        }

        ;
    });

    //carrusel noticia final

    $('#back').click(function () {
        if (navigator.appName.indexOf("Microsoft Internet") != -1) {
            $(".item").each(function (index, domEle) {
                for (i = 0; i < $(this).children().length; i++) {
                    if (($(this).children().get(i).id).indexOf("video") != -1) {
                        var capa = $(this).children().get(i).id;

                        var play = $("#" + capa).children().get(0).id;
                        if (window.document[play]) {
                            window.document[play].stop();
                        }
                    }
                }
            })
        }
    });

    $('#next').click(function () {
        if (navigator.appName.indexOf("Microsoft Internet") != -1) {
            $(".item").each(function (index, domEle) {
                for (i = 0; i < $(this).children().length; i++) {
                    if (($(this).children().get(i).id).indexOf("video") != -1) {
                        var capa = $(this).children().get(i).id;

                        var play = $("#" + capa).children().get(0).id;
                        if (window.document[play]) {
                            window.document[play].stop();
                        }
                    }
                }
            })
        }
    });

    $('#media-items').cycle({
        fx: 'scrollHorz',
        timeout: 0,
        prev: '#back',
        next: '#next'
    });

    $(".mediaItem").click(function () {
        if (navigator.appName.indexOf("Microsoft Internet") != -1) {
            $(".item").each(function (index, domEle) {
                for (i = 0; i < $(this).children().length; i++) {
                    if (($(this).children().get(i).id).indexOf("video") != -1) {
                        var capa = $(this).children().get(i).id;

                        var play = $("#" + capa).children().get(0).id;
                        if (window.document[play]) {
                            window.document[play].stop();
                        }
                    }
                }
            })
        }

        var agt = navigator.userAgent.toLowerCase()
        var index = Math.abs(this.id);
        $('#media-items').cycle(index);
    });

    //mas vitos

    $('#mas-news').cycle({
        fx: 'scrollLeft',
        speed: 'slow',
        timeout: 0,
        next: '#nextHome',
        prev: '#backHome'
    });

    //MENU SUPEIOR

    $("#list1 .head").click(function () {
        if ($("#list1 ul").is(":hidden")) {
            $("#list1 ul").slideDown("slow");
        } else {
            $("#list1 ul").slideUp("slow");
        }
    });

    $("#list2 .head").click(function () {
        if ($("#list2 ul").is(":hidden")) {
            $("#list2 ul").slideDown("slow");
        } else {
            $("#list2 ul").slideUp("slow");
        }
    });

    $("#list3 .head").click(function () {
        if ($("#list3 ul").is(":hidden")) {
            $("#list3 ul").slideDown("slow");
        } else {
            $("#list3 ul").slideUp("slow");
        }
    });

    $("#list4 .head").click(function () {
        if ($("#list4 ul").is(":hidden")) {
            $("#list4 ul").slideDown("slow");
            $("#list4").css('backgroundImage', 'url(/images/menu-item.png)');

            var alto = $("#list4 ul li").height() * $("#list4 ul li").length
            $("#list4").css('margin-bottom', 50 + alto + 'px');
        } else {
            $("#list4 ul").slideUp("slow");
            $("#list4").css('backgroundImage', 'url(/images/menu-item-last.png)');

            $("#list4").css('margin-bottom', '10px');
        }
    });

    $('#media-items .lightbox').click(function () {
        var SRC = this.parentElement.parentElement.firstChild.nextSibling.src

        $(document).ready(function () {
            $('html').css('overflow', 'hidden');
            $.blockUI({ message: "<img src='" + SRC + "'>" });
            setTimeout($.unblockUI, 4000)
        });
    });

    //FAVORITOS

    $("#closeNav").click(function () {
        $("#ulNav .sound").hide();
        $("#ulNav .video").hide();
        $("#ulNav .news").hide();
        $("#ulNav .sound").hide();
        $("#ulNav .empty").show();
    });

    $("#openNav").click(function () {
        $("#menu-favoritos li.first").css('height', 'auto');
        $("#ulNav .sound").show();
        $("#ulNav .video").show();
        $("#ulNav .news").show();
        $("#ulNav .sound").show();
    });

    //XBox
});

function openWin() {
    var oWnd = radopen("/registro", "RadWindow1");
    oWnd.SetSize(955, 750);
    oWnd.center();
}

//CAMBIAR DE VIDEO DINAMICAMENTE
function cambiavideo(id, i, tipo) {
    $("#ply" + id).remove();

    if (tipo == "hd") {
        $("#video" + i).append("<script src='/provider/GetMediaJs.ashx?tokenid=" + id + "&height=288&width=480&capa=video" + i + "&tipo=hd'></script>");
        $("#enlace" + i).replaceWith("<a href=\"#\" id=\"enlace" + i + "\"  onclick=\"cambiavideo('" + id + "','" + i + "','ld');\" title=\"Download\"><img src=\"/images/ld.png\" alt=\"Ver video ld\"   height=\"28px\" width=\"28px\" ></a>");
    }
    else {
        $("#video" + i).append("<script src='/provider/GetMediaJs.ashx?tokenid=" + id + "&height=288&width=480&capa=video" + i + "&tipo=ld'></script>");
        $("#enlace" + i).replaceWith("<a href=\"#\" id=\"enlace" + i + "\"  onclick=\"cambiavideo('" + id + "','" + i + "','hd');\" title=\"Hd\"><img src=\"/images/hd.png\" alt=\"Ver video en hd\"    height=\"28px\" width=\"28px\"  ></a>");
    }

    idVideo = id.replace(".swf", "");

    if ($("#bot" + idVideo).is(":hidden")) {
        $("#inf" + idVideo).slideUp("slow");
        $("#bot" + idVideo).slideDown("slow");
    }
    else {
        $("#bot" + idVideo).slideUp("slow");
    }
}

function openrecuperar() {
    var oWnd = radopen("/recuperar", "RadWindow4");
    oWnd.SetSize(460, 340);
    oWnd.center();
}

function openzoom(id) {
    var oWnd = radopen("/Zoom/" + id, "RadWindow3");
    oWnd.SetSize(760, 608);
    oWnd.center();
}

function copiar(id) {
    var oWnd = radopen("/Copiar/" + id, "RadWindow5");
    oWnd.SetSize(670, 360);
    oWnd.center();
}

function openenviar(url) {
    var oWnd = radopen("/EnviarAmigo", "RadWindow6");
    oWnd.SetSize(460, 420);
    oWnd.center();
}

function addfavorito(id) {
    $.ajax({
        type: "POST",
        url: "/favorito",
        data: "id=" + id,
        success: function (html) {
            location.reload();
        }
    });
}
