/*
Junciona-JS : Copyright (C) 2001 Luis Navalpotro.
Distributed under the terms of the GNU Library General Public License
Avalaible at http://sourceforge.net
Prohibido su uso o distribucion en su totalidad o en parte del codigo sin autorizacion del autor.
questions&contact: lnavalpotro@ya.com
http://www.junciona.net
version 2.0
*/
function junciona(obj,parent,x,y,w,h,visib,stack,bgColor,content) {
  if (!junciona.nav) junciona.setNav();
  objeto = new junciona.objLayer(obj,parent,x,y,w,h,bgColor,visib,stack,content);
  eval ("self."+obj+" = obj = objeto");
  return objeto;
}

junciona.setNav = function(){
  if (document.all && !document.getElementById) junciona.ie = junciona.ie4 = true;
  else if(document.all && document.getElementById) junciona.ie = junciona.ie5x = true;
  else if(document.layers) junciona.ns4 = true;
  else if(!document.all && document.getElementById) junciona.ns6 = true;
  junciona.nav = true;
  junciona.loadingPage = false;
}

junciona.objLayer = function(obj,parent,x,y,w,h,bgColor,visib,stack,content){
  this.id = this.strObj = obj;
  this.layerId = obj+"Layer";
  this.initArgs = arguments;
  this.node = null;
  this.parent = (parent!=null)?eval(parent):null;
  this.stopClipWatching = false;
  this.hasIframe = false;
  this.getTreeNode();
  this.mkLayer();
  return this;
}

junciona.objLayer.prototype.getTreeNode = function(){
  if (junciona.ie) this.getIeNode();
  else if (junciona.ns4) this.getNs4Node();
  else if (junciona.ns6) this.getNs6Node();
}

junciona.objLayer.prototype.getIeNode = function(){
  this.node = (this.parent==null)?document.body:document.all[this.parent.layerId];
  this.strNode = "document.all['"+this.layerId+"']";
}

junciona.objLayer.prototype.getNs4Node = function(){
 if (this.parent==null) this.node = "document.layers['" + this.layerId +"']"; 
 else this.node = this.parent.node + ".document.layers['" + this.layerId +"']";
}

junciona.objLayer.prototype.getNs6Node = function(){
  this.node = (this.parent==null)? document.getElementsByTagName("BODY").item(0): document.getElementById(this.parent.layerId);
  this.strNode = "document.getElementById('"+this.layerId+"')";
}

junciona.objLayer.prototype.mkLayer = function(){
  var layer;
  var content = this.initArgs[9];
  if (junciona.ie){
    var aux = '<DIV id="' + this.layerId + '" style="position:absolute;left:' + this.initArgs[2] + ';top:' + this.initArgs[3] + ';width:' + this.initArgs[4] +((this.initArgs[5]!=null)?";height:"+this.initArgs[5]:"")+ '"></div>';
    this.node.insertAdjacentHTML("BeforeEnd",aux);
    layer = this.node.children[this.node.children.length-1];
  }else if (junciona.ns4){
    (this.parent==null)? layer = document.layers[this.layerId] = new Layer(this.initArgs[4]) : layer = eval(this.node +'= new Layer('+this.initArgs[4]+','+this.parent.node+')');
  }else if (junciona.ns6){
    layer = document.createElement("DIV");
    layer.style.position = "absolute";
    layer.style.width = this.initArgs[4]+"px";
    layer.id = this.layerId;
    this.node.appendChild(layer);
  }
  this.layer = layer;
  this.layer.obj = this;
  this.style = this.layer.style;
  if(junciona.ns4) this.style = this.layer;
  this.move(this.initArgs[2],this.initArgs[3]);
  if (content!=null) this.setContent(content);
  if (this.initArgs[5]!=null) this.resize(this.initArgs[4],this.initArgs[5]);
  if (this.initArgs[6]!=null) this.setBgColor(this.initArgs[6]);
  if (this.initArgs[8]!=null) this.setZindex(this.initArgs[8]);
  (this.initArgs[7]=="show")?this.show():this.hide();
}

junciona.objLayer.prototype.move = function(x,y,timeLine) {
	this.x = this.style.left = x;
	this.y = this.style.top = y;
  if (timeLine) junciona.mgrTimeLine(timeLine);
}

junciona.objLayer.prototype.resize = function(w,h){
	this.w = w;	this.h = h;
	if (junciona.ns4) this.layer.resizeTo(w,h);
	else {
		this.style.width = (junciona.ns6) ? w+"px" : w;
		this.style.height = (junciona.ns6) ? h+"px" : h;
    this.clip(w,h);
	}
}

//arena compatibility
junciona.objLayer.prototype.fill = function(cont,rf) {
  this.setContent(cont,rf)
}

junciona.speed = function(time){ return Math.round(time*junciona.spd); }

junciona.spd = (navigator.userAgent.indexOf("Mac")!=-1)? 5 : (navigator.userAgent.indexOf("NT")!=-1)? 1 : 1/5;
//end arena compatibility module

