﻿/* 
 * Funciones para la carga de imagenes aleatorias
 */
var intervalo;
var xmlhttp;
var xml2;

function mostrarSwf(swf)
{
    AC_FL_RunContent(
	    'codebase', 'https://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0',
	    'width', '780',
	    'height', '180',
	    'src', swf,
	    'quality', 'high',
	    'pluginspage', 'https://www.macromedia.com/go/getflashplayer',
	    'align', 'middle',
	    'play', 'true',
	    'loop', 'true',
	    'scale', 'showall',
	    'wmode', 'opaque',
	    'devicefont', 'false',
	    'id', swf,
	    'bgcolor', '#999999',
	    'name', swf,
	    'menu', 'false',
	    'allowScriptAccess','sameDomain',
	    'movie', swf,
	    'salign', ''
	    ); //end AC code
}

function mostrarImagen()
{
    if (xmlhttp.readyState==4) {
        if (xmlhttp.status==200) {
            var xml = xmlhttp.responseXML.getElementsByTagName("Obra")[0];
            xml2 = xml;
            
            var autor = xml.getElementsByTagName("Autores")[0].firstChild.data;
            var image = xml.getElementsByTagName("Imagen")[0].firstChild.data;
            var guid = xml.getElementsByTagName("Guid")[0].firstChild.data;
            document.getElementById("sample_link").href = "DetalleObra.aspx?id=" + guid;
            document.getElementById("sample_link").onclick = function(){return detalleObra(['id='+guid]);};
            document.getElementById("sample_link").innerHTML = autor;
            document.getElementById("sample_link_img").href = "DetalleObra.aspx?id=" + guid;
            document.getElementById("sample_link_img").onclick = function(){return detalleObra(['id='+guid]);};
            document.getElementById("sample_img").src = "Contenido/Imagenes/Obras/" + image + ".jpg";
            document.getElementById("sample_img").style.display = "inline";
        } else {
            //alert("Error cargando datos.");
        }
        intervalo = setInterval(imagenAleatoria, 7500);
    }
}

function imagenAleatoria()
{
    clearInterval(intervalo);

    if (window.XMLHttpRequest) {
        xmlhttp=new XMLHttpRequest()
    } else if (window.ActiveXObject) {
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
    } if (xmlhttp!=null) {
        xmlhttp.onreadystatechange=mostrarImagen;
        xmlhttp.open("GET", "ImagenAleatoria.ashx?" + Math.random(), true)
        xmlhttp.send(null)
    } else {
        alert("error XMLHTTP")
    }
}

/* 
 * Funciones para la visualización de obra y conjuntos de obras
 */
 var v;
 function detalleObra(p)
 {
    var url = 'DetalleObra.aspx?' + p.join('&');
    var specs = 'width=800,height=600,location=no,status=yes,titlebar=yes,scrollbars=yes,resizable=yes';
    v = window.open(url, 'detalle', specs);
    v.focus();
    return false;
 }


function cambiarVisibilidad(id)
{
    var elemento = document.getElementById(id);
    if (elemento.style.display == 'none')
        elemento.style.display = '';
    else
        elemento.style.display = 'none';
    return false;
}