// JavaScript Process Modul
// Copyright © 2005 by AQUILA-IT. All rights reserved.
// 2005-01-01



var ie4, ns4, ns6, 

		area_w = 700,
		area_h = 600;


function CreateWin() {

 	ie4 = (document.all) ? true : false;
 	ns4 = (document.layers) ? true : false;

	if (ie4) ns6 = false;
	else ns6 = (document.getElementById) ? true : false;

	win = new InitLayerWin();
}



function InitLayerWin() {

	this.w = GetWidthWin();
	this.h = GetHeightWin();
	this.w2 = Math.round(this.w / 2);
	this.h2 = Math.round(this.h / 2);
	this.stepX = 8;
	this.stepY = 6;
}



function InitCheckSize() {

	TimerWin = window.setInterval("CheckSizeWin()",100);
}



function DeInitCheckSize() {

	clearInterval(TimerWin);
}



function GetWidthWin() {

	if (ie4) return parseInt(document.body.clientWidth);
	if (ns4||ns6) return parseInt(window.innerWidth);
}



function GetHeightWin() {

	if (ie4) return parseInt(document.body.clientHeight);
	if (ns4||ns6) return parseInt(window.innerHeight);
}



function CheckSizeWin() {

	if (win.w != GetWidthWin() || win.h != GetHeightWin()) {

		win.w = GetWidthWin();
		win.h = GetHeightWin();
		
		if (win.w > area_w && win.h > area_h) {
			location.reload();
		}
	}
}



function CreateLayers() {

	CreateWin();

	InitLayer.prototype.show          	= ShowLayer;
  InitLayer.prototype.hide          	= HideLayer;
  InitLayer.prototype.write         	= WriteLayer;
  InitLayer.prototype.clip          	= ClipLayer;
  InitLayer.prototype.setBgColor    	= SetBgColorLayer;
  InitLayer.prototype.setBackground 	= SetBackgroundLayer;
  InitLayer.prototype.setZIndex     	= SetZIndexLayer;
  InitLayer.prototype.setLeft       	= SetLeftLayer;
  InitLayer.prototype.setTop        	= SetTopLayer;
  InitLayer.prototype.setWidth      	= SetWidthLayer;
  InitLayer.prototype.setHeight     	= SetHeightLayer;
  InitLayer.prototype.getLeft       	= GetLeftLayer;
  InitLayer.prototype.getTop        	= GetTopLayer;
  InitLayer.prototype.getWidth      	= GetWidthLayer;
  InitLayer.prototype.getHeight     	= GetHeightLayer;
  InitLayer.prototype.moveTo        	= MoveToLayer;
  InitLayer.prototype.moveBy        	= MoveByLayer;
  InitLayer.prototype.resizeTo      	= ResizeToLayer;
  InitLayer.prototype.resizeBy      	= ResizeByLayer;
  InitLayer.prototype.adjust      		= AdjustLayer;
  InitLayer.prototype.slideTo     		= SlideToLayer;
  InitLayer.prototype.initSlider   		= InitSliderLayer;

	if (ie4) {

	 	for (var i=0; i < document.all.length; i++) {
	 		if (document.all[i].tagName=="DIV") {
		 		window[document.all[i].id] = new InitLayer(document.all[i].id);
		 	}
		}
	}

	if (ns4) {

	 	for (var i=0; i < document.layers.length; i++) {
	 		window[document.layers[i].id] = new InitLayer(document.layers[i].id);
		}
	}

	if (ns6) {

	 	for (var i=0; i < document.getElementsByTagName("DIV").length; i++) {
	 		window[document.getElementsByTagName("DIV")[i].id] = new InitLayer(document.getElementsByTagName("DIV")[i].id);
		}
	}
}



function InitLayer(id) {

 	if (ie4) this.elm = document.all[id];
 	if (ns4) this.elm = document.layers[id];
 	if (ns6) this.elm = document.getElementById(id);

	this.css = (ns4) ? this.elm : this.elm.style;

	this.x 	= parseInt(this.css.left);
	this.y 	= parseInt(this.css.top);
	this.w	= parseInt(this.css.width);
	this.h 	= parseInt(this.css.height);

  this.clipLeft 	= 0;
  this.clipTop  	= 0;
  this.clipRight 	= 0;
  this.clipBottom = 0;

	this.name 	= id;
	this.timer 	= null;
	this.obj 		= this.name + "Object";

	eval(this.obj + "=this");
}



function ShowLayer() {

	this.css.visibility = "visible";
}



