var ani = false;
var ani2 = false;
var stepb;
var bgCookie;
var bgurl;
var steps;
var fullBg;
var responseDesk;
var xLang = lang == 'de' ? 'de' : 'en';

//Sprache für Activities
if(lang == 'en' || lang == 'jp'){
	var cLang = 'en';
}else if(lang == 'de'){
	var cLang = 'de'
}else if(lang == 'cn'){
	var cLang = 'cn'
}else if(lang == 'es'){
	var cLang = 'es'
}else if(lang == 'pt'){
	var cLang = 'pt'
}else if(lang == 'fr'){
	var cLang = 'fr'
}



tags = JSON.decode(tags);



if(!Object.keys) Object.keys = function(o){
 if (o !== Object(o))
      throw new TypeError('Object.keys called on non-object');
 var ret=[],p;
 for(p in o) if(Object.prototype.hasOwnProperty.call(o,p)) ret.push(p);
 return ret;
}


//IE 6

//lokal testing
if (server == '192.168.128.13') {
	var lokal = true;
	var tmpDir = 'http://192.168.128.13/go4webdesk.ch/httpdocs/users/titlis3/upload/';
	var path = 'http://192.168.128.13/go4webdesk.ch/httpdocs/desk/prevsites/previewSite/';
}
else {
	var lokal = false;
	var path = root;
	var tmpDir = root;
	var tmpDir = 'http://www.titlis.ch/upload/';
}


var monthsA = ['Januar', 'Februar', 'März', 'April', 'Mai', 'Juni', 'Juli', 'August', 'September', 'Oktober', 'November', 'Dezember'];
var daysA = ['Sonntag', 'Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag', 'Samstag'];

var monthsAf = ['Janvier', 'Februar', 'März', 'April', 'Mai', 'Juni', 'Juli', 'August', 'September', 'Oktober', 'November', 'Dezember'];
var daysAf = ['Dimanche ', 'Lundi', 'Mardi', 'Mercredi', 'Jeudi', 'Vendredi', 'Samedi'];


var monthsAe = ['January', 'February' ,'March', 'April','May', 'June', 'July' ,'August','September','October','November','December'];
var daysAe = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];

function getWidth(){
	var de = document.documentElement;
	var myWidth = window.innerWidth || self.innerWidth || (de && de.clientWidth) || document.body.clientWidth;
	return myWidth;
}
document.getWidth=getWidth;


