var mf;

var Site = {
	
	init: function(){
		$$('a').each(function(el){
			el.addEvent('focus', function(){
				el.blur();
			});
		});
		
		new Asset.images([
			images_url+'nav/over/home.jpg',
			images_url+'nav/over/events.jpg',
			images_url+'nav/over/gastro.jpg',
			images_url+'nav/over/infos.jpg',
			images_url+'nav/over/kultur.jpg',
			images_url+'nav/over/vereine.jpg'
		], {
			onComplete: function(){
				if ($('navigation')) Site.navigation();
			}
		});
		
		var tooltips = new Tips($$('.tips', '.listArrows'), {
			className: 'custom-tip'
		});
				
		var helptips = new Tips($$('.help'), {
			className: 'help-tip'
		});
		
		if ($('loginUsername') && $('loginPassword')) Site.prepareLogin();
		
		if ($('formDetails')) Site.detailSearch();
		
		if ($('recommend')) Site.recommend();
		
		if ($('toggleImprint')) Site.imprint();
		
		if ($('slideImprint')) Site.slideToImprint();
		
		if ($$('.showImprint')) Site.showImprint();
		
		if ($('contact')) Site.contact();
		
		if ($('requestFirstCategory') && $('requestSecondCategory')) Site.requestCategory();
		
		if ($('requestFirstCategory') && $('requestSecondCategory') && $('tags')) Site.tagManagment();
		
		if ($('promoteRequestLocation') && $('promoteRequestAll')) Site.promoteRequestForm();
		
		if ($('checkURI') && $('updateURI')) Site.updateURI();
		
		if ($('setPerPage')) Site.setPerPage();
		
		if ($$('.checkTimeFormat')) Site.checkTimeFormat();
		
		if ($$('.checkDisclaimer')) Site.checkDisclaimer();
		
		$$('.verify').each(function(el){
			el.addEvent('click', function(e){
				e = new Event(e).stop();
				
				if (confirm(el.getProperty('title'))) {
					location.href = el.getProperty('href');
				}
			});
		});
		
		if ($('searchbar')) Site.manageSearchbar();
		
		if ($('sortAsc') && $('sortDesc')) Site.manageSort();
		
		if ($('sortDates')) Site.sortDates();
		
		if ($('pleaseWait')) Site.pleaseWait();
		
		if ($$('.transferToMessage')) Site.transferToMessage();
		
		if ($$('.pleaseWait')) Site.pleaseWaitClass();
		
		if ($('anotherPleaseWait')) Site.anotherPleaseWait();
		
		Site.checkThisDate();

		Site.checkTextFormatting();
		
		if ($('venue')) Site.selectVenue();
		
		if ($('transferKitchen')) Site.transferKitchen();
		
		Site.initCalendars();
		
		if ($('newPromoter')) Site.newPromoter();
		
		if ($$('.checkbox_day')) Site.checkOpeningHoursForm();
		
		if ($$('.kitchen_checkbox_day')) Site.checkKitchenHoursForm();
		
		if ($$('.check')) Site.venueAndVague();
 	},
 	
 	checkDisclaimer: function(){
 		$$('.checkDisclaimer').each(function(el){
 			el.addEvent('click', function(e){
		 		if ($('agree').get('checked') == false) {
		 			e = new Event(e).stop();
		 			alert('Sie müssen den Disclaimer aktzeptieren um fortzufahren!');
		  		} else {
		  			Site.pleaseWait(true);
		  		}
 			});
 		});
 	},
	
	showImprint: function(id){
		if (id > 0) {
			windowTop 	= screen.availHeight/4;
			windowLeft	= (screen.availWidth/2) - 215;
			
			imprint = window.open(site_url+"imprint/"+id, "Impressum", "top="+windowTop+",left="+windowLeft+",width=425,height=250,status=no,scrollbars=yes,resizable=no");
			imprint.focus();
		} else {
			$$('.showImprint').each(function(el){
				el.addEvent('click', function(){
					id = el.getProperty('id').replace('imprint_', '');
					
					windowTop 	= screen.availHeight/4;
					windowLeft	= (screen.availWidth/2) - 215;
					
					imprint = window.open(site_url+"imprint/"+id, "Impressum", "top="+windowTop+",left="+windowLeft+",width=425,height=250,status=no,scrollbars=yes,resizable=no");
					imprint.focus();
				});
			});
		}
	},
	
	checkTextFormatting: function(){
		$$('.toggleTextFormatInfo').each(function(el){
			el.addEvent('focus', function(){
				id = el.getProperty('id').replace('info_', '');

				$('format_'+id).setStyle('display', 'block');
				var mySlider = new Fx.Slide('format_' + id, {duration: 500}).hide();
				mySlider.toggle();				
			});

			el.addEvent('blur', function(){
				id = el.getProperty('id').replace('info_', '');

				var mySlider = new Fx.Slide('format_' + id, {duration: 500});
				mySlider.toggle();				
			});
		});
	},
	
	checkOpeningHoursForm: function(){
		$$('.checkbox_day').each(function(box){
			box.addEvent('click', function(){
				prototype = box.getProperty('id');
				status	  = box.value;
				day		  = prototype.replace('day_', '');
				
				if (status == 0) {
					status = box.value = 1;
					$('from_and_to_'+day).removeProperty('disabled');
					$('from_and_to_2_'+day).removeProperty('disabled');
				} else {
					status = box.value = 0;
					$('from_and_to_'+day).setProperty('disabled');
					$('from_and_to_2_'+day).setProperty('disabled');
				}
				
			});
		});
	},
	
	checkTimeFormat: function(){
		$$('.checkTimeFormat').each(function(el){
			el.addEvent('blur', function(){
				tmp = el.get('value').replace('.', ':');
				el.set('value', tmp);
					
				times = el.get('value').split(' - ');
				
				if (!el.get('value').match(/ - .+/)) {
					times = el.get('value').replace('-', ' - ');	
					times = times.split(' - ');				
				}
				
				if (times[0] != '') {
					if (times.length < 2) {
						if (!times[0].match(/:.+/)) {
							times[0] = times[0] + ':00';
						}
						
						el.value = times[0];
					} else {
						for (z = 0; z <= 1; z++) {
							if (!times[z].match(/:.+/)) {
								times[z] = times[z] + ':00';
							}
						}
						
						el.value = times[0] + ' - ' + times[1];	
					}					
				}			
			});
		});
	},
	
	venueAndVague: function(){
		$$('.check').each(function(field){
		
			field.addEvent('click', function(){
				element = field.getProperty('id');

				if (element == 'venue') {
					$('vague').setProperty('disabled', 'disabled');
				} else if (element == 'vague') {
					$('venue').setProperty('disabled', 'disabled');					
				}
			});
			
			field.addEvent('blur', function(){
				element = field.getProperty('id');
				
				if (element == 'venue') {
					if ($('venue').get('value') == '') {
						$('vague').removeProperty('disabled');
					}
				} else if (element == 'vague') {
					if ($('vague').get('value') == '') {
						$('venue').removeProperty('disabled');
					}					
				}
			});
		});
	},

	checkKitchenHoursForm: function(){
		$$('.kitchen_checkbox_day').each(function(box){
			box.addEvent('click', function(){
				prototype = box.getProperty('id');
				status	  = box.value;
				day		  = prototype.replace('kitchen_day_', '');
				
				if (status == 0) {
					status = box.value = 1;
					$('kitchen_from_and_to_'+day).removeProperty('disabled');
					$('kitchen_from_and_to_2_'+day).removeProperty('disabled');
				} else {
					status = box.value = 0;
					$('kitchen_from_and_to_'+day).setProperty('disabled');
					$('kitchen_from_and_to_2_'+day).setProperty('disabled');
				}
				
			});
		});
	},

	transferKitchen: function(){
		$('transferKitchen').addEvent('click', function(e){
			e = new Event(e).stop();
			
			var days = new Array ( 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday' );
			
			for (i = 0; i <= days.length-1; i++) {
				$('kitchen_from_and_to_'+days[i]).value = $('from_and_to_'+days[i]).get('value');

				if ($('kitchen_from_and_to_'+days[i]).value != '') {
					$('kitchen_day_'+days[i]).setProperty('checked');
					$('kitchen_from_and_to_'+days[i]).removeProperty('disabled');
					$('kitchen_from_and_to_2_'+days[i]).removeProperty('disabled');
				}

				$('kitchen_from_and_to_2_'+days[i]).value = $('from_and_to_2_'+days[i]).get('value');
			}

		});
	},

	navigation: function(){
		$each($('navigation').getElementsByTagName('a'), function(el){
			if (el.rel && el.rel.test(/^nav/i)){
				var element = $(el).rel;
				
				$($(element)).addEvent('mouseover', function(e){
					e = new Event(e);
					
					$(element).setProperty('src', images_url+'nav/over/'+$(element).name);
					
					e.stop();
				});
				
				$($(element)).addEvent('mouseout', function(e){
					e = new Event(e);
					
					$(element).setProperty('src', images_url+'nav/link/'+$(element).name);
					
					e.stop();
				});
			}
		});
	},
	
	recommend: function(){
		$('slideRecommend').addEvent('click', function(){
			$('recommend').setStyle('display', 'block');
			$('imprint').setStyle('display', 'none');
		});
		
		$('recommendSubmit').addEvent('click', function(e){
			e = new Event(e).stop();

			var submit = true;
			
			if ($('recommendFrom').value == '') {
				$('recommendFrom').setProperty('style', 'background-color: #ffd1d1');
				
				submit = false;
			}
			
			if ($('recommendTo').value == '') {
				$('recommendTo').setProperty('style', 'background-color: #ffd1d1');

				submit = false;
			}
			
			if ($('recommendMessage').value == '') {
				$('recommendMessage').setProperty('style', 'background-color: #ffd1d1');
			
				submit = false;
			}
			
			if ($('recommendCode').value == '') {
				$('recommendCode').setProperty('style', 'background-color: #ffd1d1');
			
				submit = false;
			}
			
			if (submit == true) {
				$('recommendForm').submit();
			}
		});
	},

	imprint: function(){
		$('toggleImprint').addEvent('click', function(){
			$('imprint').setStyle('display', 'block');
			$('recommend').setStyle('display', 'none');
		});
	},
	
	slideToImprint: function(){
		$('slideImprint').addEvent('click', function(){
			$('imprint').setStyle('display', 'block');
		});
	},
	
	contact: function(){
		$('contactSubmit').addEvent('click', function(e){
			e = new Event(e).stop();

			var submit = true;
			
			if ($('contactName').value == '') {
				$('contactName').setStyle('background-color', '#ffd1d1');
				
				submit = false;
			}
			
			if ($('contactEmail').value == '') {
				$('contactEmail').setStyle('background-color', '#ffd1d1');

				submit = false;
			}
			
			if ($('contactMessage').value == '') {
				$('contactMessage').setStyle('background-color', '#ffd1d1');
			
				submit = false;
			}
			
			if ($('contactCode').value == '') {
				$('contactCode').setStyle('background-color', '#ffd1d1');
			
				submit = false;
			}
			
			if (submit == true) {
				$('contactForm').submit();
			}
		});
	},
	
	prepareLogin: function(){
		var usernameValue 	= $('loginUsername').get('value');
		var passwordValue 	= $('loginPassword').get('value');
		
		$('loginUsername').addEvent('focus', function(){
			$('loginUsername').value = '';
		});
		
		$('loginUsername').addEvent('blur', function(){
			var usernameValue 	= $('loginUsername').get('value');
			
			$('loginUsername').value = usernameValue;
		});
		
		$('loginPassword').addEvent('focus', function(){
			$('loginPassword').value = '';
		});
		
		$('loginPassword').addEvent('blur', function(){
			var passwordValue 	= $('loginPassword').get('value');
			
			$('loginPassword').value = passwordValue;
		});
	},
	
	start: function(){
		$each($$('.deleteable'), function(el){
			$(el).addEvent('click', function(e){
				e = new Event(e).stop();
				
				if (confirm(el.getProperty('title'))) {
					id = $(el).getProperty('rel');
					
					new Ajax(site_url+'admin/downloads/delete/'+id, {
						method: 'post',
						onComplete: $('download'+id).remove()
					}).request();

					location.href = '';
				}
			});
		});
		
		if ($('toolsPrint')) Site.printPage();
		
		if ($('newsletterSubscribe')) Site.clearNewsletterSubscribe();
		
		if ($('showGoogleMaps')) Site.showGoogleMaps();
		
		if ($('googleMaps')) Site.googleMaps();
		
		if ($('MooFlow')) {
			mf = new MooFlow($('MooFlow'), {
			  	useSlider: true,
			  	useCaption: true,
			  	useMouseWheel: true,
			  	useKeyInput: true,
			  	startIndex: 0,
  				interval: 3000,
  				useAutoPlay: true,
  				useResize: true
			});
		}
	},
	
	printPage: function(){
		$('toolsPrint').addEvent('click', function(){
			print();
		});
	},
	
	clearNewsletterSubscribe: function(){
		$('newsletterSubscribe').addEvent('click', function(){
			$('newsletterSubscribe').value = '';
		});
	},
	
	requestCategory: function(){
		function requestAjax()
		{
			$('requestSecondCategory').setStyle('display', 'none');
			$('requestSecondCategory').getNext().setStyle('display', 'block');
			
			var url = site_url+'categories/'+$('requestFirstCategory').get('value');
					 	
		 	if ($('secondCategory')) {
		 		var url = site_url+'categories/'+$('requestFirstCategory').get('value')+'/'+$('secondCategory').get('value');
		 	}
		 	
			new Ajax(url, {
				method: 'post',
				update: $('requestResult'),
				onComplete: function(){
					checkCosts();
					
					if ($('tags')) {
						$('requestSecondCategory').addEvent('change', function(e) {
							e = new Event(e).stop();

							new Ajax(site_url+'admin/search_options/categories', {
								method: 'post',
								data: 'sub_category='+$('requestSecondCategory').get('value')
							}).request();
						});
					}
				}
			}).request();
		}
		
		if ($('requestFirstCategory').get('value') != 0) {
			requestAjax();
		}
			
		$('requestFirstCategory').addEvent('change', function(e) {
			e = new Event(e).stop();
			
			requestAjax();
			checkCosts();
		});
	},
	
	promoteRequestForm: function(){
		$('promoteRequestLocation').addEvent('click', function(e){
			e = new Event(e).stop();
			
			$('formRequest').type.value = 'location';
			
			$('formRequest').submit();
		});
		
		$('promoteRequestAll').addEvent('click', function(e){
			e = new Event(e).stop();
			
			$('formRequest').type.value = 'all';
			
			$('formRequest').submit();
		});
	},
	
	tagManagment: function(){
		var AllowedTips = new Tips($('requestFirstCategory'));
		
		$('requestFirstCategory').addEvent('change', function(e) {
			e = new Event(e).stop();
			
			new Ajax(site_url+'admin/search_options/categories', {
				method: 'post',
				data: 'category='+$('requestFirstCategory').get('value')
			}).request();
			
			new Ajax(site_url+'admin/search_options/tags', {
				method: 'post',
				data: 'category='+$('requestFirstCategory').get('value'),
				update: $('tags')
			}).request();
		});
	},
	
	manageSearchbar: function(){
		if ($('searchKeywords').get('value') == 'Suchbegriffe') {
			var keywordsValue 	= $('searchKeywords').get('value');
		} else {
			var keywordsValue 	= '';
		}
		
		if ($('city').get('value') == 'PLZ/Stadt') {
			var cityValue 	= $('city').get('value');
		} else {
			var cityValue 	= '';
		}

		if ($('category')) {
			$('category').addEvent('change', function(){
				new Ajax(site_url+'search/categories', {
					method: 'post',
					data: 'category='+$('category').get('value'),
					update: 'sub_category_container',
					onComplete: function(){
						$('sub_category').disabled = false;
						
						$('calendarSearchBarDate').value = '';
					}
				}).request();
			});
			
			if ($('showSubCategory')) {
				new Ajax(site_url+'search/categories', {
					method: 'post',
					data: 'category='+$('category').get('value'),
					update: $('sub_category_container'),
					onComplete: function(){
						if ($('sub_category')) $('sub_category').disabled = false;
					}
				}).request();
			}
		}
				
		$('searchKeywords').addEvent('focus', function(){
			$('searchKeywords').value = '';
		});

		$('city').addEvent('focus', function(){	
			$('city').value = '';
		});
		
		$('searchKeywords').addEvent('blur', function(){
			if ($('searchKeywords').value == '') {
				$('searchKeywords').value = keywordsValue;
			}
		});

		$('city').addEvent('blur', function(){
			if ($('city').value == '') {
				$('city').value = cityValue;
			}
		});
		
		if ($('searchDetails')) {
			$('searchDetails').addEvent('click', function(e){
				e = new Event(e).stop();
				
				if ($('category').get('value') == '0' && $('slideLocation').getStyle('display') == 'block') {
					$('hint').setStyle('display', 'block');
				} else {
					$('searchType').value = 'goto_details';
					
					$('searchForm').submit();
				}
			});
		}
				
		if ($('switchSearchCategory')) {
			$('switchSearchCategory').addEvent('change', function(){
				location.href = site_url+'search/category/'+$('switchSearchCategory').get('value');
			});
		}
	},
	
	manageSort: function(){
		$('sortAsc').addEvent('click', function(e){
			$('order').value = 'asc';
			
			$('formSort').submit();
		});
		
		$('sortDesc').addEvent('click', function(e){
			$('order').value = 'desc';
			
			$('formSort').submit();
		});

	},
	
	detailSearch: function(){
		$('formDetails').addEvent('submit', function(e){
			e = new Event(e).stop();
			
			$('detailsKeywords').value = $('searchKeywords').get('value');
			$('detailsCity').value = $('city').get('value');
						
			$('formDetails').submit();
		});
	},
	
	sortDates: function(){
		$('sortDates').addEvent('change', function(){
			$('formSortDates').submit();
		});
	},
	
	pleaseWait: function(alternativeMode){    
		if (alternativeMode == true) {
			var lightbox = new Element('div', {                                                                                                                                                                        
				'styles': {                                                                                                                                                                                        
						'width': window.getWidth()+'px',                                                                                                                                                           
						'height': window.getHeight()+'px'                                                                                                                                                         
				}                                                                                                                                                                                                  
			}).setProperty('id', 'lightbox').setOpacity('.6').injectInside(document.body);                                                                                                                     
			
			$('lightboxMessage').setStyle('display', 'block');
			$('lightboxMessage').setStyle('left', window.getWidth()/2-150+'px');
		} else {
			$('pleaseWait').addEvent('click', function(e){			
				var lightbox = new Element('div', {                                                                                                                                                                        
					'styles': {                                                                                                                                                                                        
							'width': window.getWidth()+'px',                                                                                                                                                           
							'height': window.getHeight()+'px'                                                                                                                                                         
					}                                                                                                                                                                                                  
				}).setProperty('id', 'lightbox').setOpacity('.6').injectInside(document.body);                                                                                                                     
				
				$('lightboxMessage').setStyle('display', 'block');
				$('lightboxMessage').setStyle('left', window.getWidth()/2-150+'px');
			});                                                                                                                                                                                                                                                                                                                                                                                        
		}
	},

	pleaseWaitClass: function(){    
		$$('.pleaseWait').addEvent('click', function(e){	
			var lightbox = new Element('div', {                                                                                                                                                                        
				'styles': {                                                                                                                                                                                        
						'width': window.getWidth()+'px',                                                                                                                                                           
						'height': window.getHeight()+'px'                                                                                                                                                         
				}                                                                                                                                                                                                  
			}).setProperty('id', 'lightbox').setOpacity('.6').injectInside(document.body);                                                                                                                     
			
			$('lightboxMessage').setStyle('display', 'block');
			$('lightboxMessage').setStyle('left', window.getWidth()/2-150+'px');
		});                                                                                                                                                                                                                                                                                                                                                                                        
	},
	
	transferToMessage: function(){
		$$('.transferToMessage').each(function(el){
			el.addEvent('click', function(){
				id = el.getProperty('id').replace('multimediaBox_', '');
				
				$('data_message_'+id).setStyle('display', 'block');
				
				if (el.getProperty('class').match(/full/)) {
					Site.multimediaBox(id, true);
				} else {
					Site.multimediaBox(id, false, el.getCoordinates().top);
				}
			});
		});
	},
	
	multimediaBox: function(id, full, fromTop){	
		if ($('lightbox_'+id)) {
			$('lightbox_'+id).setStyle('display', 'block');
			$('lightboxMessage_2_'+id).setStyle('display', 'block');
		} else {
			var scHeight = 0;
			
			if (window.getScroll()) {
				scHeight = window.getScroll().y;
			}
		
			var lightbox = new Element('div', {                                                                                                                                                                        
				'styles': {     
						'width': window.getWidth()+'px',                                                                                                                                                           
						'height': window.getHeight()+scHeight+'px'                                                                                                                                                         
				}                                                                                                                                                                                                  
			}).addClass('lightbox').setProperty('id', 'lightbox_'+id).setOpacity('.6').injectInside(document.body);                                                                                                                     
			
			$('lightboxMessage_2_'+id).setStyles({
				display: 'block'
			});
			
			if (full) {
				var cTop = 0;
				
				if (scHeight > 0) {
					// scroll bar is alive
					cTop = scHeight + (window.getHeight()/2);
				} else {
					cTop = window.getHeight()/2;
				}
				$('lightboxMessage_2_'+id).setStyles({
					'left': (window.getWidth()/2)-212 + 'px',
					'top': (cTop)-$('lightboxMessage_2_'+id).getCoordinates().height/2
				});				
			} else {
				var posi = fromTop
				var width = $('lightboxMessage_2_'+id).getWidth()/2;
				
				$('lightboxMessage_2_'+id).setStyles({
					left: window.getWidth()/2-width+'px',
					top: posi - $('lightboxMessage_2_'+id).getCoordinates().height / 2
				});		
			}
		}		
	}, 
	
	removeMessage: function(id){
		if ($('lightbox_'+id)) $('lightbox_'+id).setStyle('display', 'none');
		if ($('lightboxMessage_2_'+id)) $('lightboxMessage_2_'+id).setStyle('display', 'none');
	},
	
	anotherPleaseWait: function(){    
		$('anotherPleaseWait').addEvent('click', function(e){			
			var lightbox = new Element('div', {                                                                                                                                                                        
				'styles': {                                                                                                                                                                                        
						'width': window.getWidth()+'px',                                                                                                                                                           
						'height': window.getHeight()+'px'                                                                                                                                                         
				}                                                                                                                                                                                                  
			}).setProperty('id', 'lightbox').setOpacity('.6').injectInside(document.body);                                                                                                                     
			
			$('lightboxMessage').setStyle('display', 'block');
			$('lightboxMessage').setStyle('left', window.getWidth()/2-150+'px');
		});                                                                                                                                                                                                                                                                                                                                                                                     
	},
	
	showMooFlow: function(){
		$('lightbox').setOpacity(.6);
		$('lightbox').setStyle('width', window.getWidth()+'px');
		$('lightbox').setStyle('height', window.getHeight()+'px');
		$('lightbox').setStyle('display', 'block');
		
		$('MooFlow').setStyle('top', window.getScroll().y+100+'px');
		$('MooFlow').setStyle('left', (window.getSize().x/2)-400+'px');
		$('MooFlow').setStyle('display', 'block');
	},
	
	hideMooFlow: function(){
		$('lightbox').setStyle('display', 'none');
		$('MooFlow').setStyle('display', 'none');
	},
	
	checkThisDate: function()
	{
		$$('.checkThisDate').each(function(el){
			el.addEvent('change', function(){
				new Ajax(site_url+'admin/dates/check', {
					method: 'post',
					data: 'date_year='+$('dateYear').get('value')+'&date_month='+$('dateMonth').get('value')+'&date_day='+$('dateDay').get('value')+'&date_to_year='+$('dateToYear').get('value')+'&date_to_month='+$('dateToMonth').get('value')+'&date_to_day='+$('dateToDay').get('value'),
					update: $('checkDateMessage'),
					onComplete: function(){
						$('checkDateMessage').setStyle('display', 'block');
					}
				}).request();
			});
		});
	},
	
	updateURI: function(){
		$('checkURIButton').addEvent('click', function(e){
			e = new Event(e).stop();
			
			$('URILoader').setStyle('display', 'block');
			$('updateURI').setHTML('');
			
			new Ajax(site_url+'admin/search_options/uri', {
				method: 'post',
				data: 'uri='+$('checkURI').get('value'),
				update: $('updateURI'),
				onComplete: function(){
					$('URILoader').setStyle('display', 'none');
				}
			}).request();
		});
	},
	
	selectVenue: function(){
		var completer = new Autocompleter.Request.JSON($('venue'), site_url+'admin/dates/venue', {
							onRequest: function(){
								$('loader').setStyle('display', 'block')                                                                                        
							},

							onComplete: function(){                                                                                                                  
								$('loader').setStyle('display', 'none')                                                                                       
							},
							
							'maxChoices': 100,
							'multiple': true,
							'selectFirst': true,
							'selectMode': false,
							'minLength': 2
						});
	},
		
	setPerPage: function(){
		$('setPerPage').addEvent('change', function(){
			location.href = '/search/set/per_page/'+$('setPerPage').get('value');
		});
	},
	
	initCalendars: function(){
		window.addEvent('domready', function(){
			var initialize = true;
			
			var today = new Date();
			
			var dateon = [];
			var todayIsThe = (today.getMonth()+1)+'-'+today.getDate()+'-'+today.getFullYear();
			
			dateon[todayIsThe] = function(td, date_str){
				td.setStyle('font-weight', 'bold');
				td.setStyle('text-decoration', 'underline');
			};
			
			if ($('calendarSearchBar')) {
				if ($('selectedDay')) {
					var calender = new Calendar("calendarSearchBar", null, {
						visible: true,
						allowSelection: true,
						startDate: new Date(today.getFullYear(), 0, 1),
						endDate:new Date(2017,0,1),
						idPrefix: 'cal4',
						inputField: 'calendarSearchBarDate',
						dateFormat:"Y-m-d",
						startDay: 1,
						allowWeekendSelection: true,
						selectedDate: new Date($('selectedYear').get('value'), ($('selectedMonth').get('value')-1), $('selectedDay').get('value')),
						onSelect: function(){
							var toDate = $('calendarSearchBarDate').get('value').split("-");
							
							if ($('calendarFrom')) {
								$('selectDateFrom').value = toDate[2]+'.'+toDate[1]+'.'+toDate[0];
							}
							
							if (!initialize) {
								if ($('selectDateFrom').get('value') != '') {
									$('selectDateTo').value = $('selectDateFrom').get('value');
									$('timeframeTo').value = $('selectDateFrom').get('value');
								}
							}
							
							initialize = false;
						},
						dateOnAvailable:dateon
					});
				} else {
					var calender = new Calendar("calendarSearchBar", null, {
						visible: true,
						allowSelection: true,
						startDate: new Date(today.getFullYear(), 0, 1),
						endDate:new Date(2017,0,1),
						idPrefix: 'cal4',
						inputField: 'calendarSearchBarDate',
						dateFormat:"Y-m-d",
						startDay: 1,
						allowWeekendSelection: true,
						dateOnAvailable:dateon
					});
				}
			}
			
			if ($('selectDateFrom')) {	
				var calenderFrom = new Calendar("calendarFrom", "openDateFrom", {
					visible: false,
					allowSelection: true,
					startDate: new Date(today.getFullYear(), 0, 1),
					endDate:new Date(2017,0,1),
					idPrefix: 'cal3',
					inputField: 'selectDateFrom',
					dateFormat:"d.m.Y",
					startDay: 1,
					allowWeekendSelection: true,
					onSelect: function(){
						this.closeCalendar();
						
						$('calendarSearchBar').setHTML('');
						
						var toDate = $('selectDateFrom').get('value').split(".");
						
						var calender = new Calendar("calendarSearchBar", null, {
							visible: true,
							allowSelection: true,
							startDate: new Date(today.getFullYear(), 0, 1),
							endDate:new Date(2017,0,1),
							idPrefix: 'cal4',
							inputField: 'calendarSearchBarDate',
							dateFormat:"Y-m-d",
							startDay: 1,
							allowWeekendSelection: true,
							selectedDate: new Date(toDate[2], toDate[1]-1, toDate[0])
						});
					},
					closeLinkHTML: '',
					dateOnAvailable:dateon
				});
			}
			
			if ($('selectDateTo')) {		
				var calenderTo = new Calendar("calendarTo", "openDateTo", {
					visible: false,
					allowSelection: true,
					startDate: new Date(today.getFullYear(), 0, 1),
					endDate:new Date(2017,0,1),
					idPrefix: 'cal2',
					inputField: 'selectDateTo',
					dateFormat:"d.m.Y",
					startDay: 1,
					allowWeekendSelection: true,
					onSelect: function(){
						this.closeCalendar();
						
						$('timeframeTo').value = $('selectDateTo').get('value');
					},
					closeLinkHTML: '',
					dateOnAvailable:dateon
				});
			}
		});
	},
	
	showGoogleMaps: function(){
		if (GBrowserIsCompatible()) {
			geocoder = new GClientGeocoder();
			
			if (geocoder) {
				if ($('hiddenLocation')) {
					geocoder.getLatLng($('hiddenLocation').get('value'), function(point) {
						if (point) {
							if ($('linkGoogleMaps')) $('linkGoogleMaps').setStyle('display', 'block');
							$('showGoogleMaps').setStyle('display', 'block');
				
							$('showGoogleMaps').addEvent('click', function(e){
								e = new Event(e).stop();
								
								var map = null;
								var geocoder = null;
								
								if ($('googleMaps')) $('googleMaps').setStyle('display', 'block');
																
								if ($('closeGoogleMaps')) $('closeGoogleMaps').setStyle('display', 'block');
								
								if (GBrowserIsCompatible()) {
									var map = new GMap2(document.getElementById("googleMaps"));
									map.setCenter(new GLatLng(37.4419, -122.1419), 13);
									geocoder = new GClientGeocoder();
									
									if (geocoder) {
										geocoder.getLatLng($('hiddenLocation').get('value'), function(point) {
											if (point) {
												map.setCenter(point, 15);
												var marker = new GMarker(point);
												map.addOverlay(marker);
												map.addControl(new GSmallMapControl());
												map.addControl(new GMapTypeControl());
											}
										});
									}
								}
								
								if ($('closeGoogleMaps')) {
									$('closeGoogleMaps').addEvent('click', function(e){
										e = new Event(e).stop();
										
										$('googleMaps').setStyle('display', 'none');
										$('closeGoogleMaps').setStyle('display', 'none');
									});
								}
							});
						}
					});
				}
			}
		}
	},
	
	googleMaps: function(){
		var map = null;
		var geocoder = null;
		
		if (GBrowserIsCompatible()) {
			var map = new GMap2($('googleMaps'));
			map.setCenter(new GLatLng(37.4419, -122.1419), 13);
			geocoder = new GClientGeocoder();
			
			if (geocoder) {
				geocoder.getLatLng(document.getElementById("hiddenLocation").value, function(point) {
					if (!point) {
						$('googleMaps').remove();
					} else {
						map.setCenter(point, 15);
						var marker = new GMarker(point);
						map.addOverlay(marker);
						map.addControl(new GSmallMapControl());
						map.addControl(new GMapTypeControl());
					}
				});
			}
		}
	},
	
	newPromoter: function()
	{
		$('newPromoter').addEvent('click', function(){
			$('formNewPromoter').setStyle('display', 'block');
		});
	}
	
};

function growl(message, duration) {                                                                                                                                                          																																			 
	growl = new Element('div').addClass('growl').setStyle('left', (window.getWidth()/2)-110+'px').setHTML(message).injectInside(document.body);                                         
																																														 
	fade = new Fx.Style(growl, 'opacity', {                                                                                                                                              
		duration: 500,                                                                                                                                                               
		transition: Fx.Transitions.Quart.easeInOut,                                                                                                                                  
		wait: false                                                                                                                                                        
	});                                                                                                                                                                                  
																																														 
	slide = new Fx.Style(growl, 'top', {                                                                                                                                                 
		duration: 500,                                                                                                                                                               
		transition: Fx.Transitions.Quint.easeOut,                                                                                                                                    
		wait: false                                                                                                                                                       
	});                                                                                                                                                                                  
																																														 
	slide.set(100)                                                                                                                                                                       
	slide.start(150);                                                                                                                                                                    
	fade.start(.8);                                                                                                                                                                       
																																														 
	setTimeout("fade.start(0)", 4000);                                                                                                                                                   
	setTimeout("slide.start(200)", 4000);                                                                                                                                                
} 

function showArticle(id){
	$('ajaxLoader').setStyle('display', 'block');
	
	new Ajax(site_url+'builder/article/'+id, {
		method: 'post',
		update: $('templates'),
		onComplete: function(){
			$('ajaxLoader').setStyle('display', 'none');
		}
	}).request();
}

function tag(tag, location){
	new Ajax(site_url+'admin/search_options/tag', {
		method: 'post',
		data: 'tag='+tag+'&location='+location
	}).request();
}

function updateSpecials(tag, location, specials){
	new Ajax(site_url+'admin/search_options/specials', {
		method: 'post',
		data: 'tag='+tag+'&location='+location+'&specials='+specials
	}).request();
}

function showFull(id)
{
	$('limit'+id).setStyle('display', 'none');
	$('full'+id).setStyle('display', 'block');
}

function hideFull(id)
{
	$('full'+id).setStyle('display', 'none');
	$('limit'+id).setStyle('display', 'block');
}

function switchContent(object, layer)
{
	if ($('current')) $('current').removeProperty('id', '');
	
	var arr = [$('contentHome'), $('contentSpecials'), $('contentGalleries'), $('contentDates'), $('contentInfos'), $('contentMap'), $('contentContact')];
	
	arr.each(function(el){
		if (el != null) {
			el.setStyle('display', 'none');
		}
	});
	
	if ($(layer)) {
		$(layer).setStyle('display', 'block');
		$$(object).setProperty('id', 'current');
	}
}

function nextStep(form)
{
	$('nextStep').value = '1';
}

function checkCosts()
{
	if ($('costInfo')) {
		new Ajax(site_url+'register/costs', {
			method: 'post',
			data: 'category='+$('requestFirstCategory').get('value')+'&sub_category='+$('requestSecondCategory').get('value'),
			update: $('costInfo'),
			onComplete: function(){
				$('costInfo').setStyle('display', 'block');
			}
		}).request();
	}
}

function checkChars(object, maxchars)
{	
	var value = $(object).get('value');
	
	if (value.length <= maxchars) {
		$('counter').setHTML(maxchars-value.length);
	} else if (value.length > maxchars) {
		$(object).value = value.substr(0, maxchars);
	} 
}

window.addEvent('domready', Site.init);
window.addEvent('load', Site.start);
