
// User-Agent-String auslesen
var UserAgent = navigator.userAgent.toLowerCase();
var scrollV;
// User-Agent auf gewisse Schlüsselwörter prüfen
if(UserAgent.search(/(iphone|ipod|ipad|opera mini|fennec|palm|blackberry|android|symbian|series60)/)>-1){
  // mobiles Endgerät
  var touchdevice = 1;
}else{
  var touchdevice = 0;
}


// css für mac
if(navigator.userAgent.indexOf("Mac") != -1 ){
document.write('<style type="text/css"><!-- body {font-family: Courier;font-size: 14px;line-height: 16px;} --></style>');
}
	

//window.onresize=startInit;
function startInit(){
	
	window.resizeTo(screen.availWidth,screen.availHeight);
	window.moveTo(0,0);
	
	if ( (navigator.userAgent.indexOf("Mac") != -1 )&& ( navigator.appName.indexOf("Explorer") != -1 )){
		window.location = 'macie5.html';
	}
	myScrollWin0 = new ScrollObj(5,82,502,"track0","up0","down0","drag0","winBox0","winCont0");
}

// Index nachladen 
function home() {
  if(!parent.fenster1)
   document.write('<a href="http://www.dns-transport.ch" target="_self">Startseite</a><br>');
}

function schliessen(anzahl){
	var blank = 'blank.html';
	if(!anzahl) { anzahl = activewin; blank = '../blank.html';}
	var a = new Array('fenster1','fenster2','fenster3a','fenster3b','fenster4','fenster5');
	if (anzahl==2) { var a = new Array('fenster2','fenster3a','fenster3b','fenster4','fenster5'); fenster3b.location = blank; //fenster5.location = 'blank.html'; 	
	}
	if (anzahl==3) { var a = new Array('fenster3a','fenster3b');  fenster3b.location = blank; 
	}
	if (anzahl==4) { var a = new Array('fenster3a','fenster3b','fenster4','fenster5'); }
	if (anzahl==5) { var a = new Array('fenster5'); }
	
	document.getElementById("scrollbar3b").style.visibility = 'hidden';
	y = a.length;
	for (var i = 0; i < y; ++i){
		var win = a[i];
		var e = document.getElementById(win);
		if(e){ 	e.style.visibility = 'hidden'; 
		}
	}
	activewin -=1;
	if(anzahl == 3) { activewin -= 1; }
	anzahl = '';
}
var activewin= '';
function openWin1(seite,hoehe){
	schliessen();
	fenster1.location = seite;
	document.getElementById("fenster1").style.visibility = 'visible';
	document.getElementById("winCont1").style.top = "0px";
	document.getElementById("drag1").style.top = "0px";
	document.getElementById("winCont1").style.height = hoehe + 'px';
	myScrollWin1 = new ScrollObj(5,82,502,"track1","up1","down1","drag1","winBox1","winCont1");
	activewin = 1;
}
function openWin2(seite,hoehe){
	schliessen(3);
	fenster2.location = seite;
	document.getElementById("fenster2").style.visibility = 'visible';
	document.getElementById("winCont2").style.top = "0px";
	document.getElementById("drag2").style.top = "0px";
	document.getElementById("winCont2").style.height = hoehe + 'px';
	myScrollWin2 = new ScrollObj(5,82,502,"track2","up2","down2","drag2","winBox2","winCont2");
	activewin = 2;
}
function openWin3(seite,hoehe){
	schliessen(4);
	document.getElementById("winCont3b").style.top = "0px";
	document.getElementById("drag3b").style.top = "0px";
	document.getElementById("winCont3a").style.top = "0px";
	document.getElementById("drag3a").style.top = "15px";
	var p = seite.lastIndexOf(".");
	var teil = seite.substring(0, p);
	var seiteb = teil + 'b.html';
	fenster3a.location = seite;
	fenster3b.location = seiteb;
	document.getElementById("fenster3a").style.visibility = 'visible';	
	document.getElementById("fenster3b").style.visibility = 'visible';	
	document.getElementById("scrollbar3b").style.visibility = 'hidden';
	document.getElementById("winBox3b").style.overflow = 'hidden';
	document.getElementById("winCont3a").style.height = hoehe + 'px';
	myScrollWin3a = new ScrollObj(5,82,235,"track3a","up3a","down3a","drag3a","winBox3a","winCont3a");
	activewin = 3;
	}
