
// numero de pixels de separacion con la parte superior de la ventana
var theTop = 0;
var menu;
// posicion actual
var old = theTop;
// a true, la posición del menu se mantiene a "theTop" pixels, aunque se desplace la pagina verticalmente
// a false, el menu es fijo
var scrollIt= false;

// INICIALIZACION
function init() {
	// obtiene referencia al objeto con el menu
	capa_contenido = new getObj('contenido_video');
	capa_mostrar = new getObj('mostrar_video');
	
	// obtiene si hay que mantenerlo fijo o moverlo, a partir del checkbox del propio menu
//	scrollIt = (document.layers) ?
	scrollIt=true;
//		document.menu.document.forms[0].elements[0].checked :
//		document.forms["capamenu"].elements[0].checked
	// inicia el proceso que mantiene la posicion a "theTop" pixels
	mover();
}

//MOVIMIENTO
function mover() {
	if (scrollIt) {
		if (window.innerHeight) {
			  pos = window.pageYOffset;
		} else if (document.documentElement && document.documentElement.scrollTop) {
			pos = document.documentElement.scrollTop;
		} else if (document.body) {
			  pos = document.body.scrollTop;
		}
		
		if (pos < theTop)
			pos = theTop;
		if (pos == old){
			capa_contenido.style.top = pos + 'px';
			capa_mostrar.style.top = pos + 'px';
		}
		old = pos;
	}
	moveID = setTimeout('mover()',10)
}

//OBTENCION DE REFERENCIA AL OBJETO
function getObj(name) {
  // si soporta DOM Lelvel 2
  if (document.getElementById) {
  	this.obj = document.getElementById(name)
	this.style = document.getElementById(name).style
  // si soporta el DOM del IE4.x
  } else if (document.all) {
	this.obj = document.all[name]
	this.style = document.all[name].style
  // si soporta el DOM del N4.x
  } else if (document.layers) {
   	this.obj = document.layers[name]
   	this.style = document.layers[name]
  }
}

window.onload = init;
if (document.captureEvents) {		//N4 requiere invocar la funcion captureEvents
	document.captureEvents(Event.LOAD);
}


// Esta función pertenece al pack SCRIPTACULOUS (dentro del cual
//  aparece como Effect.Appear en el fichero effects.js), pero ha sido
//  modificada para poder variar la visibilidad de la capa que muestra.
// Los valores de visibilidad van desde 0.0 hasta 1.0
Effect.AppearTransparente = function(element,visibilidad) {
	var visibilidad = visibilidad || 1.0;
	if (visibilidad > 1.0) visibilidad = 1.0;
	if (visibilidad < 0.0) visibilidad = 0.0;
  element = $(element);
  var options = Object.extend({
  from: (element.getStyle('display') == 'none' ? 0.0 : element.getOpacity() || 0.0),
  to:   visibilidad,
  // force Safari to render floated elements properly
  afterFinishInternal: function(effect) {
    effect.element.forceRerendering();
  },
  beforeSetup: function(effect) {
    effect.element.setOpacity(effect.options.from);
    effect.element.show(); 
  }}, arguments[1] || {});
  return new Effect.Opacity(element,options);
}

// Esta función pertenece al pack SCRIPTACULOUS (dentro del cual
//  aparece como Effect.Shrink en el fichero effects.js), pero ha sido
//  modificada para poder variar la visibilidad de la capa que muestra.
// Los valores de visibilidad van desde 0.0 hasta 1.0
Effect.ShrinkTransparente = function (element, visibilidad) {
	var visibilidad = visibilidad || 1.0;
	if (visibilidad > 1.0) visibilidad = 1.0;
	if (visibilidad < 0.0) visibilidad = 0.0;
  element = $(element);
  var options = Object.extend({
    direction: 'center',
    moveTransition: Effect.Transitions.sinoidal,
    scaleTransition: Effect.Transitions.sinoidal,
    opacityTransition: Effect.Transitions.none
  }, arguments[1] || {});
  var oldStyle = {
    top: element.style.top,
    left: element.style.left,
    height: element.style.height,
    width: element.style.width,
    opacity: element.getInlineOpacity() };

  var dims = element.getDimensions();
  var moveX, moveY;
  
  switch (options.direction) {
    case 'top-left':
      moveX = moveY = 0;
      break;
    case 'top-right':
      moveX = dims.width;
      moveY = 0;
      break;
    case 'bottom-left':
      moveX = 0;
      moveY = dims.height;
      break;
    case 'bottom-right':
      moveX = dims.width;
      moveY = dims.height;
      break;
    case 'center':  
      moveX = dims.width / 2;
      moveY = dims.height / 2;
      break;
  }
  
  return new Effect.Parallel(
    [ new Effect.Opacity(element, { sync: true, to: 0.0, from: visibilidad, transition: options.opacityTransition }),
      new Effect.Scale(element, window.opera ? 1 : 0, { sync: true, transition: options.scaleTransition, restoreAfterFinish: true}),
      new Effect.Move(element, { x: moveX, y: moveY, sync: true, transition: options.moveTransition })
    ], Object.extend({            
         beforeStartInternal: function(effect) {
           effect.effects[0].element.makePositioned();
           effect.effects[0].element.makeClipping(); },
         afterFinishInternal: function(effect) {
           effect.effects[0].element.hide();
           effect.effects[0].element.undoClipping();
           effect.effects[0].element.undoPositioned();
           effect.effects[0].element.setStyle(oldStyle); }
       }, options)
  );
}

