function GoogleMap() {
	this.stadt = 'm';
	this.anfahrt = function() {
		if (GBrowserIsCompatible()) {
			document.getElementById('googleMap').style.display = 'block';
			var map = new GMap2(document.getElementById("googleMap"));
			if (this.stadt=='m') {
				var point = new GLatLng(48.139067, 11.566707);
				if (lang=='en') {
					var html = '<p class="map"><b>FREYER Marktforschung GmbH</b><br />Neuhauser Straße 47<br />D-80331 München<br />Phone +49-89-54 58 80-0<br />Fax: +49-89-55 40 46</p>';
				} else {
					var html = '<p class="map"><b>FREYER Marktforschung GmbH</b><br />Neuhauser Straße 47<br />80331 München<br />Tel. 089 - 54 58 80-0<br />Fax: 089 - 55 40 46</p>';
				}
			} else {
				var point = new GLatLng(52.503015, 13.331169);
				if (lang=='en') {
					var html = '<p class="map"><b>FREYER Marktforschung GmbH</b><br />Joachimstaler Straße 12<br />D-10719 Berlin<br />Phone +49-30-23 50 91-0<br />Fax: +49-30-213 23 66</p>';
				} else {
					var html = '<p class="map"><b>FREYER Marktforschung GmbH</b><br />Joachimstaler Straße 12<br />10719 Berlin<br />Tel. 030 - 23 50 91-0<br />Fax: 030 - 213 23 66</p>';
				}
			}
			map.addControl(new GSmallMapControl());
			map.setCenter(point, 14);
			var marker = new GMarker(point);
			marker.bindInfoWindowHtml(html);
			map.addOverlay(marker);
			return map;
		} else {
			return false;
		}
	}
	
	this.hotels = function() {
		if (map = this.anfahrt()) {
			var hotelIcon = new GIcon(G_DEFAULT_ICON, root+'img/marker.png');			
			$('dt').each(function() {
				if (this.id != "") {
					var coord = this.id.split("-");
					if (coord.length == 2) {
						coord[0] = coord[0].substr(1);
						var point = new GLatLng(coord[0], coord[1]);
						var marker = new GMarker(point,hotelIcon);
						html = '<div class="map"><b>'+$(this).html()+'</b><br />';
						html += $(this).next('dd').html()+'</div>';
						marker.bindInfoWindowHtml(html);
						map.addOverlay(marker);
						if (lang=='en') {
							$(this).append('<br /><span>show in map</span>');
						} else {
							$(this).append('<br /><span>in Karte zeigen</span>');
						}
						$(this).addClass("link");
						this.marker = marker;
						this.html = html;
						$(this).bind("click", function() {
							this.marker.openInfoWindowHtml(this.html);
							var gm = $('#googleMap');
							if (gm.offset().top < $().scrollTop()) {
								$.scrollTo(gm, 500);
							}
						});
					}
				}
			});
		}
	}
}


function nextFormTab() {
	actpanel = $("#testperson-form .panel-selected:first");
	var isValid = true;
	$("input",actpanel).each(function() {
		if (!$(this).valid() && ($(this).rules().required || $(this).attr("value")!='')) {
			isValid = false;
		}
	});
	if (isValid) {
		actpanel.removeClass('panel-selected').addClass('panel-hide');
		actpanel.next().removeClass('panel-hide').addClass('panel-selected');
		
		actlink = $("#anmeldung-list .act:first");
		actlink.removeClass('act').addClass('done');
		actlink.next().addClass('act');
		actlink.click(function() {
			var m = $(this).attr("id").match(/link-(.+)/);
			if (m) {
				$(this).removeClass('done').addClass('act');
				$(this).nextAll().removeClass('done act').unbind();
				actpanel = $('#'+m[1]);
				actpanel.removeClass('panel-hide').addClass('panel-selected');
				actpanel.nextAll('.panel-selected').removeClass('panel-selected').addClass('panel-hide');
			}
		});
	}
}

function submitForm() {
	actpanel = $("#testperson-form .panel-selected:first");
	var isValid = true;
	$("input",actpanel).each(function() {
		if (!$(this).valid() && ($(this).rules().required || $(this).attr("value")!='')) {
			isValid = false;
		}
	});
	if (isValid) {
		$("#mailform").submit();
	}
}

jQuery(document).ready(function() {
	$("img[usemap]").maphilight({'stroke':false})	
	
	// Create different tabs for form
	var count = 1;
	$("#testperson-form").prepend('<div class="box_umfrage right"><div class="box_anmeldung_inner">					<ul id="anmeldung-list"></ul></div></div>');
	$("#testperson-form .tab").each(function() {
		var id = $(this).attr("id");
		var txt = $("legend",this).html();
		if (count==1) {
			var c = ' class="act"';
			$(this).addClass('panel-selected')
		} else {
			$(this).addClass('panel-hide')
		}
		var submit = $(":submit",this);
		if (submit.length>0) {
			submit.replaceWith('<div class="box_anmeldung"><a class="button" href="javascript:submitForm()">Formular absenden</a></div>');
		} else {
			$(this).append('<div class="box_anmeldung"><a class="button" href="javascript:nextFormTab()">weiter &gt;</a></div>');
		}
		$("#anmeldung-list").append('<li id="link-'+id+'"'+c+'><strong id="prog'+count+'"><span>'+txt+'</span></strong></li>');
		count++;
	});
	
	// Activate all carousels
	$(".jcarousel").jcarousel({
		scroll: 4
	});
	
	$(".maplink").each(function() {
		var c = $(this).attr('class');
		var m = c.match(/img(\d+)/);
		if (m) {
			this.imglink = m[1];
			$(this).mouseover(function() {
				$("#maparea"+this.imglink).trigger("mouseover");
			});
			$(this).mouseout(function() {
				$("#maparea"+this.imglink).trigger("mouseout");
			});
		}
	});
	
	$("#map1 area").each(function() {
		var id = $(this).attr('id');
		var m = id.match(/maparea(\d+)/);
		if (m) {
			var obj = $(".pg_sliderGallery .img"+m[1]+":first");
			if (obj) {
				this.imgobj = obj;
				$(this).attr("href","javascript:");
				$(this).click(function() {
					$(this.imgobj).trigger("click");
				});
			}
		}
	});	
});

