var isNS4 = (document.layers) ? true : false;
var isIE4 = (document.all && !document.getElementById) ? true : false;
var isIE5 = (document.all && document.getElementById) ? true : false;
var isNS6 = (!document.all && document.getElementById) ? true : false;

var fake_height; // Sichtbare Hoehe des Browsers
var fake_width;	// Sichtbare Breite des Browsers
var top_position = 0; // X Koordinate des Bildes
var left_start_position = 0; // Y Koordinate des Bildes beim START
var img_height = 0; // Hoehe des Bildes
var img_width = 0; // Breite des Bildes
var img_width_sichtbar = 0; // Breite des Bildes
var startbild_top_position = 0; // Start Bild Y Koordinate
var startbild_left_position = 0; // Start Bild X Koordinate
var scroll_top_position = 0; // Scroll Bild Koordinate
var scroll_bottom_position = 0; // Scroll Bild Koordinate
var scroll_left_position = 0; // Scroll Bild Koordinate
var scroll_right_position = 0; // Scroll Bild Koordinate
var scrollbild_left_position = 0; // Scroll Bild Koordinate
var img_width_einzeln = 0; // halbes Scrollbild
var right_postion = 0;
var curr_left_position = 0;
var left_button_width = 0;
var left_button_height = 0;
var right_button_width = 0;
var right_button_height = 0;
var left_button_left = 0;
var left_button_top = 0;
var right_button_left = 0;
var right_button_top = 0;
var scroll_timer;

function groesse_fake() {
	/* Berechnung sichtbares Browser Fenster */
	if (isNS4) {
		fake_height = document.groesse_fake_div.clip.height;
		fake_width = document.groesse_fake_div.clip.width;
		img_width = document.scrollbild.clip.width;
		left_button_width = document.buttonlinks.clip.width;
		left_button_height = document.buttonlinks.clip.height;
		right_button_width = document.buttonrechts.clip.width;
		right_button_height = document.buttonrechts.clip.height;
	}
	else if (isIE4) {
		fake_height = document.all["groesse_fake_div"].offsetHeight;
		fake_width = document.all["groesse_fake_div"].offsetWidth;
		img_width = document.all["scrollbild"].offsetWidth;
		left_button_width = document.all["buttonlinks"].offsetWidth;
		left_button_height = document.all["buttonlinks"].offsetHeight;
		right_button_width = document.all["buttonrechts"].offsetWidth;
		right_button_height = document.all["buttonrechts"].offsetHeight;
	} else {
		fake_height = document.getElementById("groesse_fake_div").offsetHeight;
		fake_width = document.getElementById("groesse_fake_div").offsetWidth;
		img_width = document.getElementById("scrollbild").offsetWidth;
		left_button_width = document.getElementById("buttonlinks").offsetWidth;
		left_button_height = document.getElementById("buttonlinks").offsetHeight;
		right_button_width = document.getElementById("buttonrechts").offsetWidth;
		right_button_height = document.getElementById("buttonrechts").offsetHeight;
	}
	
	img_width_sichtbar = fake_width;
	img_height = fake_height;
	
	/* Berechnung Start Positionen */
	top_position = 0;
	left_start_position = 0;
	curr_left_position = 0;
	
	/* Setzen Start Positionen */
	if (isNS4) {
		document.layers["scrollbild"].left = startbild_left_position;
		document.layers["scrollbild"].top = top_position;
		document.layers["scrollbild"].visibility = 'visible';
	} else if (isIE4) {
		document.all["scrollbild"].style.pixelLeft = startbild_left_position;
		document.all["scrollbild"].style.pixelTop = top_position;
		document.all["scrollbild"].style.visibility = 'visible';
	} else if (isNS6) {
		document.getElementById("scrollbild").style.left = startbild_left_position;
		document.getElementById("scrollbild").style.top = top_position;
		document.getElementById("scrollbild").style.visibility = 'visible';
	} else {
		document.getElementById("scrollbild").style.pixelLeft = startbild_left_position;
		document.getElementById("scrollbild").style.pixelTop = top_position;
		document.getElementById("scrollbild").style.visibility = 'visible';
	}
	
	/* Berechnen der Button Positions */
	left_button_left = 0;
	left_button_top = 0;//(fake_height - left_button_height) / 2;
	right_button_left = fake_width - right_button_width;
	right_button_top = 0;//(fake_height - right_button_height) / 2;
	
	/* Beginn Scrollen */
	img_width_einzeln = img_width;
	scroll_top_position = 0;
	scroll_bottom_position = img_height;
	
	if (img_width >= (fake_width - 30)) {
		/* Setzen der Button Positions */
		if (isNS4) {
			document.layers["buttonlinks"].left = left_button_left;
			document.layers["buttonlinks"].top = left_button_top;
			document.layers["buttonlinks"].visibility = 'visible';
			document.layers["buttonrechts"].left = right_button_left;
			document.layers["buttonrechts"].top = right_button_top;
			document.layers["buttonrechts"].visibility = 'visible';
		} else if (isIE4) {
			document.all["buttonlinks"].style.pixelLeft = left_button_left;
			document.all["buttonlinks"].style.pixelTop = left_button_top;
			document.all["buttonlinks"].style.visibility = 'visible';
			document.all["buttonrechts"].style.pixelLeft = right_button_left;
			document.all["buttonrechts"].style.pixelTop = right_button_top;
			document.all["buttonrechts"].style.visibility = 'visible';
		} else if (isNS6) {
			document.getElementById("buttonlinks").style.left = left_button_left;
			document.getElementById("buttonlinks").style.top = left_button_top;
			document.getElementById("buttonlinks").style.visibility = 'visible';
			document.getElementById("buttonrechts").style.left = right_button_left;
			document.getElementById("buttonrechts").style.top = right_button_top;
			document.getElementById("buttonrechts").style.visibility = 'visible';
		} else {
			document.getElementById("buttonlinks").style.pixelLeft = left_button_left;
			document.getElementById("buttonlinks").style.pixelTop = left_button_top;
			document.getElementById("buttonlinks").style.visibility = 'visible';
			document.getElementById("buttonrechts").style.pixelLeft = right_button_left;
			document.getElementById("buttonrechts").style.pixelTop = right_button_top;
			document.getElementById("buttonrechts").style.visibility = 'visible';
		}
	} else {
		var image_left_without_scroll = (fake_width - img_width) / 2;
		if (isNS4) {
			document.layers["scrollbild"].left = image_left_without_scroll;
		} else if (isIE4) {
			document.all["scrollbild"].style.pixelLeft = image_left_without_scroll;
		} else if (isNS6) {
			document.getElementById("scrollbild").style.left = image_left_without_scroll;
		} else {
			document.getElementById("scrollbild").style.pixelLeft = image_left_without_scroll;
		}			
	}
}

