/*
 *
 * Copyright (c) 2006-2008 Sam Collett (http://www.texotela.co.uk)
 * Licensed under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 * 
 * Version 2.0.2
 * Demo: http://www.texotela.co.uk/code/jquery/newsticker/
 *
 * $LastChangedDate$
 * $Rev$
 *
 */
 
(function($) {
/*
 * A basic news ticker.
 *
 * @name     newsticker (or newsTicker)
 * @param    delay      Delay (in milliseconds) between iterations. Default 4 seconds (4000ms)
 * @author   Sam Collett (http://www.texotela.co.uk)
 * @example  $("#news").newsticker(); // or $("#news").newsTicker(5000);
 *
 */
$.fn.newsTicker = $.fn.newsticker = function(delay)
{
	delay = delay || 4000;
	initTicker = function(el)
	{
		$.newsticker.clear(el);
		el.items = $("li", el);
		// hide all items (except first one)
		el.items.not(":eq(0)").hide().end();
		// current item
		el.currentitem = 0;
		startTicker(el);
	};
	startTicker = function(el)
	{
		el.tickfn = setInterval(function() { doTick(el) }, delay)
	};
	doTick = function(el)
	{
		// don't run if paused
		if(el.pause) return;
		// pause until animation has finished
		$.newsticker.pause(el);
		// hide current item
		$(el.items[el.currentitem]).fadeOut("slow",
			function()
			{
				$(this).hide();
				// move to next item and show
				el.currentitem = ++el.currentitem % (el.items.size());
				$(el.items[el.currentitem]).fadeIn("slow",
					function()
					{
						$.newsticker.resume(el);
					}
				);
			}
		);
	};
	this.each(
		function()
		{
			if(this.nodeName.toLowerCase()!= "ul") return;
			initTicker(this);
		}
	)
	.addClass("newsticker")
	.hover(
		function()
		{
			// pause if hovered over
			$.newsticker.pause(this);
		},
		function()
		{
			// resume when not hovered over
			$.newsticker.resume(this);
		}
	);
	return this;
};


$.newsticker = $.newsTicker =
{
	pause: function(el)
	{
		(el.jquery ? el[0] : el).pause = true;
	},
	resume: function(el)
	{
		(el.jquery ? el[0] : el).pause = false;
	},
	clear: function(el)
	{
		el = (el.jquery ? el[0] : el);
		clearInterval(el.tickfn);
		el.tickfn = null;
		el.items = null;
		el.currentItem = null;
	}
}

})(jQuery);
/**
 * This jQuery plugin displays pagination links inside the selected elements.
 *
 * @author Gabriel Birke (birke *at* d-scribe *dot* de)
 * @version 1.2
 * @param {int} maxentries Number of entries to paginate
 * @param {Object} opts Several options (see README for documentation)
 * @return {Object} jQuery Object
 */
