// Constantes de uso global
var CONST_Selected_Menu_Class = "selected_menu";

/*
 *   Escribe el texto 'text' en la capa que se le pasa como parámetro 'obj'
 */
function layerWrite( obj, text )
{
	obj.innerHTML = text;
}

/*
 *   Devuelve el valor de la variable que se pasa en la url
 */
function getValueOfVariable( variable )
{
    var value = " ";
	var url   = document.location.search+"";
    var iPos  = url.indexOf( variable+"=" );
    var iPos2 = 0; 

    if( iPos != -1 )
	{
	    iPos += (variable.length + 1)
		url = url.substring( iPos, url.length );
		iPos2 = url.indexOf( "&" );
		if( iPos2 == -1 )
    		value = url;
		else
		    value = url.substring( 0, iPos2 );
	}
	
	return unescape( value );
}

/*
 *   Inicializa las variables que sirven para mostrar las distintas obras
 */
function loadWork( name, num, gallery, view, picture, text )
{
    var iFramon = eval( 'top.frames[0]' );
	if( iFramon == null ) iFramon = document;

  iFramon.location.href = "./works.html?NAME="+name+"&NUMBER="+num+"&GALLERY="+gallery+"&VIEW="+view+"&PICTURE="+picture+"&TEXT="+text;
}

/*
 *   Dada una opción de menú, le cambia el estilo para que aparezca como seleccionada
 */
function selectMenuOption( obj )
{
    obj.className = CONST_Selected_Menu_Class;
}

/*
 *   Carga todas las vistas de la galería en cuestión en el iframe
 *   principal de descargas
 */
function loadViews( pagina, obj )
{
    var iFramon = eval( 'top.frames[0]' );
	if( iFramon == null ) iFramon = document;

    if( obj != null )
    {
        restoreMenus( obj.className ); 		
        selectMenuOption( obj );
    }
		
    var gallery = getGallery( pagina );
    var direccion = "./";
    
    if( (pagina == 'metta') || (pagina == 'alcazar') )
        direccion += "4views.html";
	else if( (pagina == 'stadtgalerie') )
        direccion += "8views.html";
    else if( (pagina == 'metta2') || (pagina == 'ditesheim') )
        direccion += "1view.html";
    else
        direccion += "2views.html";
        
    iFramon.location.href = direccion+"?GALLERY="+gallery+"&NAME="+pagina;
}


/*
 *   Restaura los estilos de los menúes a su condición original
 */
function restoreMenus( name )
{
	  if( name == CONST_Selected_Menu_Class ) return;
	  
	  var orden = 1;
	  var obj = eval( document.getElementById( 'menu1' ) );
	  
	  while( obj != null )
	  {
		  obj.className = name;
		  orden++;
    	  obj = eval( document.getElementById( 'menu'+orden ) );
	  }
}

/*
 * Devuelve el nombre completo de la galería en función del nombre abreviado
 */
function getGallery( pagina )
{
    var retorno = "desconocida"
    
	if(pagina == 'stadtgalerie')
		retorno = "STADTGALERIE 2009, Klagenfurt";
	else if(pagina == 'magnet')
		retorno = "GALERIE MAGNET 2009, Klagenfurt";
	else if (pagina == 'sales')
		retorno = "ALEJANDRO SALES 2008, Barcelona";
    else if( pagina == 'alcazar' )
       retorno = "GALERIA ALVARO ALCAZAR 2007, Madrid";
    else if( pagina == 'metta2' )
       retorno = "GALERIA METTA (GROUP) 2005, Madrid";
    else if( pagina == 'metta' )
       retorno = "GALERIA METTA 2003, Madrid"
    else if( pagina == 'torbandena' )
       retorno = "GALLERIA TORBANDENA 1999, Trieste"
    else if( pagina == 'deutsche' )
       retorno = "DEUTSCHE BANK 1998, Madrid"
    else if( pagina == 'beitzel' )
       retorno = "DAVID BEITZEL 1991, New York"
	
    return retorno;	
}

/*
 *   Carga las vistas individuales de cada galería en el iframe
 *   principal de descargas
 */
function loadViewDetail( pagina, v )
{
    var iFramon = eval( 'top.frames[0]' );
	if( iFramon == null ) iFramon = document;
	
    var picture = pagina+"_view"+v+".jpg";
    var gallery = getGallery( pagina );	
    var view = "View "+v;	
	
    iFramon.location.href = "./view_detail.html?PICTURE="+picture+"&GALLERY="+gallery+"&NAME="+pagina+"&VIEW="+view+"&NUMBER="+v
}

/*
 *   Carga la imagen grande de una obra en un marco individual
 */
function loadWorkDetail( gallery, numero, pagina, view, picture, texto )
{
    var gallery = getGallery( pagina );	
    var view = "View "+numero;	
    var big_picture = picture.replace(".","_big.");
	
    top.location.href = "./work_detail.html?PICTURE="+big_picture+"&GALLERY="+gallery+"&NAME="+pagina+"&VIEW="+view+"&NUMBER="+numero+"&TEXT="+texto
}