function dapHide (){
	$('contenido_video').innerHTML = '';
	$('contenido_video').style.display = "none";
	Effect.ShrinkTransparente('mostrar_video',0.8);
	scrollIt = false;
}

function createRequestObject(){
	var ro;
	var browser = navigator.appName;
	if(browser == "Microsoft Internet Explorer"){
		ro = new ActiveXObject("Microsoft.XMLHTTP");	
	} else {
		ro = new XMLHttpRequest();	
	}
	return ro;
}

var http = createRequestObject();

function dapShow(id_buscado,tit,desc){
	var tit= tit || '';
	var desc= desc || '';
	var url_envio = '/videodata.php?id_buscado='+id_buscado;
	http.open('post',url_envio);
	http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	http.setRequestHeader('Accept-Charset', 'UTF-8');
	http.onreadystatechange = dapShowHandle;
	http.send('tit='+tit+'&desc='+desc);
}

function dapShowHandle() {
	if(http.readyState == 4){
		var txt = http.responseText;
		if (txt != ''){
			var datos= txt.split(' ||| ');
			if (datos[0].indexOf('OK') > -1 ){
				//Por alguna extraña razon se inserta un salto de linea antes de OK y KO
				var contenido= '<center><div id="capa_video" style="width: 480px; text-align: left; visibility:visible;">'
					+ '<!-- Reproductor de Vídeo -->'
					+ '<div style="background-color:#000000;padding:10px 10px 5px 10px;">'
					+ '<div style="text-align:right; margin:10px;">'
					+ '<a href="javascript:;" onclick="dapHide()" class="cerrar_video" style="text-align:left;">CERRAR [X]</a>'
					+ '</div>'
					+ '<center><div id="reproductorDiv">'
					+ '<div style="padding: 20px; font-size:14px; font-weight: bold;">'
					+ '<br><p style=\'text-align:center;color:#ff0000;\'>Tu navegador tiene desactivado JavaScript o usa una versión antigua de Macromedia Flash Player. '
					+ '<a href="http://www.macromedia.com/go/getflashplayer/">PINCHA AQUÍ</a> para descargarte la última versión y disfrutar de los videos de Dale Al Play.'
					+ '<br><br></p></div>'
					+ '</div></center>'
					+ '<br><br><span class="titulo_video">'+datos[3]+'</span>'
					+ '<br><span class="descripcion_video">'+datos[4]+'</span>'
					/*+ '<br><br><span class="mas_info_video">Todos los detalles de este v&iacute;deo en <a target="_blank" href="http://www.dalealplay.com/informaciondecontenido.php?con='+datos[1]+'">www.dalealplay.com</a></span></div>'*/
					+ '<!-- FIN Reproductor de Vídeo -->'
					+ '</div></center>';
				Effect.AppearTransparente('mostrar_video',0.8);
				$('contenido_video').innerHTML = contenido;
				setTimeout("$('contenido_video').style.display = 'block';",1000);
				// <![CDATA[
				var fo = new SWFObject("http://www.dalealplay.com/video.swf?file="+datos[1]+"/"+datos[2]+"&autoStart=true", "movie_player", "450", "340", 8, "#000000");
				fo.write("reproductorDiv");
				// ]]>
				scrollIt = true;
			}
		}
	}
}

