if(typeof jQuery != 'undefined') {
	$('html').addClass('jsenabled');
	$(function() {
		// special treatment for IE7
		if(!jQuery.support.hrefNormalized) {
			$('label[for]').append(':');
		}
		// end special treatment
		if(jQuery().cycle) {
			// logo switch
			$('#header h1 img').wrapAll($('<div>', {id: 'logos'})).parent().cycle({
				delay: -8000,
				timeout: 10000,
				sync: 0,
				speed: 300
			});
			// end logo switch
			// home page slideshow
			/*$('#intro .section2 blockquote').wrap($('<div>', {'class': 'section'}));
			$('#intro .section2 .section').each(function() {
				$(this).next('cite').appendTo($(this));
			});
			$('#intro .section1, #intro .section2').cycle({
				speed: 1000,
				timeout: 9000
			});*/
			// end home page slideshow
		}
		// end home page slideshow
		$('.videolist li:nth-child(3n+1),.gallerydetail li:nth-child(3n+1)').addClass('start');
		if(jQuery().overlay) {
			$('body').append(
				$('<div>', {id: 'overlay'}).append(
					$('<div>', {id: 'overlay_content'})
				)
			);
			$('.videolist a').attr('rel','#overlay').overlay({
				mask: 'black',
				effect: 'apple',
				onBeforeLoad: function() {
					var wrap = this.getOverlay().find("#overlay_content").empty();
					wrap.load(this.getTrigger().attr("href")+' #content .s1');
				}
			});
			$('#promo a[href*="youtube"]').click(function(e) {
				e.preventDefault();
				var ref = $(this).attr('href');
				location.href = '/musik#'+ref;
			});/*
			(function() {
				var loc = window.location.href;
				if(loc.indexOf('youtubeplayer/detail') != -1) {
					//alert('hi');
				}
			})();*/
			if($('.videolist').length && (window.location.hash.indexOf('youtube') != -1)) {
				$('#overlay').overlay({
					mask: 'black',
					onBeforeLoad: function() {
						var wrap = this.getOverlay().find("#overlay_content").empty();
						wrap.load(window.location.hash.substring(1)+' #content .s1');
					},
					load: true
				});
			}
			$('a[href="#newsletter"]').attr('rel','#newsletter').overlay({
				mask: 'black',
				onBeforeLoad: function() {
					var overlay = this.getOverlay();
					if(!overlay.find('.overlay_content').length) {
						overlay.find('> *:not(.close)').wrap($('<div>', {'class': 'overlay_content'}));
					}
				},
				onClose: function() {
					this.getOverlay().find('form').show().next('.success').remove();
				}
			});
			$('#newsletter').hide();
		} // end “if overlay”
		if($('#newsletter').length && jQuery().ajaxForm) {
			$('#newsletter').find('form').ajaxForm({
				beforeSubmit: function(formData, jqForm, options) {
					$('#newsletter').find('.invalid').remove();
					$('#newsletter').find('.error').removeClass('error');
	        var emailAddr = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
	        var inp = $('#newsletter').find('input[id$=email]');
	        var val = inp.val();
	        if(val == '') {
	        	inp.before(
	        		$('<div>', {
	        			'class': 'invalid',
	        			text: 'ist erforderlich!'
	        		})
	        	).parent().addClass('error');
	        	return false;
	        }
	        else if(!emailAddr.test(val)) {
	        	inp.before(
	        		$('<div>', {
	        			'class': 'invalid',
	        			text: 'Bitte eine gültige E-Mail-Adresse angeben.'
	        		})
	        	);
	        	return false;
	        }
	        else {
						$('#newsletter .overlay_content').append(
							$('<img>', {
								src: 'images/loading.gif',
								'class': 'loading'
							})
						).children('form').hide();
	        }
				},
				success: function(data) {
					var message = $('#newsletter', data).html();
					$('#newsletter .overlay_content').append(message).find('.loading').remove();
				},
				clearForm: true
			});
		}
		$('.gallerydetail li:nth-child(7n+1)').addClass('start_long');
		$('#main .gallerydetail li:first-child')
			.addClass('current')
			.parent()
			.before(
			$('<div>', {'class': 'bigimg'})
				.append(
					$('<span>')
						.append($('<img>', {src: $('.gallerydetail li:first-child a').attr('href')}))
						.append($('<span>', {'class': 'title', text: $('.gallerydetail li:first-child a').attr('title')}))
				)
				.append($('<div>', {'class': 'comment', text: $('.gallerydetail li:first-child .comment').text()}))
			).find('a').click(function(e) {
				$(this)
					.parent()
						.addClass('current')
					.siblings()
						.removeClass('current')
				.closest('ul')
				.prev()
					.find('img')
						.attr('src',$(this).attr('href'))
						.end()
					.find('.title')
						.text($(this).attr('title'))
						.end()
					.children('.comment')
						.text($(this).next('.comment').text());
				e.preventDefault();
		});/*
		$('#sub .calendar caption a').live('click', function(e) {
			e.preventDefault();
			var url = $(this).attr('href');
			$(this).closest('#sub').load(url+' #sub .calendar', function() {
				$('body').removeClass('loading');
			}).closest('body').addClass('loading');
		});*/
		$('#main .guestbook form, .guestbook .note').addClass('guestbook_form').appendTo('#sub');
		$('#home .al_container .pagination a').live('click', function(e) {
			e.preventDefault();
			var url = $(this).attr('href');
			var container = $(this).closest('.al_container');
			$('body').addClass('loading');
			$.get(url, function(html) {
				var data = $(html);
				container.children('.article_list').replaceWith(data.find('.article_list'));
				container.children('.pagination').replaceWith(data.find('.pagination'));
				$('body').removeClass('loading');
			});
		});
		if(jQuery().flash) {
			$('#album').flash({
				swf: 'http://player.zimbalam.com/player/3661585609872/6/black/0/0/0/de/',
				width: 420,
				height: 490
			});
		}
	});
}
