
if(typeof securely == "undefined")
{
	var securely = false;
}

if(document.location.protocol == "https:") {
	securely = true;
}

path = new Array();
path.push('/static/js/lib/animator.js');
path.push('/static/js/lib/prototype.js');
path.push('/static/js/lib/swfobject.js');
path.push('/static/js/calendar.js');
path.push('/static/js/elementsCalendar.js');
path.push('/static/js/classes.js');
path.push('/static/js/webcams.js');
path.push('/static/js/imgReplace.js');

path.push('/static/js/lib/effects.js');
path.push('/static/js/lib/builder.js');
path.push('/static/js/lightbox.js');
path.push('/static/js/adserver.js');

path.push('/static/js/custom_form_elements.js');
path.push('/static/js/skiticketselector.js');
path.push('/static/js/portalteaserslider.js');

//path.push('/static/js/regionselector.js');

loadScrips(path);


function onDocumentLoad () {
	//Initialisierung custom form elements
	try {
		Custom.init();
	}
	catch(err) {
	}
	
	if($('w_portalteaser') != null)
	{
		var teaserhover = new classSwitcherIchWill( [ $$('div.btn') ],[ $$('div.teaserbody') ] );
		var formslider = new formSlider( [ $('submit_urlaub_s1'), $('submit_urlaub_s2') ],[$$('div#urlaub div.form div.container')] );
		var teaserSliderBtn = new classSwitcher( [ $$('div.teasertext div.sliderbutton') ] );
		var teaserSliderSpecials = new portalTeaserSlider( $$('div#specials.teaserbody') );
		var teaserSliderEvents = new portalTeaserSlider( $$('div#events.teaserbody') );
	}
	

	window.setTimeout(function () {
		var ads = new adserverReplace($$(".adserver"));
	}, 2000);

	var elementhover = new classSwitcher( [ $$('#metanav li'), $$('#metanav li ul li'), $$('#metanav li ul li ul li') ] );
	var themenhover = new classSwitcher( [ $$('a#i_mail'), $$('a#i_media'), $$('a#i_board'), $$('a#i_family'), $$('a#i_chart') ] );

	
	if($('mediabox') != null)
	{
		var mediaboxhover = new switcherMediabox( $('slider'), [ $$('#mediabox div.text') ] );
	}
	if($('languages') != null)
	{
		var languages = new dropDown($('languages'));
	}
	if($('skiregions') != null)
	{
		var skiregions = new dropDown($('skiregions'));
	}
	
		if(lang == "de" || lang == "en" || lang == "nl")
		{
		
			/*if(lang == "de" || lang == "en" || lang == "nl")
			{*/
				var interstateLight = "Interstate-Light.ttf";
				var interstateRegular = "Interstate-Regular.ttf";
			/*}
			else
			{
				var interstateLight = "ArialUnicode.otf";
				var interstateRegular = "ArialUnicode.otf";
			}*/
			
			text2image($$('#textarea h1.white'),{
				font: interstateLight,
				width: '520',
				height: '',
				color: 'ffffff',
				size: '16',
				positionx: 0,
				positiony: 17,
				replaceElement: {
					tagName: "span",
					className: "h1"
				}
			});
		
			text2image($$('#textarea h1'),{
				font: interstateLight,
				width: '520',
				height: '',
				color: '283746',
				size: '16',
				positionx: 0,
				positiony: 17,
				replaceElement: {
					tagName: "span",
					className: "h1"
				}
			});
			
			/*
			text2image($$('#sidebar .top_teaser h3.img'),{
				font: interstateRegular,
				width: '130',
				height: '',
				color: '283746',
				size: '9.5',
				positionx: 0,
				positiony: 0,
				replaceElement: {
					tagName: "span",
					className: "h3"
				}
			});
			*/
			
			text2image($$('#weatherbox h3.img'),{
				font: interstateRegular,
				width: '200',
				height: '',
				color: 'ffffff',
				size: '9.5',
				positionx: 0,
				positiony: 0,
				replaceElement: {
					tagName: "span",
					className: "h3"
				},
				modifyValue : function (vari)
				{
					return vari.toUpperCase();
				}
			});
			
			text2image($$('#vacationplaner h3.img'),{
				font: interstateRegular,
				width: '200',
				height: '',
				color: '283746',
				size: '9.5',
				positionx: 0,
				positiony: 0,
				replaceElement: {
					tagName: "span",
					className: "h3"
				},
				modifyValue : function (vari)
				{
					return vari.toUpperCase();
				}
			});
			
			/*
			text2image($$('#subnavigation em'),{
				font: interstateRegular,
				width: '160',
				height: '',
				color: '283746',
				size: '9.5',
				positionx: 0,
				positiony: 0,
				replaceElement: {
					tagName: "span",
					className: "em"
				},
				modifyValue : function (vari)
				{
					return vari.toUpperCase();
				}
			});

			text2image($$('#metanav em','#seasons em'),{
				font: interstateRegular,
				width: '',
				height: '',
				color: 'ffffff',
				size: '9.5',
				positionx: 0,
				positiony: 0,
				replaceElement: {
					tagName: "span",
					className: "em"
				},
				modifyValue : function (vari)
				{
					return vari.toUpperCase();
				}
			});
			*/
			
			text2image($$('#portalteaser .teaser h3.img'),{
				font: interstateRegular,
				width: '160',
				height: '',
				color: '283746',
				size: '9.5',
				positionx: 0,
				positiony: 0,
				replaceElement: {
					tagName: "span",
					className: "h3"
				}
			});
			
			
			text2image($$('#textarea .weatherinfo .temperatures em, #textarea .contentweather .today .degree em'),{
				font: interstateLight,
				width: '60',
				height: '',
				color: 'ffffff',
				size: '15',
				positionx: 0,
				positiony: 0,
				replaceElement: {
					tagName: "span",
					className: "em"
				}
			});
			
			text2image($$('#flashpanorama_teaser_container h3.img'),{
				font: interstateRegular,
				width: '200',
				height: '',
				color: 'ffffff',
				size: '9.5',
				positionx: 0,
				positiony: 0,
				replaceElement: {
					tagName: "h3",
					className: "img"
				},
				modifyValue : function (vari)
				{
					return vari.toUpperCase();
				}
			});
		}

	
	skiTicketSelector();
	
	
	//Initialisierung Calendar
	if( $('urlaub'))
	{
		new elementsCalendar({
			button : 'u_calendar',
			output : 'input',
			dayInput: 'u_day',
			monthInput: 'u_month',
			yearInput: 'u_year',
			updateFieldOnStartup : true
		});
	}
	if( $('tickets'))
	{
		new elementsCalendar({
			button : 't_calendar',
			output : 'singleinput',
			input: 'desireddate',
			updateFieldOnStartup : false
		});
	}
	
	if( $$('div#vacationplaner div.vacationtxt').length >= 1 )
	{
		new elementsCalendar({
			button : 'u_calendar',
			output : 'input',
			dayInput: 'u_day',
			monthInput: 'u_month',
			yearInput: 'u_year',
			updateFieldOnStartup : true
		});
	}
	if( $$('div#vacationplaner div.vacationtxt').length >= 1 )
	{
		new elementsCalendar({
			button : 't_calendar',
			output : 'singleinput',
			input: 't_validfrom',
			updateFieldOnStartup : false
		});
	}
	
	// track external links with google analytics
	externalLinks = $$('#contentarea a', '.teaser a', '#bluetab a');
	for(var i=0; i<externalLinks.length; i++) {
		if (externalLinks[i].getAttribute("href")) {
			if(externalLinks[i].getAttribute("href").indexOf("http") >= 0) {
				if(externalLinks[i].getAttribute("href").indexOf("skiamade.com") < 0) {
					var hostname = parseUri(externalLinks[i].getAttribute("href")).host;
					externalLinks[i].setAttribute("trackKey",hostname);
					externalLinks[i].onclick = externalLinkClick;
				}
			}
		}
	}
	
	// google maps header
	if ($('gm_header')) {
		gm_header = new GoogleMapsHeader();
	}
	
	initLightbox();
}


