function Win(lyr, x, y, w, h) {

	this.x = x;
	this.y = y;
	this.w = w;
	this.h = h;
	this.lyr = getLyr(lyr, '');
	this.visible = false;
	this.draw = winDraw;
	this.hide = winHide;
	this.show = winShow;

}

function winDraw() {
	this.lyr.left = this.x;
	this.lyr.top = this.y;
	this.lyr.width = this.w;
	this.lyr.height = this.h;
	if(ns) {
		this.lyr.clip.left = 0;
		this.lyr.clip.right = this.w;
		this.lyr.clip.top = 0;
		this.lyr.clip.bottom = this.h;
	} else {
		this.lyr.clip = 'rect(0px '+this.w+'px '+this.h+'px 0px)';
	}
}

function winHide() {
	this.lyr.visibility = 'hidden';
	this.visible = false;
}

function winShow() {
	this.lyr.visibility = 'visible';
	this.visible = true;
}

function Dragger(img, lyr, parent, x, y, w, h) {
	
	this.x = x;
	this.w = w;
	this.y = y;
	this.h = h;
	this.ox = 0;
	this.oy = 0;
	this.drag = false;
	this.img = img;
	this.lyr = getLyr(lyr, parent);
	this.lyrcover = getLyr(lyr+'cover', parent);
	
	this.draw = draggerDraw;

}

function draggerDraw() {
	this.lyr.left = this.x;
	this.lyr.top = this.y;
	this.lyr.width = this.w;
	this.lyr.height = this.h;
	this.lyrcover.left = this.x;
	this.lyrcover.top = this.y;
	this.lyrcover.width = this.w;
	this.lyrcover.height = this.h;
}

function Intro(lyr, parent, x, y) {
	
	this.x = x;
	this.y = y;
	this.lyr = getLyr(lyr, parent);
	this.lyr.left = this.x;
	this.lyr.top = this.y;
	
}

function Slider(img, lyrSlider, lyrScrollbar, lyrParent, x, y, w, h, min, max) {

	this.x = x;
	this.w = w;
	this.y = y;
	this.h = h;
	this.min = min;
	this.max = max;
	this.oy = 0;
	this.drag = false;
	this.img = img;
	this.lyr = getLyr(lyrSlider, lyrParent);
	this.lyrcover = getLyr(lyrSlider+'cover', lyrParent);
	this.lyrscrollbar = getLyr(lyrScrollbar, lyrParent);
	this.lyrscrollbarmasktop = getLyr(lyrScrollbar+'masktop', lyrParent);
	this.lyrscrollbarmaskbottom = getLyr(lyrScrollbar+'maskbottom', lyrParent);
	this.lyrscrollbar.left = this.x;
	this.lyrscrollbar.top = this.y+6;
	this.lyrscrollbarmasktop.left = this.x;
	this.lyrscrollbarmasktop.top = this.y-6;
	this.lyrscrollbarmaskbottom.left = this.x;
	this.lyrscrollbarmaskbottom.top = this.y+271;
	this.visible = false;

	this.draw = sliderDraw;
	this.go = sliderGo;
	this.show = sliderShow;
	this.hide = sliderHide;

}

function sliderDraw() {
	this.lyr.left = this.x;
	this.lyr.top = this.y;
	this.lyrcover.left = this.x;
	this.lyrcover.top = this.y;
}

function sliderGo(y) {
	this.y = y;
}

function sliderShow() {
	this.visibility = true;
	this.lyr.visibility = 'visible';
	this.lyrcover.visibility = 'visible';
	this.lyrscrollbar.visibility = 'visible';
}

function sliderHide() {
	this.visibility = false;;
	this.lyr.visibility = 'hidden';
	this.lyrcover.visibility = 'hidden';
	this.lyrscrollbar.visibility = 'hidden';
}

function Scroller(lyr, parent, x, y, w, h, b, s) {
	
	this.x = x;						// initial x position
	this.y = y;						// initial y position
	this.w = w;						// width
	this.h = h;						// height
	this.t = 0;						// clip rectangle top
	this.r = w;						// clip rectangle right
	this.b = b;						// clip rectangle bottom
	this.l = 0;						// clip rectangle left
	this.s = (n.userAgent.indexOf("Win")!=-1) ? s : 2*s;	// s specifies auto-scroll speed - 0 for manual scroll
	
	
	this.yoffset = y;					// page y offset
	this.clipheight = b;
	this.visibility = false;
	this.lyr = getLyr(lyr, parent);
	
	this.draw = scrollerDraw;
	this.hide = scrollerHide;
	this.show = scrollerShow;
	this.go = scrollerGo;
	
}