window.addEvent('domready', function(){

	
	if(tags.webcam==1){
		new webCamPopUp();
	}
//////////////////////////////////////////////////////////////////////////////////////
	 /**
	 * deskJS-Functions
	 *  
	 *  Parameters:
	 *    verzDebug: Debugstatus für den JSON-Output (bolean)
	 *    verzLocal: Request auf lokale/externe Daten (bolean)
	 *    verzUser: DBName des Benutzer (string)
	 *    
	 *  Methods:
	 *    _loadStatus: Aufruf bei jeder Interaktion - Load, Request, usw (bereich, json-aktion)
	 *    _directLink: Aufruf durch direktlink Verz-Verz und Internen Seiten (mode = verz/site)
	 *    _afterRendering: Aufruf nach Einbindung der Plugins und Rendering des Templates
	 */
	deskJS = new Class({
	
		// Implements
		Implements: addDeskJS	// options
		,
		options: {
			verzDebug: 0,
			verzLocal: 0,
			verzUser: 'titlis3'
		
		/**
		 * User-Parameters
		 *
		 */
		
		}	// initialization
		
		,initialize: function(options){
		
			//set options
			this.setOptions(options);
			
			// pluginload
			this._jsPreload({
				templating: false,
				slider: false,
				scrollspy: false,
				popup: false,
				sortOn: false,
				historymanager: true
			});
		
			// Historymanager
			HistoryManager = new HistoryManager();
			
			this.history = HistoryManager.register('verz', [''], function(values){
			
				if (values.length > 1) {
					this._directLink('verz', values[0], values[1], values[2]);
				}
				
			}.bind(this)
			, function(values){
				return 'verz(' + values[0] + '_' + values[1] + '_' + values[2] + ')';
			}.bind(this)
			, /verz\((.*)_(.*)_(.*)\)/);
			HistoryManager.start();
		}	// Ladestatus der Plugins oder des Request
		
		,_loadStatus: function(part, action){
		
		}	// Aufruf durch Verzeichnisverlinkung
		/**
		 * Direktlink aufruf
		 * @param {Object} mode - leer aber notwendig, da es sonst nicht funktioniert
		 * @param {Object} DBstr - zu verwendende Datenbank
		 * @param {Object} lrID - Rubrik ID
		 * @param {Object} ldID - Eintrag ID
		 */
		//Wichtig, hier keine Parameter entfernen, da sonst die Direktlinks bei Titlis nicht funktionieren!
		,_directLink: function(mode, DBstr, lrID, ldID){
			//direktlinks Events
			if (DBstr == 'events') {
				if (LANG == 'de') openEvent('index.php?id=33', ldID);
				else openEvent('index.php?id=120', ldID);
			}
			//direktlinks Aktivitäten
			else {
				if(LANG == 'de'){
					if (lrID == 1) followlink(path + 'index.php?id=31/' + 'verz/_' + lrID + '_' + ldID);
					else if (lrID == 2) followlink(path + 'index.php?id=32/' + 'verz/_' + lrID + '_' + ldID);
					else followlink(path + 'index.php?id=40/' + 'verz/_' + lrID + '_' + ldID);
				}
				else{
					if (lrID == 5) followlink(path + 'index.php?id=118/' + 'verz/_' + lrID + '_' + ldID);
					else if (lrID == 6) followlink(path + 'index.php?id=119/' + 'verz/_' + lrID + '_' + ldID);
					else followlink(path + 'index.php?id=128/' + 'verz/_' + lrID + '_' + ldID);
				}
			}
		},
		_afterRendering: function(){
		
		}
		
	/**
	 * User-Functions
	 *
	 *  Methods:
	 *
	 */
	});
	deskJS = new deskJS();
	
//////////////////////////////////////////////////////////////////////////////////////
	
	headNavAni.delay(3000);
	//RANDOM GALLERY IMG
	/* var reqData = {
	 	'type': 'all',
	 	'user': 'titlis3',
	 	'table': {
	 		'listingdatas_medien': 'ld',
	 		'listingrows_medien': 'lr',
	 		'listings_medien': 'l'
	 	},
	 	
	 	'condition': {
	 		'lr.rubrikname not like': '%film%'
	 	},
	 	
	 	'fields': 'ld.bilder',
	 	'order': 'RAND() LIMIT 1',
	 	'language': 'de'
	 };
	    
	var allEv = new Request({
		url: path + 'index.php',
		method: 'post',
		data: 'mode=verzeichnis&local=0&debug=1&request=' + encodeURIComponent(JSON.encode(reqData)),
		onComplete: function(response){
			var res = JSON.decode(response);
			var randomNr = Math.floor(Math.random() * (res.result[0].ld.bilder.media.length));
			if (res.result[0].ld.bilder.media[randomNr].name.contains('.jpg')) {
				$('mediapic').setProperty('src', root + 'images/picsandmovies/play.png');
				$('mediapic').setStyle('background-image', 'url("' + root + 'upload/250_verz_' + res.result[0].ld.bilder.media[randomNr].name + '")')
			}
		}
	}).send()*/
	
	if(lang == 'de' && pType == 'main'){
		$('btn_reservation').setStyle('margin-top',8)
	}else if(pType == 'main'){
		$('btn_reservation').setStyle('margin-top',8)
	}
	
	//Navigation layout
	if (Browser.Engine.name == 'trident') {
		if (Browser.Engine.version == 6) {
			if ($('unavbg') != null) {
				$('unavbg').getChildren().getChildren().each(function(li){
					var i = 0;
					while (i < li.length) {
						li[i].setStyle('padding-top', '2px');
						i++;
					}
				})
			}
		}
		else 
			if (Browser.Engine.version == 5 && lang == 'jp') {
				if ($('unavbg') != null) {
					$('unavbg').getChildren().getChildren().each(function(li){
						var i = 0;
						while (i < li.length) {
							li[i].setStyles({
								'padding': '2px 0 0px 0',
								'margin':'0 0 0 20px'
							});
							i++;
						}
					})
				}
			}
	}
	if (Browser.Engine.name == 'gecko' && lang == 'jp'||Browser.Engine.name == 'gecko' && lang == 'cn') {
		if ($('unavbg') != null) {
			$('unavbg').getChildren().getChildren().each(function(li){
				var i = 0;
				while (i < li.length) {
					li[i].setStyles({
						'padding': '2px 0px 2px 0px'
					});
					i++;
				}
			})
		}
	}
	
	$$('#social a img').each(function(soc){
		
		soc.addEvents({
			'click': function(){
				//console.log(soc.alt);

				new Request({
				            url: path + 'includes/socialcounter.php',
				            method: 'post',
				            data: 'mode=ajax&request=' + soc.alt,
				            onComplete: function(response){
							//console.log(response);	
					    }
			        }).send();
				        
			    }
				
		});
	});
	 

	
    if (lang == 'de') {
		MooTools.lang.set('en-US', 'Date', {
		
			months: ['Januar', 'Februar', 'Maerz', 'April', 'Mai', 'Juni', 'Juli', 'August', 'September', 'Oktober', 'November', 'Dezember'],
			days: ['Sonntag', 'Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag', 'Samstag'],
			dateOrder: ['month', 'date', 'year', '/'],
			AM: "AM",
			PM: "PM",
			//members can be functions; these will be executed and passed any arguments with .get(member[,args])
			ordinal: function(dayOfMonth){
				return (dayOfMonth > 3 && dayOfMonth < 21) ? 'th' : ['th', 'st', 'nd', 'rd', 'th'][Math.min(dayOfMonth % 10, 4)];
			},
			lessThanMinuteAgo: 'less than a minute ago',
			minuteAgo: 'about a minute ago',
			minutesAgo: '{delta} minutes ago',
			hourAgo: 'about an hour ago',
			hoursAgo: 'about {delta} hours ago',
			dayAgo: '1 day ago',
			daysAgo: '{delta} days ago',
			lessThanMinuteUntil: 'less than a minute from now',
			minuteUntil: 'about a minute from now',
			minutesUntil: '{delta} minutes from now',
			hourUntil: 'about an hour from now',
			hoursUntil: 'about {delta} hours from now',
			dayUntil: '1 day from now',
			daysUntil: '{delta} days from now'
		
		});
	}
	else {
		MooTools.lang.set('en-US', 'Date', {
		
			months: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
			days: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
			dateOrder: ['month', 'date', 'year', '/'],
			AM: "AM",
			PM: "PM",
			//members can be functions; these will be executed and passed any arguments with .get(member[,args])
			ordinal: function(dayOfMonth){
				return (dayOfMonth > 3 && dayOfMonth < 21) ? 'th' : ['th', 'st', 'nd', 'rd', 'th'][Math.min(dayOfMonth % 10, 4)];
			},
			lessThanMinuteAgo: 'less than a minute ago',
			minuteAgo: 'about a minute ago',
			minutesAgo: '{delta} minutes ago',
			hourAgo: 'about an hour ago',
			hoursAgo: 'about {delta} hours ago',
			dayAgo: '1 day ago',
			daysAgo: '{delta} days ago',
			lessThanMinuteUntil: 'less than a minute from now',
			minuteUntil: 'about a minute from now',
			minutesUntil: '{delta} minutes from now',
			hourUntil: 'about an hour from now',
			hoursUntil: 'about {delta} hours from now',
			dayUntil: '1 day from now',
			daysUntil: '{delta} days from now'
		
		});
		
	}
    
   
    if (pType == 'main' && theme == 'ti') {
		$('webcam').addEvent('click', function(){
		
			var newani = new boxani();
			newani.tout(-1, 100, 170, 20, 500, 'close');
			
			
			if (lang == 'de') {
				setTimeout("followlink('" + path + "index.php?id=22')", 1300);
			}
			else 
				if (lang == 'en') {
					setTimeout("followlink('" + path + "index.php?id=109')", 1300);
				}
				else 
					if (lang == 'jp') {
						setTimeout("followlink('" + path + "index.php?id=847')", 1300);
					}
					else 
						if (lang == 'cn') {
							setTimeout("followlink('" + path + "index.php?id=479')", 1300);
						}
						
						else 
							if (lang == 'es') {
								setTimeout("followlink('" + path + "index.php?id=1171')", 1300);
							}
							else 
								if (lang == 'pt') {
									setTimeout("followlink('" + path + "index.php?id=3483')", 1300);
								}
								else 
									if (lang == 'fr') {
										setTimeout("followlink('" + path + "index.php?id=4724')", 1300);
									}
								
			
		});
		
		
		$('snow').addEvent('click', function(){
		
			var newani = new boxani();
			newani.tout(-1, 100, 170, 20, 500, 'close');
			if (lang == 'de') {
				setTimeout("followlink('" + path + "index.php?id=359')", 1300);
			}
			else 
				if (lang == 'en') {
					setTimeout("followlink('" + path + "index.php?id=360')", 1300);
				}
				else 
					if (lang == 'jp') {
						setTimeout("followlink('" + path + "index.php?id=842')", 1300);
					}
					else 
						if (lang == 'cn') {
							setTimeout("followlink('" + path + "index.php?id=474')", 1300);
						}
						
						else 
							if (lang == 'es') {
								setTimeout("followlink('" + path + "index.php?id=1173')", 1300);
							}
							else 
								if (lang == 'pt') {
									setTimeout("followlink('" + path + "index.php?id=3485')", 1300);
								}
								else 
									if (lang == 'fr') {
										setTimeout("followlink('" + path + "index.php?id=4975')", 1300);
									}
			
		});
		
		$('pas').addEvent('click', function(){
		
			var newani = new boxani();
			newani.tout(-1, 100, 170, 20, 500, 'close');
			if (lang == 'de') {
				setTimeout("followlink('" + path + "index.php?id=341')", 1300);
			}
			else 
				if (lang == 'en') {
					setTimeout("followlink('" + path + "index.php?id=110')", 1300);
				}
				else 
					if (lang == 'jp') {
						setTimeout("followlink('" + path + "index.php?id=848')", 1300);
					}
					else 
						if (lang == 'cn') {
							setTimeout("followlink('" + path + "index.php?id=480')", 1300);
						}
						
						else 
							if (lang == 'es') {
								setTimeout("followlink('" + path + "index.php?id=1490')", 1300);
							}
							else 
								if (lang == 'pt') {
									setTimeout("followlink('" + path + "index.php?id=3802')", 1300);
								}
								else 
									if (lang == 'fr') {
										setTimeout("followlink('" + path + "index.php?id=4725')", 1300);
									}
			
			
		});
	}
    
    
    //Hintergrundbild
    rnd = $random(0, 1);
    if (pType != 'main') {
	
		if (lokal == true) {
			bgurl = 'url(' + picpath + ')';
			fullBg = picpath;
		}
		else {
			bgurl = 'url(' + root + picpath + ')';
			fullBg = root + picpath;
		}
		
		//BoxFollow Accordion
		new Accordion($$('dl#unav_boxes dt'), $$('dl#unav_boxes dd'), {
			fixedHeight: 179,
			opacity: 0,
			show: 0
		
		});
		
	}
	else {
		bgurl = 'url(' + root + 'images/mainpics/' + theme + '/home_' + rnd + '.jpg)';
		fullBg = root + 'images/mainpics/' + theme + '/home_' + rnd + '.jpg';
		
	}
    
	
	
	
    createMenu();
    
    //Boxani Startseiten, Aufruf und Init
    if (pType == 'main') {
		var newani = new boxani();
		
		try {
			stepb = $$('#boxes .bani').getElements('div').length;
			
			newani.tout(-1, 1200, 0, 200, 700, 'open');
			
		} 
		catch (err) {
		
		}
	}
    
    $('search').setStyles({
		'background-color': '#fff',
		'padding': '2px',
		'color': '#5F5F5F'
	});
	
    if (lang == 'fr') {
    	$$('#searchfield div').setStyles({
			'background': 'url(' + root + 'images/searchbg-fr.png)',
			'width': '100px'
		});
		
    }
    
    
    
    if (imapBtn == 1) {
		makeMapLink();
	}
  
    if (tags) {
	
		if (tags.pan == 1) {
		//makePans();
		}
		
		if (tags.round == 1) {
			make360();
		}
		
		if (tags.webcam == 1) {
			makeWebcamLinks();
		}
		
		if (tags.weather == 1) {
			showWeather();
		}
		
		if (tags.events == 1) {
			showAllEvents();
		}
		
		if (tags.winteraktD == 1) {
			showActivities('Winteraktivität');
		}
		
		if (tags.winteraktE == 1) {
			showActivities('Winter Activities');
		}
		
		if (tags.sommeraktD == 1) {
		
			showActivities('Sommeraktivität');
		}
		
		if (tags.sommeraktE == 1) {
			showActivities('Summer Activities');
		}
		
		if (tags.erlebnisD == 1) {
			showActivities('Erlebnisangebot');
		}
		
		if (tags.erlebnisE == 1) {
			showActivities('Special Mountain Offers');
		}
		
		
	}
     
	if (map == 'true') {
		gmap();
	}

 
  overlay = new Element('div', {
		'id': 'BoxOverlay',
		'styles': {
			'display': 'block',
			'z-index': '990',
			'position': 'absolute',
			'top': '0',
			'left': '0',
			'background-color': '#000',
			'opacity': 0
		}
	})
	

	 
	 
   overlay.injectInside(document.body);
   
    
    if (theme == 'ti' || pType != 'main') {
		//Events anzeigen
		showEventsBox();
	}
    
    
    //ZebraTables
    var zTables = new ZebraTables('tablemain');
    
//    $('backgroundp').setStyle('opacity', 0);
    
    //FontCookie lesen
//    if(pType != 'main'){
//		 zoomSFont('reload');
//	 }
    
    
    var allinps = $('main').getElements('input');
    
    
    allinps.each(function(theInput){
	
		theInput.addEvents({
			'focus': function(e){
				if ((theInput.value == "Suchbegriff" && theInput.id == "search") || (theInput.value == "search" && theInput.id == "search") || (theInput.value == "recherche" && theInput.id == "search")) {
					theInput.value = "";
				}
			},
			'blur': function(e){
				if (theInput.value == "" && theInput.id == "search") {
					if (lang == 'de') {
						theInput.value = "Suchbegriff";
					}else if (lang == 'fr') {
						theInput.value = "recherche";
					}
					else {
						theInput.value = "search";
					}
					
				}
			}
		});
	});
    
   
    //Hauptseite Navi Klickverzögerung
    if (pType == 'main') {
		var alllink = $$('a');
		
		alllink.each(function(link, item, index){
		
		
		
			var sitelink = link.href;
			
			if (link.hasClass('externlink') == false && link.get('html').indexOf('snowtubing') == -1) {
				link.href = '#';
			}
			
			if (link.get('html').indexOf('snowtubing') == -1 && link.get('html').indexOf('extbanner') == -1 && link.hasClass('externlink') == false && link.id != "fullscreen" && link.id != 'mediaLink' && link.id != 'homeLink' && link.hasClass('noani') == false) {
			
				link.addEvent('click', function(e){
					if (anistat == 'open') {
						var newani = new boxani();
						newani.tout(-1, 100, 170, 20, 500, 'close');
						
						setTimeout("followlink('" + sitelink + "')", 1300);
					}
					bgCookie = Cookie.write('bg', $('pic').getStyle('background-image'), {
						duration: 1
					});
					
				});
			}
			
		});
		
	}
	else {
		
		var alllink = $$('a');
		
		alllink.each(function(link, item, index){
		
			if (link.id != "fullscreen" && link.id != 'mediaLink' && link.id != 'homeLink') {
				link.addEvent('click', function(e){
				
					bgCookie = Cookie.write('bg', $('pic').getStyle('background-image'), {
						duration: 1
					});
					
				});
			}
			
		});
		
		//Specials einlesen auf Folgeseiten
		if (lang == 'de') {
			pid = 1;
		}
		else {
			pid = 2;
		}
		
		
		
		var specials = new Request({
			url: path + 'index.php',
			method: 'post',
			data: 'mode=ajax&id=' + pid + '&reqCol=text, menuname',
			onComplete: function(response){
				txt = JSON.decode(response);
				if (txt.text.indexOf('[advent]') != -1) {
					txt.text = txt.text.replace('[advent]', '<a href="#" onclick="adventsK()"><img id="advent" style="cursor:pointer" src="' + root + 'images/advent.png" border="0" /></a>');
				}
			
				$$('#bc1 div')[0].set('html', txt.text);
			}
		}).send();
		
	}
    
    //INPUT HIGHLIGHTS
    var allinps = $('main').getElements('input');
    var fadein = function(){
		this.start({
			'background-color': '#ffffff'
		});
	}
    
    var fadeout = function(){
		this.start({
			'background-color': '#DFDFDF'
		});
	};
    
    //wetter
    if (pType == 'main' && theme == 'ti') {
		var reqData = {
			'get': 'ajax'
		};
		
		
		if (jsH > 12) {
			wicon = 'N';
		}
		else 
			if (jsH > 16) {
				wicon = 'A';
			}
			else {
				wicon = 'V';
			}
		
		new Request.JSON({
			url: path + 'includes/weather.php',
			method: 'post',
			data: 'mode=ajax&request=' + encodeURIComponent(JSON.encode(reqData)),
			onComplete: function(response){
				
				$('weather').set('html', '');
				
				try {

					response = response[0];

					var tmpkeys = Object.keys(response['tt']);
					var symbkeys = Object.keys(response['sy']);
					
					tmp = response['tt'][tmpkeys[0]][wicon];
					
					weathersymbol = response['sy'][symbkeys[0]][wicon];
					
					
					if (weathersymbol != undefined) {
						$('weather').setStyle('background-image', 'url(' + root + 'images/weather/' + weathersymbol + '.png)');
					}
					
					$('weather').addEvent('click', function(){
					
						var newani = new boxani();
						newani.tout(-1, 100, 170, 20, 500, 'close');
						if (lang == 'de') {
							setTimeout("followlink('" + path + "index.php?id=24')", 1300);
						} else if (lang == 'en') {
							setTimeout("followlink('" + path + "index.php?id=111')", 1300);
						} else if (lang == 'jp') {
							setTimeout("followlink('" + path + "index.php?id=849')", 1300);
						}else if (lang == 'cn') {
							setTimeout("followlink('" + path + "index.php?id=481')", 1300);
						}else if (lang == 'es') {
							setTimeout("followlink('" + path + "index.php?id=1173')", 1300);
						}else if (lang == 'pt') {
							setTimeout("followlink('" + path + "index.php?id=3485')", 1300);
						}else if (lang == 'fr') {
							setTimeout("followlink('" + path + "index.php?id=4726')", 1300);
						}
					});
					
					$('panel_val_temp').set('html', tmp + '&deg;C');
				}catch (err) {}
				
			},
			onRequest: function(){
				$('weather').set('html', '<div style="padding:8px 0 0 0"><img src="' + root + 'images/loader.gif" width="16" height="16"></div>');
				$('panel_val_temp').set('html', 'lade');
				
			}
		}).send();
		
	}
    
    
   /* $('lang_menu').addEvent('mouseenter', function(e){
    
        var blenddown = new Fx.Tween($('lang_menu'), {
            duration: 120
        });
        blenddown.start('height', $('lang_menu').getStyle('height'), "68px");
    });
    
    $('lang_menu').addEvent('mouseleave', function(e){
    
        var blenddown = new Fx.Tween($('lang_menu'), {
            duration: 120
        });
        blenddown.start('height', $('lang_menu').getStyle('height'), "15px");
    });*/
    
    
    if (Cookie.read("bg") != bgurl) {
	
		$('pic').setStyle('background-image', bgurl);
		
		$('pic').setStyle('opacity', 0);
		var blenddown = new Fx.Tween($('pic'), {
			duration: 300
		});
		blenddown.start('opacity', 0, 1);
		bgCookie = Cookie.write('bg', $('pic').getStyle('background-image'), {
			duration: 1
		});
	}
	else {
	
		$('pic').setStyle('background-image', bgurl);
		
	}
    
    
    //BANNER einlesen!
    if (pType == 'main' && theme != 'ti') {
		
		
		if (lang == 'de') {
			pid = 1;
		}
		else {
			pid = 2;
		}
		
	
		new Request.JSON({
			url: 'index.php',
			method: 'post',
			data: 'mode=ajax&id='+pid+'&reqCol=text, title',
			onComplete: function(response){
			
				//console.log(response)
				$$('#box_lastmin .hold')[0].set('html', response.text);
			}
		}).send();
		
		
	}
    
    
    
    //Reservations Button Aktion zuweisen
    
    /*$('btn_reservation').addEvent('click',function(e){
     createWin('Hotelreservation',resContent,'Hotelreservationen auf titlis.ch',358);
     });*/
    //Button Aktion zuweisen
    
    
    
    
    if ((pType == 'main' && theme == 'ti') || pType != 'main') {
		$('btn_erlebnisangebot').addEvent('click', function(e){
			var newani = new boxani();
			newani.tout(-1, 100, 170, 20, 500, 'close');
			if (lang == 'de') {
				setTimeout("followlink('" + path + "index.php?id=40')", 1300);
			}
			else 
				if (lang == 'en') {
					setTimeout("followlink('" + path + "index.php?id=128')", 1300);
				}
				else 
					if (lang == 'cn') {
						setTimeout("followlink('" + path + "index.php?id=498')", 1300);
					}
					else 
						if (lang == 'jp') {
							setTimeout("followlink('" + path + "index.php?id=866')", 1300);
						}
						else 
							if (lang == 'es') {
								setTimeout("followlink('" + path + "index.php?id=1189')", 1300);
							}
							else 
								if (lang == 'pt') {
									setTimeout("followlink('" + path + "index.php?id=3501')", 1300);
								}
								else 
									if (lang == 'fr') {
										setTimeout("followlink('" + path + "index.php?id=4743')", 1300);
									}
			
		});
		
		//Adventskalender
		try {
			$('advent').addEvent('click', function(){
				txt = '<div style="width:100%;height:100%;background-color:#000;text-align:center"><iframe src="' + root + 'kalender/index.html" width="800" height=100%" scrolling="auto" frameborder="0"></iframe></div>';
				createWin('Adventskalender', txt, 'Adventskalender 2009', 600);
			});
		} 
		catch (err) {
		}
		
		$('btn_erlebnisangebot').addEvent('click', function(e){
			if (pType == 'main') {
				var newani = new boxani();
				newani.tout(-1, 100, 170, 20, 500, 'close');
				if (lang == 'de') {
					setTimeout("followlink('" + path + "index.php?id=40')", 1300);
				}
				else 
					if (lang == 'en') {
						setTimeout("followlink('" + path + "index.php?id=128')", 1300);
					}
					else 
						if (lang == 'cn') {
							setTimeout("followlink('" + path + "index.php?id=498')", 1300);
						}
						else 
							if (lang == 'jp') {
								setTimeout("followlink('" + path + "index.php?id=866')", 1300);
							}
							else 
								if (lang == 'es') {
									setTimeout("followlink('" + path + "index.php?id=1189')", 1300);
								}
								else 
									if (lang == 'pt') {
										setTimeout("followlink('" + path + "index.php?id=3501')", 1300);
									}
									else 
										if (lang == 'fr') {
											setTimeout("followlink('" + path + "index.php?id=4743')", 1300);
										}
			}
			else {
				if (lang == 'de') {
					followlink(path + "index.php?id=40");
				}
				else 
					if (lang == 'en') {
						followlink(path + "index.php?id=128");
					}
					else 
						if (lang == 'cn') {
							followlink(path + "index.php?id=498");
						}
						else 
							if (lang == 'jp') {
								followlink(path + "index.php?id=866");
							}
							else 
								if (lang == 'es') {
									followlink(path + "index.php?id=1189");
								}
								else 
									if (lang == 'pt') {
										followlink(path + "index.php?id=3501");
									}
									else 
										if (lang == 'fr') {
											followlink(path + "index.php?id=4743");
										}
			}
		});
		
		$('btn_tickets').addEvent('click', function(e){
			txt = '<div style="position:absolute;top:25px;left:0;background-color:#F1F4F5;"><iframe src="https://axess.at/skipass.cx/skipass/oshop.php?locale=' + xLang + '&projectId=355&projectName=Engelberg" width="980" height="650" scrolling="auto" frameborder="0"></iframe></div>';
			createWin('tickets', txt, 'Tickets', 600);
			
		//window.open('<a href="https://axess.at/skipass.cx/skipass/oshop.php?locale=de&projectId=355&projectName=Engelberg" target="_blank">','Tickets');
		});
		
		$('btn_shop').addEvent('click', function(e){
			if (pType == 'main') {
				var newani = new boxani();
				newani.tout(-1, 100, 170, 20, 500, 'close');
				if (lang == 'de') {
					setTimeout("followlink('" + path + "index.php?id=1129')", 1300);
				}
				else 
					if (lang == 'en') {
						setTimeout("followlink('" + path + "index.php?id=1130')", 1300);
					}
					else 
						if (lang == 'cn') {
							setTimeout("followlink('" + path + "index.php?id=501')", 1300);
						}
						else 
							if (lang == 'jp') {
								setTimeout("followlink('" + path + "index.php?id=1131')", 1300);
							}
							
							else 
								if (lang == 'es') {
									setTimeout("followlink('" + path + "index.php?id=2278')", 1300);
								}
								else 
									if (lang == 'pt') {
										setTimeout("followlink('" + path + "index.php?id=4590')", 1300);
									}
									else 
										if (lang == 'fr') {
											setTimeout("followlink('" + path + "index.php?id=5745')", 1300);
										}
			}
			else {
				if (lang == 'de') {
					followlink(path + "index.php?id=1129");
				}
				else 
					if (lang == 'en') {
						followlink(path + "index.php?id=1130");
					}
					else 
						if (lang == 'cn') {
							followlink(path + "index.php?id=501");
						}
						else 
							if (lang == 'jp') {
								followlink(path + "index.php?id=1131");
							}
							
							else 
								if (lang == 'es') {
									followlink(path + "index.php?id=2278");
								}
								else 
									if (lang == 'pt') {
										followlink(path + "index.php?id=4590");
									}
									else 
										if (lang == 'fr') {
											followlink(path + "index.php?id=5745");
										}
			}
		});
		
		$('btn_passes').addEvent('click', function(e){
			if (pType == 'main') {
				var newani = new boxani();
				newani.tout(-1, 100, 170, 20, 500, 'close');
				if (lang == 'de') {
					setTimeout("followlink('" + path + "index.php?id=301')", 1300);
				}
				else 
					if (lang == 'en') {
						setTimeout("followlink('" + path + "index.php?id=347')", 1300);
					}
					else 
						if (lang == 'cn') {
							setTimeout("followlink('" + path + "index.php?id=717')", 1300);
						}
						else 
							if (lang == 'jp') {
								setTimeout("followlink('" + path + "index.php?id=1085')", 1300);
							}
							
							else 
								if (lang == 'es') {
									setTimeout("followlink('" + path + "index.php?id=1190')", 1300);
								}
								else 
									if (lang == 'pt') {
										setTimeout("followlink('" + path + "index.php?id=3502')", 1300);
									}
									/*
									else 
										if (lang == 'fr') {
											setTimeout("followlink('" + path + "index.php?id=')", 1300);
										}
										*/
			}
			else {
				if (lang == 'de') {
					followlink(path + "index.php?id=301");
				}
				else 
					if (lang == 'en') {
						followlink(path + "index.php?id=347");
					}
					else 
						if (lang == 'cn') {
							followlink(path + "index.php?id=717");
						}
						else 
							if (lang == 'jp') {
								followlink(path + "index.php?id=1085");
							}
							
							else 
								if (lang == 'es') {
									followlink(path + "index.php?id=1190");
								}
								
								else 
									if (lang == 'pt') {
										followlink(path + "index.php?id=3502");
									}
									/*
									else 
										if (lang == 'fr') {
											followlink(path + "index.php?id=");
										}
										*/
			}
		});
		
		
	}


	if (pType == 'main' && theme != 'ti'){
		
		 $('mediapic').setStyle('cursor', 'pointer');
		
		 $('mediapic').addEvent('click', function(e){
       	 MediaGallery();
		});
		
	}else{
		 $('btn_Pics').addEvent('click', function(e){
       		 MediaGallery();
    	});
	}
	
    if ($('date2') != null) {
		if ($('date2').value == '') {
			$('date2').value = ndy;
		}
	}
	
	
	new DatePicker($('date1'),{days:['Sonntag','Montag','Dienstag','Mittwoch','Donnerstag','Freitag','Samstag'],months:['Januar','Februar','März','April','Mai','Juni','Juli','August','September','Oktober','November','Dezember'],format:'d.m.Y',inputOutputFormat:'Ymd',pickerClass:'datepicker_jqui'});
	new DatePicker($('date2'),{days:['Sonntag','Montag','Dienstag','Mittwoch','Donnerstag','Freitag','Samstag'],months:['Januar','Februar','März','April','Mai','Juni','Juli','August','September','Oktober','November','Dezember'],format:'d.m.Y',inputOutputFormat:'Ymd',pickerClass:'datepicker_jqui'});
	
	

	
$('btn_reservation').addEvent('click', function(e){
		
		try{
			if($('date1').value == ''){
		
				aDate = tdy;
			}else{
				aDate = $('date1').value;
			}
			if($('date2').value == ''){
				dDate = ndy;
			}else{
				dDate = $('date2').value ;
			}	
		}catch(err){
			aDate = tdy;
			dDate = ndy;
		}
		
	
		if (theme == 'ti') {
			txt = '<div style="position:absolute;top:25px;left:0;background-color:#F1F4F5;"><iframe src="http://www.titlis.ch/proTel/index.php?applanguage=' + xLang + '&arrdate=' + aDate + '&Depdate=' + dDate + '&number=' + $('zimmer').value + '" width="980" height="650" scrolling="auto" frameborder="0"></iframe></div>';
				//txt = '<div style="position:absolute;top:25px;left:0;background-color:#F1F4F5;"><iframe src="https://booking.titlis.ch/" width="980" height="650" scrolling="auto" frameborder="0"></iframe></div>';
		
		}
		else 
			if (theme == 'te') {
			
				txt = '<div style="position:absolute;top:25px;left:0;background-color:#F1F4F5;"><iframe src="https://booking.titlis.ch/booking/Booking_test/reserv.aspx?hotelref=3&applanguage=' + xLang + '&arrdate=' + aDate + '&Depdate=' + dDate + '&number=' + $('zimmer').value + '" width="980" height="650" scrolling="auto" frameborder="0"></iframe></div>';
			}
			else 
				if (theme == 'tr') {
					txt = '<div style="position:absolute;top:25px;left:0;background-color:#F1F4F5;"><iframe src="https://booking.titlis.ch/booking/Booking_test/reserv.aspx?hotelref=2&applanguage=' + xLang + '&arrdate=' + aDate + '&Depdate=' + dDate + '&number=' + $('zimmer').value + '" width="980" height="650" scrolling="auto" frameborder="0"></iframe></div>';
				}
		
		//txt = 'down for maintenance';
		
        createWin('reservation', txt, 'Reservation', 600);
    });
    
    //Scroller
	if (pType != 'main' && shop != 'true') {
		$('track').setStyle('display', 'none');
		$('thumb').setStyle('display', 'none');
		
		makeScrollbar($('content_text'), $('track'), $('thumb'));
		
	}
    
    
//    getScreen();

	if (tags) {
	
		if (tags.live == 1) {
			new Accordion($$('div.toggler'), $$('div.element'), {
				display: 0,
				opacity: 0,
				onActive: function(toggler, element){
					toggler.getChildren()[0].set('src', root + 'images/minus.gif');
				},
				onBackground: function(toggler, element){
					toggler.getChildren()[0].set('src', root + 'images/plus.gif');
				},
				onComplete: function(){
				
				
					if (pType != 'main') {
						steps = -2;
						makeScrollbar($('content_text'), $('track'), $('thumb'));
					}
				}
			});
		}
	}
});

