/*
Creator : Copyright (C) 2001 Oscar Caraballo.
Distributed under the terms of the GNU Library General Public License
Basado en las librerias de Emiliano Benitez(EMI) DINAJS@terra.es y código de paso a Hexadecimal de Israel Pastrana (Isra) isra_pv@hotmail.com 
Avalaible at http://sourceforge.net/projects/jscreator/
questions&contact: prototipos@netscape.net
*/
 
function creator(id,padre,left,top,visibility,width,height,zIndex,bgColor,contenido){
 creator.getDOM();
 objeto = new creator.compila(id,padre,left,top,visibility,width,height,zIndex,bgColor,contenido);
 eval('self.' + id + '= objeto');
 return objeto;
}

creator.bufferLoad = [];
creator.queryTime = 0;  

creator.getDOM = function(){
  if (!creator.DOM) creator.DOM = creator.setDOM(); 
}

creator.setDOM = function(){
  if(document.all)creator.ie = true;
  else if(document.layers) creator.ns4 = true;
  else if(document.getElementById) creator.ns6 = true;
  return true;
}


creator.compila = function(id,padre,left,top,visibility,width,height,zIndex,bgColor,contenido){
  this.id = id;
  this.idx = "div"+id ;
  this.iniArgs = arguments;
  this.nodo;
  this.getNodo();
  this.creaDIV();
  this.setStyle();
  this.xdrag==0;
  this.ydrag==0;
}

creator.compila.prototype.getNodo = function(){
  if (creator.ie) this.getNodoIe();
  else if (creator.ns4) this.getNodoNs4();
  else if (creator.ns6) this.getNodoNs6();
}

creator.compila.prototype.getNodoIe = function(){
 this.nodo = (this.iniArgs[1]=="document") ? document.body :  document.all[this.iniArgs[1].idx]; 
}

creator.compila.prototype.getNodoNs4 = function(){
 if (this.iniArgs[1]=="document") this.nodo = "document.layers['" + this.idx +"']"; 
 else this.nodo = this.iniArgs[1].nodo + ".document.layers['" + this.idx +"']";
}

creator.compila.prototype.getNodoNs6 = function(){
this.nodo = (this.iniArgs[1]=="document")? document.getElementsByTagName("BODY").item(0): document.getElementById(this.iniArgs[1].idx); 
}


creator.compila.prototype.creaDIV = function(){
 var div;
 if (creator.ns4) (this.iniArgs[1].nodo == div) ? div = document.layers[this.idx] = new Layer(this.iniArgs[5]) : div = eval(this.nodo +'= new Layer('+this.iniArgs[5]+','+this.iniArgs[1].nodo+')'); 
 else if (creator.ie){
  var divHTML = '<div id="' + this.idx + '" style="position:absolute; left:0px; top:0px; width:'+this.iniArgs[5]+'px;"></div>';
  this.nodo.insertAdjacentHTML("beforeEnd", divHTML);
  div = this.nodo.children[this.nodo.children.length-1];
 }
 else if (creator.ns6){
  div = document.createElement("DIV");
  div.style.position = "absolute";
  div.id = this.idx;
  this.nodo.appendChild(div);
 }
 this.div = div
  if(creator.ns4)this.div.style = this.div;
}


creator.compila.prototype.setStyle = function(){
  this.move(this.iniArgs[3],this.iniArgs[2]);
  this.resize(this.iniArgs[5],this.iniArgs[6]);
  (this.iniArgs[1]=="document")?(this.iniArgs[4]=="show")?this.show():this.hide():this.div.style.visibility="inherit";
  this.stack(this.iniArgs[7]);
  if(this.iniArgs[8]!=null)this.paint(this.iniArgs[8]);
  if(this.iniArgs[9]!=null)this.fill(this.iniArgs[9]);
}
  
creator.compila.prototype.move = function(x,y){
 this.x = this.div.style.left = x;
 this.y = this.div.style.top = y;
}

creator.compila.prototype.resize = function(ancho,alto){
 this.w = this.div.style.width = ancho;
 this.h = this.div.style.height = alto;
 (creator.ns4)?this.div.resizeTo(ancho,alto):this.clip(ancho,alto,0,0);
 }

