﻿/*
* modified loopedSlider 0.5.6 - jQuery plugin
* written by Nathan Searles
* http://nathansearles.com/loopedslider/
*
* Copyright (c) 2009 Nathan Searles (http://nathansearles.com/)
* Dual licensed under the MIT (MIT-LICENSE.txt)
* and GPL (GPL-LICENSE.txt) licenses.
*
* Built for jQuery library
* http://jquery.com
* Compatible with jQuery 1.3.2+
*
*/

/*
* markup example for $("#loopedSlider").loopedSlider();
*
* <div id="loopedSlider">
* <div class="container">
* <div class="slides">
* <div><img src="01.jpg" alt="" /></div>
* <div><img src="02.jpg" alt="" /></div>
* <div><img src="03.jpg" alt="" /></div>
* <div><img src="04.jpg" alt="" /></div>
* </div>
* </div>
* <a href="#" class="previous">previous</a>
* <a href="#" class="next">next</a>
* </div>
*
*/

if(typeof jQuery != 'undefined') {
	jQuery(function($) {
		$.fn.extend({
			loopedSlider: function(options) {
				var settings = $.extend({}, $.fn.loopedSlider.defaults, options);
				
				return this.each(
					function() {
						if($.fn.jquery < '1.3.2') {return;}
						var $t = $(this);
						var o = $.metadata ? $.extend({}, settings, $t.metadata()) : settings;
						
						var distance = 0;
						var times = 1;
						var slides = $(o.slides,$t).children().size();
						var width = $(o.slides,$t).children().outerWidth();
						var position = 0;
						var active = false;
						var ot=$(o.slides,$t);
						var nxt=$(".next",$t);
						var prt=$(".previous",$t);
						var cot=$(o.container,$t);
						
						if (slides===1) {
							ot.children().css({position:"absolute",left:position,display:"block"});
							$(".gallery_nav").addClass("hide");
							return;
						}
						
						ot.css({width:(slides*width)});
						
						ot.children().each(function(){
							$(this).css({position:"absolute",left:position,display:"block"});
							position=position+width;
						});			
						nxt.click(function(){
							if(active===false){
								animate("next",true);
							} return false;
						});
						
						prt.click(function(){
							if(active===false){
								animate("prev",true);
							} return false;
						});
			
						if (o.containerClick) {
							cot.click(function(){
								if(active===false){
									animate("next",true);
								} return false;
							});
						}
						
						function animate(dir,clicked){
							active = true;
							switch(dir){
								case "next":	
									times = times+1;
									if (times<=slides){
										distance = (-(times*width-width));			
										ot.animate({left: distance}, o.slidespeed,function(){
											active = false;
										});
									}else{
										times = 1;
										distance = (-(times*width-width));
										ot.animate({left: distance}, o.slidespeed*slides/2,function(){
											active = false;
										});
									}
								break;
								
								case "prev":
									times = times-1;
									if (times>0){
										distance = (-(times*width-width));
										ot.animate({left: distance}, o.slidespeed,function(){
											active = false;
										});
				  					}else{
										times = slides;
										distance = (-(times*width-width));
										ot.animate({left: distance}, o.slidespeed*slides/2,function(){
											active = false;
										});
									}
								break;
					
								default:
								break;
							}
						};
					}
				);
			}
		});
	
		$.fn.loopedSlider.defaults = {
			container: ".container", //Class/id of main container. You can use "#container" for an id.
			slides: ".slides", //Class/id of slide container. You can use "#slides" for an id.
			containerClick: true, //Click slider to goto next slide? true/false
			slidespeed: 300, //Speed of slide animation, 1000 = 1second.
			fadespeed: 200 //Speed of fade animation, 1000 = 1second.
		};
	});
}











var timerArrayFadeIn = new Array();
var timerArrayFadeOut = new Array();
var currentOpacity = new Array();

var tFadeOut;
var tFadeIn;



function fadeOut(cID){
	//set global opacity var
	//call recursive fadeout function
	currentID=cID;
	if(timerArrayFadeIn[currentID]){
		clearTimeout(timerArrayFadeIn[currentID]);
	}
	if(!currentOpacity[currentID]){
		currentOpacity[currentID]=100;
	}
	
	fadeOutEffect(currentID);
}


function fadeOutEffect(cID){
	
	if(currentOpacity[cID]>=0){
		currentOpacity[cID] = currentOpacity[cID] - 1 ;
		currentElement = document.getElementById(cID);
		setOpacity(currentElement , currentOpacity[cID]);
		timerArrayFadeOut[cID]=setTimeout('fadeOutEffect("'+cID+'")', 10);
	}
	//set timer to call self
}

function fadeIn(cID){
	//set global opacity var
	//call recursive fadeout function
	currentID=cID;
	
	if(timerArrayFadeOut[currentID]){
		clearTimeout(timerArrayFadeOut[currentID]);
	}
	
	fadeInEffect(currentID);
}

function fadeInEffect(cID){

	if(currentOpacity[cID]<=100){
		currentOpacity[cID] = currentOpacity[cID] + 1 ;
		currentElement = document.getElementById(cID);
		setOpacity(currentElement, currentOpacity[cID]);	
		timerArrayFadeIn[cID]=setTimeout('fadeInEffect("'+cID+'")', 10);
	}
	//set timer to call self
}


function setOpacity(currentElement,newOpacity) {

	currentElement.style.opacity=newOpacity/100;
	currentElement.style.MozOpacity=newOpacity/100;
	currentElement.style.filter='alpha(opacity='+newOpacity+')';
	
}



/*
 * puts the corresponding side link into an active state when hovering above a referenze img 
 */

function activateSideLink(sourceID){
	document.getElementById(sourceID+"_l").className="ref_active";
}

function deactivateSideLink(sourceID){
	document.getElementById(sourceID+"_l").className="";
}


/*
 * wraper functions for mouse over effects of referenzes
 */

function referencesOnMouseOver(sourceID){
	activateSideLink(sourceID);
	fadeOut(sourceID);

}
function referencesOnMouseOut(sourceID){
	deactivateSideLink(sourceID);
	fadeIn(sourceID);
}
function referencesOnClick(sourceID){
	
	deactivateSideLink(sourceID);
	fadeIn(sourceID);
	

	
}

/* slideable textbox
 *	click on the textbaustein link -> tb_klapptext un/folds 
 * 	tb_klapptext is hidden initialy (css display:none)
 */


$(document).ready(function(){
	$('.dropdown div a').click(function() {									// catch event click on link of textbaustein 
		$tb_klapptext=$(this).parent().parent().children('.tb_klapptext');		// find the child tb_klapptext
		if($tb_klapptext.is(":hidden")){										// check if tb_klapptext is hidden
			$(this).removeClass('tb_closed');									// change class of textbaustein link
			$(this).addClass('tb_open');										// from closed to open
			$tb_klapptext.slideDown('slow');									// unfold tb_klapptext
		}else{																	// tb_klapptext is visible
			$(this).removeClass('tb_open');										// change class of textbaustein link
			$(this).addClass('tb_closed');										// form open to closed
			$tb_klapptext.slideUp('slow');										// fold tb_klapptext
		}
	});
})


/*
 *  Fade effect f�r Kacheln auf der Startseite
 *
 */

$(function(){
	$('a.fader img').hover(
		function() { $(this).fadeTo("fast", 0.66); },
		function() { $(this).fadeTo("fast", 1); }
	);
});






