// scripts by johan@orbitsville.com
// with ideas from dan steinman

// version 1.1

// variable used for showing and hiding layers
hidden = (bNS)? 'hide': 'hidden';
visible = (bNS)? 'show': 'visible';
var currLyr
var slideRepeat = false;

function samLyr(name,pth) {
// properties
	if (is_ie4) {
		this.obj = document.all[name];
		this.style = this.obj.style;
		this.left = this.obj.offsetLeft;
		this.top = this.obj.offsetTop;			
		this.width = this.obj.offsetWidth;
		this.height = this.obj.offsetHeight;
		this.x = this.left;
		this.y = this.top;		
	}
	
	else if (bNS){
		if (pth) this.obj = pth.document.layers[name];
		else this.obj = document.layers[name];
		this.style = this.obj
		this.left = this.obj.left;
		this.top = this.obj.top;			
		this.width = this.obj.clip.width;
		this.height = this.obj.clip.height;
		this.x = this.left;
		this.y = this.top;
	}
	
	else {
		this.obj = document.getElementById(name);
		this.style = this.obj.style;
		this.left = this.obj.offsetLeft;
		this.top = this.obj.offsetTop;		
		this.width = this.obj.offsetWidth;
		this.height = this.obj.offsetHeight;
		this.x = this.left;
		this.y = this.top;
	}
this.obj2 = name + "samLyr"
eval(this.obj2 + "=this")		

	
// methods
	this.moveBy = samMoveBy
	this.moveTo = samMoveTo
	this.show = samShow
	this.hide = samHide
	this.w = samChangeWidth
	this.h = samChangeHeight
	this.remove = samRemove
	this.bringback = samReturn
	this.lyrwrite = samWrite
	this.getOT = samGetOTop
	this.getOL = samGetOLeft

	this.slideTo = samSlideTo
	this.slideStart = samSlideStart
	this.slide = samSlide
	this.sliding = false

	//if (bNS) this.obj.captureEvents(Event.MOUSECLICK | Event.MOUSEMOVE)

	//this.obj.onmouseover = samMouseover
	//this.obj.onclick = samClick
	//this.obj.onmousedown = samClick	
}

function samSlideTo(endx,endy,inc,speed,fn) {
	if (endx==null) endx = this.x
	if (endy==null) endy = this.y
	var distx = endx-this.x
	var disty = endy-this.y
	this.slideStart(endx,endy,distx,disty,inc,speed,fn)
}
function samSlideStart(endx,endy,distx,disty,inc,speed,fn) {
	if (this.slideActive) return
	if (!inc) inc = 10
	if (!speed) speed = 20
	var num = Math.sqrt(Math.pow(distx,2) + Math.pow(disty,2))/inc
	if (num==0) return
	var dx = distx/num
	var dy = disty/num
	if (!fn) fn = null
	this.slideActive = true
	this.slide(dx,dy,endx,endy,num,1,speed,fn,inc)
}
function samSlide(dx,dy,endx,endy,num,i,speed,fn,inc) {
	if (!this.slideActive) return
	if (i++ < num) {
		this.moveBy(dx,dy)
		if (this.slideActive) setTimeout(this.obj2+".slide("+dx+","+dy+","+endx+","+endy+","+num+","+i+","+speed+",\""+fn+"\")",speed)
	}
	else {
		this.slideActive = false
		this.moveTo(endx,endy)
		if(slideRepeat)
		{
			resetLyr(this,endx,endy,inc,speed);
		}
	}
}
function samMoveBy(x,y) {
	this.x += parseInt(x)
	this.style.left = this.x
	this.left = this.x
	this.y += parseInt(y)
	this.top = this.y
	this.style.top = this.y
}
function samMoveTo(x,y) {
	this.x = parseInt(x)
	this.style.left = this.x
	this.left = this.x
	this.y = parseInt(y)
	this.style.top = this.y
	this.top = this.y
}

function samShow() {
	this.style.visibility = visible
}

function samHide() {
	this.style.visibility = hidden	
}

function samChangeWidth(w) {
	if (bNS) this.obj.clip.width = w
	else this.style.width = w
	this.width = w
}

function samChangeHeight(h) {
	if (bNS) this.obj.clip.height = h
	else this.style.height = h
	this.height = h
}

function samImg(name,pth) {
	if (pth != '') this.obj = pth.document.images[name];
	else this.obj = document.images[name];
}

function samRemove () {
	if (!bNS) {
		this.style.display = "none";
	}
	else {
		alert ('IE/NS6 only');
	}	
}

function samReturn () {
	if (!bNS) {
		this.style.display = "block";
	}
	else {
		alert ('IE/NS6 only');
	}	
}

function samWrite (text) {
	if (bNS) {
		this.obj.document.open()
		this.obj.document.write(text)
		this.obj.document.close()
	}
	else {
		this.obj.innerHTML = text
	}
	updateProperties(this)
}

function samMouseover(e) {
	if (!bNS && !is_nav6) e = event
	evLyr.lyrwrite('Latest event: '+e.type+' Layer: '+this.id)
	if (!bNS) this.style.background = '#FF0000'
}

function samClick(e) {
	if (!bNS && !is_nav6) e = event
	evLyr.lyrwrite('Latest event: '+e.type+' Layer: '+this.id)
	cLyr.lyrwrite('Current layer: '+this.id)
	if (!bNS) this.style.background = '#00FF00'
	currLyr = this.ref;
}

function samGetOTop () {
  el = this.obj
  var ot = el.offsetTop;
  while((el = el.offsetParent) != null)
   ot += el.offsetTop;
  return ot;
}

function samGetOLeft () {
  el = this.obj
  var ot = el.offsetLeft;
  while((el = el.offsetParent) != null)
   ot += el.offsetLeft;
  return ot;
}


function updateProperties (o) {
	if (is_ie4) {		
		o.style = o.obj.style;
		o.left = o.obj.offsetLeft;
		o.top = o.obj.offsetTop;			
		o.width = o.obj.offsetWidth;
		o.height = o.obj.offsetHeight;
	}
	else if (bNS){
		o.style = o.obj
		o.left = o.obj.left;
		o.top = o.obj.top;			
		o.width = o.obj.clip.width;
		o.height = o.obj.clip.height;
	}
	else {
		o.style = o.obj.style;
		o.left = o.obj.offsetLeft;
		o.top = o.obj.offsetTop;		
		o.width = o.obj.offsetWidth;
		o.height = o.obj.offsetHeight;
	}
}