function HideLayer() {

	this.css.visibility = "hidden";
}



function WriteLayer(value) {

	if (ns4) {
		with (this.elm.document) {

			open();
			write("<table width=\"" + this.w + "\" height=\"" + this.h + "\" cellspacing=\"0\" cellpadding=\"0\" border=\"0\"><tr><td>");
  		write(value);
  		write("</td></tr></table>");
  		close();
  	}
 	} else this.elm.innerHTML = value;
}



function ClipLayer(x1, y1, x2, y2) {

  if (ns4) {
    with (this.css.clip) {
      left 	 = x1;
      top 	 = y1;
      right  = x2;
      bottom = y2;
    }
  } else this.css.clip = 'rect(' + y1 + ' ' + x2 + ' ' + y2 + ' ' + x1 + ')';

  this.clipLeft 	= x1;
  this.clipTop  	= y1;
  this.clipRight 	= x2;
  this.clipBottom = y2;
}



function SetBgColorLayer(value) {

	if (ns4) this.css.bgColor = value;
	else this.css.backgroundColor = value;
}



function SetBackgroundLayer(value) {

	if (ns4) this.css.background.src = value;
	else this.css.backgroundImage = 'url('+ value +')';
}



function SetZIndexLayer(value) {

	this.css.zIndex = value;
}



function SetLeftLayer(value) {

	this.x = value;
	this.css.left = this.x;
}



function SetTopLayer(value) {

	this.y = value;
	this.css.top = this.y;
}



function SetWidthLayer(value) {

	this.w = value

	if (ns4) this.css.clip.width = this.w;
	else this.css.width = this.w;
}



function SetHeightLayer(value) {

	this.h = value

	if (ns4) this.css.clip.height = this.h;
	else this.css.height = this.h;
}



function GetLeftLayer() {

	return (this.x);
}



function GetTopLayer() {

	return (this.y);
}



function GetWidthLayer() {

	return (this.w);
}



function GetHeightLayer() {

	return (this.h);
}



function MoveToLayer(x, y) {

	this.setLeft(x);
	this.setTop(y);
}



function MoveByLayer(x, y) {

	this.setLeft(this.x + x);
	this.setTop(this.y + y);
}



function ResizeToLayer(w, h) {

	this.setWidth(w);
	this.setHeight(h);
}



function ResizeByLayer(w, h) {

	this.setWidth(this.w + w);
	this.setHeight(this.h + h);
}



function AdjustLayer(x, y) {

	if (this.x + this.w > win.w) this.setWidth(win.w - this.x - x);
	if (this.y + this.h > win.h) this.setHeight(win.h - this.y - y);
}



function SlideToLayer(x, y, speed, fn) {

	if (this.x != x) {

		if (this.x > x) (this.x - win.stepX > x) ? this.moveBy(-win.stepX, 0) : this.moveTo(x, this.y);
		else (this.x + win.stepX < x) ? this.moveBy(win.stepX, 0) : this.moveTo(x, this.y);
	}
	if (this.y != y) {

		if (this.y > y) (this.y - win.stepY > y) ? this.moveBy(0, -win.stepY) : this.moveTo(this.x, y);
		else (this.y + win.stepY < y) ? this.moveBy(0, win.stepY) : this.moveTo(this.x, y);
	}
	if ((this.x != x)||(this.y != y)) {

		if (arguments.length == 4) this.timer = setTimeout(this.obj+'.slideTo('+x+','+y+','+speed+','+fn+')',speed);
		else  this.timer = setTimeout(this.obj+'.slideTo('+x+','+y+','+speed+')',speed);
	}
	else {

		clearTimeout(this.timer);
		if (arguments.length == 4) fn();
	}
}



var SliderObj, SliderW, SliderH, SliderBarH, TimerSlider;



