﻿var locations = {
	gruenstadt:			['Hauptstraße 89, 67269 Grünstadt, Deutschland'],
	landstuhl:			['Bahnstraße 96, 66849 Landstuhl, Deutschland'],
	homburg:			['Talstraße 27, 66424 Homburg, Deutschland', 'Talstraße 36, 66424 Homburg, Deutschland'],
	homburg_i: 			['Talstraße 27, 66424 Homburg, Deutschland'],
	homburg_ii:			['Talstraße 36, 66424 Homburg, Deutschland'],
	kaiserslautern:		['Eisenbahnstraße 18, 67655 Kaiserslautern, Deutschland', 'Marktstraße 7, 67655 Kaiserslautern, Deutschland'],
	kaiserslautern_i:	['Eisenbahnstraße 18, 67655 Kaiserslautern, Deutschland'],
	kaiserslautern_ii:	['Marktstraße 7, 67655 Kaiserslautern, Deutschland'],
	alzey:				['Rossmarkt 8, 55232 Alzey, Deutschland'],
	pirmasens:			['Hauptstraße 23, 66953 Pirmasens, Deutschland']
};

function initialize() {
	geocoder = new google.maps.Geocoder();
	var where = window.location.hash.replace('#', '');
	if(where == 'shops')
		where = 'gruenstadt';
	for(i = 0; i < locations[where].length; i++) {
		if (geocoder) {
			geocoder.geocode( { 'address': locations[where][i]}, function(results, status) {
				if (status == google.maps.GeocoderStatus.OK) {
					var map_id = 'map_'+where;
					if(locations[where].length == 2) {
						for(var z = 0; z <= locations[where].length; z++) {
							if(locations[where][z] == results[0].formatted_address)
								break;
						}
						if(z == 1)
							var map_id = 'map_'+where+'_ii';
					}
					else {
						z = 0;
					}
					
					$('#'+map_id).css({
						display: 'block',
						width: '520px',
						height: '339px'
					});

					var myOptions = {
						zoom: 15,
						center: results[0].geometry.location,
						mapTypeId: google.maps.MapTypeId.HYBRID,
						navigationControl: true,
						mapTypeControl: true,
						scaleControl: true
					};
					map = new google.maps.Map(document.getElementById(map_id), myOptions);
					var marker = new google.maps.Marker({
					    position: results[0].geometry.location, 
					    map: map, 
					    title: locations[where][z]
					});
				}
				else{}
			});
		}
	}
}

$(document).ready(function() {
	$('html').css({overflowY: 'scroll'});
	if(anchor = $(window.location.hash).get(0)) {
		$.scrollTo('#'+anchor.id);
	}
	
	//$('.bubble').css('display', 'none').slideDown(1000);
	setTimeout(function() {
		$('.bubble').fadeOut(2000);
	}, 5000);
	
	$('a.lightbox').lightBox({
		boxShadow: '0 0 20px #000',
		overlayBgColor: 'none',
		overlayOpacity: 1,
		imageBtnClose: 'schließen',
		imageBtnPrev: '',
		imageBtnNext: '',
		btnNext: 'weiter &#x25B6;',
		btnPrev: '&#x25C0; zurück',
		containerResizeSpeed: 1,
		txtImage: 'Bild',
		txtOf: 'von'
	});
	
	$('a.lightbox2').lightBox({
		boxShadow: '0 0 20px #000',
		overlayBgColor: 'none',
		overlayOpacity: 1,
		imageBtnClose: 'schließen',
		imageBtnPrev: '',
		imageBtnNext: '',
		btnNext: 'weiter &#x25B6;',
		btnPrev: '&#x25C0; zurück',
		containerResizeSpeed: 1,
		txtImage: 'Bild',
		txtOf: 'von'
	});
	
	$('a.lightbox3').lightBox({
		boxShadow: '0 0 20px #000',
		overlayBgColor: 'none',
		overlayOpacity: 1,
		imageBtnClose: 'schließen',
		imageBtnPrev: '',
		imageBtnNext: '',
		btnNext: 'weiter &#x25B6;',
		btnPrev: '&#x25C0; zurück',
		containerResizeSpeed: 1,
		txtImage: 'Bild',
		txtOf: 'von'
	});			
	
	if(jQuery.browser.msie) {
		$('#mainnav li a').each(function(i,element) {
			child = $(element).children();
			child.css({
				'position': 'relative',
				'z-index':	2
			});
			child.clone().appendTo(element).css({
				'color': '#f66',
				'top': '2px',
				'left': 0,
				'position': 'absolute',
				'z-index':	1	
			});
		});
		$('hr').each(function(index,element) {
			$('<div style="margin-top: -15px;"></div>').insertAfter(element);
		});
	}
	else {
		$('#mainnav li a').css('text-shadow', '0 2px 0 #f66');
	}
	
	$('.headlinertable').not('#table_1').hide();
	$('.headliner').click(function() {
		if($(this).attr('id') != 'headline_1')
			$('#'+$(this).attr('id').replace('headline', 'table')).slideToggle(function() {
				if($(this).is(':visible'))
					$('#'+$(this).attr('id').replace('table', 'headline')+' .morearrow').text('weniger').addClass('lessarrow').removeClass('morearrow');
				else
					$('#'+$(this).attr('id').replace('table', 'headline')+' .lessarrow').text('mehr Info').removeClass('lessarrow').addClass('morearrow');
			});
	});
	
	
	$('area').hover(function() {
		$('div.'+$(this).attr('id').replace('area_', 'name_')+' h3 a').addClass('nred2');
		$('div.'+$(this).attr('id').replace('area_', 'name_')+'_i h3 a').addClass('nred2');
		$('div.'+$(this).attr('id').replace('area_', 'name_')+'_ii h3 a').addClass('nred2');
	}, function() {
		$('div.'+$(this).attr('id').replace('area_', 'name_')+' h3 a').removeClass('nred2');
		$('div.'+$(this).attr('id').replace('area_', 'name_')+'_i h3 a').removeClass('nred2');
		$('div.'+$(this).attr('id').replace('area_', 'name_')+'_ii h3 a').removeClass('nred2');		
	});

	if(typeof google != 'undefined')
		initialize();

	$('.extern').click(function(event){
		event.preventDefault();
		window.open(this.href);
	});
	
	$('textarea').focus(function(event) {
		if($(this).val().indexOf('Ihre Anfrage') != -1)
			$(this).val('');
	});
	$('textarea').blur(function(event) {
		if($(this).val() == '')
			$(this).val('Ihre Anfrage');
	});
});

