/*
	PHOWL
	Application Server
	
(c) 2002-2003-2004 Praetorians MSAT S.L.
	Development sponsored and started by
	Praetorians MSAT S.L.
	Luis Martin-Santos Garcia <luis@webalianza.com>
	
This file is part of Phowl.

    Phowl is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    Phowl is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Phowl; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    
    $Id: wbanimator.js,v 1.2 2005/03/25 18:28:14 lolaine Exp $
*/

	var pace = 35;
	var flag = false;
	var quehago = false;
	var n=1;

	var RGB = new Array(256);
	var k = 0;

	var hex = new Array("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F");

	for (i = 0; i < 16; i++) {
        for (j = 0; j < 16; j++) {
                RGB[k] = hex[i] + hex[j];
                k++;
        }
	}

	
	var TDObj = new Array (255);

		for (i = 0; i < 255; i++)
     		TDObj[ i] = new Array( 3);

	function rgb2hex(r,g,b)
	{
		rr = RGB[r];
	        gg = RGB[g];
	        bb = RGB[b];

		 color = "#" + rr + gg + bb; 
		 return color;
	}
		
		
	function getObj(nm)     {if (document.layers) return document.layers[nm];if (document.all) return document.all[nm];if (document.getElementById) return document.getElementById(nm);}
	function getTd(nm)      {if (document.getElementById) return document.getElementById(nm); }
	function getLayer(nm)	{if (document.layers) return document.layers[nm];if (document.all) return document.all[nm].style;if (document.getElementById) return document.getElementById(nm).style;}

	// Mueve un objeto con aceleraci�
	function Move(x2,y2,nx,ny,nm,dir)
	{

		var x1 = parseInt(getLayer(nm).left);var y1 = parseInt(getLayer(nm).top);
		dx = x2-x1;dy = y2-y1;
		dx *= 2;dy *= 2;
		sX = dx/pace;sY = dy/pace;
		if (dir==1) {aX = -(sX/(pace+1));aY = -(sY/(pace+1));}
		if (dir==0){aX = (sX/(pace-1));aY = (sY/(pace-1));}
		var t = 0;	var x = y = 0;

		while(t<=pace)
		{
			t+=1;sY+=aY;sX+=aX;	x+= sX;	y+= sY;
			setTimeout("setPos("+(x1+x)+","+(y1+y)+",'"+nm+"')",t*50);
		}

	}

	function setwidth(w,nm)
	{
		getTd(nm).style.width = w+"%";
	}
	


	function Color(x2,y2,nx,ny,nm,dir)
	{

		var x1 = parseInt(getLayer(nm).left);var y1 = parseInt(getLayer(nm).top);
		dx = x2-x1;dy = y2-y1;
		dx *= 2;dy *= 2;
		sX = dx/pace;sY = dy/pace;
		if (dir==1) {aX = -(sX/(pace+1));aY = -(sY/(pace+1));}
		if (dir==0){aX = (sX/(pace-1));aY = (sY/(pace-1));}
		var t = 0;	var x = y = 0;

		while(t<=pace)
		{
			t+=1;sY+=aY;sX+=aX;	x+= sX;	y+= sY;
			setTimeout("setColor("+(x1+x)+","+(y1+y)+",'"+nm+"')",t*50);
		}

	}

	
	// Mueve la ventana actual con aceleraci�
	function MoveWin(x2,y2,x1,y1,dir)
	{

		dx = x2-x1;dy = y2-y1;
		dx *= 2;dy *= 2;
		sX = dx/pace;sY = dy/pace;
		if (dir==1) {aX = -(sX/(pace+1));aY = -(sY/(pace+1));}
		if (dir==0){aX = (sX/(pace-1));aY = (sY/(pace-1));}
		var t = 0;	var x = y = 0;
		while(t<=pace)
		{
			t+=1;sY+=aY;sX+=aX;	x+= sX;	y+= sY;
			setTimeout("SetWPos("+(x1+x)+","+(y1+y)+")",t*50);}
		}

	// Mueve la ventana actual sin aceleraci�
	function SetWPos (w,h)
	{
	window.moveTo((screen.width/2)-400,h);}

	// Mueve un objeto sin aceleraci�
	function setPos(x,y,nm){
	getObj(nm).visibility='visible';
	//getLayer(nm).position = 'absolute';
	getLayer(nm).top       = y+"px";
	getLayer(nm).left      = x+"px";
 	//getLayer(nm).pixelTop  = y+"px";
	//getLayer(nm).pixelLeft = x+"px";

	}

	function setColor(x,y,z,nm){
	getObj(nm).visibility='visible';
	getLayer(nm).color = rgb2hex(x,y,z);
	}
	
	function setbg(x,y,z,nm){
	getObj(nm).visibility='visible';
	getLayer(nm).background = rgb2hex(x,y,z);
	}
	function Navigate(url) {document.location=url;}

	// Hace que un iframe vaya a una direcci�
	function Go(location,iframe){ getTd(iframe).src=location;}

	// Funcion para hacer mens desplegables
	function Fold(name,count,url)
	{
	var tname,direction,now;
	tname=name+"_1";
	if (getTd(tname).style.display=='none') {
	now=1;
	direction=1;
	} else {
	now=count;
	direction=-1;
	}
	Fold_Step(name,count,now,url,direction);
	}

	function Fold_Step(name,count,now,url,direction)
	{
	var i;

	if (now < 1) { return 0; }
		var tname;
		if (now <= count)
			{
			tname=name+"_"+now;
			if (getTd(tname).style.display=='') {
			getTd(tname).style.display='none';
			now = now + direction;
			setTimeout("Fold_Step('"+name+"',"+count+","+now+",'"+url+"',"+direction+");",50);
			} else {
			getTd(tname).style.display='';
			now = now + direction;
			setTimeout("Fold_Step('"+name+"',"+count+","+now+",'"+url+"',"+direction+");",50);
			}
		}
	}

	
	/* 

	Funciones 3D

	*/

	function TDCreate(id,x,y,z,obj)
	{
		TDObj[id][1]=x;
		TDObj[id][2]=y;
		TDObj[id][3]=z;
		setPos(x,y,obj);

	}

	function TDRotate(id,axis,q)
	{

	var newx,newy,newz;

	x =  TDObj[id][1];
	y =  TDObj[id][2];
	z =  TDObj[id][3];



	if (axis==2)
	{
		newx = x*Math.cos(q) - y*Math.sin (q);
		newy = x*Math.sin(q) + y*Math.cos (q);
		newz = z;
		TDObj[id][1]=newx;
		TDObj[id][2]=newy;
		TDObj[id][3]=newz;

	return 1;

	}

	if (axis==1)
	{

		newy = y*Math.cos(q) - z*Math.sin (q);
		newz = y*Math.sin (q) + z*Math.cos (q);
		newx = x;
		TDObj[id][1]=newx;
		TDObj[id][2]=newy;
		TDObj[id][3]=newz;

	return 1;

	}

	if (axis=3)
	{
		newz = z*Math.cos (q) - x*Math.sin (q);
		newx = z*Math.sin (q) + x*Math.cos (q);
		newy = y;
		TDObj[id][1]=newx;
		TDObj[id][2]=newy;
		TDObj[id][3]=newz;


	return 1;

	}
	}


	function TDPut(obj,id,incx,incy)
	{
	var newx,newy;
	x =  TDObj[id][1];
	y =  TDObj[id][2];
	z =  TDObj[id][3];

	newx = x + incx;
	newy = y + incy;
	getLayer(obj).fontSize=(z/2)+"pt";
	setPos(newx,newy,obj);

	}
	
	function newWindow(mypage,myname,w,h,features) {
 	if(screen.width){
 	var winl = (screen.width-w)/2;
 	var wint = (screen.height-h)/2;

  	}else{winl = 0;wint =0;}
  	if (winl < 0) winl = 0;
  	if (wint < 0) wint = 0;
  
  	var settings = 'height=' + h + ',';
  	settings += 'width=' + w + ',';
  	settings += 'top=' + wint + ' ,';
  	settings += 'left=' + winl + ',';
  	settings += features;
  	win = window.open(mypage,null,settings+",resizeable=no,toolbar=no,menubar=no");
  	win.window.focus();

}