function headNavAni(){
	
	me = $('headnav');
	
	showHeadNav = new Fx.Morph(me,{
		duration: 4000
		,transition: Fx.Transitions.Pow.easeOut

	});
	
	showHeadNav.start({
		
		'height': 50
	})
	
	
}


function makePans(){

	$$('#content_text img').each(function(im){
	
		if (im.src.indexOf('pan_') != -1) {
		
			im.setStyle('cursor', 'pointer');
			
			panNo = im.src.split('_');
			panNo = panNo[2].replace('.jpg', '');
			
			im.addEvent('click', function(){
				txt = '<div style="width:100%;height:100%;text-align:center"><iframe src="http://www.titlis.ch/_rundgang/rotair/html/' + panNo + '.html" width="400" height=100%" scrolling="no" frameborder="0"></iframe></div>';
				createWin('Panorama', txt, 'Panorama', 400);
			})
		}
	})
}

function make360(){
	
	$$('#content_text img').each(function(im){
			
		if(im.src.indexOf('round_')!=-1){
		
			im.setStyle('cursor','pointer');
			
			im.addEvent('click',function(){
				txt = '<div style="width:100%;height:100%;text-align:center"><iframe src="http://www.titlis.ch/panorama/multires.html" width="800" height=100%" scrolling="no" frameborder="0"></iframe></div>';
				createWin('Panorama', txt, 'Panorama', 600);
			})
		}
	})
}