function scrollerDraw() {

	if(!this.visibility) {
		this.lyr.visibility = 'visible';
		this.visibility = true;
	}
	if(this.s>0) {
		this.y -= this.s;
		this.t += this.s;
		this.b += this.s;
		if(this.y <= -this.h) this.y = this.yoffset;
	}
	this.lyr.left = this.x;
	this.lyr.top = this.y;
	this.lyr.width = this.w;
	this.lyr.height = this.h;
	this.t = this.yoffset-this.y;
	this.b = this.t+this.clipheight;
	if(ns) {
		this.lyr.clip.left = this.l;
		this.lyr.clip.right = this.r;
		this.lyr.clip.top = this.t;
		this.lyr.clip.bottom = this.b;
	} else {
		this.lyr.clip = 'rect('+this.t+'px '+this.r+'px '+this.b+'px '+this.l+'px)';
	}

}

function scrollerHide() {
	this.lyr.visibility = 'hidden';
	this.visible = false;
}

function scrollerShow() {
	this.lyr.visibility = 'visible';
	this.visible = true;
}

function scrollerGo(y) {
	this.y = y;
}

function set() {
	document.onmousedown = mousedown;
	document.onmousemove = mousemove;
	document.onmouseup = mouseup;
	if(ns) document.captureEvents(Event.MOUSEMOVE | Event.MOUSEDOWN | Event.MOUSEUP);
}

function getLyr(lyr, parent) {
	if(ie) return eval(lyr).style;
	if(n6) return document.getElementById(lyr).style;
	if(ns) {
		if(parent!='') {
			return document.eval(parent).document.eval(lyr);
		}else{
			return document.eval(lyr);
		}
	}
	return false;
}

function getObj(e, obj) {
	if(ns) {
		for(i in wrapper) {
			var clickX = e.pageX - document.layers[wrapper[i]].left;
			var clickY = e.pageY - document.layers[wrapper[i]].top;
			if((clickX > obj.x) && (clickX < obj.x+obj.w) && (clickY > obj.y) && (clickY < obj.y+obj.h)) return true;
		}
	} else if(ie) {
		elem = window.event.srcElement;
		if(elem.style == obj.lyrcover || elem.name == obj.img) return true;
	}
	else if(n6) {
		if(e.target.style == obj.lyrcover) return true;
	}
	return false;
}

function mousedown(e) {

	if(slide!=null) {
		if(getObj(e, slide)) {
			slide.drag = true;
			slide.oy = (ns||n6) ? e.pageY-parseInt(slide.lyr.top) : window.event.clientY-parseInt(slide.lyr.top);
		}
	}
	if(drag!=null) {
		if(getObj(e, drag)) {
			drag.drag = true;
			drag.ox = (ns||n6) ? e.pageX-parseInt(drag.lyr.left)-parseInt(win.lyr.left) : window.event.clientX-parseInt(drag.lyr.left)-parseInt(win.lyr.left);
			drag.oy = (ns||n6) ? e.pageY-parseInt(drag.lyr.top)-parseInt(win.lyr.top) : window.event.clientY-parseInt(drag.lyr.top)-parseInt(win.lyr.top);
		}
	}
	return false;

}

function mousemove(e) {

	release = true;
	if(slide!=null) {
		if(slide.drag && slide.y>=slide.min && slide.y<=slide.max) {
			slide.y = (ns||n6) ? e.pageY-slide.oy : window.event.clientY-slide.oy;
			if(slide.y < slide.min) slide.y = slide.min;
			if(slide.y > slide.max) slide.y = slide.max;
			slide.draw();
			var ratio = (scr.h-scr.clipheight)/(slide.max-slide.min);
			var pos = slide.y-slide.min;
			scr.y = scr.yoffset-pos*ratio;
		}
		if(getObj(e, slide) || slide.drag) release = false;
	}
	if(drag!=null) {
		if(drag.drag) {
			win.x = (ns||n6) ? e.pageX-drag.ox : window.event.clientX-drag.ox;
			win.y = (ns||n6) ? e.pageY-drag.oy : window.event.clientY-drag.oy;
			win.draw();
		}
		if(getObj(e, drag) || drag.drag) release = false;
	}
	if(release) {
		if(ns) document.releaseEvents(Event.MOUSEMOVE | Event.MOUSEDOWN | Event.MOUSEUP);
	}
	return false;
	
}

function mouseup(e) {
	if(slide!=null) slide.drag = false;
	if(drag!=null) drag.drag = false;
}

win = null;
drag = null;
intro = null;
slide = null;
scr = null;
auto = null;
wrapper = new Array();