// THIS SCRIPT WAS CREATED BY JANI TURUNEN AND LEIF ERIKSSON AT DIMENSION DATA E-BUSINESS SERVICES. ALL RIGHTS RESERVED. CONTACT: jturunen@proxicom.com

var ns4=ie4=ie5=ie45=ns6=mac=false; var screenw,screenh,windoww,windowh;
var lCnt=iCnt=0; var d=document;

function detect(){
	mac=(navigator.appVersion.indexOf("Mac")!=-1)?true:false;
	ns4=(d.layers)?true:false;
	ie4=(d.all)?true:false;
	ie5=(d.getElementById&&document.all)?true:false;if(ie5){ie4=false;}
	ns6=(d.getElementById && parseInt(navigator.appVersion)>=5)?true:false;
	ie45=(mac&&navigator.appVersion.indexOf("4.5")!=-1)?true:false;
	if(ns4){
		onresize=Resize;
		ie4=ie5=ie45=ns6=false;
		screenw=screen.width;
		screenh=screen.height;
		windoww=innerWidth;
		windowh=innerHeight;
	}
	if(ie4||ie45){
		if(ie45){
			ie4=false;
		}
		screenw=screen.availWidth;
		screenh=screen.availHeight;
		windoww=document.body.clientWidth;
		windowh=document.body.clientHeight;
	}
	if(ie5||ns6){
		screenw=screen.availWidth;
		screenh=screen.availHeight;
		windoww=(ns6)?innerWidth:document.body.clientWidth;
		windowh=(ns6)?innerHeight:document.body.clientHeight;
	}
	if(ie5)ns6=false;if(ns6)ie5=false;
}

function dlayer(id,left,top,width,height,z,nest){ 
	top=(!top)?0:top;
	left=(!left)?0:left;
	width=(!width)?0:width; 
	height=(!height)?0:height;
	z=(!z)?1:z;
	if(ie4||ie45||ie5||ns6){
		html_s='<div id="'+id+'" style="position:absolute; top:'+top+'px; left:'+left+'px;"></div>\n';
		if(ie4||ie45||ie5){
			if(!nest){
				d.body.insertAdjacentHTML("beforeEnd",html_s);
				this.obj=new layer(id);
			}else{
				d.all[nest].insertAdjacentHTML("beforeEnd",html_s);
				this.obj = new layer(id,nest);
			}
		}else if(ns6){
			e=d.createElement('div');
			e.setAttribute('id',id);
			e.setAttribute('style','position:absolute;top:'+top+';left:'+left+';');
			if(nest){
				d.getElementById(nest).appendChild(e);
				this.obj=new layer(id,nest);
			}else{
				d.body.appendChild(e);
				this.obj=new layer(id);
			}
		}
	}else if(ns4){
		width=(width==0)?500:width;
		if(!nest){
			d.layers[id]=new Layer(width);
			d.layers[id].left=left;
			d.layers[id].top=top;
			d.layers[id].height=height;
			d.layers[id].zIndex=z;
			d.layers[id].visibility='show';
			this.obj=new layer(id);
		}
		else{
			d.layers[nest].document.layers[id]=new Layer(width,d.layers[nest]);
			d.layers[nest].document.layers[id].left=left;
			d.layers[nest].document.layers[id].top=top;
			d.layers[nest].document.layers[id].height=height;
			d.layers[nest].document.layers[id].zIndex=z;
			d.layers[nest].document.layers[id].visibility='show';
			this.obj=new layer(id,nest);
		}
	}
}

function layer(id,nestref){
	if(ns4){
		if(nestref){
			this.css=eval("d.layers."+nestref+".document.layers."+id);
		}
		else{
			this.css=d.layers[id];
		}
		this.x=this.css.left;
		this.y=this.css.top;
		this.w=this.css.document.width;
		this.h=this.css.document.height;
		this.z=this.css.zIndex;
	}
	else if(ie4){
		this.css=d.all[id].style;
		this.h=d.all[id].scrollHeight;
		this.w=d.all[id].scrollWidth;
		this.x=this.css.pixelLeft;
		this.y=this.css.pixelTop;
		this.z=this.css.zIndex;
	}
	else if(ie5||ns6){
		this.css=d.getElementById(id).style;
		this.x=d.getElementById(id).offsetLeft;
		this.y=d.getElementById(id).offsetTop;
		this.z=this.css.zIndex;
		this.w=d.getElementById(id).offsetWidth;
		this.h=d.getElementById(id).offsetHeight;
		if(ns6&&nestref){
			this.x-=d.getElementById(nestref).offsetLeft;
			this.y-=d.getElementById(nestref).offsetTop;
		}
	}
	else{
		alert("Desafortunadamente este sitio Web usa opciones t&eacute;cnicas avanzadas de scripting scripting que no son soportadas por el navegador que esta utilizando.");
	}
	if(nestref){
		this.nestref=nestref;
	}
	else{
		this.nestref=false;
	}
	this.obj=id+"o";
	eval(this.obj+'=this');
	this.relayer=relayer;
	this.id=id;
	this.active=false;
	this.moving=false;
	this.move=move_Layer;
	this.level=level_Layer;
	this.resize=resize_Layer;
	this.clip=clip_Layer;
	this.show=show_Layer;
	this.hide=hide_Layer;
	this.write=layer_Write;
	this.glide=glide_Layer;
}

