
// init loader
var loader = new Loader();
loader.setScriptPath("/static/source/js/");
loader.addFile("lib/prototype.js");
loader.addFile("src/scriptaculous.js");

loader.addFile("lib/animator.js");
loader.addFile("lib/swfobject.js");
loader.addFile("lib/trimpath-template.js");
loader.addFile("cookie.js");
loader.addFile("lightbox.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.elements.textreplace.image");
loader.addClass("at.elements.tooltip");

loader.addClass("at.nassfeld.main_navigation.hover");
loader.addClass("at.nassfeld.dropdowns.dropDown");
loader.addClass("at.nassfeld.prices.toggler");
loader.addClass("at.nassfeld.toppackages.hover");

loader.addClass("at.nassfeld.webcamslider.camslider");

loader.load();
//loader.loadProxy("http://cms.salzburg.info/index.php/de/intern/script-proxy/");


function onDocumentLoad ()
{

	//Main Navigation
	try {
		new at.nassfeld.main_navigation.hover( [ $$('#main_nav li')] );
	} catch (e) {}



	try {
		if($('languages') != null)
		{
			new at.nassfeld.dropdowns.dropDown($('languages'));
		}
	} catch (e) {}


	//Initialisierung fuer Anfragebox
	try {
		if($('vacancybox') != null)
		{

			//init Calendar
			new at.elements.calendar.init({
				button : 'box_arrival_Cal',
				output : "input",
				dayInput: 'box.arrivalDay',
				monthInput: 'box.arrivalMonth',
				yearInput: 'box.arrivalYear',
				updateFieldOnStartup : true
			});
			/*
			new at.elements.calendar.init({
				button : 'box_departure_Cal',
				output : "input",
				dayInput: 'box.departureDay',
				monthInput: 'box.departureMonth',
				yearInput: 'box.departureYear',
				updateFieldOnStartup : true
			});
			*/
		}
	} catch (e) {}

	//Initialisierung fuer Eventsuche
	try {
		if($('event_search') != null)
		{

			//init Calendar
			new at.elements.calendar.init({
				button : 'event_start_Cal',
				output : "input",
				dayInput: 'event.startDay',
				monthInput: 'event.startMonth',
				yearInput: 'event.startYear',
				updateFieldOnStartup : false
			});

			new at.elements.calendar.init({
				button : 'event_end_Cal',
				output : "input",
				dayInput: 'event.endDay',
				monthInput: 'event.endMonth',
				yearInput: 'event.endYear',
				updateFieldOnStartup : false
			});
		}
	} catch (e) {}

	//Initialisierung fuer Packageanfrageformular
	try {



		if($('package_inquiry') != null) {
			//init Calendar
			new at.elements.calendar.init({
				button : 'packageinquiry_Cal',
				output : "input",
				dayInput: 'packageinquiry.startDay',
				monthInput: 'packageinquiry.startMonth',
				yearInput: 'packageinquiry.startYear',

				updateFieldOnStartup : false
			});
		}
	} catch (e) {}


	//Initialisierung fuer Gewinnspiel
	/*try {
		if($('geburtsdatum.fulldate') != null) {
			//init Calendar
			new at.elements.calendar.init({
				button : 'birthday_Cal',
				output : "singleinput",
				singleInput: 'geburtsdatum.fulldate',
				updateFieldOnStartup : false
			});
		}
	} catch (e) {}*/



	//Tooltip Top Packages
	var template = '<div id="package_tooltip"><div class="tooltip_text">${text}</div></div>';

	tp_container = $$('#top_packages .top_package');
	if(tp_container.length > 0)
	{
		for(i=0; i<tp_container.length; i++)
		{
			try {
				var data = {
					text: tp_container[i].getElementsBySelector(".tooltiptext")[0].innerHTML
				};
				new at.elements.tooltip(tp_container[i].getElementsBySelector(".name")[0],{
					offsetY: -85,
					offsetX: 5,
					template: template,
					data: data
				});
			}
			catch (e) {}
			new at.nassfeld.toppackages.hover(tp_container[i]);
		}
	}

	try {
		if($('ticket_prices') != null)
		{
			pricecats = $('ticket_prices').getElementsByClassName('price_category');
			new at.nassfeld.prices.toggler(pricecats);
		}
	} catch (e) {}

	try {
		if($('webcams_portal') != null)
		{
			new at.nassfeld.webcamslider.camslider($('webcams_portal'));
		}

	} catch (e) {}

	try {
		if($('special_teaser_simple_counter') != null) {
			countdown();
		}
	} catch (e) {}

	// replace text to images

	/*if (language == "de" || language == "en") {
		var imageReplacer = new at.elements.textreplace.image("/static/cache/headlines/",{appendFilename: true});

		if (portal == "salzburginfo") {
			imageReplacer.add({
				elements: $$('#portal_teasers .tab_content h2'),
				options: {
				font: 'cg.ttf',
				width: '167',
				height: '',
				color: '505a64',
				size: '10.2',
				positionx: 0,
				positiony: 13,
				replaceElement: {
					tagName: "h2",
					className: "r_img"
				},
				modifyValue : function (vari)
				{
					return vari.toUpperCase();
				}
			}});

			imageReplacer.add({
				elements: $$('#portal_teasers .tab_content h3'),
				options: {
				font: 'cgb.ttf',
				width: '167',
				height: '',
				color: '990000',
				size: '10.2',
				positionx: 0,
				positiony: 13,
				replaceElement: {
					tagName: "h3",
					className: "r_img"
				},
				modifyValue : function (vari)
				{
					return vari.toUpperCase();
				}
			}});
		}

		if (portal == "congress") {
			imageReplacer.add({
				elements: $$('#portal_teasers_congress h3'),
				options: {
				font: 'cgb.ttf',
				width: '167',
				height: '',
				color: '003C78',
				size: '10.2',
				positionx: 0,
				positiony: 13,
				replaceElement: {
					tagName: "h3",
					className: "r_img"
				},
				modifyValue : function (vari)
				{
					return vari.toUpperCase();
				}
			}});

			imageReplacer.add({
				elements: $$('#enquirybox .head_line h3'),
				options: {
				font: 'cgb.ttf',
				width: '170',
				height: '',
				color: '003C78',
				size: '10.2',
				positionx: 0,
				positiony: 13,
				replaceElement: {
					tagName: "h3",
					className: "r_img"
				},
				modifyValue : function (vari)
				{
					return vari.toUpperCase();
				}
			}});
		}

		imageReplacer.start();
	}*/

	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(destinationURL.length > 0) {
		if(target == "_blank") {
			window.open(destinationURL);
		}
		else {
			location.href = destinationURL;
		}
	}
	return false;
}

