// JavaScript Document
(function(w){var E=w(window),u,f,F=-1,n,x,D,v,y,L,r,m=!window.XMLHttpRequest,s=[],l=document.documentElement,k={},t=new Image(),J=new Image(),H,a,g,p,I,d,G,c,A,K;w(function(){w("body").append(w([H=w('<div id="lbOverlay" />')[0],a=w('<div id="lbCenter" />')[0],G=w('<div id="lbBottomContainer" />')[0]]).css("display","none"));g=w('<div id="lbImage" />').appendTo(a).append(p=w('<div style="position: relative;" />').append([I=w('<a id="lbPrevLink" href="#" />').click(B)[0],d=w('<a id="lbNextLink" href="#" />').click(e)[0]])[0])[0];c=w('<div id="lbBottom" />').appendTo(G).append([w('<a id="lbCloseLink" href="#" />').add(H).click(C)[0],A=w('<div id="lbCaption" />')[0],K=w('<div id="lbNumber" />')[0],w('<div style="clear: both;" />')[0]])[0]});w.slimbox=function(O,N,M){u=w.extend({loop:true,overlayOpacity:0.8,overlayFadeDuration:400,resizeDuration:400,resizeEasing:"swing",initialWidth:400,initialHeight:400,imageFadeDuration:400,captionAnimationDuration:200,counterText:"Bild {x} von {y}",closeKeys:[27,88,67],previousKeys:[37,80],nextKeys:[39,78]},M);if(typeof O=="string"){O=[[O,N]];N=0}y=E.scrollTop()+(E.height()/2);L=u.initialWidth;r=u.initialHeight;w(a).css({top:Math.max(0,y-(r/2)),width:L,height:r,marginLeft:-L/2}).show();v=m||(H.currentStyle&&(H.currentStyle.position!="fixed"));if(v){H.style.position="absolute"}w(H).css("opacity",u.overlayOpacity).fadeIn(u.overlayFadeDuration);z();j(1);f=O;u.loop=u.loop&&(f.length>1);return b(N)};w.fn.slimbox=function(M,P,O){P=P||function(Q){return[Q.href,Q.title]};O=O||function(){return true};var N=this;return N.unbind("click").click(function(){var S=this,U=0,T,Q=0,R;T=w.grep(N,function(W,V){return O.call(S,W,V)});for(R=T.length;Q<R;++Q){if(T[Q]==S){U=Q}T[Q]=P(T[Q],Q)}return w.slimbox(T,U,M)})};function z(){var N=E.scrollLeft(),M=E.width();w([a,G]).css("left",N+(M/2));if(v){w(H).css({left:N,top:E.scrollTop(),width:M,height:E.height()})}}function j(M){if(M){w("object").add(m?"select":"embed").each(function(O,P){s[O]=[P,P.style.visibility];P.style.visibility="hidden"})}else{w.each(s,function(O,P){P[0].style.visibility=P[1]});s=[]}var N=M?"bind":"unbind";E[N]("scroll resize",z);w(document)[N]("keydown",o)}function o(O){var N=O.keyCode,M=w.inArray;return(M(N,u.closeKeys)>=0)?C():(M(N,u.nextKeys)>=0)?e():(M(N,u.previousKeys)>=0)?B():false}function B(){return b(x)}function e(){return b(D)}function b(M){if(M>=0){F=M;n=f[F][0];x=(F||(u.loop?f.length:0))-1;D=((F+1)%f.length)||(u.loop?0:-1);q();a.className="lbLoading";k=new Image();k.onload=i;k.src=n}return false}function i(){a.className="";w(g).css({backgroundImage:"url("+n+")",visibility:"hidden",display:""});w(p).width(k.width);w([p,I,d]).height(k.height);w(A).html(f[F][1]||"");w(K).html((((f.length>1)&&u.counterText)||"").replace(/{x}/,F+1).replace(/{y}/,f.length));if(x>=0){t.src=f[x][0]}if(D>=0){J.src=f[D][0]}L=g.offsetWidth;r=g.offsetHeight;var M=Math.max(0,y-(r/2));if(a.offsetHeight!=r){w(a).animate({height:r,top:M},u.resizeDuration,u.resizeEasing)}if(a.offsetWidth!=L){w(a).animate({width:L,marginLeft:-L/2},u.resizeDuration,u.resizeEasing)}w(a).queue(function(){w(G).css({width:L,top:M+r,marginLeft:-L/2,visibility:"hidden",display:""});w(g).css({display:"none",visibility:"",opacity:""}).fadeIn(u.imageFadeDuration,h)})}function h(){if(x>=0){w(I).show()}if(D>=0){w(d).show()}w(c).css("marginTop",-c.offsetHeight).animate({marginTop:0},u.captionAnimationDuration);G.style.visibility=""}function q(){k.onload=null;k.src=t.src=J.src=n;w([a,g,c]).stop(true);w([I,d,g,G]).hide()}function C(){if(F>=0){q();F=x=D=-1;w(a).hide();w(H).stop().fadeOut(u.overlayFadeDuration,j)}return false}})(jQuery);