function openWin4(seite,hoehe){
	schliessen(4);	
	fenster4.location = seite;
	document.getElementById("fenster4").style.visibility = 'visible';
	document.getElementById("winCont4").style.top = "0px";
	document.getElementById("drag4").style.top = "0px";
	document.getElementById("winCont4").style.height = hoehe + 'px';
	myScrollWin4 = new ScrollObj(5,82,502,"track4","up4","down4","drag4","winBox4","winCont4");	
	activewin = 4;
}
function openWin5(seite){
	schliessen(5);
	fenster5.location = seite;
	document.getElementById("fenster5").style.visibility = 'visible';
	 activewin = 5;
}
function scrolltotop(){
	if(activewin == 1){
	document.getElementById("drag1").style.top = "0px";
	document.getElementById("winCont1").style.top = "0px";
	}
	if(activewin == 2){
	document.getElementById("drag2").style.top = "0px";
	document.getElementById("winCont2").style.top = "0px";
	}
	if(activewin == 3){
		document.getElementById("drag3a").style.top = "15px";
	document.getElementById("winCont3a").style.top = "0px";
	}
	if(activewin == 4){
		document.getElementById("drag4").style.top = "0px";
	document.getElementById("winCont4").style.top = "0px";
	}
	if(activewin == 5){
		document.getElementById("drag5").style.top = "0px";
	document.getElementById("winCont5").style.top = "0px";
	}
}
// ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// 
// Coded by Travis Beckham
// http://www.squidfingers.com | http://www.podlob.com
// If want to use this code, feel free to do so, but please leave this message intact.
//
// ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// --- version date: 01/24/03 ---------------------------------------------------------

// ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// Cross-Browser Functions

var dom = document.getElementById;
var iex = document.all;
var ns4 = document.layers;

function addEvent(event,method){
	this[event] = method;
	if(ns4) this.captureEvents(Event[event.substr(2,event.length).toUpperCase()]);
	
}
function removeEvent(event){
	this[event] = null;
	if(ns4) this.releaseEvents(Event[event.substr(2,event.length).toUpperCase()]);
}
function getElement(name,nest){
	nest = nest ? "document."+nest+"." : "";
	var el = dom ? document.getElementById(name) : iex ? document.all[name] : ns4 ? eval(nest+"document."+name) : false;
	el.css = ns4 ? el : el.style;
	el.getTop = function(){return parseInt(el.css.top) || 0};
	el.setTop = function(y){el.css.top = ns4 ? y: y+"px"};
	el.getHeight = function(){return ns4 ? el.document.height : el.offsetHeight};
	el.getClipHeight = function(){return ns4 ? el.clip.height : el.offsetHeight};
	el.hideVis = function(){el.css.visibility="hidden"};
	el.addEvent = addEvent;
	el.removeEvent = removeEvent;
	
	return el;
}
function getYMouse(e){
	return iex ? event.clientY : e.pageY;
}

document.addEvent = addEvent;
document.removeEvent = removeEvent;

// ||||||||||||||||||||||||||||||||||||||||||||||||||
// Scroller Class