function mostrar_videos_sub(id, titulo, descripcion, subtitulo, flv) {
/*
	alert(id);
	alert(titulo);
	alert(descripcion);
	alert(subtitulo);
	alert(flv);
*/
	var contenido= '<center><div id="capa_video" style="width: 480px; text-align: left; visibility:visible;">'
		+ '<!-- Reproductor de Vídeo -->'
		+ '<div style="background-color:#000000;padding:10px 10px 5px 10px;">'
		+ '<div style="text-align:right; margin:10px;">'
		+ '<a href="javascript:;" onclick="dapHide()" class="cerrar_video" style="text-align:left;">CERRAR [X]</a>'
		+ '</div>'
		+ '<center><div id="reproductorDiv">'
		+ '<div style="padding: 20px; font-size:14px; font-weight: bold;">'
		+ '<br><p style=\'text-align:center;color:#ff0000;\'>Tu navegador tiene desactivado JavaScript o usa una versión antigua de Macromedia Flash Player. '
		+ '<a href="http://www.macromedia.com/go/getflashplayer/">PINCHA AQUÍ</a> para descargarte la última versión y disfrutar de los videos de Dale Al Play.'
		+ '<br><br></p></div>'
		+ '</div></center>'
		+ '<br><br><span class="titulo_video">'+titulo+'</span>'
		+ '<br><span class="descripcion_video">'+descripcion+'</span>'
		/*+ '<br><br><span class="mas_info_video">Todos los detalles de este v&iacute;deo en <a target="_blank" href="http://www.dalealplay.com/informaciondecontenido.php?con='+id+'">www.dalealplay.com</a></span></div>'*/
		+ '<!-- FIN Reproductor de Vídeo -->'
		+ '</div></center>';
	Effect.AppearTransparente('mostrar_video',0.8);
	$('contenido_video').innerHTML = contenido;
	setTimeout("$('contenido_video').style.display = 'block';",1000);
	// <![CDATA[
	var fo = new SWFObject("http://www.dalealplay.com/video.swf?file="+id+"/"+flv+"&autoStart=true&fileSub="+subtitulo, "movie_player", "450", "340", 8, "#000000");
	fo.write("reproductorDiv");
	// ]]>
	scrollIt = true;
}

function mostrar_videos(id, titulo, descripcion, subtitulo, flv) {

if (titulo.length > 40)
	titulo = titulo.substr(0,40)+'...';
if (descripcion.length > 170)
	descripcion = descripcion.substr(0,170)+'...';

	descripcion += '<br> <a class="cerrar_video" href="http://www.dalealplay.com/informaciondecontenido.php?con=' + id + '">Pulsa aquí para más información sobre el vídeo</a>';

var contenido= '<center>'
+ '	<div id="capa_video" style="width: 481px; text-align: left; visibility:visible;">'
+ '		<div class="total">'
+ '			<div class="player_top">'
+ '				<span class="titulo_video">'+titulo+'</span>'
+ '				<a href="javascript:;" onclick="dapHide()" class="cerrar">&nbsp;</a>'
+ '			</div>'
+ '			<center>'
+ '				<div id="reproductorDiv" class="player_centro">'

		+ '<div style="padding: 20px; font-size:14px; font-weight: bold;">'
		+ '<br><p style=\'text-align:center;color:#ff0000;\'>Tu navegador tiene desactivado JavaScript o usa una versión antigua de Macromedia Flash Player. '
		+ '<a href="http://www.macromedia.com/go/getflashplayer/">PINCHA AQUÍ</a> para descargarte la última versión y disfrutar de los videos de Dale Al Play.'
		+ '<br><br></p></div>'


+ '				</div>'
+ '			</center>'
+ '			<div class="player_down">'
+ '				<span class="descripcion_video">'+descripcion+'</span>'
+ '			</div>'
+ '		</div>'
+ '	</div>'
+ '</center>';

	Effect.AppearTransparente('mostrar_video',0.8);
	$('contenido_video').innerHTML = contenido;
	setTimeout("$('contenido_video').style.display = 'block';",1000);
	// <![CDATA[
	var fo = new SWFObject("http://www.dalealplay.com/video.swf?file="+id+"/"+flv+"&autoStart=true&fileSub="+subtitulo, "movie_player", "450", "340", 8, "#000000");
	fo.write("reproductorDiv");
	// ]]>
	scrollIt = true;
}