function InitSliderLayer(value) {

	var disH	= (this.clipBottom - this.clipTop > 32) ? this.clipBottom - this.clipTop : 32;
	var disX 	= 12;

	SliderObj = this;

  SliderUp.moveTo(this.x + this.w + disX, this.y);
	SliderUp.show();

	Slider.moveTo(this.x + this.w + disX, this.y + 16);
	Slider.resizeTo(11, 23);
	Slider.setBackground(value);
	Slider.show();

  SliderBar.moveTo(this.x + this.w + disX, this.y + 16);
  SliderBar.resizeTo(11, disH - 32);
	SliderBar.show();

  SliderDown.moveTo(this.x + this.w + disX, this.y  + disH - 16);
	SliderDown.show();

	SliderW 		= Slider.getWidth();
	SliderH 		= Slider.getHeight();
	SliderBarH	= SliderBar.getHeight();

	if (ie4) {

	  document.onmousedown 			= StartDragSlider;
	  document.onmouseup 	 			= EndDragSlider;
	  SliderUp.elm.onmouseout 	= ClearScrollSlider;
	  SliderDown.elm.onmouseout = ClearScrollSlider;
	}

  if (ns4) {

		Slider.elm.document.captureEvents(Event.MOUSEDOWN | Event.MOUSEUP);
		Slider.elm.document.onmousedown = StartDragSlider;
		Slider.elm.document.onmouseup   = EndDragSlider;

		SliderUp.elm.document.captureEvents(Event.MOUSEDOWN | Event.MOUSEUP | Event.MOUSEOUT);
		SliderUp.elm.document.onmousedown = ScrollUpSlider;
		SliderUp.elm.document.onmouseup   = ClearScrollSlider;
		SliderUp.elm.document.onmouseout  = ClearScrollSlider;

		SliderDown.elm.document.captureEvents(Event.MOUSEDOWN | Event.MOUSEUP | Event.MOUSEOUT);
		SliderDown.elm.document.onmousedown = ScrollDownSlider;
		SliderDown.elm.document.onmouseup   = ClearScrollSlider;
		SliderDown.elm.document.onmouseout  = ClearScrollSlider;
	}

	if (ns6){

		document.captureEvents(Event.MOUSEDOWN | Event.MOUSEUP);
    document.onmousedown = StartDragSlider;
	  document.onmouseup = EndDragSlider;
	}
}



function StartDragSlider(e) {

	if ((ie4) && (window.event.srcElement.id=="Slider")) {

		dy = window.event.clientY - Slider.css.pixelTop;
		document.onmousemove = DragSlider;
	}

	if ((ns4) && ((e.pageX > Slider.x) && (e.pageX < Slider.x + SliderW) &&(e.pageY > Slider.y) && (e.pageY < Slider.y + SliderH))) {

		dy = e.pageY - Slider.y;
		document.captureEvents(Event.MOUSEMOVE);
		document.onmousemove = DragSlider;
	}

	if ((ns6) && (e.target.id=="Slider")) {

		dy = e.clientY - parseInt(Slider.y);
		document.captureEvents(Event.MOUSEMOVE);
		document.onmousemove = DragSlider;
	}

	return false;
}



function DragSlider(e) {

	if (ie4) var pos  = parseInt(window.event.clientY - dy);
	if (ns4) var pos  = parseInt(e.pageY - dy);
	if (ns6) var pos =  parseInt(e.clientY - dy);

  var min  = SliderBar.y
	var max  = SliderBar.y + SliderBarH - SliderH;
	var disH = SliderObj.clipBottom - SliderObj.clipTop;
	var newY = Math.round(SliderUp.y + ((SliderBar.y - pos) * ((SliderObj.h - disH) / (max - min))));

	if ((pos >= min) && (pos <= max)) {

		Slider.moveTo(Slider.x, pos);
	  Text.moveTo(SliderObj.x, newY);
		Text.clip(0, SliderUp.y - newY, SliderObj.w, SliderDown.y + 16 - newY);
	}

	return false;
}



function EndDragSlider() {

  if (ns4) document.releaseEvents(Event.MOUSEMOVE);
  else document.onmousemove = null;

	ClearScrollSlider();
}



function ScrollSlider(pos) {

  var min  = SliderBar.y
	var max  = SliderBar.y + SliderBarH - SliderH;
	var disH = SliderObj.clipBottom - SliderObj.clipTop;
	var newY = Math.round(SliderUp.y + ((SliderBar.y - pos) * ((SliderObj.h - disH) / (max - min))));

	if ((pos >= min) && (pos <= max)) {

		Slider.moveTo(Slider.x, pos);
	  Text.moveTo(SliderObj.x, newY);
		Text.clip(0, SliderUp.y - newY, SliderObj.w, SliderDown.y + 16 - newY);
	}

	return false;
}



function ScrollUpSlider() {

	ScrollSlider(Slider.y - 1);
	TimerSlider = window.setTimeout("ScrollUpSlider()",5);
}



function ScrollDownSlider() {

	ScrollSlider(Slider.y + 1);
	TimerSlider = window.setTimeout("ScrollDownSlider()",5);
}



function ClearScrollSlider(){

	window.clearTimeout(TimerSlider);
}

