/**********************************************************************************   
    Libreria hau Tomas Brattliren eta
	Dan Steinmanen DynApi librerietan oinarrituta dago.

	http://www.bratta.com
	http://www.dansteinman.com/dynduo
*********************************************************************************/

function checkBrowser(){
	this.ver=navigator.appVersion
	this.agent=navigator.userAgent
	this.dom=document.getElementById?1:0
	this.opera5=this.agent.indexOf("Opera 5")>-1
	this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom && !this.opera5)?1:0; 
	this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom && !this.opera5)?1:0;
	this.ie4=(document.all && !this.dom && !this.opera5)?1:0;
	this.ie=this.ie4||this.ie5||this.ie6
	this.mac=this.agent.indexOf("Mac")>-1
	this.ns6=(this.dom && parseInt(this.ver) >= 5) ?1:0; 
	this.ns4=(document.layers && !this.dom)?1:0;
	this.bw=(this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.opera5)
	return this
}

bw=new checkBrowser()

function makePageCoords(){
	this.x=0;this.x2=(bw.ns4 || bw.ns6)?innerWidth:document.body.offsetWidth;
	this.y=0;this.y2=(bw.ns4 || bw.ns6)?innerHeight:document.body.offsetHeight;
	this.x50=this.x2/2;	this.y50=this.y2/2;
	this.x10=(this.x2*10)/100-5;this.y10=(this.y2*10)/100-5
	this.x15=(this.x2*15)/100-5;this.y15=(this.y2*15)/100-5; 
	return this;
}

function makeObj(obj,nest,dnest,ddnest,num){
	this.num=num	
	if(!bw.bw){
		alert('Nabigatzaile zaharra erabiltzen ari zara. Webgune hau ikusteko eguneratu beharko duzu.')
		return -1;
	}
	if(!bw.ns4)
		this.evnt=bw.dom && document.getElementById(obj)||bw.ie4 && document.all[obj]
	else{
		if(ddnest){
			this.evnt=document[nest].document[dnest].document[ddnest].document[obj]?document[nest].document[dnest].document[ddnest].document[obj]:0;
		}else if(dnest){
			this.evnt=document[nest].document[dnest].document[obj]?document[nest].document[dnest].document[obj]:0;
		}else if(nest){
			this.evnt=document[nest].document[obj]?document[nest].document[obj]:0;
		}else{
			this.evnt=document.layers[obj]?document.layers[obj]:0;
		}	
	}
	if(!this.evnt){
		alert('Geruza hau ez da existitzen ('+obj+') - Exiting script\n\nIf your using Netscape please check the nesting of your tags!')
		return -1;
	}
	this.css=bw.dom||bw.ie4?this.evnt.style:this.evnt;      
	this.ref=bw.dom||bw.ie4?document:this.css.document;
	this.x=this.css.left||this.css.pixelLeft||this.evnt.offsetLeft||0
	this.y=this.css.top||this.css.pixelTop||this.evnt.offsetTop||0
	this.w=this.ref.width||this.evnt.offsetWidth||this.css.pixelWidth||0
	this.h=this.ref.height||this.evnt.offsetHeight||this.css.pixelHeight||0
	
	this.moveIt=fMugi; 
	this.moveBy=fMugiBy;
	this.showIt=fErakutsi;
	this.hideIt=fIzkutatu; 
	this.writeIt=fIdatzi; 
	this.bg=fBgAldatu;
	
	//Clip values
	this.c=new Array(4)
	if((bw.dom || bw.ie4) && this.css.clip) {
		this.c=this.css.clip; this.c=this.c.slice(5,this.c.length-1); 
		this.c=this.c.split(' '); 
		for(var i=0;i<4;i++){this.c[i]=parseInt(this.c[i])}
	}
	this.ct=this.css.clip.top||this.c[0]||0; 
	this.cr=this.css.clip.right||this.c[1]||this.w||0
	this.cb=this.css.clip.bottom||this.c[2]||this.h||0; 
	this.cl=this.css.clip.left||this.c[3]||0
	
	this.clipTo=fClipTo;
	this.clipBy=fClipBy; 
	this.clip=fClip; 
	this.clipIt=fClipIt;
	this.slideIt=fSlideIt; 
	this.slide=fSlide;
	
	this.obj = obj + "Object"; 	eval(this.obj + "=this")
	return this
}
	
function fErakutsi(){this.css.visibility="visible"}

function fIzkutatu(){this.css.visibility="hidden"}

function fBgAldatu(color){
	if(bw.opera5) this.css.background=color
	else if(bw.dom || bw.ie4) this.css.backgroundColor=color
	else if(bw.ns4) this.css.bgColor=color 
}

