/**
 * @author Carlos
 */

function mouseOverDiscoSeleccion(objeto){
	objeto.style.backgroundColor='#F3F4C1';
	objeto.style.cursor=(objeto.all)?'hand':'pointer';
}

function mouseOutDiscoSeleccion(objeto){
	objeto.style.backgroundColor='';
	objeto.style.cursor='';
}

function cursorMano(objeto){
	objeto.style.cursor=(objeto.all)?'hand':'pointer';
}
function finCursor(objeto){
	objeto.style.cursor='';
}


function mouseOnClickDiscoSeleccion(id){
	mostrarDetalleDisco(id);
}


var scroll_clipTop = 0;
var scroll_clipWidth;
var scroll_clipBottom;
var scroll_topper;
var scroll_lyrheight = 0;
var scroll_time,scroll_amount,scroll_theTime,scroll_theHeight, scroll_thelayer;
var scroll_interval;
function creaVentanaScroll(parent, top, left, width, height, title, contents, opacidad){
	scroll_clipTop = 0;
	scroll_lyrheight = 0;
	var myWindow=document.getElementById('scroll_window');
	if (myWindow) myWindow.parentNode.removeChild(myWindow);
	
		myWindow = document.createElement('div');
		myWindow.id='scroll_window';
		parent.appendChild(myWindow);
		myWindow.style.display='none';
	
	
	myWindow.style.position='absolute';
	myWindow.style.width=width+'px';
	myWindow.style.height=height+'px';
	myWindow.style.top=top+'px';
	myWindow.style.left=left+'px';
	myWindow.innerHTML='<div id="scroll_window_title">'+title+'</div><div id="scroll_window_close">close</div><div id="scroll_window_contents">'+contents+'</div><div id="scroll_window_up">up</div><div id="scroll_window_down">down</div>'
	myWindow.style.backgroundColor='#F4F0E6';
	myWindow.style.border='1px solid #B4975A';
	
	/*colocamos el titulo*/
	var theTitle=myWindow.childNodes[0];
	theTitle.style.width=(width-20)+'px';
	theTitle.style.backgroundColor='#F4D68C';
	theTitle.style.color='#785A3C';
	theTitle.style.overflow='hidden';
	theTitle.style.position='absolute';
	theTitle.style.height='20px';
	theTitle.style.paddingLeft='4px';
	theTitle.style.paddingTop=(document.all)?'2px':'0px';
	theTitle.style.borderBottom='1px solid #B4975A';
	var theClose=myWindow.childNodes[1];
	theClose.innerHTML="";
	theClose.style.position='absolute';
	theClose.style.left=(document.all)?(width-22)+'px':(width-21)+'px';
	theClose.style.top='0px';
	theClose.style.height=theClose.style.width='20px';
	//theClose.style.backgroundColor='#FF0000';
	theClose.style.backgroundImage="url('css/front/iconos/ventana_scroll_close.gif')";
	theClose.style.borderBottom=theClose.style.borderLeft='1px solid #B4975A';
	
	theClose.onmouseover=function(){
		this.style.backgroundImage="url('css/front/iconos/ventana_scroll_close_over.gif')";
		this.style.cursor=(document.all)?'hand':'pointer';
	}
	theClose.onmouseout=function(){
		this.style.backgroundImage="url('css/front/iconos/ventana_scroll_close.gif')";
		this.style.cursor='';
	}
	theClose.onclick=function(){
		this.parentNode.parentNode.removeChild(this.parentNode);
	}
	

	
	var theContents=myWindow.childNodes[2];
	theContents.style.visibility='hidden';
	theContents.style.position='absolute';
	theContents.style.left='4px';
	theContents.style.top='24px';
	scroll_topper=24;
	
	theContents.style.width=(width-28)+'px';
	theContents.style.textAlign='justify';
	
	scroll_clipWidth=width-24;
	scroll_clipBottom=height-28;
	
	scroll_lyrheight = (Element.getDimensions(theContents).height+20);
	if (document.layers)
	{
		theContents.style.clip.top = 0;
		theContents.style.clip.left = 0;
		theContents.style.clip.right = (width-24)+'px';
		theContents.style.clip.bottom = (height-28)+'px';
	}
	else if (document.getElementById || document.all)
	{
		var clipstring = 'rect('+0+'px,'+(width-28)+'px,'+(height-28)+'px,0)';
		theContents.style.clip = clipstring;
	}
	theContents.style.visibility='';
	
	var upButton=myWindow.childNodes[3];
	var downButton=myWindow.childNodes[4];
	upButton.innerHTML=downButton.innerHTML="";
	
	upButton.style.position=downButton.style.position='absolute';
	upButton.style.left=downButton.style.left=(width-20)+'px';
	upButton.style.width=downButton.style.width=upButton.style.height=downButton.style.height='16px';
	upButton.style.backgroundImage="url('css/front/iconos/bio_arriba.gif')";
	downButton.style.backgroundImage="url('css/front/iconos/bio_abajo.gif')";
	downButton.style.backgroundRepeat=upButton.style.backgroundRepeat='no-repeat';
	upButton.style.top='24px';
	downButton.style.top=(height-20)+'px';
	
	downButton.onmouseover=function(){
		this.style.cursor=(document.all)?'hand':'pointer';
		scrollVentana(this.parentNode.childNodes[2], 20, 100);
		}
	upButton.onmouseover=function(){
		this.style.cursor=(document.all)?'hand':'pointer';
		scrollVentana(this.parentNode.childNodes[2], -20, 100);
		}		
	downButton.onmouseout=upButton.onmouseout=function(){
		paraScroll();
		this.style.cursor='';
		}
	
	
	if (opacidad==null){
		myWindow.style.opacity = 0.85;
		myWindow.style.filter = 'alpha(opacity=' + 85 + ')';
	}else{
		myWindow.style.opacity = opacidad;
		myWindow.style.filter = 'alpha(opacity=' + Math.floor(opacidad*100) + ')';
	}
		
	myWindow.style.display='';
}