function adventsK(){

	txt = '<div style="width:100%;height:100%;background-color:#000;text-align:center"><iframe src="' + root + 'kalender/index.html" width="800" height=100%" scrolling="auto" frameborder="0"></iframe></div>';
	createWin('Adventskalender', txt, 'Adventskalender 2009', 600);
	
}

function followlink(link){
//	console.log(link)
	window.location.href = link;
}

function showWeather(){
	
	
	
	
	hr = jsH;
	
	//console.log(jstime);
	var reqData = {
		'get': 'ajax'
	};
	new Request.JSON({
		url: path + 'includes/weather.php',
		method: 'post',
		data: 'mode=ajax&request=' + encodeURIComponent(JSON.encode(reqData)),
		onComplete: function(response){
		
			try {
				var response = response[0];
				tab = new Element('table', {
					'id': 'weatherTable',
					'cellpadding': '0',
					'cellspacing': '0',
					'border': '0',
					'width': '420',
					'height': '1%'
				});
				
				
				try {
					tab.injectBefore($$('div.text')[0]);
				} 
				catch (err) {
					tab.injectInside($('content_text'));
				}
				
				
				// tab.injectBefore($('betrieb'));
				
				thead = new Element('thead').inject(tab);
				tbody = new Element('tbody').inject(tab);
				
				headTR = new Element('tr').injectInside(thead);
				
				if (lang == 'de') {
					dtimes = ['Vormittag', 'Nachmittag', 'Abend'];
				}else if(lang == 'fr'){
					dtimes = ['Le matin', 'L’après-midi', 'Le soir'];
				}
				else {
					dtimes = ['Morning', 'Afternoon', 'Evening'];
				}
				
				for (p = 0; p < 3; p++) {
					headTD = new Element('td', {
						'html': '<b>' + dtimes[p] + '</b>',
						'align': 'center',
						'styles': {
							'padding': '5px 0 5px 6px',
							'background-image': 'url(' + root + 'images/dateheader.png)',
							'color': '#fff'
						}
					
					}).injectInside(headTR);
				}
				
				n = 0;
				p = 0;
				x=0;
				
				Object.keys(response['tt']).each(function(dayWeather,keyWeather){
					trday = new Element('tr').injectInside(tbody);
					wDate = dayWeather.split('-');
					
					if (parseInt(pwday) + p > 6) {
						p = 0;
						pwday = 0;
						
						
						if (lang == 'de') {
							tag = daysA[0];
						}else if(lang == 'fr'){
							tag = daysAf[0];
						}
						else {
							tag = daysAe[0];
						}
						
						
						
						
					}
					else {
						
						
						
						if (lang == 'de') {
							tag = daysA[parseInt(pwday) + p];
						}else if(lang == 'fr'){
							tag = daysAf[parseInt(pwday) + p];
						}
						else {
							tag = daysAe[parseInt(pwday) + p];
						}
						
						
					}
					
					d = wDate[2].split(' ');
					
					if (lang == 'de'){
						wDate = tag + ', ' + d[0] + '. ' + monthsA[parseInt(wDate[1], 10) - 1] + ' ' + wDate[0];
					}else if(lang == 'fr'){
						wDate = tag + ', ' + d[0] + '. ' + monthsAf[parseInt(wDate[1], 10) - 1] + ' ' + wDate[0];
					}else{
						wDate = tag + ', ' + d[0] + '. ' + monthsAe[parseInt(wDate[1], 10) - 1] + ' ' + wDate[0];
					}
					
					
					
					
					tdday = new Element('td', {
						'html': wDate,
						'bgcolor': '#eeeeee',
						'colspan': 3,
						'styles': {
							'padding': '4px 0 4px 4px'
						}
					
					}).injectInside(trday);
					p++;
					x = keyWeather;
					tr = new Element('tr').injectInside(tbody);
					var dtimes = ['V','N','A'];
					
					var tmpkeys = Object.keys(response['tt']);
					var symbkeys = Object.keys(response['sy']);
					
					for (i = 0; i < 3; i++) {
						var weathersymbol = response['sy'][symbkeys[keyWeather]][dtimes[i]];
						td = new Element('td', {
							'html': '<img src="' + root + 'images/weather/' + weathersymbol + '.png">',
							'width': '140',
							'align': 'center',
							'styles': {
								'padding': '5px 0',
								'border-bottom': '1px #ccc solid'
							}
						}).injectInside(tr);
					}
					tr = new Element('tr').injectInside(tbody);
					for (i = 0; i < 3; i++) {
						var tmp = response['tt'][tmpkeys[keyWeather]][dtimes[i]];
						td = new Element('td', {
							'html': tmp + '&deg;C',
							'width': '140',
							'align': 'center',
							'styles': {
								'padding': '5px 0',
								'border-bottom': '1px #fff solid'
							}
						}).injectInside(tr);
					}
					if (keyWeather % 2 == true) n = n + 3;
				});
			} 
			catch (err) {
				c(err)
			}
		},
		onRequest: function(){}
	}).send();
}



//BOXANIMATIONSKLASSE für Startseiten
var anistat = 'closed';

function boxani(){

	this.ani = function(it, marg, h, dur, direction){
	
		if ((anistat == 'closed' && marg == 0) || (anistat == 'open' && marg == 170)) {
		
			it++;
			
			var boxes = $$('#boxes .bani');
			
			if (it < stepb) {
			
				if (direction == 'close') {
					var dur1 = dur
					var dur2 = dur / 2
				}
				else {
					var dur2 = dur
					var dur1 = dur / 2
				}
				
				var morphElement = boxes[it];
				var morphObject = new Fx.Morph(morphElement, {
					fps: 60,
					duration: dur2,
					onComplete: function(){
					
						var morphObject2 = new Fx.Morph(morphElement, {
							fps: 60,
							duration: dur1,
							onComplete: function(){
							
								if (marg == 170) {
									anistat = 'closed';
								}
								else {
									anistat = 'open'
									
								}
							}
						});
						
						if (direction == 'close') {
							morphObject2.start({
								'margin-top': marg
							});
						}
						else {
							morphObject2.start({
								'height': h
							});
						}
						
					}
					
				});
				
				if (direction == 'close') {
					morphObject.start({
						'height': h
					});
				}
				else {
					morphObject.start({
						'margin-top': marg
					});
				}
				
				var t = 10;
				this.tout(it, t, marg, h, dur, direction);
				
			}
		}
	}
	
	this.tout = function(it, t, marg, h, dur, direction){
	
		var newani = new boxani();
		setTimeout(function(){
			newani.ani(it, marg, h, dur, direction);
		}, t);
		
	}
	
}


function collectionToArray(collection)
{
	var ary = [];
	for(var i=0, len = collection.length; i < len; i++)
	{
		ary.push(collection[i]);
	}
	return ary;
}


Array.implement('clone', function(){
	var i = this.length, clone = new Array(i);
	while (i--) clone[i] = cloneOf(this[i]);
	return clone;
});


var cloneOf = function(item){

	switch ($type(item)){
		case 'array': return item.clone();
		case 'object': return Object.clone(item);
		default: return item;
	}
};
Object.extend({

	clone: function(object){
		var clone = {};
		for (var key in object) clone[key] = cloneOf(object[key]);
		return clone;
	}


});

var date_sort_asc = function(date1, date2){
	if (date1.ld.datumOB > date2.ld.datumOB) 
		return 1;
	if (date1.ld.datumOB < date2.ld.datumOB) 
		return -1;
	return 0;
}


function createEventsInclMulti(allEvents){
	var sortedEvents = [];
				
	//ERWEITERUNG MULTIDATUM
	allEvents.each(function(ev){
		
		//Wenn Multidatum ausgefüllt
		if(ev.ld.multi && ev.ld.multi.text[0] != '' && ev.ld.multi.text[0] != '<br>'){

			var allMulti =  ev.ld.multi.text[0].split('<br>');
			allMulti.erase('');
			
			allMulti.each(function(md,key){
				
				
				var md = md.replace('&#8203;','');
				
				md = md.split('.');
				
				var stD = md[2]+'-'+md[1]+'-'+md[0]+' 00:00:00';
				
				
				md = new Date(md[2].toInt(), md[1].toInt()-1, md[0].toInt())
				
				
			
				
				if(md >= jstime){
					var newEv = Object.clone(ev);
				
					newEv.ld.datumOB = md;
					
					newEv.ld.accID = ev.ld.id+'_'+(key+1);
					
					newEv.ld.datum = stD;
					
					sortedEvents.push(newEv)
				}
				
				
			})
			
		}
		
		//Wenn Datumsfeld ausgefüllt
		if (ev.ld.datum != '0000-00-00 00:00:00') {
			
			
			var md = ev.ld.datum.split(' ');
			md = md[0].split('-');;
			var stD = md[0]+'-'+md[1]+'-'+md[2]+' 00:00:00';
			
			md = new Date(md[0].toInt(), md[1].toInt()-1, md[2].toInt())
			
			
			
			if (md >= jstime) {

				var newEv = Object.clone(ev);
				newEv.ld.accID = ev.ld.id+'_'+(0);
				newEv.ld.datumOB = md;
				newEv.ld.datum = stD;
				
				sortedEvents.push(newEv)
			}
		}
		
		
	})
	//sortieren
	sortedEvents.sort(date_sort_asc)
	
	return sortedEvents;
}