function fIdatzi(text){
  if(bw.ns4){
    if(!startHTML){startHTML=""; endHTML=""}
      this.ref.write(startHTML+text+endHTML); this.ref.close()
    }else this.evnt.innerHTML=text
}

function fMugi(x,y){
	this.x=x; 
	this.css.left=x; 
	if(y!=-1){
		this.y=y; 
		this.css.top=y
	}
}

function fMugiBy(x,y){
	x=this.x+x
	y=y==0?-1:this.y+y
	this.moveIt(x,y)
}

function fSlideIt(endx,endy,inc,speed,fn,wh) {
	if (!this.slideactive) {var distx = endx - this.x;var disty = endy - this.y
	var num = Math.sqrt(Math.pow(distx,2) + Math.pow(disty,2))/inc
	var dx = distx/num;var dy = disty/num
	this.slideactive = 1; this.slide(dx,dy,endx,endy,speed,fn,wh)}
}
	
function fSlide(dx,dy,endx,endy,speed,fn,wh) {
	if (!fn) fn = null; if(!wh) wh=null
	if (this.slideactive && (Math.floor(Math.abs(dx))<Math.floor(Math.abs(endx-this.x)) || Math.floor(Math.abs(dy))<Math.floor(Math.abs(endy-this.y)))) {
	this.moveBy(dx,dy); eval(wh)
	slidTim=setTimeout(this.obj+".slide("+dx+","+dy+","+endx+","+endy+","+speed+",'"+fn+"','"+wh+"')",speed)
	}else{this.slideactive = 0;this.moveIt(endx,endy);eval(fn)}
}

function fClipTo(t,r,b,l,setwidth){ 
	this.ct=t; this.cr=r; this.cb=b; this.cl=l
	if(bw.ns4){
		this.css.clip.top=t;this.css.clip.right=r
		this.css.clip.bottom=b;this.css.clip.left=l
	}else{
		if(t<0)t=0;if(r<0)r=0;if(b<0)b=0;if(b<0)b=0
		this.css.clip="rect("+t+","+r+","+b+","+l+")";
		if(setwidth){
			if(bw.opera5){this.css.pixelWidth=r; this.css.pixelHeight=b}
			else{this.css.width=r; this.css.height=b}
			this.w=r; this.h=b
		}
	}
}

function fClipIt(tstop,rstop,bstop,lstop,step,fn,wh,www){
	if(!fn) fn=null; if(!wh) wh=null; var clipval=new Array()
	if(bw.dom || bw.ie4) {clipval=this.css.clip; clipval=clipval.slice(5,clipval.length-1);
	clipval=clipval.split(' '); for(var i=0;i<4;i++){clipval[i]=parseInt(clipval[i])}
	}else{clipval[0]=this.css.clip.top; clipval[1]=this.css.clip.right
	clipval[2]=this.css.clip.bottom; clipval[3]=this.css.clip.left}
	totantstep=Math.max(Math.max(Math.abs((tstop-clipval[0])/step),Math.abs((rstop-clipval[1])/step)),
	Math.max(Math.abs((bstop-clipval[2])/step),Math.abs((lstop-clipval[3])/step)))
	if(!this.clipactive)this.clip(clipval[0],clipval[1],clipval[2],clipval[3],(tstop-clipval[0])/totantstep,
	(rstop-clipval[1])/totantstep,(bstop-clipval[2])/totantstep,
	(lstop-clipval[3])/totantstep,totantstep,0, fn,wh,www)
}

function fClip(tcurr,rcurr,bcurr,lcurr,tperstep,rperstep,bperstep,lperstep,totantstep,antstep,fn,wh,www){
	tcurr=tcurr+tperstep; rcurr=rcurr+rperstep; bcurr=bcurr+bperstep; lcurr=lcurr+lperstep
	if(www)this.clipTo(tcurr,rcurr,bcurr,lcurr,1);
	else this.clipTo(tcurr,rcurr,bcurr,lcurr);
	eval(wh); if(antstep<totantstep){this.clipactive=true;	antstep++
	setTimeout(this.obj+".clip("+tcurr+","+rcurr+","+bcurr+","+lcurr+","+tperstep+","
	+rperstep+","+bperstep+","+lperstep+","+totantstep+","+antstep+",'"+fn+"','"+wh+"','"+www+"')",50)	
	}else{this.clipactive=false; eval(fn)}
}

function fClipBy(t,r,b,l,setwidth){ //Clip by a spesified number of pixels
	this.clipTo(this.ct+t,this.cr+r,this.cb+b,this.cl+l,setwidth)
}