function paraScroll(){
	clearInterval(scroll_interval);
}

function scrollVentana(layer,amt,tim){
	
	var lay=$('scroll_window_contents');
	scroll_lyrheight=Element.getDimensions(lay).height+20;
		
	scroll_thelayer = lay;
	if (!scroll_thelayer) return;
	scroll_amount = amt;
	scroll_theTime = tim;
	ejecutaScrollVentana();
}

function verFotoZonaMedios(ruta,ancho, alto){
	var ventana = window.open(ruta,'','width='+(ancho+10)+',height='+(alto+20)+'menubar=no, location=no, resizable=no, menubar=no, scrollbars=no, status=no, toolbar=no' );
}




function ejecutaScrollVentana(){
	
	scroll_clipTop += scroll_amount;
	scroll_clipBottom += scroll_amount;
	scroll_topper -= scroll_amount;
	if (scroll_clipTop < 0 || scroll_clipBottom > scroll_lyrheight)
	{
		if (scroll_lyrheight<Element.getDimensions(scroll_thelayer).height+20){
			scroll_lyrheight=Element.getDimensions(scroll_thelayer).height+20;
			ejecutaScrollVentana();
			return;
		}
		scroll_clipTop -= scroll_amount;
		scroll_clipBottom -= scroll_amount;
		scroll_topper += scroll_amount;
		return;
	}
	if (document.getElementById || document.all)
	{
		clipstring = 'rect('+scroll_clipTop+'px,'+scroll_clipWidth+'px,'+scroll_clipBottom+'px,0)'
		scroll_thelayer.style.clip = clipstring;
		scroll_thelayer.style.top = scroll_topper + 'px';
	}
	else if (document.layers)
	{
		scroll_thelayer.style.clip.top = scroll_clipTop;
		scroll_thelayer.style.clip.bottom = scroll_clipBottom;
		scroll_thelayer.style.top = scroll_topper;
	}
	scroll_interval = setTimeout('ejecutaScrollVentana()',scroll_theTime);
}

function transformaFecha(stringFecha){
	var salida=null;
	var expresion = /(\d+)-0?(\d+)-0?(\d+)/;
	
	var partes = expresion.exec(stringFecha);
	var meses=["enero", "febrero", "marzo", "abril", "mayo", "junio", "julio", "agosto", "septiembre", "octubre", "noviembre", "diciembre"];
	if (partes!=null && partes.length	 == 4){
		salida=new Object();
		salida.year=parseInt(partes[1]);
		salida.month=parseInt(partes[2]);
		salida.day=parseInt(partes[3]);
		salida.strMonth=meses[salida.month-1];
	}
	
	return salida;
}

function enviaCorreo(){
	var miformulario = $('formularioEmail');
	
	var pars=encodeURI("email_nombre="+miformulario.email_nombre.value+"&email_email="+miformulario.email_email.value+"&email_texto="+miformulario.email_texto.value);
	
	/*creamos una caja mientras que se mandan los datos*/
	new Insertion.After(miformulario,'<span id="enviando_mail"><span>Enviando el correo...</span></span>');
	
	
	var a = $('femail_nombre');
	var b = $('femail_enviar');
	var contenido=$('contenido_contacto');
	
	
	var enviando=$('enviando_mail');
	enviando.style.opacity = 0;
	enviando.style.filter = 'alpha(opacity=' + 0 + ')';
	enviando.style.display='none';
	enviando.style.position='absolute';
	enviando.style.width=(Element.getDimensions(a).width)+"px";;
	enviando.style.height=(b.offsetTop-a.offsetTop+Element.getDimensions(a).height)+"px";
	enviando.style.top=a.offsetTop+"px";
	enviando.style.left=a.offsetLeft+"px";
	
	enviando.style.backgroundColor=Element.getStyle(contenido,"background-color");
	enviando.style.borderColor=Element.getStyle(contenido,"border-top-color");
	enviando.style.borderWidth="1px";
	enviando.style.borderStyle="solid";
	
	var mensaje=enviando.childNodes[0];
	
	mensaje.style.position = 'absolute';
	mensaje.style.display= 'block';
	mensaje.style.textAlign='center';
	mensaje.style.width='100%';
	mensaje.style.top=(Math.round((Element.getDimensions(enviando).height/2)-(Element.getDimensions(mensaje).height/2)))+"px";
	
	var myAjax = new Ajax.Request(
			"sendmail.php", 
			{
				method: 'post', 
				postBody: pars, 
				onComplete: respuestaCorreo
			});
	enviando.style.display='';
	new Effect.Opacity($('enviando_mail'),{duration:0.5,from:0.0,to:1.0});
}

function respuestaCorreo(envioOriginal){
	var mensaje=$('enviando_mail').childNodes[0];
	if (envioOriginal.responseText=="false"){
		Element.update(mensaje,"Se ha producido un error al enviar el correo.<br>Por favor, int&eacute;ntalo de nuevo pasados unos minutos");
		setTimeout(ocultarRespuestaCorreo, 7000);
		mensaje.style.top=(Math.round((Element.getDimensions('enviando_mail').height/2)-(Element.getDimensions(mensaje).height/2)))+"px";
	}else{
		Element.update(mensaje,"El correo se ha enviado correctamente :)");
	}
	
}

function ocultarRespuestaCorreo(){
		new Effect.Opacity($('enviando_mail'),{duration:1.0,from:1.0,to:0.0,
						afterFinish:function(){Element.remove('enviando_mail');}
						});
	
}

