/************************************************************
Liquid (Javascript Animation)
Copyright by Dennis Loewel
www.loewel-it.de
 ************************************************************/

/************************************************************************/
/* Onload Event Loader 1.0  - Copyright by Loewel IT - www.loewel-it.de */
/** ********************************************************************* */
document.onload_array = new Array();
function AddOnload(command) {
	document.onload_array.push(command);
}
function DoOnload() {
	for ( var i = 0; i < document.onload_array.length; i++) {
		setTimeout(document.onload_array[i], 0);
	}
}

/** ******************************************************** */
/* Popup 0.70 - Copyright by Loewel IT - www.loewel-it.de */
/** ******************************************************** */
function popup(url, target, width, height) {
	window
			.open(
					url,
					target,
					'scrollbars=no,toolbar=yes,location=no,directories=no,status=no,menubar=yes,resizable=yes,width='
							+ (width + 10) + ',height=' + (height + 10));
}

/** *********************************************************************************** */
/*
 * Objekt Animation Grundfunktionen 1.31 - Copyright by Loewel IT -
 * www.loewel-it.de
 */
/** *********************************************************************************** */
/* fade */
function ELEM_opac(obj, newopac) {
	if (typeof obj == 'object'
			&& obj != null
			&& (typeof obj.fading == 'undefined'
					|| typeof obj.opac == 'undefined'
					|| (obj.fading == 'out' && obj.opac > newopac) || (obj.fading == 'in' && obj.opac < newopac))) {
		obj.opac = (newopac < 0 || newopac > 100) ? ((newopac < 0) ? 0 : 100)
				: newopac;
		// newopac = (newopac == 100) ? 99.999 : newopac;
		obj.style.filter = "alpha(opacity:" + newopac + ")";
		obj.style.KHTMLOpacity = newopac / 100;
		obj.style.MozOpacity = newopac / 100;
		obj.style.opacity = newopac / 100;
	}
}

function ELEMID_opac(id, newopac, cmd_after) {
	var obj = document.getElementById(id);
	ELEM_opac(obj, newopac);
	if (typeof cmd_after == 'string' && typeof obj == 'object' && obj != null
			&& typeof obj.target == 'number' && obj.target == obj.opac) {
		setTimeout(cmd_after, 0);
	}
}

function ELEM_fade(obj, newopac, stretch, cmd_after) {
	if (typeof obj.id != 'string' || obj.id == '') {
		obj.id = GET_newid();
	}
	if (typeof obj.opac != 'number') {
		obj.opac = 100;
	}
	if (typeof stretch != 'number') {
		stretch = 5;
	}
	var opac = obj.opac;
	var time = 0;
	obj.fading = (opac > newopac) ? 'out' : 'in';
	if (typeof cmd_after == 'string') {
		obj.target = newopac;
		while (opac != newopac) {
			time++;
			opac = (opac > newopac) ? opac - 1 : opac + 1;
			setTimeout('ELEMID_opac(\'' + obj.id + '\', ' + opac + ', "'
					+ cmd_after + '")', time * stretch);
		}
	} else {
		while (opac != newopac) {
			time++;
			opac = (opac > newopac) ? opac - 1 : opac + 1;
			setTimeout('ELEMID_opac(\'' + obj.id + '\', ' + opac + ')', time
					* stretch);
		}
	}
}
function ELEMID_fade(id, newopac, stretch, cmd_after) {
	var obj = document.getElementById(id);
	if (typeof obj == 'object' && obj != null) {
		ELEM_fade(obj, newopac, stretch, cmd_after);
	}
}

function ELEM_insertfade(obj, newchild, cmd_after) {
	ELEM_opac(newchild, 0);
	obj.appendChild(newchild);
	if (typeof cmd_after == 'string') {
		ELEM_fade(newchild, 100, 5, cmd_after);
	} else {
		ELEM_fade(newchild, 100);
	}
}

/* Misc */
function GET_newid() {
	x = 'rand_1';
	while (document.getElementById(x)) {
		x = 'rand_' + Math.floor(Math.random() * 100000 + 1);
	}
	return x;
}

function ELEM_pos(obj, x, y) {
	if (typeof obj == 'object' && obj != null) {
		obj.style.left = x + 'px';
		obj.style.top = y + 'px';
	}
}
function ELEMID_pos(id, x, y) {
	var obj = document.getElementById(id);
	ELEM_pos(obj, x, y);
}