/*
 * Selecciona por defecto la galería más moderna y carga sus vistas
 */ 
function selectDefaultMenuOption()
{
   var gallery = getValueOfVariable('GALLERY');
    
    if( gallery.length < 2 )
        loadViews( 'stadtgalerie', document.getElementById( 'menu9' ) )
    else
    {
        var nombre = getValueOfVariable('NAME');
        var objMenu;
		
        if( nombre == 'beitzel' )
            objMenu = document.getElementById( 'menu1' );
        else if( nombre == 'deutsche' )
            objMenu = document.getElementById( 'menu2' );
        else if( nombre == 'torbandena' )
            objMenu = document.getElementById( 'menu3' );
        else if( nombre == 'metta' )
            objMenu = document.getElementById( 'menu4' );
        else if( nombre == 'metta2' )
            objMenu = document.getElementById( 'menu5' );
        else if( nombre == 'alcazar' )
            objMenu = document.getElementById( 'menu6' );
		else if( nombre == 'sales')
			objMenu = document.getElementById( 'menu7' );
		else if( nombre == 'magnet')
			objMenu = document.getElementById( 'menu8' );
		else if	( nombre == 'stadtgalerie')
			objMenu = document.getElementById( 'menu9' );
        
        selectMenuOption( objMenu );
        
        var picture = getValueOfVariable('PICTURE') 
        picture = picture.replace( "_big.", "." );
        loadViewDetail( nombre, getValueOfVariable('NUMBER') );
    }    
}

function writeExhibitionsBody()
{
    document.write( "<!-- CUERPO CENTRAL -->" );
    document.write( "<table width=\"100%\"  border=\"0\" cellspacing=\"0\" cellpadding=\"0\">" );
    document.write( "<tr><td rowspan=\"100\"><img src=\"images/bs.gif\" width=\"50\" height=\"1\"></td>" );
    document.write( "<td><img src=\"images/bs.gif\" width=\"355\" height=\"1\"></td>" );
    document.write( "<td><img src=\"images/bs.gif\" width=\"500\" height=\"1\"></td>" );
    document.write( "<td rowspan=\"100\"><img src=\"images/bs.gif\" width=\"50\" height=\"1\"></td>" );
    document.write( "</tr><tr><td align=\"left\">" );
	document.write( "<a class=\"left_menu\" href=\"#\" id=\"menu9\" onClick=\"loadViews( 'stadtgalerie', this )\">STADTGALERIE 2009, Klagenfurt</a><br><br>" );
	document.write( "<a class=\"left_menu\" href=\"#\" id=\"menu8\" onClick=\"loadViews( 'magnet', this )\">GALERIE MAGNET 2009, Klagenfurt</a><br><br>" );
	document.write( "<a class=\"left_menu\" href=\"#\" id=\"menu7\" onClick=\"loadViews( 'sales', this )\">ALEJANDRO SALES 2008, Barcelona</a><br><br>" );
	document.write( "<a class=\"left_menu\" href=\"#\" id=\"menu6\" onClick=\"loadViews( 'alcazar', this )\">GALER&Iacute;A &Aacute;LVARO ALC&Aacute;ZAR 2007, Madrid</a><br><br>" );
	document.write( "<a class=\"left_menu\" href=\"#\" id=\"menu5\" onClick=\"loadViews( 'metta2', this )\">GALER&Iacute;A METTA (GROUP) 2005, Madrid</a><br><br>" );
    document.write( "<a class=\"left_menu\" href=\"#\" id=\"menu4\" onClick=\"loadViews( 'metta', this )\">GALER&Iacute;A METTA 2003, Madrid</a><br><br>" );
    document.write( "<a class=\"left_menu\" href=\"#\" id=\"menu3\" onClick=\"loadViews( 'torbandena', this )\">GALLERIA TORBANDENA 1999, Trieste</a><br><br>" );
    document.write( "<a class=\"left_menu\" href=\"#\" id=\"menu2\" onClick=\"loadViews( 'deutsche', this )\">DEUTSCHE BANK 1998, Madrid</a><br><br>" );
    document.write( "<a class=\"left_menu\" href=\"#\" id=\"menu1\" onClick=\"loadViews( 'beitzel', this )\">DAVID BEITZEL 1991, New York</a>" );
    document.write( "</td><td><iframe name=\"IFRAME_MARCO\" id=\"IFRAME_MARCO\" hspace=\"0\" vspace=\"0\" frameborder=\"0\" height=\"530\" width=\"540\"></iframe></td>" );
    document.write( "</tr><tr><td><img src=\"images/bs.gif\" width=\"355\" height=\"1\"></td><td><img src=\"images/bs.gif\" width=\"500\" height=\"1\"></td>" );
    document.write( "</tr></table><!-- FIN CUERPO CENTRAL -->" );
}