function imagescroll(richtung) {
	left_position = curr_left_position;
	right_postion = left_position + img_width_einzeln;
	
	/* Berechnung der ScrollBild Koordinaten für das aktuelle Clipping */
	scroll_left_position = left_position;
	scroll_right_position = img_width_sichtbar + left_position;
	scrollbild_left_position = - left_position + left_start_position;
	
	/* Setzen nächster Leftwert */
	ScrollWeiter = true;	
	if (richtung <= 0) {
		// links
		left_position = (left_position + 3);
		if (left_position >= (img_width_einzeln - img_width_sichtbar + 21)) ScrollWeiter=false;
	} else {
		// rechts
		left_position = (left_position - 3);
		if (left_position <=  -21) ScrollWeiter=false;
	}

	if (ScrollWeiter) {	
		/* Setzen des Clippings */
		if (isNS4) {
			document.layers["scrollbild"].clip.top = scroll_top_position;
			document.layers["scrollbild"].clip.bottom = scroll_bottom_position;
			document.layers["scrollbild"].clip.left = scroll_left_position;
			document.layers["scrollbild"].clip.right = scroll_right_position;
			document.layers["scrollbild"].left = scrollbild_left_position;
		} else if (isIE4) {
			document.all["scrollbild"].style.clip = "rect(" + scroll_top_position + "px " + scroll_right_position + "px " + scroll_bottom_position + "px " + scroll_left_position + "px)";
			document.all["scrollbild"].style.left = scrollbild_left_position;
		} else {
			document.getElementById("scrollbild").style.clip = "rect(" + scroll_top_position + "px " + scroll_right_position + "px " + scroll_bottom_position + "px " + scroll_left_position + "px)";
			document.getElementById("scrollbild").style.left = scrollbild_left_position;
		}
	
	curr_left_position = left_position;
	scroll_timer = setTimeout("imagescroll(" + richtung + ")", 10);
	}
}

function NeueRichtung(richtung) {
	if (scroll_timer) clearTimeout(scroll_timer);
	imagescroll(richtung);
}

function StopScroll() {
	if (scroll_timer) clearTimeout(scroll_timer);
}

elem=null
function markieren (obj) {
	if (obj.createTextRange) 
	obj.caretPos = document.selection.createRange().duplicate();
	elem=obj
}
function einfuegenSingle (ptext) {
	if(elem!=null) {
		if(document.selection.createRange().text=="") {
			if (elem.createTextRange && elem.caretPos) {
				var caretPos = elem.caretPos;
				caretPos.text = caretPos.text + "<"+ptext+">";
			} else {
				elem.value = "<"+ptext+">";
			}
		} else {
			if (elem.createTextRange && elem.caretPos) {
				var caretPos = elem.caretPos;
				caretPos.text = caretPos.text + "<"+ptext+">";
			}
		}
	}
}
function einfuegenDouble (ptext,etext) {
	if(elem!=null) {
		if(document.selection.createRange().text=="") {
			if (elem.createTextRange && elem.caretPos) {
				var caretPos = elem.caretPos;
				caretPos.text ="<"+ptext+">" + caretPos.text + "</"+etext+">";
			} else {
				elem.value = "<"+ptext+"></"+etext+">";
			}
		} else {
			if (elem.createTextRange && elem.caretPos) {
				var caretPos = elem.caretPos;
				caretPos.text = "<"+ptext+">" + caretPos.text + "</"+etext+">";
			}
		}
	}
}
function einfuegen (ptext) {
	if(elem!=null) {
		if(document.selection.createRange().text=="") {
			if (elem.createTextRange && elem.caretPos) {
				var caretPos = elem.caretPos;
				caretPos.text ="<"+ptext+">" + caretPos.text + "</"+ptext+">";
			} else {
				elem.value = "<"+ptext+"></"+ptext+">";
			}
		} else {
			if (elem.createTextRange && elem.caretPos) {
				var caretPos = elem.caretPos;
				caretPos.text = "<"+ptext+">" + caretPos.text + "</"+ptext+">";
			}
		}
	}
}
// Alle Typen der Formatierung
function setBreak() {
	einfuegenSingle("br");
}
function setBold() {
	einfuegen("b");
}
function setItalic() {
	einfuegen("i");
}
function setBigger() {
	einfuegenDouble("font size='+1'","font");
}
function setSmaller() {
	einfuegenDouble("font size='-1'","font");
}
function setWhite() {
	einfuegenDouble("font color='DDDDDD'","font");
}
function setOrange() {
	einfuegenDouble("font color='FF7F00'","font");
}