//window.onload = onDocumentLoad;


function externalLinkClick ()
{
	var trackKey = this.getAttribute("trackKey");
	// google analytics
	pageTracker._trackPageview('/external/' + trackKey);
	// E-Tracker
	clickTracker('/external/' + trackKey);
}


function loadScrips (path)
{
	for(i=0;i<path.length;i++)
	{
		if(securely == true)
		{
			document.write('<script type="text/javascript" src="https://secure.skiamade.com' + path[i] + '"></script>');
		}
		else
		{
			document.write('<script type="text/javascript" src="' + path[i] + '"></script>');
		}
	}
}


function getLink(vari,target)
{
	if(target == "_blank")
	{
		window.open(vari);
	}
	else
	{
		window.location.href = vari;
	}
}










function parseUri (str) {
	var	o   = parseUri.options,
		m   = o.parser[o.strictMode ? "strict" : "loose"].exec(str),
		uri = {},
		i   = 14;

	while (i--) uri[o.key[i]] = m[i] || "";

	uri[o.q.name] = {};
	uri[o.key[12]].replace(o.q.parser, function ($0, $1, $2) {
		if ($1) uri[o.q.name][$1] = $2;
	});

	return uri;
};

parseUri.options = {
	strictMode: false,
	key: ["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"],
	q:   {
		name:   "queryKey",
		parser: /(?:^|&)([^&=]*)=?([^&]*)/g
	},
	parser: {
		strict: /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,
		loose:  /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/
	}
};




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;
	}
}










function dtaNavigationHighlight () {
	var currentLink, currentPosition, tmpElement, tmpUl;
	var links = $$("#subnavigation a");
	var naviContainer = $("subnavigation");
	
	currentPosition = parseUri(location.href).path;
	
	for (var i=0; i<links.length; i++) {
		currentLink = parseUri(links[i].getAttribute("href")).path;
		if(currentPosition == currentLink) {
			links[i].addClassName("active");			
			
			tmpElement = links[i].up();
			while (tmpElement != naviContainer) {
				
				tmpUl = tmpElement.getElementsBySelector("ul.active")[0];
				if(tmpUl) {
					tmpUl.setStyle({
						display: ""
					});
				}
				
				tmpElement.addClassName("active");
				tmpElement = tmpElement.up();
			}			
		}
	}
}