function ELEM_display(obj, style) {
	if (typeof obj == 'object' && obj != null) {
		obj.style.display = style;
	}
}
function ELEMID_display(id, style) {
	var obj = document.getElementById(id);
	ELEM_display(obj, style);
}

function PAGE_jump(href) {
	location = href;
}
/* ####################################### */

/** ************************************************************************ */
/* Grafik Menu 1.23 (3-States) - Copyright by Loewel IT - www.loewel-it.de */
/** ************************************************************************ */
function IMGMenu_init(menu_id, path, aktive_href, aktive_fullhref) {
	var objs = document.getElementById(menu_id).getElementsByTagName("a");

	for ( var i = 0; i < objs.length; i++) {
		objs[i].removeChild(objs[i].firstChild);

		if ((typeof aktive_href == 'string' && aktive_href == objs[i].name)
				|| (typeof aktive_fullhref == 'string' && aktive_fullhref == objs[i].name)) {
			var img = document.createElement("img");
			img.src = path + '/aktiv/' + objs[i].name + '.png';
			objs[i].appendChild(img);
		}

		else {
			var sub_img = document.createElement("img");
			var top_img = document.createElement("img");

			sub_img.src = path + '/hover/' + objs[i].name + '.png';
			top_img.src = path + '/normal/' + objs[i].name + '.png';

			top_img.name = objs[i].name;

			top_img.onmouseover = function() {
				ELEM_fade(this, 0, 2);
			};
			top_img.onmouseout = function() {
				ELEM_fade(this, 100, 2);
			};

			objs[i].appendChild(sub_img);
			objs[i].appendChild(top_img);
		}
	}
}

/** *********************************************************************** */
/* Slideshow Animation v.2.06 - Copyright by Loewel IT - www.loewel-it.de */
/** *********************************************************************** */
var SLIDE_box, SLIDE_path, SLIDE_images, SLIDE_pos = 0, SLIDE_stretch = 10, SLIDE_timeout = 8000;
function SLIDE_init(id, path, imgarray, stretch, timeout) {
	SLIDE_box = document.getElementById(id);
	SLIDE_path = path;
	SLIDE_images = imgarray;
	if (typeof stretch == 'number') {
		SLIDE_stretch = stretch;
	}
	if (typeof timeout == 'number') {
		SLIDE_timeout = timeout;
	}
	SLIDE_switch();
}

function SLIDE_switch() {
	var aktimg = SLIDE_box.getElementsByTagName("img");
	if (aktimg.length > 1) {
		if (typeof aktimg[0].id != 'string' || aktimg[0].id == '') {
			aktimg[0].id = GET_newid();
		}
		ELEM_fade(aktimg[1], 100, SLIDE_stretch,
				'SLIDE_removeold(\'' + aktimg[0].id + '\')');
	} else if (SLIDE_images.length > 1) {
		if (SLIDE_pos < SLIDE_images.length - 1) {
			SLIDE_pos++;
		} else {
			SLIDE_pos = 0;
		}
		var newimg = document.createElement("img");
		newimg.onload = function() {
			ELEM_opac(newimg, 0);
			SLIDE_box.appendChild(newimg);
			setTimeout('SLIDE_switch()', SLIDE_timeout);
		}
		newimg.src = SLIDE_path + SLIDE_images[SLIDE_pos];
	}
}

function SLIDE_removeold(id) {
	SLIDE_box.removeChild(document.getElementById(id));
	SLIDE_switch();
}

/* ##################################### */

/** *************************************************************************** */
/* Referenz Animation v.1.13 lite - Copyright by Loewel IT - www.loewel-it.de */
/** *************************************************************************** */
var REF_box, REF_run = false;
function REF_switch(src) {
	if (!REF_run || REF_box.getElementsByTagName("img").length == 0) {
		REF_run = true;
		oldimg = REF_box.getElementsByTagName("img");
		if (oldimg.length) {
			if (typeof oldimg[oldimg.length - 1].id != 'string'
					|| oldimg[oldimg.length - 1].id == '') {
				oldimg[oldimg.length - 1].id = GET_newid();
			}
			ELEM_fade(oldimg[oldimg.length - 1], 0, 10,
					'REF_removeold(\'' + oldimg[oldimg.length - 1].id + '\')');
		}

		var newimg = document.createElement("img");
		newimg.onload = function() {
			ELEM_opac(newimg, 0);
			REF_box.appendChild(newimg);
			ELEM_fade(newimg, 100);
			REF_run = false;
		}
		newimg.src = src;
	}
}