jQuery.fn.pagination = function(maxentries, opts){
	opts = jQuery.extend({
		items_per_page:10,
		num_display_entries:10,
		current_page:0,
		num_edge_entries:0,
		link_to:"#",
		prev_text:"Prev",
		next_text:"Next",
		ellipse_text:"...",
		prev_show_always:true,
		next_show_always:true,
		callback:function(){return false;}
	},opts||{});
	
	return this.each(function() {
		/**
		 * Calculate the maximum number of pages
		 */
		function numPages() {
			return Math.ceil(maxentries/opts.items_per_page);
		}
		
		/**
		 * Calculate start and end point of pagination links depending on 
		 * current_page and num_display_entries.
		 * @return {Array}
		 */
		function getInterval()  {
			var ne_half = Math.ceil(opts.num_display_entries/2);
			var np = numPages();
			var upper_limit = np-opts.num_display_entries;
			var start = current_page>ne_half?Math.max(Math.min(current_page-ne_half, upper_limit), 0):0;
			var end = current_page>ne_half?Math.min(current_page+ne_half, np):Math.min(opts.num_display_entries, np);
			return [start,end];
		}
		
		/**
		 * This is the event handling function for the pagination links. 
		 * @param {int} page_id The new page number
		 */
		function pageSelected(page_id, evt){
			current_page = page_id;
			drawLinks();
			var continuePropagation = opts.callback(page_id, panel);
			if (!continuePropagation) {
				if (evt.stopPropagation) {
					evt.stopPropagation();
				}
				else {
					evt.cancelBubble = true;
				}
			}
			return continuePropagation;
		}
		
		/**
		 * This function inserts the pagination links into the container element
		 */
		function drawLinks() {
			panel.empty();
			var interval = getInterval();
			var np = numPages();
			// This helper function returns a handler function that calls pageSelected with the right page_id
			var getClickHandler = function(page_id) {
				return function(evt){ return pageSelected(page_id,evt); }
			}
			// Helper function for generating a single link (or a span tag if it's the current page)
			var appendItem = function(page_id, appendopts){
				page_id = page_id<0?0:(page_id<np?page_id:np-1); // Normalize page id to sane value
				appendopts = jQuery.extend({text:page_id+1, classes:""}, appendopts||{});
				if(page_id == current_page){
					var lnk = jQuery("<span class='current'>"+(appendopts.text)+"</span>");
				}
				else
				{
					var lnk = jQuery("<a>"+(appendopts.text)+"</a>")
						.bind("click", getClickHandler(page_id))
						.attr('href', opts.link_to.replace(/__id__/,page_id));
						
						
				}
				if(appendopts.classes){lnk.addClass(appendopts.classes);}
				panel.append(lnk);
			}
			// Generate "Previous"-Link
			if(opts.prev_text && (current_page > 0 || opts.prev_show_always)){
				appendItem(current_page-1,{text:opts.prev_text, classes:"prev"});
			}
			// Generate starting points
			if (interval[0] > 0 && opts.num_edge_entries > 0)
			{
				var end = Math.min(opts.num_edge_entries, interval[0]);
				for(var i=0; i<end; i++) {
					appendItem(i);
				}
				if(opts.num_edge_entries < interval[0] && opts.ellipse_text)
				{
					jQuery("<span>"+opts.ellipse_text+"</span>").appendTo(panel);
				}
			}
			// Generate interval links
			for(var i=interval[0]; i<interval[1]; i++) {
				appendItem(i);
			}
			// Generate ending points
			if (interval[1] < np && opts.num_edge_entries > 0)
			{
				if(np-opts.num_edge_entries > interval[1]&& opts.ellipse_text)
				{
					jQuery("<span>"+opts.ellipse_text+"</span>").appendTo(panel);
				}
				var begin = Math.max(np-opts.num_edge_entries, interval[1]);
				for(var i=begin; i<np; i++) {
					appendItem(i);
				}
				
			}
			// Generate "Next"-Link
			if(opts.next_text && (current_page < np-1 || opts.next_show_always)){
				appendItem(current_page+1,{text:opts.next_text, classes:"next"});
			}
		}
		
		// Extract current_page from options
		var current_page = opts.current_page;
		// Create a sane value for maxentries and items_per_page
		maxentries = (!maxentries || maxentries < 0)?1:maxentries;
		opts.items_per_page = (!opts.items_per_page || opts.items_per_page < 0)?1:opts.items_per_page;
		// Store DOM element for easy access from all inner functions
		var panel = jQuery(this);
		// Attach control functions to the DOM element 
		this.selectPage = function(page_id){ pageSelected(page_id);}
		this.prevPage = function(){ 
			if (current_page > 0) {
				pageSelected(current_page - 1);
				return true;
			}
			else {
				return false;
			}
		}
		this.nextPage = function(){ 
			if(current_page < numPages()-1) {
				pageSelected(current_page+1);
				return true;
			}
			else {
				return false;
			}
		}
		// When all initialisation is done, draw the links
		drawLinks();
        // call callback function
        opts.callback(current_page, this);
	});
}




/**
 * Callback function that displays the content.
 *
 * Gets called every time the user clicks on a pagination link.
 *
 * @param {int}page_index New Page index
 * @param {jQuery} jq the container with the pagination links as a jQuery object
 */
function pageselectCallback(page_index, jq){
	// Get number of elements per pagionation page from form
	//var items_per_page = $('#items_per_page').val();
	var items_per_page = 24;
	var max_elem = Math.min((page_index+1) * items_per_page, images.length);
	var newcontent = '';
	
	// Iterate through a selection of the content and build an HTML string
	for(var i=page_index*items_per_page;i<max_elem;i++)
	{
		newcontent += '<a href="img/bildergalerie/maidult/' + images[i][0] + '" rel="bildergalerie"><img src="img/bildergalerie/maidult/tn_' + images[i][0] + '" /></a>'
	}
	
	// Replace old content with new content
	$('#gallery-content').html(newcontent);
	$('a[rel=bildergalerie]').fancybox();

	// Prevent click eventpropagation
	return false;
}


