// JavaScript Document


//Wenn Website eingebette, dann Frame loswerden
if (top.frames.length!==0) { top.location=self.document.location }

// jQuery AJAX
$(document).ready(function(){
	
	/* Value von Inputs
	 * ############################################################ */
	var formElements = new Array(
		$('#newsletter_email')
	);
	
	for(var i = 0; i < formElements.length; i++) {
		formValue(formElements[i]);
	}
	
	// Initiate GMap
	if (GBrowserIsCompatible()) {
		var map = new GMap2(document.getElementById("gmap"));
		
		// Adresse
		var name = 'Wolfgang Jansen GmbH';
		var street 	= 'Reutherstra&szlig;e 3';
		var zipCity = '53773 Hennef (Sieg)';
		
		// Anzeigepunkt berechnen
		var address = street + ', ' + zipCity + ', Deutschland';
		
		// Wie soll die Adresse angezeigt werden
		var showAddress = '<h4>' + name + '</h4>'
						+ '<p>' + street + '<br />' + zipCity + '</p>'
						+ '<p><a href="http://maps.google.de/?saddr=&daddr=Reutherstra%C3%9Fe+3%2C+53773%2C+Hennef%2FSieg">Routenplaner</a></p>';
		
		var geocoder = new GClientGeocoder();
		
		geocoder.getLatLng(
			address,
			function(point) {
				if (!point) {
					// Falls Adresse nicht gefunden wird
					$('#gmap').html(msg['noAddress']);
				} else {
					map.setCenter(point, 12);
					
					var marker = new GMarker(point);
					GEvent.addListener(marker, "click", function() {
						marker.openInfoWindowHtml(showAddress);
					});								
					map.addOverlay(marker);
					marker.openInfoWindowHtml(showAddress);
					
					// Navigation
					map.addControl(new GLargeMapControl3D());
				}
			}
		); 
	}
});


/**
 * 		Plugins
 * ###############################################################################################################
 */

/* Form value
 * ############################################################ */
function formValue(formElement) {
	formElement.each(function() {
		var attrTitle = $(this).attr('title');
		
		if($(this).val() == '' || $(this).val() == attrTitle) {
			$(this).val(attrTitle).css({'color' : '#666'});
		}
		
		$(this).focus(function() {
			if($(this).val() == attrTitle) {
				$(this).val('').css({'color' : '#333'});
			}
		}).blur(function() {
			if($(this).val() == '') {
				$(this).css({'color' : '#666'}).val(attrTitle)
			}
		});
	});
}