junciona.objLayer.prototype.setContent = function(cont,rf) {
  this.content = cont;
	if (junciona.ns4){
		this.layer.document.open();
		this.layer.document.write(cont);
		this.layer.document.close();
	} else this.layer.innerHTML = cont;
  if (rf) this.updateBoundary();
}

junciona.objLayer.prototype.updateBoundary = function() {
  this.h = this.getLayerHeight();
  this.w = this.getLayerWidth();
  this.clip(this.w,this.h);
}

//arena compatibility
junciona.objLayer.prototype.color = function(colH){
	if (colH) this.setBgColor(colH)
//	else return this.setcolor;
}

junciona.objLayer.prototype.setBgColor = function(colH) {
  (junciona.ns4)? this.style.bgColor = colH : this.style.backgroundColor = colH;
}

junciona.objLayer.prototype.setZindex = function(zI) {
	this.z = this.style.zIndex = zI;
}

junciona.objLayer.prototype.show = function() {
	this.vis = this.style.visibility = "inherit";
}

junciona.objLayer.prototype.hide = function() {
	this.vis = this.style.visibility = (junciona.ns4) ? "hide" : "hidden";
}

junciona.objLayer.prototype.getLayerHeight = function(){
  return ((junciona.ns4)?eval(this.node).document.height:(junciona.ie4)?this.style.scrollHeight:this.layer.offsetHeight)
}

junciona.objLayer.prototype.getLayerWidth = function(){
  return ((junciona.ns4)?eval(this.node).document.width:(junciona.ie4)?this.style.scrollWidth:this.layer.offsetWidth);
}

junciona.objLayer.prototype.clip = function(r,b,t,l) {
	if (junciona.ns4) {
		if (t) this.layer.clip.top = t;
		this.layer.clip.right = r;
 		this.layer.clip.bottom = b;
 		if (l) this.layer.clip.left = l;
 	} else {
		if (!t) t=0;
		if (!l) l=0;
 		this.style.clip = "rect("+t+"px "+r+"px "+b+"px "+l+"px)";
    if (junciona.ns6 && this.hasIframe){
      var w = (!l)?r:(r-l);
      var h = (!l)?b:(b-t);
      this.iframe.width = w;
      this.iframe.height = h;
      this.hide();this.show();
    }
 	}
}

junciona.objLayer.prototype.getClipValue = function(which){
  if (!junciona.ns4) var clipv = this.style.clip.split("rect(")[1].split(")")[0].split("px");
  if (which == 't') return((junciona.ns4)? this.layer.clip.top : Number(clipv[0]));
  else if (which == 'r') return((junciona.ns4)? this.layer.clip.right : Number(clipv[1]));
  else if (which == 'b') return((junciona.ns4)? this.layer.clip.bottom : Number(clipv[2]));
  else if (which == 'l') return((junciona.ns4)? this.layer.clip.left : Number(clipv[3]));   
}

junciona.objLayer.prototype.clipWatcher = function(dir,ref,speed,offsetX,offsetY,timeLine){
  this.clipDat = [];
  this.clipDat[0]=dir;
  this.clipDat[1]=ref;
  this.clipDat[2]=speed;
  this.clipDat[3]=(offsetX!=null)?offsetX:0;
  this.clipDat[4]=(offsetY!=null)?offsetY:0;
  this.stopClipWatching = false;
  this.clipWatcherGoo();
}

junciona.objLayer.prototype.clipWatcherGoo = function(){
  var cr = this.getClipValue("r");
  var cb = this.getClipValue("b");
  var ct = this.getClipValue("t");
  var cl = this.getClipValue("l");
  var clipX = eval(this.clipDat[1]).x-this.x+this.clipDat[3];
  var clipY = eval(this.clipDat[1]).y-this.y+this.clipDat[4];
  if (this.clipDat[0][0] == "r") cr = clipX;
  else if (this.clipDat[0][0] == "l") cl = clipX;
  if (this.clipDat[0][1] == "b") cb = clipY;
  else if (this.clipDat[0][1] == "t") ct = clipY;
  this.clip(cr,cb,ct,cl);
  if (!this.stopClipWatching) this.timeClip = setTimeout(this.id+".clipWatcherGoo()",this.clipDat[2]);
}

junciona.objLayer.prototype.stopClipWatcher = function(timeLine){
  this.stopClipWatching = true;
  if (timeLine) junciona.mgrTimeLine(timeLine);
}

junciona.objLayer.prototype.rollOver = function(onOff,imgFile){
  var img = this.getImage();
  var ruta = img.src.substring(0,img.src.lastIndexOf("/")+1);
  var newImg = (imgFile)?ruta+imgFile+".gif":ruta+this.id+onOff+".gif";
  img.src=newImg;
}

junciona.objLayer.prototype.getImage = function(imgId){
  var image, img = (!imgId)?this.id+"Img":imgId+"Img";
  if (junciona.ie) image = document.all[img];
  else if (junciona.ns4) image = eval(this.node).document[img];
  else if (junciona.ns6) image = document.getElementById(img);
  return image;
}
