$(function() {
	$("a.menuitem").button();

	$('.stage .hider .menu').tabSlideOut({
		tabHandle: '.handle',                     //class of the element that will become your tab
		pathToTabImage: 'Bilder/menu_rollout_a.png', //path to the image for the tab //Optionally can be set using css
		imageHeight: '26px',                     //height of tab image           //Optionally can be set using css
		imageWidth: '145px',                       //width of tab image            //Optionally can be set using css
		tabLocation: 'top',                      //side of screen where tab lives, top, right, bottom, or left
		speed: 300,                               //speed of animation
		action: 'click',                          //options: 'click' or 'hover', action to trigger animation
		topPos: '0px',                          //position from the top/ use if tabLocation is left or right
		leftPos: '0px',                          //position from left/ use if tabLocation is bottom or top
		fixedPosition: false                      //options: true makes it stick(fixed position) on scroll
	});
	
	/*
	$('#maigloeckchen').position({
		of: $('body'),
		my: 'left bottom',
		at: 'center bottom',
		offset: '-655 -180'
	}).css('height','214px').css('width', '267px');
	*/
	
	/*
	oTable = $('#tagungsplan').dataTable({
					"bJQueryUI": true,
					"sPaginationType": "full_numbers"
				});
	*/
	
	$('#tagungsplan tr').click(function(){
				var ziel = $(this).attr('title');						
	
				
				});
	
	// Seminar Anmeldung
	
		var name = $("#name"),
			email = $("#email"),
			uhrzeit = $("#uhrzeit"),
			message = $("#message"),
			workshop = $("#workshop"),
			allFields = $([]).add(name).add(email).add(message).add(workshop).add(uhrzeit),
			tips = $(".validateTips");
			

		function updateTips(t) {
			tips
				.text(t)
				.addClass('ui-state-highlight');
			setTimeout(function() {
				tips.removeClass('ui-state-highlight', 1500);
			}, 500);
		}

		function checkLength(o,n,min,max) {

			if ( o.val().length > max || o.val().length < min ) {
				o.addClass('ui-state-error');
				updateTips("Die Anzahl der Zeichen bei '" + n + "' muss zwischen "+min+" und "+max+" sein.");
				return false;
			} else {
				return true;
			}

		}

		function checkRegexp(o,regexp,n) {

			if ( !( regexp.test( o.val() ) ) ) {
				o.addClass('ui-state-error');
				updateTips(n);
				return false;
			} else {
				return true;
			}

		}
		
		$("#dialog-form").dialog({
			autoOpen: false,
			height: 450,
			width: 550,
			modal: true,
			buttons: {
				'Anmelden': function() {
					var bValid = true;
					allFields.removeClass('ui-state-error');
					
					//bValid = bValid && checkLength(name,"username",3,16);
					bValid = bValid && checkLength(email,"email",6,80);

					//bValid = bValid && checkRegexp(name,/^[a-z]([0-9a-z_])+$/i,"Username may consist of a-z, 0-9, underscores, begin with a letter.");
					// From jquery.validate.js (by joern), contributed by Scott Gonzalez: http://projects.scottsplayground.com/email_address_validation/
					bValid = bValid && checkRegexp(email,/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i,"Email bitte im Format: 'ab@cde.de' angeben.");
					
					
					if (bValid) {
						// Send Email
						var loading = "<img src='Bilder/loading.gif' style='margin-top:10px;margin-left:50px;' />";
						$('#result').html(loading);
						$('#result').css("visibility", "visible");
						$.ajax({
						  url: 'mail.php',
						  data: allFields,
						  type: 'POST',
						  success: function(data) {
							  //alert(data);
							$('#result').html(data);
							$('#result').css("visibility", "visible");
							
						  }
						});
						
						$(this).dialog('close');
					}
				},
				
			},
			close: function() {
				$('#dialog-form input.text, #dialog-form  textarea.text').val('').removeClass('ui-state-error');
			}
		});
		
		
		
		$('#anmeldung')
			.button()
			.click(function() {
				$('#dialog-form').dialog('open');
			});
			
		$.fx.speeds._default = 500;
		$(function() {
			$('#dialog').dialog({
				autoOpen: false,
				show: 'clip',
				hide: 'clip',
				height: 'auto',
				width: 750,
				maxWidth: 750
			});
			
			$('#referent').click(function() {
				$('#dialog').dialog('open');
				return false;
			});
		});


});



// JavaScript Document

/*------------------------------- Funktionen für Google Maps -------------------------------------------*/
var starttexthtml = '<table width="170" height="50" border="0"><tr><td width="80"></td><td width="181"><h3>Mai-Event 2010</h3>Westring 2a<br/>15366 Neuenhagen</td></tr></table>';





function callBigMap() {
 	var map = new GMap2(document.getElementById("map"));
	var geocoder = new GClientGeocoder();
	
	function showAddress(address) {
	  geocoder.getLatLng(
		address,
		function(point) {
		  if (!point) {
			alert(address + " not found");
		  } else {
			map.setCenter(point, 12);
			var marker = new GMarker(point);
			map.addOverlay(marker);
			marker.openInfoWindowHtml(starttexthtml);
		  }
		}
	  );
	}
 
 if (GBrowserIsCompatible()) {

	showAddress("Westring 2a, 15366 Neuenhagen bei Berlin");

  	//Navigation festlegen
	map.addControl(new GLargeMapControl());
	map.addControl(new GMapTypeControl());
	map.addControl(new GOverviewMapControl());

  } else {
	  alert("Ihr Brwoser ist leider nich mit Google Maps kompatible!");
  }
  
}

function callSmallMap() {
  if (GBrowserIsCompatible()) {
	var map = new GMap2(document.getElementById("smallMap"));
	map.setCenter(new GLatLng(52.530163,13.386551), 10);
  	//Navigation festlegen
	/*
	map.addControl(new GLargeMapControl());
	map.addControl(new GMapTypeControl());
	map.addControl(new GOverviewMapControl());
	*/
	//Marker hinzufügen
	var point = new GLatLng(52.530163,13.386551);
	var firmaMarker = new GMarker(point);
	map.addOverlay(firmaMarker);
	/*
	GEvent.addListener(firmaMarker, "click", function() {
		firmaMarker.openInfoWindowHtml(starttexthtml);
													  });
	*/
	// INFO Window
	//map.openInfoWindowHtml(map.getCenter(), (starttexthtml));
  } else {
	 // alert("Ihr Brwoser ist leider nich mit Google Maps kompatible!");
  }
  
}

