// init loader
var loader = new Loader();
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.addFile("lib/trimpath-template.js");

loader.addClass("at.elements.calendar.init");

if(language == "de") {
	loader.addClass("at.elements.calendar.de");
}
else {
	loader.addClass("at.elements.calendar.en");
}

loader.addClass("at.badwaltersdorf.main_navigation.hover");

loader.load();
//loader.loadProxy("http://www..com/tools/scriptproxy/loader.php");


function onDocumentLoad () {

	new at.badwaltersdorf.main_navigation.hover( [ $$('#metanav li') ] );
	
	//Initialisierung Calendar
	try {
		new at.elements.calendar.init({
			button : 'calendar_icon',
			output : 'select',
			daySelect: 'day',
			monthSelect: 'month',
			yearSelect: 'year',
			updateFieldOnStartup : true
		});
	}
	catch (e) {		
	}

	//Initialisierung Event Calendar
	if( $$('.eventform').length != 0 ) {		
		new at.elements.calendar.init({
			button : 'calendar_icon_from',
			output : 'select',
			daySelect: 'event_from_day',
			monthSelect: 'event_from_month',
			yearSelect: 'event_from_year',
			updateFieldOnStartup : false
		});
		
		new at.elements.calendar.init({
			button : 'calendar_icon_to',
			output : 'select',
			daySelect: 'event_to_day',
			monthSelect: 'event_to_month',
			yearSelect: 'event_to_year',
			updateFieldOnStartup : false
		});
	}
		
	if( $$('.catalog').length != 0 ) {
		new at.elements.calendar.init({
			button : 'calendar_icon_from',
			output : 'select',
			daySelect: 'event_from_day',
			monthSelect: 'event_from_month',
			yearSelect: 'event_from_year',
			updateFieldOnStartup : false
		});
		
		new at.elements.calendar.init({
			button : 'calendar_icon_to',
			output : 'select',
			daySelect: 'event_to_day',
			monthSelect: 'event_to_month',
			yearSelect: 'event_to_year',
			updateFieldOnStartup : false
		});
	}

}

function gotoLink (htmlElement) {
	
	var destinationURL = "";
	var target = "";
	
	if(htmlElement.href) {
		destinationURL = htmlElement.href;
		target = htmlElement.getAttribute("target");
	}
	else {
		if(htmlElement.childNodes) {
			if(htmlElement.getElementsByTagName("a")) {
				destinationURL = htmlElement.getElementsByTagName("a")[0].href;
				target = htmlElement.getElementsByTagName("a")[0].getAttribute("target");
			}
		}
	}
	
	if(destinationURL.length > 0) {
		if(target == "_blank") {
			window.open(destinationURL);
		}
		else {
			location.href = destinationURL;
		}
	}
	return false;
}