function REF_removeold(id) {
	var obj = document.getElementById(id);
	if (typeof obj == 'object') {
		REF_box.removeChild(obj);
	}
}

/* ##################################### */

/** ************************************************************** */
/* Unterschiedliches - Copyright by Loewel IT - www.loewel-it.de */
/** ************************************************************** */
var hbox, hlink;
function Hoverbox(hboxid, hlinkid) {
	hbox = document.getElementById(hboxid);
	hlink = document.getElementById(hlinkid);

	hlink.onmouseover = function() {
		ELEM_fade(hlink, 80, 8);
		if (typeof hbox.opac != 'number') {
			ELEM_opac(hbox, 0);
		}
		hbox.style.display = 'block';
		ELEM_fade(hbox, 100, 4);
	}
	hlink.onmouseout = function() {
		ELEM_fade(hbox, 0, 4, "ELEMID_display('" + hbox.id + "', 'none')");
		ELEM_fade(hlink, 100, 8);
	}

}

/* Referenz Special System */
var sref = null;
function sref_init(id, max_x, max_y, path_thumb, path_full) {
	sref = document.getElementById(id);
	if (typeof sref == 'object' && sref != null) {
		sref.max_x = max_x;
		sref.max_y = max_y;
		sref.path_thumb = path_thumb;
		sref.path_full = path_full;
	}
}

function sref_add(src, pos_x, pos_y, target) {
	var thumbimg = document.createElement("img");
	thumbimg.onload = function() {
		ELEM_opac(thumbimg, 0);
		ELEM_pos(thumbimg, pos_x, pos_y);
		thumbimg.onmouseover = function() {
			ELEM_fade(thumbimg, 60);
		}
		thumbimg.onmouseout = function() {
			ELEM_fade(thumbimg, 100);
		}
		thumbimg.title = 'Details ansehen';
		if (typeof target != 'undefined' && target != '') {
			thumbimg.target = 'http://' + target;
		}
		thumbimg.onclick = function() {
			ELEM_opac(thumbimg, 0);
			var fullimg = document.createElement("img");
			fullimg.onload = function() {
				ELEM_opac(fullimg, 0);
				fullimg.style.border = "solid #00879b 1px";
				if ((pos_x + fullimg.width + 2) > sref.max_x) {
					pos_x = sref.max_x - fullimg.width - 2;
				}
				if ((pos_y + fullimg.height + 2) > sref.max_y) {
					pos_y = sref.max_y - fullimg.height - 2;
				}
				ELEM_pos(fullimg, pos_x, pos_y);
				sref.appendChild(fullimg);
				
//				captionwrap = document.createElement("div");
//				captionwrap.style.position = "absolute";
//				captionwrap.style.width = fullimg.width+"px";
//				captionwrap.style.backgroundColor = "#00879B";
//				captionwrap.style.border = "solid #393939 1px";
//				captionwrap.style.textAlign = "center";
//				captionwrap.style.fontSize = "12px";
//				captionwrap.style.fontWeight = "bold";
//				captionwrap.style.lineHeight = "15px"
//				captionwrap.style.color = "#ffffff";
				
				
//				ELEM_pos(captionwrap, pos_x, pos_y + fullimg.height + 2);
//				caption = document.createTextNode('Bitte auf das Bild klicken, um die Seite zu besuchen');
//				captionwrap.appendChild(caption);
//				sref.appendChild(captionwrap);
				
				ELEM_fade(fullimg, 100);
				fullimg.onmouseout = function() {
//					sref.removeChild(captionwrap);
					sref.removeChild(fullimg);
				}
				fullimg.onclick = function() {
					if (typeof thumbimg.target != 'undefined'
							&& thumbimg.target != null) {
						window.open(thumbimg.target, "_blank", "");
					} else {
						sref.removeChild(fullimg);
					}
				}
			}
			fullimg.src = sref.path_full + src;
		}
		sref.appendChild(thumbimg);
		ELEM_fade(thumbimg, 100);
	}
	thumbimg.onerror = function() {
		sref_add(src, pos_x, pos_y, target);
	}
	thumbimg.src = sref.path_thumb + src;
}
