// 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.addFile("cookie.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.pillerseetal.teaser.verticalSlider");
loader.addClass("at.pillerseetal.dropdowns.dropdown");
loader.addClass("at.pillerseetal.main_navigation.hover");
loader.addClass("at.pillerseetal.webcams.imgswitcher");


//loader.load();
loader.loadProxy("http://www.pillerseetal.at/tools/scriptproxy/loader.php");


function onDocumentLoad ()
{
	new at.pillerseetal.main_navigation.hover( [ $$('#metaNav li')] );

	//Initialisierung Angebots-Teaser-Slider
	if( $('ev_slider') != null )
	{
		items = $('ev_slider').getElementsByClassName('ev_item');
		new at.pillerseetal.teaser.verticalSlider(items,17,64);
	}
	
	//Initialisierung LanguageSelector
	if( $('metaLanguage') != null )
	{
		new at.pillerseetal.dropdowns.dropdown( $('metaLanguage') );
	}
	
	//Initialisierung Calendar
	if( $('z_form') != null )
	{
		new at.elements.calendar.init({
			button : 'z_calendar',
			output : "input",
			dayInput: 'day',
			monthInput: 'month',
			yearInput: 'year',
			updateFieldOnStartup : true
		});
	}
	
	//Initialisierung Event Calendar
	if( $('eventform') != null )
	{
		new at.elements.calendar.init({
			button : 'event_from',
			output : "input",
			dayInput: 'eventFromDay',
			monthInput: 'eventFromMonth',
			yearInput: 'eventFromYear',
			updateFieldOnStartup : false
		});
		new at.elements.calendar.init({
			button : 'event_to',
			output : "input",
			dayInput: 'eventToDay',
			monthInput: 'eventToMonth',
			yearInput: 'eventToYear',
			updateFieldOnStartup : false
		});
	}
	
	//Initialisierung Offer Detail Form
	if( $('offerdetailblock') != null )
	{
		new at.elements.calendar.init({
			button : 'duration_from',
			output : "input",
			dayInput: 'fromDay',
			monthInput: 'fromMonth',
			yearInput: 'fromYear',
			updateFieldOnStartup : false
		});
		new at.elements.calendar.init({
			button : 'duration_until',
			output : "input",
			dayInput: 'untilDay',
			monthInput: 'untilMonth',
			yearInput: 'untilYear',
			updateFieldOnStartup : false
		});
	}
	
	//Initialisierung Default Form
	if( $('defaultform') != null )
	{
		new at.elements.calendar.init({
			button : 'form_from',
			output : "input",
			dayInput: 'formFromDay',
			monthInput: 'formFromMonth',
			yearInput: 'formFromYear',
			updateFieldOnStartup : false
		});
		new at.elements.calendar.init({
			button : 'form_to',
			output : "input",
			dayInput: 'formToDay',
			monthInput: 'formToMonth',
			yearInput: 'formToYear',
			updateFieldOnStartup : false
		});
	}
	
	//Initialisierung Webcams
	if( $('webcams') != null )
	{
		new at.pillerseetal.webcams.imgswitcher( $('webcams') );
	}

	initLightbox();

}

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(target == "_blank") {
		window.open(destinationURL);
	}
	else {
		location.href = destinationURL;
	}
}
