
/********************************************************************/
//** 
//* <descripcion>
//* @param <name> -> <valor>
//* ...
//* @param <name> -> <valor>
//* @return <retorno>
/********************************************************************/

    core.loadUnit("animate");
    core.loadUnit("color");
    core.loadUnit("drag");
    core.loadUnit("window");
    core.loadUnit("shadow");

 Fdata = new Object();




window.focus();



/********************************************************************/
/********************************************************************/


window.addEvent('domready', function() {
		var status = {
			'true': 'open',
			'false': 'close'
		};

	
	
	playerMask = $('myContent');

	
	gooutContent();
	
	
	
});



/********************************************************************/
//* Funciones de control sobre el plugin de destacados
/********************************************************************/

var isInternetExplorer = navigator.appName.indexOf("Microsoft") != -1;

var topvideoList = new Array();
var currTopvideo = 0;
var Ntop = 0;
var UserIsSliding = false;
var PLAYERISOUT = true;

var middleScreenX = 0;
var topScreenY	= 60;

var SLDTIMERID = null;
var lastcurrTopvideo = 0;

var PREVIEWDELAY = 5000;        // mseg de presentacion de los titulos


// Gestionar todos los mensajes de FSCommand de una película Flash
function preview_DoFSCommand(command, args) {
	var previewObj = isInternetExplorer ? document.all.preview : document.preview;
	document.title = "SieteyCuarto";

	switch (command)
	{

	
		case 'CLICKED':
			verFicha(Fdata[currTopvideo].codcom)
		break;
		
		case 'CLICKACTION':
			if (args!=currTopvideo)
			{
				currTopvideo = args;
				viewInfo(0);
				if (currTopvideo!=-1)
				{

					setTimeout("viewInfo(1,currTopvideo)",100);
					
					SLIDER_gotoPosIx(currTopvideo);
					SLIDER_resumeSlideshow();

				}
			}

		break;
		
		//Esta llamada desde al pelicula flash  se la pasa la lista de datos de todos los objetos.
		case 'SETDATALIST':
			topvideoList = args.split('#');

			NSteps = (topvideoList.length-1) /3;
			
			for (var i=0; i<NSteps; i++)
			{
				Fdata[i] = new Object();
				
				Fdata[i].codcom = topvideoList[i*3];
				Fdata[i].titulo = topvideoList[i*3+1];
				Fdata[i].resena = topvideoList[i*3+2];
			
			
			}
			
			
			
			SLIDER_resumeSlideshow();

		break;
		
	}

}
// Ancla para Internet Explorer
if (navigator.appName && navigator.appName.indexOf("Microsoft") != -1 && navigator.userAgent.indexOf("Windows") != -1 && navigator.userAgent.indexOf("Windows 3.1") == -1) {
	document.write('<script language=\"VBScript\"\>\n');
	document.write('On Error Resume Next\n');
	document.write('Sub preview_FSCommand(ByVal command, ByVal args)\n');
	document.write('Call preview_DoFSCommand(command, args)\n');
	document.write('End Sub\n');
	document.write('</script\>\n');
}
//-->





/********************************************************************/



/********************************************************************/

function init()
{
	setTimeout("viewInfo(1,0)",500);

	TopPreviewer = window.document["preview"];
	

	SLIDER_init();
	PL_init();

	
	
}



function PL_init()
{
	
	plhtml = document.getElementById('contentPresentation').innerHTML;

	plhtml = plhtml.replace(/fPresentation/g,'fPresentation2');


	plMain=core.createElm(null,-1000,-1000 ,1100,800);
	plMain.setText(plhtml);
	plMain.style.backgroundImage= "url('/imagenes/anaya/playermask3.png')"; 
	plMain.style.backgroundRepeat = "no-repeat";
	plMain.setZ(10);
	
	backgndMask=core.createElm(null,0,0,document.body.scrollWidth,document.body.scrollHeight);
//	backgndMask.setText('<table bgcolor=#ffffff width=100% height=100%><tr><td>&nbsp;</td></tr></table>');
	backgndMask.style.backgroundColor="#ffffff";
	//backgndMask.style.backgroundImage="url(/imagenes/anaya/fondo_mask1.jpg)";
	backgndMask.setAlpha(80);
	backgndMask.setZ(2);
	backgndMask.hide();

}




function viewInfo(mode, currvid)
{

	if (typeof currvid!='undefined' )
	{

		Minfo.setText("<div style='margin:10 10 0 13;'><font class=titulo>" + Fdata[currvid].titulo +"</font><br><br><font class=resena>" + Fdata[currvid].resena + "</font></div>")
	}

	if (mode==1)
		infoShow();
	else
		Minfo.hide();
}