ScrollObj = function(speed, dragHeight, trackHeight, trackObj, upObj, downObj, dragObj, contentMaskObj, contentObj){
	this.speed = speed;
	this.dragHeight = dragHeight;
	this.trackHeight = trackHeight;
	this.trackObj = getElement(trackObj);
	this.upObj = getElement(upObj);
	this.downObj = getElement(downObj);
	this.dragObj = getElement(dragObj);
	this.contentMaskObj = getElement(contentMaskObj);
	this.contentObj = getElement(contentObj,contentMaskObj);
	this.obj = contentObj+"Object";
	eval(this.obj+"=this");
	
	this.trackTop = this.dragObj.getTop();
	this.trackLength = this.trackHeight-this.dragHeight;
	this.trackBottom = this.trackTop+this.trackLength;
	this.contentMaskHeight = this.contentMaskObj.getClipHeight();
	this.contentHeight = this.contentObj.getHeight();
	this.contentLength = this.contentHeight-this.contentMaskHeight;
	this.scrollLength = this.trackLength/this.contentLength;
	this.scrollTimer = null;
	
	
	if(this.contentHeight <= this.contentMaskHeight){
		this.dragObj.hideVis();
	}else{
		var self = this;
		this.trackObj.addEvent("onmousedown", function(e){self.scrollJump(e);return false});
		this.upObj.addEvent("onmouseout", function(){self.stopScroll()});
		
		
		
		if(touchdevice == 0){		
			this.downObj.addEvent("onmousedown", function(){self.scroll(-self.speed);return false});			
			this.upObj.addEvent("onmousedown", function(){self.scroll(self.speed);return false});
			this.upObj.addEvent("onmouseup", function(){self.stopScroll()});		
			this.downObj.addEvent("onmouseup", function(){self.stopScroll()});
			
		}else{
			this.downObj.addEvent("onclick", function(){self.scroll(-self.speed*20);return false});			
			this.upObj.addEvent("onclick", function(){self.scroll(self.speed*20);return false});
		}
		
		
		this.downObj.addEvent("onmouseout", function(){self.stopScroll()});
		this.dragObj.addEvent("onmousedown", function(e){self.startDrag(e);return false});
		if(iex) this.dragObj.addEvent("ondragstart", function(){return false});
	}
}
ScrollObj.prototype.startDrag = function(e){
	this.dragStartMouse = getYMouse(e);
	this.dragStartOffset = this.dragObj.getTop();
	var self = this;
	document.addEvent("onmousemove", function(e){self.drag(e)});
	document.addEvent("onmouseup", function(){self.stopDrag()});
}
ScrollObj.prototype.stopDrag = function(){
	document.removeEvent("onmousemove");
	document.removeEvent("onmouseup");
}
ScrollObj.prototype.drag = function(e){
	var currentMouse = getYMouse(e);
	var mouseDifference = currentMouse-this.dragStartMouse;
	var dragDistance = this.dragStartOffset+mouseDifference;
	var dragMovement = (dragDistance<this.trackTop) ? this.trackTop : (dragDistance>this.trackBottom) ? this.trackBottom : dragDistance;
	this.dragObj.setTop(dragMovement);
	var contentMovement = -(dragMovement-this.trackTop)*(1/this.scrollLength);
	this.contentObj.setTop(contentMovement);
}
ScrollObj.prototype.scroll = function(speed){
	var contentMovement = this.contentObj.getTop()+speed;
	var dragMovement = this.trackTop-Math.round(this.contentObj.getTop()*(this.trackLength/this.contentLength));
	if(contentMovement > 0){
		contentMovement = 0;
	}else if(contentMovement < -this.contentLength){
		contentMovement = -this.contentLength;
	}
	if(dragMovement < this.trackTop){
		dragMovement = this.trackTop;
	}else if(dragMovement > this.trackBottom){
		dragMovement = this.trackBottom;
	}
	this.contentObj.setTop(contentMovement);
	this.dragObj.setTop(dragMovement);
	
	if(touchdevice == 0){		
		this.scrollTimer = window.setTimeout(this.obj+".scroll("+ speed +")",25);		
	}
}
ScrollObj.prototype.stopScroll = function(){
	if(this.scrollTimer){
		window.clearTimeout(this.scrollTimer);
		this.scrollTimer = null;
	}
}
ScrollObj.prototype.scrollJump = function(e){
	var currentMouse = getYMouse(e);
	var dragDistance = currentMouse-(this.dragHeight/2);
	var dragMovement = (dragDistance<this.trackTop) ? this.trackTop : (dragDistance>this.trackBottom) ? this.trackBottom : dragDistance;
	//this.dragObj.setTop(dragMovement);
	var contentMovement = -(dragMovement-this.trackTop)*(1/this.scrollLength);
	//this.contentObj.setTop(contentMovement);
}

// ||||||||||||||||||||||||||||||||||||||||||||||||||
// Misc Functions

function fixNetscape4(){
	if(ns4origWidth != window.innerWidth || ns4origHeight != window.innerHeight){
		window.location.reload();
	}	
}
if(document.layers){
	ns4origWidth = window.innerWidth;
	ns4origHeight = window.innerHeight;
	window.onresize = fixNetscape4;
}