// AUTOLOAD CODE BLOCK (MAY BE CHANGED OR REMOVED)
if (!/android|iphone|ipod|series60|symbian|windows ce|blackberry/i.test(navigator.userAgent)) {
	jQuery(function($) {
		$("a[href]").filter(function() {
			return /\.(jpg|png|gif)$/i.test(this.href);
		}).slimbox({}, null, function(el) {
			return (this == el) || (this.parentNode && (this.parentNode == el.parentNode));
		});
	});
}
(function($) {
	$.fn.extend($.ui.tabs.prototype,{
	
		// when widget is initiated
		_create: function() {
			var self = this, options = this.options;			
			// fire original function
			self._tabify(true);		
			// ARIA
			self.element.attr("role", "application");
			self.list.attr("role", "tablist");	
			// init aria atrributes for each panel and anchor
			for (var x = 0; x < self.anchors.length; x++) {
				self._ariaInit(x);
			}		
			
			// keyboard
			self.element.keydown( function(event){
				switch (event.keyCode) {
					case $.ui.keyCode.RIGHT: 
						event.preventDefault();
						self.select(options.selected+1);
						break;
					case $.ui.keyCode.DOWN: 
						event.preventDefault();
						self.select(options.selected+1);
						break;
					case $.ui.keyCode.UP: 
						event.preventDefault();
						self.select(options.selected-1);
						break;
					case $.ui.keyCode.LEFT: 
						event.preventDefault();
						self.select(options.selected-1);
						break;
					case $.ui.keyCode.END: 
						event.preventDefault();
						self.select(self.anchors.length-1);
						break;
					case $.ui.keyCode.HOME: 
						event.preventDefault();
						self.select(0);
						break;				
				}
			});	
		},
		
		_original_load: $.ui.tabs.prototype.load,
		// called whenever tab is called but if option collapsible is set | fired once at init for the chosen tab
		load: function(index) {	
			// hide all unselected
			for (var x = 0; x < this.anchors.length; x++) {			
				// anchors
				this._ariaSet(x, false);
				// remove ARIA live settings
				if($.data(this.anchors[x], 'href.tabs')) {
					$(this.panels[x])
						.removeAttr("aria-live")
						.removeAttr("aria-busy");
				}
			};	
			// is remote? set ARIA states 
			if($.data(this.anchors[index], 'href.tabs')) {
				$(this.panels[index])
					.attr("aria-live", "polite")
					.attr("aria-busy", "true");
			}		
			// fire original function
			this._original_load(index);			
			// is remote? end ARIA busy
			if($.data(this.anchors[index], 'href.tabs')) {
				$(this.panels[index])
					.attr("aria-busy", "false");
			}			
			// set state for the activated tab
			this._ariaSet(index, true);
		},
		
		// sets aria states for single tab and its panel
		_ariaSet: function(index, state) {		
			var tabindex = (state) ? 0 : -1;
			// set ARIA state for loaded tab
			$(this.anchors[index])
				.attr("tabindex", tabindex)
				.attr("aria-selected", state)						
			// set ARIA state for loaded tab
			$(this.panels[index])
				.attr("aria-hidden", !state)
				.attr("aria-expanded", state);
		},
		
		// sets all attributes when plugin is called or if tab is added
		_ariaInit: function(index) {
			var self = this;
			// get widget generated ID of the panel
			var panelId = $(this.panels[index]).attr("id");		
			// ARIA anchors and li's
			$(this.anchors[index])
				.attr("role", "tab")
				.attr("aria-controls", panelId)
				.attr("id", panelId+"-tab")				
			// set li to presentation role
			.parent().attr("role", "presentation");				
			// ARIA panels aka content wrapper
			$(this.panels[index])
				.attr("role", "tabpanel")
				.attr("aria-labelledby", panelId+"-tab");				
			// if collapsible, set event to toggle ARIA state
			if (this.options.collapsible) {
				$(this.anchors[index]).bind(this.options.event, function(event) {
					// get class to negate it to set states correctly when panel is collapsed
					self._ariaSet(index, !$(self.panels[index]).hasClass("ui-tabs-hide"));
				});
			}
		},		
		
		_original_add: $.ui.tabs.prototype.add,
		// called when a tab is added
		add: function(url, label, index) {
			// fire original function
			this._original_add(url, label, index);
			// ARIA			
			this.element
				.attr("aria-live", "polite")
				.attr("aria-relevant","additions");
			
			// if no index is defined tab should be added at the end of the tab list
			if (index) {
				this._ariaInit(index);
				this._ariaSet(index, false);
			} else {
				this._ariaInit(this.anchors.length-1);
				this._ariaSet(this.anchors.length-1, false);
			}			
		},
		
		_original_remove: $.ui.tabs.prototype.remove,
		// called when a tab is removed
		remove: function(index) {
			// fire original function
			this._original_remove(index);	
			// ARIA
			this.element
				.attr("aria-live", "polite")
				.attr("aria-relevant","removals");
		},		
		
		_original_destroy: $.ui.tabs.prototype.destroy,
		// removes all the setted attributes
		destroy: function() {
			var self = this, options = this.options;
			// remove ARIA attribute
			// wrapper element
			self.element
				.removeAttr("role")
				.removeAttr("aria-live")
				.removeAttr("aria-relevant");
			// ul element
			self.list.removeAttr("role");		
			for (var x = 0; x < self.anchors.length; x++) {
				// tabs
				$(self.anchors[x])
					.removeAttr("aria-selected")
					.removeAttr("aria-controls")
					.removeAttr("role")
					.removeAttr("id")
					.removeAttr("tabindex")
				// remove presentation role of the li element
				.parent().removeAttr("role");
				// tab panels
				$(self.panels[x])
					.removeAttr("aria-hidden")
					.removeAttr("aria-expanded")
					.removeAttr("aria-labelledby")
					.removeAttr("aria-live")
					.removeAttr("aria-busy")
					.removeAttr("aria-relevant")
					.removeAttr("role");
			}
			// fire original function
			this._original_destroy();	
		}		
	});
})(jQuery); 