//Start-und Folgeseite Anzeige Events in Boxen
function showEventsBox(){


	//alert(lang);	
	var reqData = {
		'type': 'all',
		'user': 'titlis3',
		'table': {
			'listings_events': 'l',
			'listingrows_events': 'lr',
			'listingdatas_events': 'ld'
		},
		'condition': {
			//'ld.title': 'Knorrli Erlebnistag mit Muisig Zmorgä'
			'ld.status': '1'
		},
		'fields': 'ld.datum,ld.title,ld.multi,ld.id',
		
		'language': xLang
	};
	
	//reqData.condition['ld.datum >= NOW() - INTERVAL 1 DAY AND ld.datum != '] = 'x';
	
	var allEv = new Request({
		url: path + 'index.php',
		method: 'post',
		data: 'mode=verzeichnis&local=0&debug=1&request=' + encodeURIComponent(JSON.encode(reqData)),
		onComplete: function(response){
		
		
			if (pType == 'main') {
				$$('#box_event div.hold')[0].set('html', '');
			}
			
			if (lang == 'de') {
				pid = 33;
			}
			else 
				if (lang == 'en') {
					pid = 120;
				}
				else 
					if (lang == 'cn') {
						pid = 490;
					}
					else 
						if (lang == 'jp') {
							pid = 858;
						}
						
						else 
							if (lang == 'es') {
								pid = 1182;
							}
							
							else 
								if (lang == 'pt') {
									pid = 3494;
								}
								else 
									if (lang == 'fr') {
										pid = 4735;
									}
							
							
							
			
			response = JSON.decode(response);
			allEvents = response.result;
			
			
			var sortedEvents = createEventsInclMulti(allEvents);
			
			
			
			
			sortedEvents = sortedEvents.slice(0,3)
			
			
			var allEvents = sortedEvents;
			
			
			dNow = new Date();
			allEvents.each(function(e, key){
			
				padT = key == 0 ? 0 : 8;

				
				wDate = e.ld.datum.split('-');
				d = wDate[2].split(' ');
				
				
				wDate[1] = wDate[1].replace(/^(0+)/g, '');
				
				if (lang == 'de') {
					var evDate = d[0] + '. ' + monthsA[parseInt(wDate[1]) - 1] + ' ' + wDate[0];
				}
				else {
					var evDate = d[0] + '. ' + monthsAe[parseInt(wDate[1]) - 1] + ' ' + wDate[0];
				}
				
				
				var tmpM = parseInt(wDate[1]) < 10 ? '0'+parseInt(wDate[1]) : parseInt(wDate[1]);
				
				cDate = evDate = d[0] + '.' + (tmpM) + '.' + wDate[0];
				
				
				
				if (pType == 'main') {
					tmp = $$('#box_event div.hold')[0].get('html');
					$$('#box_event div.hold')[0].set('html', tmp + '<div style="padding:' + padT + 'px 0 0 0"><a href="#" onclick="openEvent(\'index.php?id=' + pid + '\',\'' + e.ld.accID + '\');return false"><b>' + evDate.replace('ae', 'ä') + '</b> ' + e.ld.title + '</a></div>');
				}
				else {
					tmp = $$('#bc4 .hold')[0].get('html');
					$$('#bc4 .hold')[0].set('html', tmp + '<div style="padding:' + padT + 'px 0 0 0"><a href="#" onclick="openEvent(\'index.php?id=' + pid + '\',\'' + e.ld.accID + '\');return false"><b>' + evDate.replace('ae', 'ä') + '</b> '+ e.ld.title + '</a></div>');
				}
				
			});
			
			if (lang == 'de') {
				str = 'Alle Events anzeigen';
			}
			else {
				str = 'Show all events';
			}
			
			
			if (Browser.Engine.name != "trident" && Browser.Platform.mac == true){
				p = '<br/>';
			}else{
				p = '<br/><br/>'
			}
			
			if (pType == 'main') {
				tmp = $$('#box_event div.hold')[0].get('html');
				$$('#box_event div.hold')[0].set('html', tmp + p+'<button style="position:absolute;top:162px;" onclick="followlink(\'' + path + 'index.php?id=' + pid + '\')">' + str + '</button>');
			}
			else {
				tmp = $$('#bc4 .hold')[0].get('html');
				 
				$$('#bc4 .hold')[0].set('html', tmp + p+'<button onclick="window.location.href=\'' + path + 'index.php?id=' + pid + '\'">' + str + '</button>');
			}
			
			
		},
		onRequest: function(){
			if (pType == 'main') {
				$$('#box_event div.hold')[0].set('html', 'lade Events...');
			}
		}
	}).send();
}

//Klick auf Event 
function openEvent(page, evId){
	
	if (pType == 'main') {
		var newani = new boxani();
		newani.tout(-1, 100, 170, 20, 500, 'close');
		setTimeout("followlink('" + path + page + "&evId=" + evId + "')", 1300);
	}
	else {
		followlink(path + page + "&evId=" + evId);
	}
	
}

//Events anzeigen, aktueller Monat oder gewählter Event
function showAllEvents(){
	

if(window.location.href.contains('evId')){
	var eurl = window.location.href.split('&evId=');
		
	var chId = eurl[1];

	
	
}else{
	var chId=0;
}


	
	//mod = "Events";
	
	var reqData = {
		'type': 'all',
		'user': 'titlis3',
		'table': {
			'listings_events': 'l',
			'listingrows_events': 'lr',
			'listingdatas_events': 'ld'
		},
		
		'condition': {
			//'ld.title': 'Knorrli Erlebnistag mit Muisig Zmorgä'
			
			'ld.status': '1'
			
			
		},
		
		'fields': 'ld.*,lr.*,l.rowID',
		'language': xLang
	};
	
	
	var allEv = new Request({
		url: path + 'index.php',
		method: 'post',
		data: 'mode=verzeichnis&local=0&debug=1&request=' + encodeURIComponent(JSON.encode(reqData)),
		onComplete: function(response){
			
			response = JSON.decode(response);
			var allEvents = response.result;
			
			
			var sortedEvents = createEventsInclMulti(allEvents);
			
			allEvents = sortedEvents;
			
			
			actM = tdy.substr(4, 2).toInt();
			actY = tdy.substr(0, 4).toInt();
			actD = tdy.substr(6, 2).toInt();
			
			//wenn bestimmter event von startseite angeklickt
			
			if (chId != 0) {
				
				
				/*if (!chId.contains('_')) {
					chId = chId+'_0';
				}*/
				
				var multiCounter = 0;
				
				allEvents.each(function(item){
					
					if (item.ld.id == chId) {
					
						
						try{
							var md = item.ld.datum.split('.');
						
							md = new Date(md[2].toInt(), md[1].toInt() - 1, md[0].toInt())
						}catch(e){
							var md = item.ld.datum.split(' ');
							md = md[0].split('-');;
							var stD = md[0]+'-'+md[1]+'-'+md[2]+' 00:00:00';
							
							md = new Date(md[0].toInt(), md[1].toInt()-1, md[2].toInt())
						}

						
						if (md >= jstime) {
						
							chId = chId+'_'+multiCounter;
		
						}else{
							multiCounter++;
						}
					}
				})

				allEvents.each(function(item){
					
					if (item.ld.accID == chId) {
						var deskDate = item.ld.datum.split('-');
						

						chMonth = deskDate[1];
						chYear = deskDate[0];
					}
				})

			}
			

			try {
				actM = chMonth;
				actY = chYear;
			} 
			catch (err) {
			}
			
			//Eventsbutton für PDF-Generierung
		
			if (lang == 'de') {
				st = 'Events als RSS abonnieren';
			}
			else {
				st = 'RSS';
			}
			
			rss = new Element('div', {
				'html': '<a id="rsscount" href="http://www.titlis.ch/includes/titlis_events_' + xLang + '.xml" target="_blank"><img style="" src="' + root + 'images/rss.png" border="0"/></a>',
				'styles': {
					'height': 30
					,'margin-left':230
					,'float': 'left'
				}
			});
			
			rss.injectInside($('content_text'));
			
			$('rsscount').addEvents({
				'click': function(){
					new Request({
						url: path + 'includes/socialcounter.php',
						method: 'post',
						data: 'mode=ajax&request=rss',
						onComplete: function(response){
						
						}
					}).send();
				}
			});
			
				
			new Element('img', {
				'id': 'eBtn',
				'src': root + 'images/eBtn.jpg',
				'width': 150,
				'height': 22,
				
				'styles': {
					'float': 'left',
					'margin-left':20
					,'cursor': 'pointer'
				},
				events: {
					'click': function(){
					
						//window.location.href = 'http://www.titlis.ch/pdfgen/events.php?month='+tmp
						n = 'http://www.titlis.ch/pdfgen/events.php?month=' + actM +'&year='+actY;
						window.open(n, 'titlis', "");
						
					}
				}
			
			}).injectInside($('content_text'));
			
			
			cle = new Element('div', {
				'styles': {
					'clear': 'both'
				}
			});
			
			cle.injectInside($('content_text'));
			
			prv = new Element('div', {
				'styles': {
					'float': 'left',
					'height': 21,
					'width': 30,
					'background-image': 'url(' + root + 'images/media_prv.png)',
					'cursor': 'pointer'
				},
				'events': {
					'click': function(){
					
						showMonth('prev', sortedEvents);
						
					}
				}
			});
			
			prv.injectInside($('content_text'));
			
			monthdiv = new Element('div', {
				'id': 'mnthdiv',
				'styles': {
					'float': 'left',
					'height': 20,
					'padding': '1px 0 0 0',
					'font-size': '12px',
					'font-weight': 'bold',
					'width': 360,
					'background-image': 'url(' + root + 'images/dateheader.png)',
					'text-align': 'center',
					'color': '#fff'
				}
			});
			
			monthdiv.injectInside($('content_text'));
			
			
			
			if (lang == 'de') {
				mT = monthsA[(actM - 1)] + ' ' + actY;
			}
			else {
				mT = monthsAe[(actM - 1)] + ' ' + actY;
				
			}
			
			monthtxt = new Element('div', {
				'id': 'mnthtxt',
				'styles': {
					'padding-top': '3px',
					'color': '#fff'
				},
				'html': mT
			});
			
			monthtxt.injectInside(monthdiv);
			
			nxt = new Element('div', {
				'styles': {
					'float': 'left',
					'height': 21,
					'width': 30,
					'background-image': 'url(' + root + 'images/media_nxt.png)',
					'cursor': 'pointer'
				},
				'events': {
					'click': function(){
					
						showMonth('nxt', sortedEvents);
						
					}
				}
			});
			
			nxt.injectInside($('content_text'));
			
			cle = new Element('div', {
				'styles': {
					'clear': 'both'
				}
			});
			
			cle.injectInside($('content_text'));
			
			resDiv = new Element('div', {
				'id': 'resDiv',
				'styles': {
					'width': 420
				}
			});
			
			resDiv.injectInside($('content_text'));
			
			
			mainDl = new Element('dl', {
				'id': 'acc'
			});
			
			mainDl.injectInside($('resDiv'));
			
			secDl = new Element('dl', {
				'id': 'secDl',
				'styles': {
					'margin': 0,
					'padding': 0
				}
			});
			
			secDl.injectInside(mainDl);
			
			counter = 0;
			chElement = 0;
			
			allEvents.each(function(e, key){
							actM = tdy.substr(4, 2);
				actY = tdy.substr(0, 4);
				actD = tdy.substr(6, 2);
				
				//wenn bestimmter event von startseite angeklickt
				try {
					actM = chMonth;
					actY = chYear;
				} 
				catch (err) {
				}
				
				eDatum = e.ld.datum.split('-');
				
				d = eDatum[2].split(' ');
				//eMonth = parseInt(eDatum[1]);
				eYear = eDatum[0];
				eDay = d[0];
				eMonth = eDatum[1].replace(/^(0+)/g, '');

				

				
				if (actM.toInt() == eMonth.toInt() && actY.toInt() == eYear.toInt()) {
					try {
						if (chId == e.ld.accID) {
							chElement = counter;
						}
					} 
					catch (err) {
					}
					
					
					var tmpM = parseInt(eMonth) < 10 ? '0'+parseInt(eMonth) : eMonth;
				
			
				
					
					eventDate = eDay + '.' + tmpM + '.' + eYear;
					
				
					
					qurl = escape('http://www.titlis.ch/index.php?id='+pid+'&evId='+e.ld.accID+'&evd='+eventDate+'&mode=mobile&mlang='+xLang+'#ev');
					
					var qrTag = window.location.href.contains('showQR') ? ' <a target="_blank" href="http://api.qrserver.com/v1/create-qr-code/?size=500x500&data='+qurl+'">QR-TAG</a>' : '';
					
					
					
					evDiv = new Element('dt', {
						'html': '<div style="float:left"><b>' + eventDate + '</b></div><div style="float:left;padding:0 0 0 38px">' + e.ld.title + qrTag+'</div>',
						'styles': {
							'height': 14,
							'width': 400,
							'margin': '1px 0 0 0',
							'padding': '3px 10px 3px 10px',
							'background-color': '#EFEFEF',
							'cursor': 'pointer'
						}
					});
					
					evDiv.injectInside(secDl);
					
					try {
						txt = e.ld.text;
						if (lang == 'de') {
							infolink = 'mehr Informationen';
						}
						else {
							infolink = 'more information';
						}
						
						if (txt.text[0].length > 180) {
							shortText = txt.text[0].substr(0, 180) + '...<br/>[<a href="#" onclick="openDetailVerz(\'eventInfo\',' + e.ld.id + ',\'events\');return false;">' + infolink + '</a>]<br/><br/>';
						}
						else {
							shortText = txt.text[0];
						}
					} 
					catch (err) {
						if (lang == 'de') {
							shortText = "Informationen zu diesem Event folgen in Kürze.<br/><br/>";
						}
						else {
							shortText = "information about this event will follow in short time.<br/><br/>";
						}
					}
					
					if (e.ld.pictures != "") {
					
						ASDpic = e.ld.pictures;
						picKl = '<div style="float:left;margin-bottom:0px;"><img style="padding:2px;" src="' + tmpDir + '80_verz_' + ASDpic.media[0].name + '"/></div>';
						
					}
					else {
						picKl = '';
					}
					
					evCont = new Element('dd', {
						'html': '<div style="padding:10px 0 10px 0">' + picKl + '<div style="float:left;width:310px;padding-left:20px;margin-bottom:0px">' + shortText + '</div></div><div style="clear:both"></div>',
						'styles': {
							'overflow-x': 'hidden',
							'overflow-y': 'hidden',
							'height': '15px',
							'margin': 0
						}
					});
					
					evCont.injectInside(secDl);
					
					counter++;
				}
			});
			
			if (xLang == 'de') {
				noE = 'keine aktuellen Einträge in diesem Monat';
			}
			else {
				noE = 'no entries found';
			}
			
			if (counter == 0) {
				evDiv = new Element('div', {
					'html': noE,
					'styles': {
						'padding': '20px 0 0 0',
						'font-weight': 'bold',
						'color': '#C0001E'
					}
				
				}).injectInside(secDl);
				
				
			}
			
			new Accordion($$('dl#acc dt'), $$('dl#acc dd'), {
				display: chElement,
				opacity: 0,
				onComplete: function(){
				
					steps = -2;
					makeScrollbar($('content_text'), $('track'), $('thumb'));
					
					
				}
			});
			
			if(chElement != 0){
				(function(){
					openId = chId.split('_');
					openId = openId[0];
					openDetailVerz('eventInfo', openId ,'events');
					return false;
				}).delay(200)
			}
		}
	}).send();
}