function infoShow()
{
		Minfo.moveBy(100,0);
		Minfo.alphaTo(0);
		
		Minfo.show();
		
		Minfo.alphaTo(100,2,10,1,null);
		Minfo.glideBy( -100,0,2,5,1,null);
	
}


codcom = '0';
player = null;


function verFicha(vcodcom)
{

	url = "http://www.anaya.es/cgigeneral/newFichaElige.pl?codigo_comercial=" + vcodcom + "&id_sello_editorial_web=00"

	window.open (url, "ficha", "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=no,width=820,height=1080,screenX=1,screenY=1");



}



function openPresentation(cid)
{
	


		goinContent(cid);
//document.getElementById('contentPresentation').style.display = 'block';

	
}



function showContent(url)
{
	document.getElementById('fPresentation2').contentWindow.location= "/fichas/" + url;

}



function closeContent(cid)
{

	gooutContent();
	document.getElementById('fPresentation2').contentWindow.location= "loading.html";


	

}



/********************************************************************/
//** CONTROL DE LA APARICION DE LA FICHA
/********************************************************************/
/********************************************************************/






function gooutContent()
{
	
	backgndMask.hide();

	playerMask.fade('show');
	plMain.hide();

	var morph = new Fx.Morph('myContent');

	topScreenY = 1*core.scrollTop() + 60;


	morph.start({
		top: topScreenY + 'px',
		left:  '0px',
		width: '0px',
		height: '0px'
	});
	playerMask.fade(0)

	
}


function goinContent(cid)
{
	

	topScreenY = 1*core.scrollTop() + 60;
	
	var morph = new Fx.Morph('myContent');
	middleScreenX = (core.bodyWidth()-860)/2;

	morph.start({
		top: topScreenY + 'px',
		left: middleScreenX + 'px',
		width: '852px',
		height: '635px'
	});
	playerMask.fade(1);
	
	backgndMask.show();

	plMain.moveTo(middleScreenX,topScreenY);
	setTimeout ("playerMask.fade('hide');plMain.show();showContent('" + cid + "');",1000)

	PLAYERISOUT = false;
}








/********************************************************************/
//* Funciones de control el deslizador
/********************************************************************/


function SLIDER_init()
{

	

	SLCONTAINER = core.getElm("Tslider");
	SLIDERW = String(SLCONTAINER.style.width).slice(0,-2);
	SLIDERY = -4;
  

		Mslider = core.createElm(SLCONTAINER,0,SLIDERY,46,30);
      	Mslider.turnOnDrag(null,core.drag.dtCustom,0,null,SLIDER_boundH ,null);
		Mslider.setText('<img src="/img/slider.gif" border=0 >');
		Mslider.setZ(8);
		Mslider.style.cursor=core.cursors.hand;
		Mslider.onmousedown = function () {UserIsSliding=true;}
		Mslider.onmouseup = function () {UserIsSliding=false;}
		Mslider.show();

	INFOCONTAINER = core.getElm("Tinfo");
		Minfo = core.createElm(INFOCONTAINER,0,0,INFOCONTAINER.style.width,200);
		//Minfo.style.backgroundColor = "red";
		Minfo.setZ(0);
		Minfo.show();
	

}



function SLIDER_boundH(x,y,dX,dY){

	SLIDER_resetSlideshow();

	if(x>=SLIDERW)x=SLIDERW; 
	if(x<=0)x=0;
	Mslider.moveTo(x,SLIDERY);	
	
	slidertop =  Math.floor(x * (NSteps-1) / SLIDERW);
	
	if (slidertop != currTopvideo )
		TopPreviewer.hiliteItem(slidertop);
	
	lastcurrTopvideo = slidertop;
	SLIDER_resumeSlideshow();
		
	
}


function SLIDER_gotoPosIx(ix)
{
	if ( ix<0 || ix>NSteps-1 || UserIsSliding)
		return;
		
	pospx = Math.floor(ix*(SLIDERW/(NSteps-1)));

	Mslider.glideTo( pospx,SLIDERY,2,40,1,  null);

	lastcurrTopvideo = ix;

}






function SLIDER_resumeSlideshow()
{
	if (SLDTIMERID!=null)
		SLIDER_resetSlideshow();
		
		
	SLDTIMERID = setTimeout('SLIDER_nextSlide()',PREVIEWDELAY);
	
}
	


function SLIDER_resetSlideshow()
{
	if (SLDTIMERID!=null)
		clearTimeout(SLDTIMERID);

}


function SLIDER_nextSlide()
{

	nextix = 1*lastcurrTopvideo + 1;
	
	if (nextix >= NSteps)
		nextix = 0;
	
	SLIDER_gotoPosIx(nextix);
	TopPreviewer.hiliteItem(nextix);
	


	SLIDER_resumeSlideshow();
	
	lastcurrTopvideo = nextix;
	
}