(function($) {
	$.fn.niceTitle = function(options){
		var opts = $.extend({}, $.fn.niceTitle.defaults, options);
		var _self = this, _imgAlt = "", _imgTitle = "", _hasImg = false, _imgObj, _winWidth = $(window).width(), _winHeight = $(window).height(), _scrollTop = $(document).scrollTop(), _domHeight = $(document).height();
		this.initialize = function(_opts){
			$(window).scroll(function () {
			    _scrollTop = $(document).scrollTop();
		    });
			var htmlStr = "";
			if(jQuery.browser.msie){
				htmlStr = '<div id="niceTitle">' +
							   '<span>' +
								   '<span class="r1"></span>' +
								   '<span class="r2"></span>' +
								   '<span class="r3"></span>' +
								   '<span class="r4"></span>' +
							   '</span>' +
							   '<div id="niceTitle-ie"><p><em></em></p></div>' +
							   '<span>' +
								   '<span class="r4"></span>' +
								   '<span class="r3"></span>' +
								   '<span class="r2"></span>' +
								   '<span class="r1"></span>' +
							   '</span>' +
						    '</div>';
			}else{
				htmlStr = '<div id="niceTitle"><p><em></em></p></div>';
			}
			$(_self).mouseover(function(e){
				var _reg=new RegExp("\\" + _opts.brFlag, "g");
			    this.tmpTitle = this.title.replace(_reg, "<br />");
				if($(this).is("a")){this.tmpHref = this.href;
				}else if($(this).is("img")) {this.tmpHref = this.src;
				}else {this.tmpHref = ""};
			    _imgObj = $(this).find("img");
			    if(_imgObj.length > 0){
			    	_imgAlt = _imgObj.attr("alt");
			    	_imgObj.attr("alt", "");
			    	_imgTitle = _imgObj.attr("title");
			    	_imgObj.attr("title", "");
			    	_hasImg = true;
			    }
				var _length = _opts.urlSize;
				this.title = "";
				if(this.tmpHref.length > 0 && _opts.showLink){
				    this.tmpHref = (this.tmpHref.length > _length ? this.tmpHref.toString().substring(0,_length) + "..." : this.tmpHref);
					$(htmlStr).appendTo("body").find("p").prepend(this.tmpTitle).css({"color": _opts.titleColor}).find("em").text(this.tmpHref).css({"color": _opts.urlColor});
				}else{
					$(htmlStr).appendTo("body").find("p").prepend(this.tmpTitle).css({"color": _opts.titleColor}).find("em").remove();
				}
				var obj = $('#niceTitle');
			    obj.css({
					"position":"absolute",
	                "text-align":"left",
	                "padding":"5px",
					"opacity": _opts.opacity,
				    "top": (_winHeight + _scrollTop - e.pageY - _opts.y) - 10 < obj.height() ? (e.pageY - obj.height() - _opts.y) + "px" : (e.pageY + _opts.y) + "px",
					"left": (_winWidth - e.pageX - _opts.x) - 10 < _opts.maxWidth ?  (e.pageX - _opts.maxWidth - _opts.x) + "px" : (e.pageX + _opts.x) + "px",
					"z-index": _opts.zIndex,
					"max-width": _opts.maxWidth + "px",
					"width": "auto !important",
					"width": _opts.maxWidth + "px",
					"min-height": _opts.minHeight + "px",
					"-moz-border-radius": _opts.radius + "px",
					"-webkit-border-radius": _opts.radius + "px"
				});
				if(!jQuery.browser.msie){
				    obj.css({"background": _opts.bgColor});
				}else{
				    $('#niceTitle span').css({"background-color": _opts.bgColor, "border-color": _opts.bgColor});
					$('#niceTitle-ie').css({"background": _opts.bgColor, "border-color": _opts.bgColor});
				}
				obj.show('fast');
				return false;
		    }).mouseout(function(e){
			    this.title = this.tmpTitle;
			    $('#niceTitle').remove();
			    if(_hasImg){
			    	_imgObj.attr("alt", _imgAlt);
			    	_imgObj.attr("title", _imgTitle);
			    }
				return false;
		    }).mousemove(function(e){
				var obj = $('#niceTitle');
			    obj.css({
			   	    "top": (_winHeight + _scrollTop - e.pageY - _opts.y) - 10 < obj.height() ? (e.pageY - obj.height() - _opts.y) + "px" : (e.pageY + _opts.y) + "px",
					"left": (_winWidth - e.pageX - _opts.x) - 10 < _opts.maxWidth ?  (e.pageX - _opts.maxWidth - _opts.x) + "px" : (e.pageX + _opts.x) + "px"
			    });
				return false;
		    });
			return _self;
		};
		this.initialize(opts);
	};
    $.fn.niceTitle.defaults = {
		x: 10,

		y: 10,
		urlSize: 30,
		bgColor: "#555",
		titleColor: "#FFF",
		urlColor: "#EEE",
		zIndex: 999,
		maxWidth: 300,
		minHeight: 20,
		opacity: 0.9,
		radius: 10,
		showLink: true,
		brFlag: '|'
	};
})(jQuery);