//Aktivitäten anzeigen
function showActivities(season,ldID,lrID){
	
	if (season != 'direct') {
		var reqData = {
			'type': 'all',
			'user': 'titlis3',
			'table': {
				'listings': 'l',
				'listingrows': 'lr',
				'listingdatas': 'ld'
			},
			
			'condition': {
				'ld.status': '1',
				'lr.rubrikname': season
			},
			
			'fields': 'ld.*,lr.*,l.rowID',
			'order': 'ld.position ASC',
			'language': cLang
		};
	}
	else{
		var reqData = {
			'type': 'all',
			'user': 'titlis3',
			'table': {
				'listings': 'l',
				'listingrows': 'lr',
				'listingdatas': 'ld'
			},
			
			'condition': {
				'lr.id': lrID
			},
			
			'fields': 'ld.*,lr.*,l.rowID',
			'order': 'ld.position ASC',
			'language': cLang
		};
	}
	
	
	var allAct = new Request({
		url: path + 'index.php',
		method: 'post',
		data: 'mode=verzeichnis&local=0&debug=0&request=' + encodeURIComponent(JSON.encode(reqData)),
		onComplete: function(response){
		
			response = JSON.decode(response);
			allActivities = response.result;
			
			titleDiv = new Element('div', {
				'id': 'mnthdiv',
				'styles': {
					'height': 20,
					'padding': '1px 0 0 0',
					'font-size': '12px',
					'font-weight': 'bold',
					'width': 420,
					'background-image': 'url(' + root + 'images/dateheader.png)',
					'text-align': 'center',
					'color': '#fff'
				}
			});
			if(season=='direct'){
				season = allActivities[0].lr.rubrikname;
			}
			titleDiv.injectInside($('content_text'));
			
			titletxt = new Element('div', {
				'id': 'mnthtxt',
				'styles': {
					'padding-top': '3px',
					'color': '#fff'
				},
				'html': season
			});
			
			titletxt.injectInside(titleDiv);
			
			resDiv = new Element('div', {
				'id': 'resDiv',
				'styles': {
					'margin': 0,
					'padding': 0,
					'position': 'relative',
					'width': 420
				}
			});
			
			resDiv.injectInside($('content_text'));
			
			
			mainDl = new Element('dl', {
				'id': 'acc',
				'styles': {
					'margin': 0,
					'padding': 0
				}
			
			});
			
			mainDl.injectInside($('resDiv'));
			
			secDl = new Element('dl', {
				'id': 'secDl',
				'styles': {
					'margin': 0,
					'padding': 0
				}
			});
			
			secDl.injectInside(mainDl);
			
			
			allActivities.each(function(e){
				evDiv = new Element('dt', {
					'html': '<b>' + e.ld.titel + '</b>',
					'id': e.ld.id,
					'styles': {
						'height': 14,
						'width': 400,
						'margin': '1px 0 0 0',
						'padding': '3px 10px 3px 10px',
						'background-color': '#EFEFEF',
						'cursor': 'pointer'
					}
				});
				
				evDiv.injectInside(secDl);
				
				
				try {
					txt = e.ld.text;
					if (lang == 'de') {
						infolink = 'mehr Informationen';
					}
					else {
						infolink = 'more information';
					}
					
					if (txt.text[0].length > 180) {
						shortText = txt.text[0].substr(0, 180) + '...<br/>[<a href="#" onclick="openDetailVerz(\'eventInfo\',' + e.ld.id + ',\'activities\');return false;">' + infolink + '</a>]<br/><br/>';
					}
					else {
						shortText = txt.text[0];
					}
				} 
				catch (err) {
					if (lang == 'de') {
						shortText = "Informationen zu diesem Event folgen in Kürze.<br/><br/>";
					}
					else {
						shortText = "information about this event will follow in short time.<br/><br/>";
					}
				}
				
				if (e.ld.bilder != "") {
					ADpic = e.ld.bilder;
					picKl = '<div style="float:left;margin-bottom:10px;"><img style="padding:2px;" src="' + tmpDir + '80_verz_' + ADpic.media[0].name + '"/></div>';
					
				}
				else {
					picKl = '';
					
				}
				
				evCont = new Element('dd', {
					'html': '<div style="padding:10px 0 10px 0">' + picKl + '<div style="float:left;width:300px;padding-left:20px;margin-bottom:0px">' + shortText + '</div></div><div style="clear:both"></div>',
					'styles': {
						'overflow-x': 'hidden',
						'overflow-y': 'hidden',
						'height': '15px',
						'margin': 0
					}
				});
				
				evCont.injectInside(secDl);
				
				
			});
			var nr= 0;
			ldID = window.location.href.split('_')[window.location.href.split('_').length-1]
			$$('dl#acc dt').each(function(headTitle,key){
				if(headTitle.id==ldID){
					nr=key;
				}
			});
						
			new Accordion($$('dl#acc dt'), $$('dl#acc dd'), {
				
				display: nr,
				opacity: 0
			});
			
		}
		
	}).send();
	
}

var dNext;
var dirC = 0;
var stopper;

 var actM = tdy.substr(4,2);
 var actY = tdy.substr(0,4);
  var actD = tdy.substr(6,2);

//Eventmodul Monat anzeigen -> Direktlink auf Event
function showMonth(dir, response){
	
    allEvents = response;
    
    if (dir == 'nxt') {
       actM = actM.toInt()+ 1;
    }
    else {
       actM = actM.toInt()- 1;
    }
	
     
     
     if(actM < 10)actM = '0'+actM;
  
     
     if(actM.toInt() > 12){
     	actM = '01';
	actY = actY.toInt()+1;
     }
     
     if(actM.toInt() < 1){
     	actM = 12;
	actY = actY.toInt()-1;
     }
	
	
	
    dNext = actY+''+actM+''+actD;
    
    $('eBtn').removeEvent('click');
    $('eBtn').addEvents({
    	'click': function(){
		
		window.location.href = 'http://www.titlis.ch/pdfgen/events.php?month='+actM
	}
    })
    
   
    
    if (dNext.toInt() >= tdy.toInt()) {
    
        $('resDiv').empty();
        
        morphElement = $('mnthtxt');
        morphObject = new Fx.Morph(morphElement, {
            fps: 60,
            duration: 400,
            onComplete: function(){
	    	
		
		  if(lang == 'de'){
	    	 mT = monthsA[(actM-1)] + ' '+ actY;
	    }else{
	    	 mT = monthsAe[(actM-1)] + ' '+ actY;;
	    }
		
                $('mnthtxt').set('html', mT );
                
			
		
                morphElement2 = $('mnthtxt');
                
                morphObject2 = new Fx.Morph(morphElement2, {
                    fps: 60,
                    duration: 400
                });
                
                morphObject2.start({
                    'opacity': 1
                });
                
            }
        });
        
        
        morphObject.start({
            'opacity': 0
        });
        
        
        mainDl = new Element('dl', {
            'id': 'acc',
            'styles': {
                'margin': 0,
                'padding': 0
            }
        
        });
        
        mainDl.injectInside($('resDiv'));
        
        secDl = new Element('dl', {
            'id': 'secDl',
            'styles': {
                'margin': 0,
                'padding': 0
            }
        });
        
        secDl.injectInside(mainDl);
       
       counter = 0;
       
        allEvents.each(function(e){
        	
	  

	    	eDatum = e.ld.datum.split('-');
		
	
		
		d = eDatum[2].split(' ');
		//eMonth = parseInt(eDatum[1]);
		eYear =  eDatum[0];
		eDay = d[0];
	    	eMonth = eDatum[1].replace( /^(0+)/g, '' );
			mm=eDatum[1];

	    
	   
           //console.log(e.ld.title+'--->'+eDatum+'------------>'+eMonth);
           
//  			var mm = eMonth;
//			if(eMonth.length==1){
//				mm='0'+eMonth;
//			}
//			else{
//				mm=eMonth;
//			}
            if (actM.toInt() == eMonth && actY.toInt() == eYear) {
				
	 eventDate = eDay+'.'+mm+'.'+eYear;
					qurl = escape('http://www.titlis.ch/index.php?id='+pid+'&evId='+e.ld.accID+'&evd='+eventDate+'&mode=mobile&mlang='+xLang+'#ev');
				
				var qrTag = window.location.href.contains('showQR') ? ' <a target="_blank" href="http://api.qrserver.com/v1/create-qr-code/?size=500x500&data='+qurl+'">QR-TAG</a>' : '';
					
				
               
                evDiv = new Element('dt', {
                    'html': '<div style="float:left"><b>' + eventDate + '</b></div><div style="float:left;padding:0 0 0 38px">' + e.ld.title + qrTag+ '</div>',
                    'styles': {
                        'height': 14,
                        'width': 400,
                        'margin': '1px 0 0 0',
                        'padding': '3px 10px 3px 10px',
                        'background-color': '#EFEFEF',
                        'cursor': 'pointer'
                    }
                });
                
                evDiv.injectInside(secDl);
                
                try {
                    txt = e.ld.text;
                    if (lang == 'de') {
                        infolink = 'mehr Informationen';
                    }
                    else {
                        infolink = 'more information';
                    }
                    
                    
                    if (txt.text[0].length > 180) {
                        shortText = txt.text[0].substr(0, 180) + '...<br/>[<a href="#" onclick="openDetailVerz(\'eventInfo\',' + e.ld.id + ',\'events\');return false;">' + infolink + '</a>]<br/><br/>';
                    }
                    else {
                        shortText = txt.text[0];
                    }
                } 
                catch (err) {
                    if (lang == 'de') {
                        shortText = "Informationen zu diesem Event folgen in Kürze.<br/><br/>";
                    }
                    else {
                        shortText = "information about this event will follow in short time.<br/><br/>";
                    }
                }
                
                
                if (e.ld.pictures != "") {
                
                    ADpic = e.ld.pictures;
                    picKl = '<div style="float:left;margin-bottom:0px; width: 84px;"><img style="padding:2px;" src="' + tmpDir + '80_verz_' + ADpic.media[0].name + '"/></div>';
                    
                    
                }
                else {
                
                    picKl = '';
                    ADpic = '';
                    
                }
                
                evCont = new Element('dd', {
                    'html': '<div style="padding:10px 0 10px 0;">' + picKl + '<div style="float:left;width:310px;padding-left:25px;margin-bottom:0px">' + shortText + '</div></div><div style="clear:both"></div>',
                    'styles': {
                        'overflow-x': 'hidden',
                        'overflow-y': 'hidden',
                        'height': 0,
                        'padding': 0,
                        'margin': 0
                    }
                });
                
                evCont.injectInside(secDl);
                
		
		
                new Accordion($$('dl#acc dt'), $$('dl#acc dd'), {
                    opacity: 0
		    ,onComplete: function(){
		    	
				steps = -2;
				makeScrollbar($('content_text'), $('track'), $('thumb'));
				
		    	
			 
		    }
                });
               
	        counter ++; 
            }
           
        });
	
	
	 if(xLang == 'de'){
	    	noE = 'keine aktuellen Einträge in diesem Monat';
	    }else{
	    	noE = 'no entries found';
	    }
	    
	    if(counter == 0){
	    	 evDiv = new Element('div', {
	                'html': noE
			,'styles':{
				'padding': '20px 0 0 0'
				,'font-weight': 'bold'
				,'color': '#C0001E'
			}
	              
	         }).injectInside(secDl);;
	
	    }
	    
	
    }
    else {
        dirC++;
        dToday = tdy;
        dNext = dToday;
    }
    


}



