/*
Junciona-JS : Copyright (C) 2001 Luis Navalpotro.
Distributed under the terms of the GNU Library General Public License
Avalaible at http://sourceforge.net/projects/junciona/
questions&contact: lnavalpotro@terra.es
http://ns1.junciona.com
version 1.0.5b
*/

function junciona(obj,parent,x,y,w,h,bgColor,visib,stack,content) {
  var undefined;
  if (junciona.auxBufferLoadCreated == undefined) junciona.setAuxBufferLoad();
  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.setAuxBufferLoad = function(){
  junciona.auxBufferLoadCreated = false;
  junciona.auxBufferLoadReady = true;
  junciona.auxBufferLoadNav = null;
  junciona.auxBufferLoad = junciona("juncionaAuxBufferLoad",null,0,0,0,0,"#aaaaaa","show",0,"");
}

junciona.setMath = function(){
  radianes = Math.PI/180;
  junciona.sins = [];
  junciona.coss = [];
  for (i=0;i<=360;i++){
    var angulo = i*radianes;
    junciona.sins[i] = Math.sin(angulo);
    junciona.coss[i] = Math.cos(angulo);
  }
}

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.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, 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);
	}
}

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);
}

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.style.visibility = "inherit";
}

junciona.objLayer.prototype.hide = function() {
	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.slide = function(xf,yf,resolution,speed,kine,nextEv,scoreChannel) {
	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,scoreChannel);
}

junciona.objLayer.prototype.cut = function(xi,yi,xf,yf,resolution,speed,kine,nextEv,scoreChannel) {
	this.whatToMove(xi,yi,xf,yf,resolution,speed,Math.round(xi+(xf-xi)/20*(10+kine)),Math.round(yi+(yf-yi)/20*(10+kine)),'this.clip',nextEv,scoreChannel);
}

junciona.objLayer.prototype.whatToMove = function(xi,yi,xf,yf,resolution,speed,xbeizer,ybeizer,func,nextEv,scoreChannel) {
	this.datGoo=[resolution+1,speed,1,0,1/resolution,func,nextEv,[],[],scoreChannel];
	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[7][i] = Math.round((auxS1*xi)+(auxS3*xbeizer)+(auxS2*xf));
		this.datGoo[8][i] = Math.round((auxS1*yi)+(auxS3*ybeizer)+(auxS2*yf));
		this.datGoo[3] = i * this.datGoo[4];	
	}
	this.runGoo();
}

junciona.objLayer.prototype.runGoo = function() {
	if (++this.datGoo[2] <= this.datGoo[0]) {
		eval(this.datGoo[5]+'('+this.datGoo[7][this.datGoo[2]]+','+this.datGoo[8][this.datGoo[2]]+')');
		setTimeout(this.id+".runGoo()",this.datGoo[1]);		
	} else { 
		if (this.datGoo[6]) eval(this.datGoo[6]);
    if (this.datGoo[9]) junciona.mgrTimeLine(this.datGoo[9]);
	}	
}

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)";
 	}
}

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.load = function(page, nextEv, timeLine) {
  var iFrameID = this.id+"iFrm";
  var style = "WIDTH="+this.w+" HEIGHT="+this.h+" MARGINWIDTH=0 MARGINHEIGHT=0 SCROLLING=NO FRAMEBORDER=NO BORDER=0";
  junciona.auxBufferLoadReady = false;
	if (junciona.ie){
    if (junciona.auxBufferLoadCreated == false){
      junciona.auxBufferLoadCreated = true;
      junciona.auxBufferLoad.setContent("<IFRAME NAME="+iFrameID+" ID="+iFrameID+" "+style+"></IFRAME>");
      junciona.auxBufferLoad.iframe = document.frames[iFrameID];
    }
    junciona.auxBufferLoad.iframe.location.href = page;
    this.auxBufferLoadNav="ieBufferLoad('"+timeLine+"')";
    this.chkBufferLoaded();
	}else if (junciona.ns4){
    this.layer.src = page;
		this.timeLoad=setTimeout(this.id+".ns4BufferLoad('"+timeLine+"')",200);	
  }else if (junciona.ns6){
      if (junciona.auxBufferLoadCreated == false){
        junciona.auxBufferLoadCreated = true;
        junciona.auxBufferLoad.iframe = document.createElement("IFRAME");
        junciona.auxBufferLoad.iframe.id = iFrameID;
        junciona.auxBufferLoad.iframe.setAttribute("STYLE",style);
        junciona.auxBufferLoad.iframe.setAttribute("SCROLLING","NO");
        junciona.auxBufferLoad.iframe.setAttribute("FRAMEBORDER","0");
        junciona.auxBufferLoad.iframe.width = 0;
        junciona.auxBufferLoad.iframe.height = 0;
        junciona.auxBufferLoad.layer.appendChild(junciona.auxBufferLoad.iframe);
      }
    junciona.auxBufferLoad.iframe.src = page;
    this.auxBufferLoadNav="ns6BufferLoad('"+timeLine+"')";
    this.chkBufferLoaded();
  }
  if (nextEv) eval(nextEv);
}

junciona.objLayer.prototype.chkBufferLoaded = function(){
  if (junciona.auxBufferLoadReady == true) eval(this.id+"."+this.auxBufferLoadNav);
  else setTimeout(this.id+".chkBufferLoaded()",200);
}

junciona.objLayer.prototype.ieBufferLoad = function(timeLine){
  this.setContent(junciona.auxBufferLoad.iframe.document.body.innerHTML);
  if (timeLine!='null'){
   junciona.mgrTimeLine(timeLine);
  }
}

junciona.objLayer.prototype.ns4BufferLoad = function(timeLine){
  (eval(this.node).document.loaded==true)? (timeLine!='null')?junciona.mgrTimeLine(timeLine):void(null) : this.timeLoad=setTimeout(this.id+".ns4BufferLoad('"+timeLine+"')",200);
}

junciona.objLayer.prototype.ns6BufferLoad = function(timeLine){
  this.setContent(unescape(junciona.auxBufferLoad.iframe.contentDocument.body.innerHTML));
  this.show();
  if(timeLine) junciona.mgrTimeLine(timeLine);
}

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.id+"Img";
    var newImg = (imgFile)?"img/"+imgFile+".gif":"img/"+this.id+onOff+".gif";
    if (junciona.ie) document.all[img].src = newImg;
    else if (junciona.ns4) eval(this.node).document[img].src = newImg;
    else if (junciona.ns6) document.getElementById(img).src=newImg;
}

junciona.objLayer.prototype.getImage = function(idx){
    var image, img = this.id+"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;
}

junciona.init = function(){
  junciona.setNav();
  junciona.setMath();
}

junciona.init();
