$(document).ready(function() {

	/* replace fonts */
	Cufon.replace('h1');

	$('#showroute').click(function() {
		var from = $('input[name=from]').val(),
			  to = $('input[name=to]').val();
		
		if(from != "" && to != "") {
			var url = 'http://maps.google.de/maps?f=d&source=s_d&saddr='+decodeURI(from)+'&daddr=In+den+Burgwiesen+3+72488+Sigmaringen&hl=de&ie=UTF8&z=10';
			window.open(url,'Route');
		} else {
			var url = 'http://maps.google.de/maps?f=d&source=s_d&saddr='+decodeURI(from)+'&daddr=In+den+Burgwiesen+3+72488+Sigmaringen&hl=de&ie=UTF8&z=10';
			window.open(url,'Route');
		}
	});

	// lightbox
//	$("a[rel^='prettyPhoto']").prettyPhoto();
	$("a[rel^='prettyPhoto']").prettyPhoto({
		animationSpeed: 'normal', /* fast/slow/normal */
		padding: 40, /* padding for each side of the picture */
		opacity: 0.4, /* Value betwee 0 and 1 */
		showTitle: false, /* true/false */
		allowresize: true, /* true/false */
		counter_separator_label: '/', /* The separator for the gallery counter 1 "of" 2 */
		theme: 'light_rounded', /* light_rounded / dark_rounded / light_square / dark_square */
		hideflash: false, /* Hides all the flash object on a page, set to TRUE if flash appears over prettyPhoto */
		modal: false, /* If set to true, only the close button will close the window */
		changepicturecallback: function(){}, /* Called everytime an item is shown/changed */
		callback: function(){} /* Called when prettyPhoto is closed */
	});


	// captcha
	$('#reloadCaptcha').click(function() {
		$('#captcha').attr('src','/captcha/'+Math.random());
		return false;
	});
	
	// language
	/*
	$('#language td').each(function() {
		$(this).mouseover(function() {
			$(this).attr('width','30%');
		}).mouseout(function() {
			$(this).attr('width','');
		});
	});*/
	
	$('#language .txtfield').each(function() {
		$(this).elastic();
	});
	
	$('#language .txtfield').click(function() {
		var el = $(this);
		el.addClass('border2px');
		
		el.blur(function() {
			var lang = el.attr('name');
			var id = el.attr('id');
			var val = el.val();
			el.removeClass('border2px');
			$.ajax({
				type: "POST",
				url: "/language/save/",
				data: "lang="+lang+"&id="+id+"&val="+encodeURIComponent(val),
				success: function(msg){
					if(msg == "ok") {
						el.addClass('txt_ok').wait(function() {
							el.removeClass('txt_ok');
						});
					}
					//alert(msg);
				}
			});
			
		});
	});

});