// Fenster für Verzeichnismodul
function openDetailVerz(win, id, type){

    if (type == "events") {
        var reqData = {
            'type': 'all',
            'user': 'titlis3',
            'table': {
                'listings_events': 'l',
                'listingrows_events': 'lr',
                'listingdatas_events': 'ld'
            },
            
            'condition': {
                'ld.id =': id
            },
            
            'fields': 'ld.*',
            'order': '',
            'language': xLang
        };
    }
    else {
        var reqData = {
            'type': 'all',
            'user': 'titlis3',
            'table': {
                'listings': 'l',
                'listingrows': 'lr',
                'listingdatas': 'ld'
            },
            
            'condition': {
                'ld.id =': id
            },
            
            'fields': 'ld.*,lr.id,l.rowID',
            'order': 'ld.titel ASC',
            'language': cLang
        };
    }
    
    
    var allEv = new Request({
        url: path + 'index.php',
        method: 'post',
        data: 'mode=verzeichnis&local=0&debug=0&request=' + encodeURIComponent(JSON.encode(reqData)),
        onComplete: function(response){
            response = JSON.decode(response);
            EvDet = response.result[0];
            
            txt = EvDet.ld.text;
            if (type == 'events') {
                titel = EvDet.ld.title;
                if (EvDet.ld.pictures != "") {
                    ADpic = EvDet.ld.pictures;
                    picKl = '<div style="float:left;margin-bottom:0px;"><img style="padding:2px;" src="' + tmpDir + '80_verz_' + ADpic.media[0].name + '"/></div>';
                    picGr = '<div style="float:left;margin-bottom:0px;"><img style="padding:2px;" src="' + tmpDir + '250_verz_' + ADpic.media[0].name + '"/></div>';
                    
                    winTxt = picGr + '<div style="float:left;width:470px;padding-left:20px;margin-bottom:0px;">' + txt.text[0] + '</div>';
                    
                }
                else {
                    picKl = '';
                    winTxt = txt.text[0];
                }
            }
            else {
                titel = EvDet.ld.titel;
                if (EvDet.ld.bilder != "") {
                    ADpic = EvDet.ld.bilder;
                    picKl = '<div style="float:left;margin-bottom:0px;"><img style="padding:2px;" src="' + tmpDir + '80_verz_' + ADpic.media[0].name + '"/></div>';
                    picGr = '<div style="float:left;margin-bottom:0px;"><img style="padding:2px;" src="' + tmpDir + '250_verz_' + ADpic.media[0].name + '"/></div>';
                    
                    winTxt = picGr + '<div style="float:left;width:470px;padding-left:20px;margin-bottom:0px;">' + txt.text[0] + '</div>';
                    
                }
                else {
                    picKl = '';
                    winTxt = txt.text[0];
                }
            }

            createWin(win, winTxt, titel, 358);
            
        }
    }).send();
    
    
}
var trophy = false;
var fackelabfahrt = false;
var endspurt = false;
var knorrli = false;
var fireride = false;
var golf = false;
var schlittel = false;

function createWin(win, winTxt, title, winHeight){

    trophy = false;
    fackelabfahrt = false;
    endspurt = false;
    knorrli = false;
    fireride = false;
	schlittel = false;
    
    if (winHeight > 500) {
        topmargin = '30px';
        winWidth = 900;
        
    }
    else {
        topmargin = '150px';
        winWidth = 768;
        
    }
    
    $('BoxOverlay').setStyles({
        width: window.getScrollWidth() + 'px',
        height: window.getScrollHeight() + 'px'
    });
    
    if (winHeight == 300) 
        winPad = '3px 20px 20px 20px';
    else 
        winPad = '60px 20px 20px 20px';
    
    if (win == 'reservation') {
        winWidth = 940;
    }
    
    
    
    center = winWidth / 2 + 20;
    
    if (win == 'map') {
        winPad = '23px 0 0 0';
        winWidth = 950;
        center = winWidth / 2;
        
        
    }
    
	if (win != 'Adventskalender') {
	
		var evDetail = new Element('div', {
			'id': win,
			'styles': {
				'position': 'absolute',
				'width': winWidth,
				'top': topmargin,
				'left': '50%',
				'z-index': '999',
				'height': winHeight + 'px',
				'margin-left': '-' + center + 'px',
				'padding': winPad,
				'text-align': 'left',
				'overflow': 'hidden',
				
				'display': 'block',
				'opacity': 0,
				'background-color': '#fff'
			}
		});
	}else{
		var evDetail = new Element('div', {
			'id': win,
			'styles': {
				'position': 'absolute',
				'width': winWidth,
				'top': topmargin,
				'left': '50%',
				'z-index': '999',
				'height': winHeight + 'px',
				'margin-left': '-' + center + 'px',
				'padding': winPad,
				'text-align': 'left',
				'overflow': 'hidden',
				'display': 'block',
				'opacity': 0,
				'background-color': '#000'
			}
		});
	}
    
    evDetail.injectBefore($('subnavcontainer'));
    
    //replace Forms
    
   chkforms(winTxt,evDetail,358);
    
    
    
    window_track = new Element('div', {
        'id': 'window_track',
        'styles': {
            'left': winWidth + 30,
            'height': winHeight + 20
        
        }
    }).injectInside(evDetail);
    
    window_thumb = new Element('div', {
        'id': 'window_thumb'
    }).injectInside(window_track);
    
    makeScrollbar($('wincont'), $('window_track'), $('window_thumb'));
    
    var zTables = new ZebraTables('tablemain');
    
    titlebar = new Element('div', {
        'id': 'titlebar',
        'html': title,
        'styles': {
            'position': 'absolute',
            'top': 0,
            'left': 0,
            'height': '18px',
            'padding': '5px 0 0 20px',
            'font-size': '11px',
            'font-weight': 'bold',
            'width': winWidth + 20,
            'background-image': 'url(' + root + 'images/dateheader.png)',
            'color': '#fff'
        }
    });
    
    titlebar.injectInside(evDetail);
    if (title == 'Blitzkarte') {
		contLogo = new Element('div', {
			'id': 'wincontLogo',
			'html': '<a href="index.php?id=1"><img src="' + root + 'images/logo_ti.png" style="border: none"/></a>',
			'styles': {
				'position': 'absolute',
				'right': '20px',
				'top': '40px'
			}
		}).injectInside(evDetail);
	}
    closer = new Element('div', {
        'id': 'closer',
        'styles': {
            'position': 'absolute',
            'top': '4px',
            'right': '10px'
        }
    }).injectInside($(win));
    
    closerA = new Element('a', {
        'href': 'javascript:closeOverlay("' + win + '")'
    }).injectInside(closer);
    
    closerImg = new Element('img', {
        'src': root + 'images/close_box.png',
        'border': 0
    }).injectInside(closerA);
    
    var fadein = new Fx.Tween($(win), {
        duration: 800
    });
    fadein.start('opacity', '0', '1');
    
    var fadein2 = new Fx.Tween($('BoxOverlay'), {
        duration: 500
    });
    fadein2.start('opacity', '0', '0.7');
}


function MediaGallery(verz){

    //xml schreiben
    var reqData = {
        'ajax': 'ajax'
    };
    
    var Gallery = new Request({
        url: path + 'mediaGallery/get_xml_content.php',
        method: 'post',
        data: 'mode=ajax&request=' + encodeURIComponent(JSON.encode(reqData)),
        onComplete: function(response){
        
            //console.log(JSON.decode(response));
            
            txt = '<div style="position:absolute;bottom:0px;left:0;background-color:#F1F4F5;"><iframe src="' + root + 'mediaGallery/mediaGallery.php" width="808" height="415" scrolling="no" frameborder="0"></iframe></div>';
            createWin('gal', txt, 'Media Gallery', 358);
            
        }
    }).send();
    
}


function makeMapLink(){
	

    
    if ($defined($('interaktivekarte'))) {
		$('interaktivekarte').addEvent('click', function(e){
		
			mlang = xLang.substr(0, xLang.length - 1);
			
			mlang = mlang.toUpperCase();
	
			tmp_link = 'http://www.titlis.ch/karte/karte.php?karte=winter&lang=' + mlang;
			
			
			var txt = '<iframe src="' + tmp_link + '" width="920" height="647" scrolling="no" frameborder="0"></iframe></div>';
			if (lang == 'de') {
				maptitle = 'Interaktive Karte';
			}
			else {
				maptitle = 'interactive map';
			}
			
			createWin('map', txt, maptitle, 650);
			
			
			$('wincont').setStyle('width',950);
			$('wincont').setStyle('height',660);


			
		});
	}
    
    if($defined($('blitzkarte'))){
    	  $('blitzkarte').addEvent('click', function(e){
    
        tmp_link = 'http://www.titlis.ch/blitzkarte.jpg';
	
        var txt = '<img src="' + tmp_link + '"height="647"  />';
	
		if(xLang == 'de'){
			maptitle = 'Blitzkarte';
		}else{
			maptitle = 'Flash Map';
		}
	        
	
	    createWin('map', txt, maptitle, 650);
		$('wincont').setStyle('width',650);
		$('wincont').setStyle('height',660);

		
		
		
		/*console.log("--");
		
		console.log(window.mIframe.document);*/
		
	    });
    }
}