creator.compila.prototype.clip = function(r,b,t,l) {
	if (creator.ns4){
			    if (t) this.div.clip.top = t;
		this.div.style.clip.right = r;
 		this.div.style.clip.bottom = b;
 		if (l) this.div.style.clip.left = l;
	}
    else if(creator.ie || creator.ns6) this.div.style.clip = "rect("+t+"px "+r+"px "+b+"px "+l+"px)";
}

creator.compila.prototype.paint = function(color){
 color = (creator.ns4)?'#'+this.pasaHex(color[0])+this.pasaHex(color[1])+this.pasaHex(color[2]) : "rgb("+color[0]+","+color[1]+","+color[2]+")"; 
 (creator.ns4)? this.div.document.bgColor = color:this.div.style.backgroundColor = color;
}

creator.compila.prototype.fill = function(inHTML){
 if (creator.ns4) { 
		this.div.document.open();
		this.div.document.write(inHTML);
		this.div.document.close();
	} 
 else this.div.innerHTML = inHTML;
}

creator.compila.prototype.show = function(){
	this.div.style.visibility  = (creator.ns4)?'show':'visible';
}

creator.compila.prototype.hide = function(){
	this.div.style.visibility  = (creator.ns4)?'hide':'hidden';
}

creator.compila.prototype.stack = function(zI) {
	this.div.style.zIndex = zI;
}

creator.compila.prototype.getDocWidth = function(){
 if(creator.ns4) return this.div.document.width;
 else return this.div.offsetWidth;
}

creator.compila.prototype.getDocHeight = function(){
 if(creator.ns4) return this.div.document.height;
 else return this.div.offsetHeight;
}

creator.compila.prototype.slide = function DivSlide(xf,yf,resolution,speed,kine,nextEv,timeLine) {
	this.whatToMove(this.x,this.y,xf,yf,resolution,speed,Math.round(this.x+(xf-this.x)/20*(10+kine)),Math.round(this.y+(yf-this.y)/20*(10+kine)),'this.move',nextEv,timeLine);
}

	
creator.compila.prototype.whatToMove = function WhatToMoveGoo(xi,yi,xf,yf,resolution,speed,xbezier,ybezier,func,nextEv,timeLine) {	
this.datGoo=[resolution+1,speed,1,0,1/resolution,func,nextEv,timeLine,[],[]];
	for (i=1;i<=this.datGoo[0];i++){
		var auxS0 = 1-this.datGoo[3];
		var auxS1 = auxS0 * auxS0;
		var auxS2 = this.datGoo[3] * this.datGoo[3];
		var auxS3 = 2 * this.datGoo[3] * auxS0; 
		this.datGoo[8][i] = Math.round((auxS1*xi)+(auxS3*xbezier)+(auxS2*xf));
		this.datGoo[9][i] = Math.round((auxS1*yi)+(auxS3*ybezier)+(auxS2*yf));
		this.datGoo[3] = i * this.datGoo[4];	
	}
	this.runGoo();
}

creator.compila.prototype.runGoo = function WhatToMoveRun() {
	if (this.datGoo[2] <= this.datGoo[0]) {
		eval(this.datGoo[5]+'('+this.datGoo[8][this.datGoo[2]]+','+this.datGoo[9][this.datGoo[2]]+')');
		this.datGoo[2]++;
		setTimeout(this.id+".runGoo()",this.datGoo[1]);		
	
	} else { 
		if (this.datGoo[7])creator.animManager(eval(this.datGoo[7]));
		else if(this.datGoo[6])eval(this.datGoo[6])
	}	
}

 
creator.hex = new Array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F');
creator.compila.prototype.convDec = function(hex){var i = 0;while (hex.toUpperCase() != creator.hex[i]) i++;return i;}
creator.compila.prototype.pasaDec = function(hex){return this.convDec(hex.substr(0,1))*16 + this.convDec(hex.substr(1,1));}	
creator.compila.prototype.pasaHex = function pasaHex(dec){if (dec < 0) return "00";	else if (dec > 255) return "ff";else return (""+creator.hex[Math.floor(dec/16)]+creator.hex[dec%16]);}