jQuery(function($) {   
  if (document.URL.search(/(suchen.php)/) == -1) {
	  $("#main a").addClass('tip');
	  $("#main a").filter(function() {
		  return $(this).prop("href").match(/\.(jpg|png|gif)/)
		  }).removeClass('tip');
  }
  else {
  	$("#col1_content a").addClass('tip');
  	$("#col2_content a").addClass('tip');
	$("#brotkruemel a").addClass('tip');
  }
  $("#footer a").addClass('tip');
  $("a[href^='http']").attr('target','_blank');
  $("a[href*='.pdf']").attr('target','_blank');
  // Reset Font Size
  var originalFontSize = $('html').css('font-size');
  $(".resetFont").click(function(){
  $('html').css('font-size', originalFontSize);
  });
  // Increase Font Size
  $(".increaseFont").click(function(){
  	var currentFontSize = $('html').css('font-size');
 	var currentFontSizeNum = parseFloat(currentFontSize, 10);
    var newFontSize = currentFontSizeNum*1.1;
	$('html').css('font-size', newFontSize);
	return false;
  });
  // Decrease Font Size
  $(".decreaseFont").click(function(){
  	var currentFontSize = $('html').css('font-size');
 	var currentFontSizeNum = parseFloat(currentFontSize, 10);
    var newFontSize = currentFontSizeNum*0.9;
	$('html').css('font-size', newFontSize);
	return false;
  });
  //NiceTitle
  $("a.tip").niceTitle({showLink: false});
  // Tabs
  $('#dialog_link, ul#icons li').hover(
	function() { $(this).addClass('ui-state-hover'); }, 
	function() { $(this).removeClass('ui-state-hover'); }
  );
});