function makeWebcamLinks(){
    $$('#content_text button').each(function(btn, item){
    
        var cam = btn.id.split('_');
        //console.log(cam[1]);
        
        switch (cam[1]) {
            case 'titlis':
                var camtitle = 'Titlis';
                break;
                
            case 'jochstock':
                var camtitle = 'Jochstock';
                break;
                
            case 'stationstand':
                var camtitle = 'Station Stand';
                break;
			
			case 'funpark':
	          	var camtitle = 'Funpark';
	            break;
                
            case 'skihuettestand':
                var camtitle = 'Skihütte Stand';
                break;
                
            case 'berghausjochpass':
                var camtitle = 'Jochpass';
                break;
                
            case 'berghoteltruebsee':
                var camtitle = 'Trübsee';
                break;
                
            case 'gerschnialp':
                var camtitle = 'Gerschnialp';
                break;
                
            case 'talstationengelberg':
                var camtitle = 'Engelberg Talstation';
                break;
		
	case 'snowtubingtruebsee':
                var camtitle = 'Rutschpark Trübsee';
                break;
                
        }
        
        var txt = '<div style="position:absolute;bottom:0px;left:0;background-color:#F1F4F5;"><iframe src="' + root + 'camSlide/slider.php?name=' + cam[1] + '" width="808" height="300" scrolling="no" frameborder="0"></iframe></div>';
        
        btn.addEvent('click', function(e){
            createWin('camslide' + item, txt, 'Webcam Timeline - ' + camtitle, 300);
        });
        
        
    });
}


function closeOverlay(win){

    var fadeout = new Fx.Tween(win, {
        duration: 500,
        onComplete: function(){ 
            $(win).destroy();
        }
    });
    fadeout.start('opacity', '1', '0');
    
    var fadeout2 = new Fx.Tween('BoxOverlay', {
        duration: 500,
        onComplete: function(){
            $('BoxOverlay').setStyle('opacity', 0);
        }
    });
    fadeout2.start('opacity', '0.7', '0');
    
}

var tmp = false;
var slider;
function makeScrollbar(content, Xscrollbar, handle, horizontal, ignoreMouse){

    if (tmp != true) {
        tmp = true;
        var f = function(){
            makeScrollbar(content, Xscrollbar, handle, horizontal, ignoreMouse);
        };
        
        setTimeout(f, 900);
    }
    
    steps = (horizontal ? (content.getScrollSize().x - content.getSize().x) : (content.scrollHeight - content.getSize().y -2))
    
   // console.log(steps)
    if (steps > 0) {
        Xscrollbar.setStyle('display', 'block');
        handle.setStyle('display', 'block');
    }
    else {
        Xscrollbar.setStyle('display', 'none');
        handle.setStyle('display', 'none');
        return;
    }
    
    slider = new Slider(Xscrollbar, handle, {
        steps: steps,
        mode: (horizontal ? 'horizontal' : 'vertical'),
        onChange: function(step){
            var x = (horizontal ? step : 0);
            var y = (horizontal ? 0 : step);
            content.scrollTo(x, y);
        }
    }).set(0);
    
    if (!(ignoreMouse)) {
        $$(content, Xscrollbar).addEvent('mousewheel', function(e){
        
            e = new Event(e).stop();
            var step = slider.step - (e.wheel / 2) * 30;
            
            slider.set(step);
        });
    }
    
    $(document.body).addEvent('mouseleave', function(){
        slider.drag.stop();
    });
}

function gmap(){
    if (GBrowserIsCompatible()) {
        var map = new GMap2($('map'));
        map.addControl(new GSmallZoomControl());
        map.addControl(new GMapTypeControl());
        
        map.setCenter(new GLatLng(46.81678148234219, 8.397116661071777), 15);
        var point = new GLatLng(46.81678148234219, 8.397116661071777);
        
        //online -> ABQIAAAAQO7vjAZDK3KEoA9w4ZoZyxTexs7A9H3Vm8wZ_Mn5AzXDa7S3sRQzL5sW4lnzlmEnwnJaQju0Pw2inw
        //local -> ABQIAAAAQO7vjAZDK3KEoA9w4ZoZyxQViYNHs_A5WglK8K_BKzzK06MAkRTwfhfMkbLQCc5eDuXBH28bWxn9jA
        var blueIcon = new GIcon(G_DEFAULT_ICON);
        
        blueIcon.image = "http://www.titlis.ch/images/gmap.gif";
        blueIcon.iconSize = new GSize(50, 29);
        markerOptions = {
            icon: blueIcon
        };
        
        if (lang == 'de') {
            langst = "Route berechnen";
            langlink = "de";
        }
        else {
            langst = "get directions";
            langlink = "en";
        }
        
        
        marker = new GMarker(point, markerOptions);
        map.addOverlay(marker);
        var html = '<b>Titlis Rotair</b><br>Gerschnistrasse 1<br>CH-6390 Engelberg<br>Tel. +41 41 639 50 50<br><br><a href="http://maps.google.com/maps?f=d&source=s_d&saddr=Gerschniweg+1,+6390+Engelberg,+Schweiz&daddr=&hl='+langlink+'&geocode=&mra=ls&sll=47.110366,8.447905&sspn=0.010223,0.01929&ie=UTF8&z=16" target="_blank">' + langst + '</a>';
        
        marker.openInfoWindowHtml(html);
    }
}




//debug
function L(x){
	if (Browser.Engine.name != "trident" )return console.log(x);else alert(x);
}

/** WEBCAM POPUP */
//Startindex für das Webcam Popup
var imgIndex = 0;
//Index der vorherigen Webcam für das Webcam Popup
var ind_RW = 0;
//Index der folgenden Webcam für das Webcam Popup
var ind_FF = 0;
/**
 * class webCamPopUp
 * 
 * Methods:
 * openCams: Aufruf um das Cam Popup zu initialisieren
 * closeCams: Aufruf um das Cam Popup zu schliessen
 * changeCams: Aufruf wenn die Webcams weitergedrückt werden
 * moveRW: Aufruf um auf die vorherige Webcam zu wechseln
 * moveFF: Aufruf um auf die nächste Webcam zu wechseln
 */
var webCamPopUp  = new Class({
	//initialisierung
	initialize: function(options){
		//Bilder Container (Objektarray mit den zu verwendenden Bilder)
		var webcamIMG = $$('.text img');
		//Webcam popup div
		var camPopUp = $('popUpWebCam');
		//hintergrund div
		var bgPage = $('bgPopUp');
		//vorhergehendes bild der webcam
		var imgCam_rw = $('webCIMG_rw');
		//aktuelles bild der webcam
		var imgCam = $('webCIMG');
		//nächstes bild der webcam
		var imgCam_ff = $('webCIMG_ff');
		//container div der Bilder
		var imageCont = $('camIMGContainer');
		
		webcamIMG.addEvents({
			'click':function(e){
				webcamIMG.each(function(img,key){
					//setze startindex
					if(img == e.target) imgIndex = key;
				});
				//initialisierung für das webcamdiv
				this.changeCams('init',webcamIMG,imgCam_rw,imgCam,imgCam_ff,imageCont);
				//öffnen des Webcam Popups
				this.openCams(bgPage,camPopUp);
			}.bind(this)
		});
		$('closeWebCam').addEvents({
			'click': function(e){
				//schliessen des Webcam Popups
				this.closeCams(bgPage,camPopUp);
			}.bind(this)
		});
		bgPage.addEvents({
			'click': function(e){
				//schliessen des Webcam Popups
				this.closeCams(bgPage,camPopUp);
			}.bind(this)
		});
		$('popupMask').addEvents({
			'click': function(e){
				//schliessen des Webcam Popups
				this.closeCams(bgPage,camPopUp);
			}.bind(this)
		});
		$('camRW').addEvents({
			'click':function(e){
				//gehe zur vorherigen Webcam
				this.moveRW(webcamIMG,imgCam_rw,imgCam,imgCam_ff,imageCont)
			}.bind(this)
		});
		$('camFF').addEvents({
			'click':function(e){
				//gehe zur nächsten Webcam
				this.moveFF(webcamIMG,imgCam_rw,imgCam,imgCam_ff,imageCont)
			}.bind(this)
		});
	},
	//öffnen des Webcampopups (parameter: bgPage: hintergrund div, camPopUp: PopUp div)
	openCams: function(bgPage,camPopUp){
		camPopUp.setStyles({
			'display': 'block',
			'opacity': '0'
		});
		bgPage.setStyles({
			'display': 'block',
			'opacity': '0'
		});
		//fade hintergrund ein
		var initCam = new Fx.Morph(bgPage, {
			duration: 500
		});
		initCam.start({
			'opacity': 0.7
		});
		//fade popup ein
		initCam = new Fx.Morph(camPopUp, {
			duration: 500
		});
		initCam.start({
			'opacity': 1
		});
	},
	//schliessen des Webcampopups (parameter: bgPage: hintergrund div, camPopUp: PopUp div)
	closeCams: function(bgPage,camPopUp){
		//fade hintergrund aus
		var closeCam = new Fx.Morph(bgPage, {
			duration: 500,
			onComplete: function(){
				bgPage.setStyle('display', 'none');
			}
		});
		closeCam.start({
			'opacity': 0
		});
		//fade popup aus
		closeCam = new Fx.Morph(camPopUp, {
			duration: 500,
			onComplete: function(){
				camPopUp.setStyle('display', 'none');
			}
		});
		closeCam.start({
			'opacity': 0
		});
	},
	//wechseln der Webcam (parameter: direction: richtung (forward-vorwärts,init-initialisierung), webcamIMG: Image Container,imgCam_rw: vorheriges Cam Bild,imgCam: aktuelles Cam Bild,imgCam_ff: folgendes Cam Bild,imageCont: container div der Bilder)
	changeCams:function(direction,webcamIMG,imgCam_rw,imgCam,imgCam_ff,imageCont){
		//wenn ein richtungswechsel
		//wenn vorwärts
		if(direction=='forward'){
			if(imgIndex >= webcamIMG.length-1) imgIndex =0;
			else imgIndex++;
		}
		//wenn rückwärts
		else if(direction!='init'){
			if (imgIndex > 0) imgIndex--;
			else imgIndex = webcamIMG.length - 1;
		}
		//setzen der indexes
		imgCam.src = webcamIMG[imgIndex].src;
		imageCont.setStyle('left', '-665px');
		if(imgIndex<=0) ind_RW = webcamIMG.length-1;
		else ind_RW = imgIndex-1;
		if(imgIndex>=webcamIMG.length-1) ind_FF = 0;
		else ind_FF = imgIndex+1;
		imgCam_rw.src = webcamIMG[ind_RW].src;
		imgCam_ff.src = webcamIMG[ind_FF].src;
	},
	//anzeigen der vorherigen Cam (parameter: webcamIMG: Image Container,imgCam_rw: vorheriges Cam Bild,imgCam: aktuelles Cam Bild,imgCam_ff: folgendes Cam Bild,imageCont: container div der Bilder)
	moveRW: function(webcamIMG, imgCam_rw, imgCam, imgCam_ff, imageCont){
		//rückwärts bewegen
		var moveRW = new Fx.Morph(imageCont, {
			duration: 500,
			onComplete: function(){
				this.changeCams('backward', webcamIMG, imgCam_rw, imgCam, imgCam_ff, imageCont);
			}.bind(this)
		});
		moveRW.start({
			'left': 0
		});
	},
	//anzeigen der folgenden Cam (parameter: webcamIMG: Image Container,imgCam_rw: vorheriges Cam Bild,imgCam: aktuelles Cam Bild,imgCam_ff: folgendes Cam Bild,imageCont: container div der Bilder)
	moveFF:function(webcamIMG, imgCam_rw, imgCam, imgCam_ff, imageCont){
		//vorwärts bewegen
		var moveFF = new Fx.Morph(imageCont, {
			duration: 500,
			onComplete: function(){
				this.changeCams('forward',webcamIMG,imgCam_rw,imgCam,imgCam_ff,imageCont);
			}.bind(this)
		});
		moveFF.start({
			'left': -1310
		});
	}
});

