$(document).ready(function() {
	var aAllA = document.getElementsByTagName('A');
	var bShowGallery = false;
	for (var i = 0; i < aAllA.length; i++) {
		if (aAllA[i].target == 'thePicture' && aAllA[i].href.match(/file=[^&]+/)) {
			var sFile = aAllA[i].href.match(/file=[^&]+/) + "";
			sFile = sFile.substr(5).replace(/%2F/g, '/');
			aAllA[i].href = sFile;
			
			bShowGallery = true;
		}
	}
	
	$("a[target='thePicture']").attr('rel', 'gallery');
	$("a[target='thePicture']").removeAttr('onclick');
	$("a[target='thePicture']").fancybox({
		'zoomSpeedIn':		0,
		'zoomSpeedOut':		0,
		'overlayShow': 		true,
		'overlayOpacity':	0.7
	});
	
	if (bShowGallery) {
		$("div#headline").append('<a id="gallery-link">Bildergalerie</a>');
		$("a#gallery-link").click(function() {$("a[target='thePicture']:first").click()});
	}
	
	$("form#search-form input#search-word").focus(function() {
		if ($(this).val() == 'Suche') {
			$(this).val('');
			$(this).attr('style', 'color: #333');
		}
	});
	$("form#search-form input#search-word").blur(function() {
		if ($(this).val() == '') {
			$(this).attr('style', 'color: #999');
			$(this).val('Suche');
		}
	});
	if ($("form#search-form input#search-word").val() == '') {
		$("form#search-form input#search-word").attr('style', 'color: #999');
		$("form#search-form input#search-word").val('Suche');
	}
	
	$("div#login input[name='user']").focus(function() {
		if ($(this).val() == 'Benutzername') {
			$(this).val('');
			$(this).attr('style', 'color: #333');
		}
	});
	$("div#login input[name='user']").blur(function() {
		if ($(this).val() == '') {
			$(this).attr('style', 'color: #999');
			$(this).val('Benutzername');
		}
	});
	$("div#login input[name='user']").attr('style', 'color: #999');
	$("div#login input[name='user']").val('Benutzername');
	
	
	$("div#login input[name='pass']").blur(function() {
		if ($(this).val() == '') {
			$('<input type="text" class="input-text" name="pass_clear" style="color: #999" value="Passwort"  />').insertAfter("div#login input[name='pass']");
			$("div#login input[name='pass_clear']").focus(function() {
				$(this).remove();
				$("div#login input[name='pass']").removeAttr('style');
				$("div#login input[name='pass']").focus();
			});
			$("div#login input[name='pass']").attr('style', 'display: none');
		}
	});
	$('<input type="text" class="input-text" name="pass_clear" style="color: #999" value="Passwort"  />').insertAfter("div#login input[name='pass']");
	$("div#login input[name='pass_clear']").focus(function() {
		$(this).remove();
		$("div#login input[name='pass']").removeAttr('style');
		$("div#login input[name='pass']").focus();
	});
	$("div#login input[name='pass']").attr('style', 'display: none');
	
	$("div.shadow").dropShadow();
});
