$(document).ready(function(){
	// accordion ***************************************************************
	if (typeof $().accordion == 'function') {
		$('ul.accordion').accordion({
			active: ".selected",
			autoHeight: false,
			header: ".opener",
			collapsible: true,
			event: "click",
			change:function(){
				if (_tab.filter('.active').length) {
					_tabHolder.animate({height:_generalDiv.height()}, 300);
				}
			}
		});
	}
	
	var _gallery = $('div.gallery');
	if (_gallery.length) {
		// gallery *************************************************************
		if (typeof $().galleryScroll == 'function') {
			$('div.gallery-box').galleryScroll({
				btPrev:'span.prev a',
				btNext:'span.next a'
			})
		}
		if (typeof $().slideShow == 'function') {
			_gallery.slideShow({
				slideEl:'div.place-holder img',
				linkNext:false,
				linkPrev:false,
				linkPause:false,
				numElementLink:'div.gallery-box li a',
				duration:500
			});
		}
		
		// tab animation *******************************************************
		var _tabHolder = $('div.tabset');
		var _tab = $('a.tab', _tabHolder);
		var _closeBt = $('span.btn-close a');
		var _generalDiv = $('div.general-inner');
		
		_tab.click(function(){
			_tabHolder.animate({height:_generalDiv.height()}, 300);
		});
		_closeBt.click(function(){
			_tab.removeClass('active');
			_tabHolder.animate({height:29}, 300);
			$('div.tab:visible').fadeOut(300);
			return false;
		});
	}
	
	// load content for more... ************************************************
	$('a.load').click(function(){
		var _url = $(this).attr('href');
		var _this = this;
		if (!$('div.more').length) {
			$.ajax({
				url: _url,
				success: function(msg){
					$(_this).text('Weniger Inhalt anzeigen').before('<div class="more"></div>');
					$('div.more').hide().append(msg).slideDown(300, function(){
						if (_tab.filter('.active').length) {
							_tabHolder.animate({height:_generalDiv.height()}, 300);
						}
					});
				}
			});
		} else {
			if ($('div.more').is(':visible')) {
				$(_this).text('Gesamten Inhalt anzeigen');
				$('div.more').slideUp(300, function(){
					if (_tab.filter('.active').length) {
						_tabHolder.animate({height:_generalDiv.height()}, 300);
					}
				});
			} else {
				$(_this).text('Weniger Inhalt anzeigen');
				$('div.more').slideDown(300, function(){
					if (_tab.filter('.active').length) {
						_tabHolder.animate({height:_generalDiv.height()}, 300);
					}
				});
			}
		}
		return false;
	});
});

