
// init loader
var loader = new Loader();
var initpopup;
loader.setScriptPath("/static/js/");
loader.addFile("lib/prototype.js");

loader.addFile("src/scriptaculous.js");
loader.addFile("src/effects.js");
loader.addFile("lightbox.js");

loader.addFile("lib/animator.js");
loader.addFile("lib/swfobject.js");
loader.addClass("at.elements.textreplace.image");

loader.addClass("com.lohberger.slider.slider");
loader.addClass("com.lohberger.slider.portal");
loader.addClass("com.lohberger.navigation.hover");
loader.addClass("com.lohberger.dropdowns.dropDown");

loader.load();

function onDocumentLoad () {

	if ($('portalmenu')  != null) {
		new com.lohberger.slider.slider($('portalmenu'));
	}

	if ($('portal')  != null) {
		new com.lohberger.slider.portal($('portal'));
	}
	if ($('menu')  != null) {
		new com.lohberger.navigation.hover([ $$('#menu ul li'), $$('#menu ul li ul li') ]);
	}
	if($('languages') != null) {
		new com.lohberger.dropdowns.dropDown($('languages'));
	}

	var imageReplacer = new at.elements.textreplace.image("/cache/headlines/",{appendFilename: true});

	/**
	 * Portal Side
	 */
	imageReplacer.add({
		elements: $$('#portalmenu span.img, #portal span.img'),
		options: {
		font: 'TheSans-B7Bold.ttf',
		width: '255',
		height: '',
		color: '7a0000',
		size: '17',
		positionx: 0,
		positiony: 18,
		replaceElement: {
			tagName: "span",
			className: "h1"
		},
		modifyValue : function (vari)
		{
			return vari.toUpperCase();
		}
	}});
	/**
	 * Slogan
	 */
	imageReplacer.add({
		elements: $$('#header p.slogan'),
		options: {
		font: 'TheSans-B7Bold.ttf',
		width: '237',
		height: '',
		color: 'ffffff',
		size: '14',
		positionx: 0,
		positiony: 16,
		replaceElement: {
			tagName: "p",
			className: "img"
		}
	}});
	/**
	 * Men�punkte aktiv und normal
	 */
	imageReplacer.add({
		elements: $$('#menu ul li.active a span.img'),
		options: {
		font: 'TheSans-B9Black.ttf',
		width: '',
		height: '14',
		color: 'd3001b',
		size: '11',
		positionx: 0,
		positiony: 13,
		replaceElement: {
			tagName: "font",
			className: "img"
		},
		modifyValue : function (vari) {
			return vari.toUpperCase();
		}
	}});

	imageReplacer.add({
		elements: $$('#menu ul li a span.img'),
		options: {
		font: 'TheSans-B6SemiBold.ttf',
		width: '',
		height: '14',
		color: 'ffffff',
		size: '10',
		positionx: 0,
		positiony: 13,
		replaceElement: {
			tagName: "font",
			className: "img"
		},
		modifyValue : function (vari) {
			return vari.toUpperCase();
		}
	}});

	/**
	 * Linkes Men�
	 */
	imageReplacer.add({
		elements: $$('#leftmenu ul li a span.imgactive'),
		options: {
		font: 'TheSans-B6SemiBold.ttf',
		width: '165',
		height: '',
		color: '636563',
		size: '11',
		positionx: 0,
		positiony: 14,
		replaceElement: {
			tagName: "span",
			className: "imgactive"
		},
		modifyValue : function (vari) {
			return vari.toUpperCase();
		}
	}});
	imageReplacer.add({
		elements: $$('#leftmenu ul li a span.img'),
		options: {
		font: 'TheSans-B6SemiBold.ttf',
		width: '165',
		height: '',
		color: 'c50a1d',
		size: '11',
		positionx: 0,
		positiony: 14,
		replaceElement: {
			tagName: "span",
			className: "img"
		},
		modifyValue : function (vari) {
			return vari.toUpperCase();
		}
	}});
	imageReplacer.add({
		elements: $$('#leftmenu ul.area li a span.imgarea'),
		options: {
		font: 'TheSans-B6SemiBold.ttf',
		width: '165',
		height: '',
		color: '5a5a5a',
		size: '11',
		positionx: 0,
		positiony: 14,
		replaceElement: {
			tagName: "span",
			className: "imgarea"
		},
		modifyValue : function (vari) {
			return vari.toUpperCase();
		}
	}});
	/**
	 * Content Bereich
	 */
	imageReplacer.add({
		elements: $$('#content h2.img'),
		options: {
		font: 'TheSans-B7Bold.ttf',
		width: '700',
		height: '',
		color: '5a5a5a',
		size: '12',
		positionx: 0,
		positiony: 12,
		replaceElement: {
			tagName: "h2",
			className: "imgdone"
		}
	}});
	imageReplacer.add({
		elements: $$('#content h2.entry'),
		options: {
		font: 'TheSans-B6SemiBold.ttf',
		width: '250',
		height: '',
		color: '5a5a5a',
		size: '13',
		positionx: 0,
		positiony: 13,
		replaceElement: {
			tagName: "span",
			className: "h2"
		},
		modifyValue : function (vari) {
			return vari.toUpperCase();
		}
	}});
	imageReplacer.start();

	if ($('mylightbox')  != null) {
		initLightbox();
	}
	if ($('googlemap')  != null) {
		google_load();
	}
	if ($('popup')  != null) {
		initpopup = window.setTimeout("initPopup()", 3000);
	}
}
function initPopup () {
	me = $('popup');
	myAnimator = new Animator()
		.addSubject(new NumericalStyleSubject(me, 'opacity', 0, 1));
	myAnimator.play();
	window.clearTimeout('initpopup');
}
function taf_box ( url ) {
	me = $('tafbox');
	myAnimator = new Animator()
		.addSubject(new NumericalStyleSubject(me, 'opacity', 0, 1))
		.addSubject(new NumericalStyleSubject(me, 'top', -350, 330));
	myAnimator.play();
}
function taf_send(element) {
	var engine = "/tools/ajax/";
	var tafparams = '&email=' + element.taf_email.value +
			 '&name=' + element.taf_name.value +
			 '&receipt_name=' + element.taf_receipt_name.value +
			 '&receipt_mail=' + element.taf_receipt_mail.value +
			 '&url=' + window.location.href +
			 '&message=' + element.taf_message.value;
	return new Ajax.Request(engine + '?m=taf' + tafparams , {
		method: 'post',
		encoding: 'UTF-8',
		parameters: tafparams,
		asynchronous: true,
		onSuccess: function(transport) {
			var response = transport.responseText;
			if (response == 'ok') {

			}
			else {
				alert (response);
			}
			closepopup();
		},
		onFailure: function() {
			element.shake();
		}
	});
}
function closepopup() {
	if ($('popup')  != null) {
		me = $('popup');
		myAnimator = new Animator()
			.addSubject(new NumericalStyleSubject(me, 'opacity', 1, 0));
		myAnimator.play();
	}
	else if ($('tafbox')  != null) {
		me = $('tafbox');
		myAnimator = new Animator()
			.addSubject(new NumericalStyleSubject(me, 'opacity', 1, 0))
			.addSubject(new NumericalStyleSubject(me, 'top', 330, -350));
		myAnimator.play();
	}
}
function handleError($message,$uri,$nr) {
	$errortext = "E: " + $message + " | Nr: " + $nr + " | Uri: " + $uri;
	// window.status = $errortext;
	return true;
}
function onDocumentUnLoad () {
	if ($('googlemap')  != null) {
		GUnload();
	}
}

//window.onerror = handleError;
window.onunload = onDocumentUnLoad;