function relayer(){
	id=this.id;
	nestref=this.nestref;
	if(ns4){
		this.x=this.css.left;
		this.y=this.css.top;
		this.w=this.css.document.width;
		this.h=this.css.document.height;
	}
	else if(ie4){ 
		this.h=d.all[id].scrollHeight;
		this.w=d.all[id].scrollWidth;
		this.x=this.css.pixelLeft;
		this.y=this.css.pixelTop;
	}
	else if(ie5||ns6){
		this.x=d.getElementById(id).offsetLeft;
		this.y=d.getElementById(id).offsetTop; 
		this.w=d.getElementById(id).offsetWidth;
		this.h=d.getElementById(id).offsetHeight;
		if(ns6&&nestref){
			this.x-=document.getElementById(nestref).offsetLeft;
			this.y-=document.getElementById(nestref).offsetTop;
		}
	}
}

function move_Layer(x,y){
	this.x=x;
	this.y=y;
	this.css.left=this.x;
	this.css.top=this.y;	
}

function level_Layer(z){ 
	this.z=z;
	this.css.zIndex=this.z;
}

function glide_Layer(orig_x,orig_y,dest_x,dest_y,max_spd){
	max_spd=(! max_spd)?50:max_spd;
	if(this.x!=dest_x){
		new_x=this.x+getSpeed(orig_x,dest_x,this.x,max_spd);
		this.move(new_x,this.y);
	}
	if(this.y!=dest_y){
		new_y=this.y+getSpeed(orig_y,dest_y,this.y,max_spd);
		this.move(this.x,new_y);
	}
	if(this.x!=dest_x||this.y!=dest_y){
		this.moving=true;
		setTimeout(this.obj+'.glide('+orig_x+','+orig_y+','+dest_x+','+dest_y+','+max_spd+');',5);
	}
	else{
		this.moving=false;
	}
}

function resize_Layer(w,h){
	this.w = w;
	this.h = h;
	this.css.width=this.w;
	this.css.height=this.h;
}

function clip_Layer(t,r,b,l){
	if(ns4){
		this.css.clip.top=t;
		this.css.clip.right=r;
		this.css.clip.bottom=b;
		this.css.clip.left=l;
	}
	else{
		this.css.clip="rect("+t+"px "+r+"px "+b+"px "+l+"px)";
	}
}

function show_Layer(){
	if(ns4){
		this.css.visibility="show";
	}
	else{
		this.css.visibility="visible";
	}
}

function hide_Layer(){
	if(ns4){
		this.css.visibility="hide";
	}
	else{
		this.css.visibility="hidden";
	}
}

function layer_Write(text){
	id=this.id;
	nest=this.nestref;
	if(ns4){l=(nest)?eval('d.layers.'+nest+'.document.layers.'+id+'.document'):d.layers[id].document;
	l.open();
	l.write(text);
	l.close();
	}
	else if(ie5||ns6){
		d.getElementById(id).innerHTML=text;
	}
	else{
		d.all[id].innerHTML=text;
	}
}

function Resize(){
	if(innerHeight!=windoww||innerWidth!=windowh)
		location.reload();
}

function getSpeed(o,d,current,max_speed){
	if(o>d){
		var dist=o-d;var perc=Math.abs((o-current)/dist);
	}
	else if(d>o){
		var dist=d-o; var perc=Math.abs((current-o)/dist);
	}
	if(max_speed>(dist/4)){
		max_speed=dist/4;
	}
	var tmp=(-(Math.PI/2))+((Math.PI/2)*perc*2);
	tmp=Math.cos(tmp)*max_speed;
	tmp=Math.ceil(tmp);
	if(o>d)	tmp=-(tmp);
	return tmp;
}