/***********************************
*
* Sitemap mit jQuery auf und zuklappen
*
* @author Sebastian May <sebastian@decide.de>
* @date 2009-05-19
* @copyright Sebastian May
* @vorlage http://www.interaktionsdesigner.de/2009/02/03/ultimative-typo3-sitemap-ohne-extension-aber-mit-jquery/
*********************************** */
/*
*	jQuery Sitemap 1.0
*	author: paul lunow
*	www.interaktionsdesigner.de
*
*	01/29/2009
*	
*/
jQuery(function($) {
	
	// Einstellungen
	var container = ".csc-sitemap";
	var toggleAll = "#sitemap-toggleAll";
	
	//Unterpunkte verstecken
	$(container+" ul li>ul").css({display:"none"});
	
	//Alle auf und zu klappen
	$(toggleAll).show().find("span.close").hide().end().click(function() {
		if($(this).is(".open")) {
			$(container+" ul li a.folder").removeClass("closed").addClass("opend")
			$(container+" ul li ul").show();
			$(this).removeClass("open").addClass("close").attr("rel", "close").find("span.open").hide().end().find("span.close").show();
		}
		else {
			$(container+" ul li a.folder").removeClass("opend").addClass("closed");
			$(container+" ul li ul").hide();
			$(this).removeClass("close").addClass("open").attr("rel", "open").find("span.close").hide().end().find("span.open").show();
		}
		return false;
	});

	//Link zum Auf- und Zuklappen hinzuf�gen - einzelne "Ordner"
	$(container+" ul li").each(function() {
			if($("ul", this).length > 0) {
				$(this).prepend("<a href='#' class='folder closed'>auf</a>").find(".folder").click(function() {
					if($(this).is(".closed")) {
						//Submen� aufklappen
						$(this).text("zu ").removeClass("closed").addClass("opend").parents("li").find(">ul").slideDown();
					}
					else {
						//Submen� zuklappen
						$(this).text("auf").removeClass("opend").addClass("closed").parent("li").find(">ul").slideUp();
					}
					return false;
				});
			}
			else {
				$(this).prepend("<a href='#' class='page'>seite</a>").find(".page").click(function() {
					window.location = $(this).next().attr("href");
				});
			}
		});
});

/**
 * syncHeight - jQuery plugin to automagically Snyc the heights of columns
 * Made to seemlessly work with the CCS-Framework YAML (yaml.de)
 * @requires jQuery v1.0.3
 *
 * http://blog.ginader.de/dev/syncheight/
 *
 * Copyright (c) 2007 
 * Dirk Ginader (ginader.de)
 * Dirk Jesse (yaml.de)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 * Version: 1.0
 *
 * Usage:
 	$(document).ready(function(){
		$('p').syncHeight();
		$(window).resize(function(){ //if you want to update the columns after a Browser resize (optional)
			$('p').syncHeight();
		});
	});
 */

(function($) {
	$.fn.syncHeight = function(settings) {
		var max = 0;
		var browser_id = 0;
		var property = [
		   ['min-height','0px'],
			['height','1%']
		];

		// check for IE6 ...
		if($.browser.msie && $.browser.version < 7){
			browser_id = 1;
		}
		
		// get maximum element height ...
		$(this).each(function() {
			// fallback to auto height before height check ...
			$(this).css(property[browser_id][0],property[browser_id][1]);
			var val=$(this).height();
			if(val > max){
			   max = val;
			}
		});
		
		// set synchronized element height ...
 		$(this).each(function() {
  			$(this).css(property[browser_id][0],max+'px');
		});
		return this;
	};	
})(jQuery);


/* Hier stehen die Aufrufe alles JS Funktionen */
$(document).ready(function(){
	$('#musik > a').click(function() {
		var element = $(this);
		var span = $('#musik > a > span');
		if (element.is('.on')) {
			element.removeClass('on');
			element.addClass('off');
			span.text('Musik aus')
		}
		else {
			element.removeClass('off');
			element.addClass('on');
			span.text('Musik an')
		}
		
		return false;
	});
	$('.dropdown').each(function () {
		/*
		$(this).parent().eq(0).hover(function () {
			$('.dropdown:eq(0)', this).fadeIn('fast');
		}, function () {
			$('.dropdown:eq(0)', this).fadeOut('slow');
		});*/
		/*
		$(this).parent().eq(0).mouseover(function() {
			$(this).children('.dropdown').show();
		}).mouseout(function() {
			$(this).children('.dropdown').hide();
		});*/
		$(this).parent().eq(0).hover(function () {
	    	$('.dropdown:eq(0)', this).show();
	    }, function () {
	    	$('.dropdown:eq(0)', this).hide();
	    });
	});
	$('.ticker').newsticker(3000);
	$('.fancybox-link').fancybox({
//		'titlePosition'		: 'inside',
		'titleShow'			: false,
		'transitionIn'		: 'fade',
		'transitionOut'		: 'fade',
		'centerOnScroll'  : true,
		'overlayOpacity'  : 0.9,
		'overlayColor'    :  '#000',
		'hideOnOverlayClick' : true,
		'autoDimensions' : true,
		'onComplete' : function() {$('#termine-alle').focus();}
	});

	$('#accordion').accordion();
	$('a[rel=bildergalerie]').fancybox();
	$('div#site > div.sync').syncHeight();
	/*
	$('#gallery-paginator').pagination(images.length, {
				'callback': pageselectCallback,
				items_per_page: 24,
				num_display_entries: 24,
				current_page: 0,
				num_edge_entries: 0,
				link_to: "#",
				prev_text: "Letzte",
				next_text: "N&auml;chste",
				ellipse_text: "...",
				prev_show_always: true,
				next_show_always: true
			});
			*/
});

