function abrirwebcam(nombre){

LeftPosition = (screen.width) ? (screen.width-640)/2 : 0;
TopPosition = (screen.height) ? (screen.height-480)/2 : 0;
settings ='height=' + 480 +',width=' + 640 + ',top=' + TopPosition + ',left=' + LeftPosition + ',scrollbars=0,resizable'
win = window.open('/camaras.aspx?d=' + nombre,'menu',settings)
}

function abrirwebcam2(nombre){

var alto;
var ancho;
ancho= 640;
alto = 480;
LeftPosition = (screen.width) ? (screen.width-ancho)/2 : 0;
TopPosition = (screen.height) ? (screen.height-alto)/2 : 0;
settings ='height=' + alto +',width=' + ancho + ',top=' + TopPosition + ',left=' + LeftPosition + ',scrollbars=0,resizable'
win = window.open('/camaras2.aspx?d=' + nombre,'menu',settings)
}

function menuPrincipal(){ 
	$$('#menu ul li a').each(function(el){
		el.addEvent('mouseover',function(){
			this.setStyle('top','-54px')
		});
		el.addEvent('mouseout',function(){
		  if (!this.hasClass('selected')){
			 this.setStyle('top','0')
		  }
		});		
	});
	
  $('desplegable').addEvent('mouseover',function(){
                                          $('desplegable_promociones').setStyle('display','block');
  });
  $('desplegable').addEvent('mouseleave',function(e){
                                        //evalúo el evento mouseout dentro de la lista de segundo nivel
                                      	if (!e) var e = window.event;
                                      	//reltg almacena el detino del mouseout
                                      	var reltg = (e.relatedTarget) ? e.relatedTarget : e.toElement;
                                      	//compruebo en el árbol de etiquetas por si el mouseout me lo
                                      	//ha dado al salir del enlace o al pasar entre los li que forman la lista
                                      		
                                      	if (reltg.nodeName== "UL") return; //si paso por la lista nivel2 no oculto la lista
                                      	
                                      	//si llego aquí es porque el mouseout es fuera de la lista de segundo nivel
                                          $('desplegable_promociones').setStyle('display','none');
                                        }
                          );	
	
  $('desplegable_promociones').addEvent('mouseleave',function(e){                          

                        $('desplegable_promociones').setStyle('display','none');
       
                    }
  );	
}

function menuPromo(){ 
	$$('#menu_promo li a').each(function(el){
	  if(!el.hasClass('selected')){
  		el.addEvent('mouseover',function(){
  			this.setStyle('top','-25px')
  		});
  		el.addEvent('mouseout',function(){
  			this.setStyle('top','0')
  		});		
	  }
	});

}

 function recomendarAmigo(){
          $('recomendar_amigo').toggleClass('oculto');
 }
 
 
 /* función que se encarga de mostrar y ocultar los formularios de la zona de promociones */
 function formulariosPromociones(){
   $$('.recomendar').each(function(el){
                el.addEvent('click',function(){recomendarAmigo();});
       
     });   
   $$('.despliega_contacto_prom').each(function(el){
                el.addEvent('click',function(){
                    $('form_contacto_promo').toggleClass('oculto');
                });
       
     });   
 }

 
function efectoDesplegable(){
  ($$('#desplegable_promociones a').addEvent('mouseover',function(ev){
    this.getParent().setStyle('background-color','#85A7A4');
  }));
  ($$('#desplegable_promociones a').addEvent('mouseout',function(ev){
    this.getParent().setStyle('background','none');
  }));
}
 
function muestraLayerTrabaja(){
  if ($('inscribir_oferta')){
    $('inscribir_oferta').addEvent('click',function(){
          $('layer_trabaja').setStyle('display','block');
    })
  }
  if ($('enviar_cv')){
    $('enviar_cv').addEvent('click',function(){
          $('layer_trabaja2').setStyle('display','block');
    })
  }
  $$('.cerrar_layer').each(function(el){
    el.addEvent('click',function(){
      this.getParent().setStyle('display','none');
  })
  })
}

function muestraNewsletter(){
  $('newsletter').addEvent('click',function(){
    $('layer_boletin').setStyle('display','block');
  })
}


function fotosGreyBox(){
	  if(window.parent){
        w=window.parent;
    }else{
        w=window;  
    }
    w.image_set = [];
    var cuenta=1;
	$$('a.greybox').each(function(el){
		var encontrado=false;
    var orden=cuenta;
		for(var k=0;k<w.image_set.length;k++){
			if(w.image_set[k].url==el.href){
				encontrado=true;
				orden=k+1;
			}
		}
		
		if(!encontrado){
	    w.image_set.push({'caption':'','url':el.href});
  		cuenta++;
		}

		el.addEvent('click',function(evt){		
			var event = new Event(evt);
     	event.preventDefault();
			w.lanzarFoto(orden);
		});
		
		if( el.hasClass('enlace_galeria') ){
			el.addEvent('mouseover',function(){
			//	try{
	      	flashProxy.call('levantarFoto', orden-1);
	    //  }catch(ex){}
			});
			
			el.addEvent('mouseout',function(){ 
				//try{
	      	setTimeout(function(){flashProxy.call('hundirFoto', orden-1)},100);
	     // }catch(ex){}
			});
			
			var boton=new Element('img');
			boton.src='/images/btn_ver_foto.gif';
			
			boton.injectInside(el);
			
		}

	});
}

function lanzarFoto(n){
	$$('embed').each(function(el){
		el.style.visibility='hidden';
	});
	GB_showImageSet(w.image_set, n,function(){
		$$('embed').each(function(el){
			el.style.visibility='visible';
		});
		
	});
}


window.addEvent('domready',function(){
  menuPrincipal();
  menuPromo();
  formulariosPromociones();
  efectoDesplegable();
  muestraLayerTrabaja();
  muestraNewsletter();
});


 
 
