/*!
 * jQuery Tools dev - The missing UI library for the Web
 * 
 * overlay/overlay.js
 * scrollable/scrollable.js
 * tabs/tabs.js
 * toolbox/toolbox.expose.js
 * 
 * NO COPYRIGHTS OR LICENSES. DO WHAT YOU LIKE.
 * 
 * http://flowplayer.org/tools/
 * 
 */
(function(a){a.tools=a.tools||{version:"dev"},a.tools.overlay={addEffect:function(a,b,d){c[a]=[b,d]},conf:{close:null,closeOnClick:!0,closeOnEsc:!0,closeSpeed:"fast",effect:"default",fixed:!a.browser.msie||a.browser.version>6,left:"center",load:!1,mask:null,oneInstance:!0,speed:"normal",target:null,top:"10%"}};var b=[],c={};a.tools.overlay.addEffect("default",function(b,c){var d=this.getConf(),e=a(window);d.fixed||(b.top+=e.scrollTop(),b.left+=e.scrollLeft()),b.position=d.fixed?"fixed":"absolute",this.getOverlay().css(b).fadeIn(d.speed,c)},function(a){this.getOverlay().fadeOut(this.getConf().closeSpeed,a)});function d(d,e){var f=this,g=d.add(f),h=a(window),i,j,k,l=a.tools.expose&&(e.mask||e.expose),m=Math.random().toString().slice(10);l&&(typeof l=="string"&&(l={color:l}),l.closeOnClick=l.closeOnEsc=!1);var n=e.target||d.attr("rel");j=n?a(n):null||d;if(!j.length)throw"Could not find Overlay: "+n;d&&d.index(j)==-1&&d.click(function(a){f.load(a);return a.preventDefault()}),a.extend(f,{load:function(d){if(f.isOpened())return f;var i=c[e.effect];if(!i)throw"Overlay: cannot find effect : \""+e.effect+"\"";e.oneInstance&&a.each(b,function(){this.close(d)}),d=d||a.Event(),d.type="onBeforeLoad",g.trigger(d);if(d.isDefaultPrevented())return f;k=!0,l&&a(j).expose(l);var n=e.top,o=e.left,p=j.outerWidth({margin:!0}),q=j.outerHeight({margin:!0});typeof n=="string"&&(n=n=="center"?Math.max((h.height()-q)/2,0):parseInt(n,10)/100*h.height()),o=="center"&&(o=Math.max((h.width()-p)/2,0)),i[0].call(f,{top:n,left:o},function(){k&&(d.type="onLoad",g.trigger(d))}),l&&e.closeOnClick&&a.mask.getMask().one("click",f.close),e.closeOnClick&&a(document).bind("click."+m,function(b){a(b.target).parents(j).length||f.close(b)}),e.closeOnEsc&&a(document).bind("keydown."+m,function(a){a.keyCode==27&&f.close(a)});return f},close:function(b){if(!f.isOpened())return f;b=b||a.Event(),b.type="onBeforeClose",g.trigger(b);if(!b.isDefaultPrevented()){k=!1,c[e.effect][1].call(f,function(){b.type="onClose",g.trigger(b)}),a(document).unbind("click."+m).unbind("keydown."+m),l&&a.mask.close();return f}},getOverlay:function(){return j},getTrigger:function(){return d},getClosers:function(){return i},isOpened:function(){return k},getConf:function(){return e}}),a.each("onBeforeLoad,onStart,onLoad,onBeforeClose,onClose".split(","),function(b,c){a.isFunction(e[c])&&a(f).bind(c,e[c]),f[c]=function(b){b&&a(f).bind(c,b);return f}}),i=j.find(e.close||".close"),!i.length&&!e.close&&(i=a("<a class=\"close\"></a>"),j.prepend(i)),i.click(function(a){f.close(a)}),e.load&&f.load()}a.fn.overlay=function(c){var e=this.data("overlay");if(e)return e;a.isFunction(c)&&(c={onBeforeLoad:c}),c=a.extend(!0,{},a.tools.overlay.conf,c),this.each(function(){e=new d(a(this),c),b.push(e),a(this).data("overlay",e)});return c.api?e:this}})(jQuery);
(function(a){a.tools=a.tools||{version:"dev"},a.tools.scrollable={conf:{activeClass:"active",circular:!1,clonedClass:"cloned",disabledClass:"disabled",easing:"swing",initialIndex:0,item:"> *",items:".items",keyboard:!0,mousewheel:!1,next:".next",prev:".prev",size:1,speed:400,vertical:!1,touch:!0,wheelSpeed:0}};function b(a,b){var c=parseInt(a.css(b),10);if(c)return c;var d=a[0].currentStyle;return d&&d.width&&parseInt(d.width,10)}function c(b,c){var d=a(c);return d.length<2?d:b.parent().find(c)}var d;function e(b,e){var f=this,g=b.add(f),h=b.children(),i=0,j=e.vertical;d||(d=f),h.length>1&&(h=a(e.items,b)),e.size>1&&(e.circular=!1),a.extend(f,{getConf:function(){return e},getIndex:function(){return i},getSize:function(){return f.getItems().size()},getNaviButtons:function(){return n.add(o)},getRoot:function(){return b},getItemWrap:function(){return h},getItems:function(){return h.find(e.item).not("."+e.clonedClass)},move:function(a,b){return f.seekTo(i+a,b)},next:function(a){return f.move(e.size,a)},prev:function(a){return f.move(-e.size,a)},begin:function(a){return f.seekTo(0,a)},end:function(a){return f.seekTo(f.getSize()-1,a)},focus:function(){d=f;return f},addItem:function(b){b=a(b),e.circular?(h.children().last().before(b),h.children().first().replaceWith(b.clone().addClass(e.clonedClass))):(h.append(b),o.removeClass("disabled")),g.trigger("onAddItem",[b]);return f},seekTo:function(b,c,k){b.jquery||(b*=1);if(e.circular&&b===0&&i==-1&&c!==0)return f;if(!e.circular&&b<0||b>f.getSize()||b<-1)return f;var l=b;b.jquery?b=f.getItems().index(b):l=f.getItems().eq(b);var m=a.Event("onBeforeSeek");if(!k){g.trigger(m,[b,c]);if(m.isDefaultPrevented()||!l.length)return f}var n=j?{top:-l.position().top}:{left:-l.position().left};i=b,d=f,c===undefined&&(c=e.speed),h.animate(n,c,e.easing,k||function(){g.trigger("onSeek",[b])});return f}}),a.each(["onBeforeSeek","onSeek","onAddItem"],function(b,c){a.isFunction(e[c])&&a(f).bind(c,e[c]),f[c]=function(b){b&&a(f).bind(c,b);return f}});if(e.circular){var k=f.getItems().slice(-1).clone().prependTo(h),l=f.getItems().eq(1).clone().appendTo(h);k.add(l).addClass(e.clonedClass),f.onBeforeSeek(function(a,b,c){if(!a.isDefaultPrevented()){if(b==-1){f.seekTo(k,c,function(){f.end(0)});return a.preventDefault()}b==f.getSize()&&f.seekTo(l,c,function(){f.begin(0)})}});var m=b.parents().add(b).filter(function(){if(a(this).css("display")==="none")return!0});m.length?(m.show(),f.seekTo(0,0,function(){}),m.hide()):f.seekTo(0,0,function(){})}var n=c(b,e.prev).click(function(){f.prev()}),o=c(b,e.next).click(function(){f.next()});e.circular||(f.onBeforeSeek(function(a,b){setTimeout(function(){a.isDefaultPrevented()||(n.toggleClass(e.disabledClass,b<=0),o.toggleClass(e.disabledClass,b>=f.getSize()-1))},1)}),e.initialIndex||n.addClass(e.disabledClass)),f.getSize()<2&&n.add(o).addClass(e.disabledClass),e.mousewheel&&a.fn.mousewheel&&b.mousewheel(function(a,b){if(e.mousewheel){f.move(b<0?1:-1,e.wheelSpeed||50);return!1}});if(e.touch){var p={};h[0].ontouchstart=function(a){var b=a.touches[0];p.x=b.clientX,p.y=b.clientY},h[0].ontouchmove=function(a){if(a.touches.length==1&&!h.is(":animated")){var b=a.touches[0],c=p.x-b.clientX,d=p.y-b.clientY;f[j&&d>0||!j&&c>0?"next":"prev"](),a.preventDefault()}}}e.keyboard&&a(document).bind("keydown.scrollable",function(b){if(!(!e.keyboard||b.altKey||b.ctrlKey||b.metaKey||a(b.target).is(":input"))){if(e.keyboard!="static"&&d!=f)return;var c=b.keyCode;if(j&&(c==38||c==40)){f.move(c==38?-1:1);return b.preventDefault()}if(!j&&(c==37||c==39)){f.move(c==37?-1:1);return b.preventDefault()}}}),e.initialIndex&&f.seekTo(e.initialIndex,0,function(){})}a.fn.scrollable=function(b){var c=this.data("scrollable");if(c)return c;b=a.extend({},a.tools.scrollable.conf,b),this.each(function(){c=new e(a(this),b),a(this).data("scrollable",c)});return b.api?c:this}})(jQuery);
(function(a){a.tools=a.tools||{version:"dev"},a.tools.tabs={conf:{tabs:"a",current:"current",onBeforeClick:null,onClick:null,effect:"default",initialIndex:0,event:"click",rotate:!1,history:!1},addEffect:function(a,c){b[a]=c}};var b={"default":function(a,b){this.getPanes().hide().eq(a).show(),b.call()},fade:function(a,b){var c=this.getConf(),d=c.fadeOutSpeed,e=this.getPanes();d?e.fadeOut(d):e.hide(),e.eq(a).fadeIn(c.fadeInSpeed,b)},slide:function(a,b){this.getPanes().slideUp(200),this.getPanes().eq(a).slideDown(400,b)},ajax:function(a,b){this.getPanes().eq(0).load(this.getTabs().eq(a).attr("href"),b)}},c;a.tools.tabs.addEffect("horizontal",function(b,d){c||(c=this.getPanes().eq(0).width()),this.getCurrentPane().animate({width:0},function(){a(this).hide()}),this.getPanes().eq(b).animate({width:c},function(){a(this).show(),d.call()})});function d(c,d,e){var f=this,g=c.add(this),h=c.find(e.tabs),i=d.jquery?d:c.children(d),j;h.length||(h=c.children()),i.length||(i=c.parent().find(d)),i.length||(i=a(d)),a.extend(this,{click:function(c,d){var i=h.eq(c);typeof c=="string"&&c.replace("#","")&&(i=h.filter("[href*="+c.replace("#","")+"]"),c=Math.max(h.index(i),0));if(e.rotate){var k=h.length-1;if(c<0)return f.click(k,d);if(c>k)return f.click(0,d)}if(!i.length){if(j>=0)return f;c=e.initialIndex,i=h.eq(c)}if(c===j)return f;d=d||a.Event(),d.type="onBeforeClick",g.trigger(d,[c]);if(!d.isDefaultPrevented()){j=c,b[e.effect].call(f,c,function(){d.type="onClick",g.trigger(d,[c])}),h.removeClass(e.current),i.addClass(e.current);return f}},getConf:function(){return e},getTabs:function(){return h},getPanes:function(){return i},getCurrentPane:function(){return i.eq(j)},getCurrentTab:function(){return h.eq(j)},getIndex:function(){return j},next:function(){return f.click(j+1)},prev:function(){return f.click(j-1)},destroy:function(){h.unbind(e.event).removeClass(e.current),i.find("a[href^=#]").unbind("click.T");return f}}),a.each("onBeforeClick,onClick".split(","),function(b,c){a.isFunction(e[c])&&a(f).bind(c,e[c]),f[c]=function(b){b&&a(f).bind(c,b);return f}}),e.history&&a.fn.history&&(a.tools.history.init(h),e.event="history"),h.each(function(b){a(this).bind(e.event,function(a){f.click(b,a);return a.preventDefault()})}),i.find("a[href^=#]").bind("click.T",function(b){f.click(a(this).attr("href"),b)}),location.hash&&e.tabs=="a"&&c.find("[href="+location.hash+"]").length?f.click(location.hash):(e.initialIndex===0||e.initialIndex>0)&&f.click(e.initialIndex)}a.fn.tabs=function(b,c){var e=this.data("tabs");e&&(e.destroy(),this.removeData("tabs")),a.isFunction(c)&&(c={onBeforeClick:c}),c=a.extend({},a.tools.tabs.conf,c),this.each(function(){e=new d(a(this),b,c),a(this).data("tabs",e)});return c.api?e:this}})(jQuery);
(function(a){a.tools=a.tools||{version:"dev"};var b;b=a.tools.expose={conf:{maskId:"exposeMask",loadSpeed:"slow",closeSpeed:"fast",closeOnClick:!0,closeOnEsc:!0,zIndex:9998,opacity:.8,startOpacity:0,color:"#fff",onLoad:null,onClose:null}};function c(){if(a.browser.msie){var b=a(document).height(),c=a(window).height();return[window.innerWidth||document.documentElement.clientWidth||document.body.clientWidth,b-c<20?c:b]}return[a(document).width(),a(document).height()]}function d(b){if(b)return b.call(a.mask)}var e,f,g,h,i;a.mask={load:function(j,k){if(g)return this;typeof j=="string"&&(j={color:j}),j=j||h,h=j=a.extend(a.extend({},b.conf),j),e=a("#"+j.maskId),e.length||(e=a("<div/>").attr("id",j.maskId),a("body").append(e));var l=c();e.css({position:"absolute",top:0,left:0,width:l[0],height:l[1],display:"none",opacity:j.startOpacity,zIndex:j.zIndex}),j.color&&e.css("backgroundColor",j.color);if(d(j.onBeforeLoad)===!1)return this;j.closeOnEsc&&a(document).bind("keydown.mask",function(b){b.keyCode==27&&a.mask.close(b)}),j.closeOnClick&&e.bind("click.mask",function(b){a.mask.close(b)}),a(window).bind("resize.mask",function(){a.mask.fit()}),k&&k.length&&(i=k.eq(0).css("zIndex"),a.each(k,function(){var b=a(this);/relative|absolute|fixed/i.test(b.css("position"))||b.css("position","relative")}),f=k.css({zIndex:Math.max(j.zIndex+1,i=="auto"?0:i)})),e.css({display:"block"}).fadeTo(j.loadSpeed,j.opacity,function(){a.mask.fit(),d(j.onLoad),g="full"}),g=!0;return this},close:function(){if(g){if(d(h.onBeforeClose)===!1)return this;e.fadeOut(h.closeSpeed,function(){d(h.onClose),f&&f.css({zIndex:i}),g=!1}),a(document).unbind("keydown.mask"),e.unbind("click.mask"),a(window).unbind("resize.mask")}return this},fit:function(){if(g){var a=c();e.css({width:a[0],height:a[1]})}},getMask:function(){return e},isLoaded:function(a){return a?g=="full":g},getConf:function(){return h},getExposed:function(){return f}},a.fn.mask=function(b){a.mask.load(b);return this},a.fn.expose=function(b){a.mask.load(b,this);return this}})(jQuery);


(function($) {
	var t = $.tools.overlay; 
	t.plugins = t.plugins || {};

	/**
	 * Overlay Gallery plugin, version: 1.0.0
	 * 
	 * Copyright (c) 2009 Tero Piirainen
	 * http://flowplayer.org/tools/overlay.html#gallery
	 *
	 * Dual licensed under MIT and GPL 2+ licenses
	 * http://www.opensource.org/licenses
	 *
	 * Since  : July 2009
	 * Date: ${date}
	 * Revision: ${revision} 
	 */
	// TODO: next(), prev(), getIndex(), onChange event
	// version number
	t.plugins.gallery = {
		version: '1.0.0', 
		conf: { 
			imgId: 'img',
			next: '.next',
			prev: '.prev',
			info: '.info',
			progress: '.progress',
			disabledClass: 'disabled',
			activeClass: 'active',
			opacity: 0.8,
			speed: 'slow',
			template: '<strong>${title}</strong> <span>Image ${index} of ${total}</span>',  
			autohide: true,
			preload: true,
			api: false,
			minWidth: 0,
			minHeight: 0,
			// Addtions by Franz Koch
			attrTarget:		'el',//'el.children(\'img\')',
			useAsTitle:		'el.attr(\'title\')'//'$(\'#\'+el.attr(\'name\')).html()', //available objects: $this (jQueryObject from matching lightbox enabled item), $tgt (jQueryObject from settings.attrTarget)
		}
	};			

	$.fn.gallery = function(opts) {
		
		var conf = $.extend({}, t.plugins.gallery.conf), api;
		$.extend(conf, opts);   	

		// common variables for all gallery images
		api = this.overlay();
		
		var links = this,
			 overlay = api.getOverlay(),
			 next = overlay.find(conf.next),
			 prev = overlay.find(conf.prev),
			 info = overlay.find(conf.info),
			 progress = overlay.find(conf.progress),
			 els = prev.add(next).css({opacity: conf.opacity}),
			 close = api.getClosers(), 			 
			 index,
			 animating = false,
			 targets = [];

		// remove duplicate links (by Franz Koch)
		links = $($.grep(links, function(o, i) {
			var l = $(o).attr('href');
			if ($.inArray(l,targets) > -1) {
				return false;
			}
			targets.push(l);
			return true;
		}));

//{{{ load 

		function load(el) {
			
			//progress.fadeIn();
			overlay.addClass('loading');
			els.hide(); close.hide(); info.hide();
			animating = true;
			
			var url = el.attr("href"); 

			// download the image 
			var image = new Image();
			
			image.onload = function() {
				
				progress.fadeOut();
				
				// find image inside overlay
				var img = $("#" + conf.imgId, overlay); 
				
				// or append it to the overlay 
				if (!img.length) { 
					img = $("<img/>").attr("id", conf.imgId).css("visibility", "hidden");
					overlay.prepend(img);
				}
				
				// make initially invisible to get it's dimensions
				img.attr("src", url).css("visibility", "hidden"); 			
					
				// animate overlay to fit the image dimensions
				var width = Math.max(image.width,conf.minWidth),
					left = ($(window).width() - width) / 2;
					
				// calculate index number
				index = links.index(links.filter(el));	

				// activate trigger
				links.removeClass(conf.activeClass).eq(index).addClass(conf.activeClass);
				
				// enable/disable next/prev links
				var cls = conf.disabledClass;
				els.removeClass(cls);

				if (index === 0) { prev.addClass(cls); }
				if (index == links.length -1) { next.addClass(cls); }

				// prepare title (by Franz Koch)
				var $tgt = eval(conf.attrTarget), title='';
				if(conf.useAsTitle) {
					title = eval(conf.useAsTitle);
				} else {
					title = el.attr("title") || el.data("title") || '';
				}
				// set info text & width
				var text = conf.template
					.replace("${title}", title)
					.replace("${index}", index + 1)
					.replace("${total}", links.length);
					
				//var padd = parseInt(info.css("paddingLeft"), 10) +  parseInt(info.css("paddingRight"), 10);
				info.html(text);//.css({width: width - padd});

				overlay.removeClass('loading').animate({
					width: width, height:  Math.max(image.height,conf.minHeight), left: left}, conf.speed, function() {
					animating = false;
					// gradually show the image
					img.add(info).hide().css("visibility", "visible").fadeIn(function() {
						if (!conf.autohide) {
							showEls();
						}
					});
				}); 
			};
			
			image.onerror = function() {
				overlay.fadeIn().html("Cannot find image " + url); 
			};
			
			image.src = url;
			
			if (conf.preload) {
				links.filter(":eq(" +(index-1)+ "), :eq(" +(index+1)+ ")").each(function()  {
					var img = new Image();
					img.src = $(this).attr("href");					
				});
			}
			
		}
		
//}}}


		// function to add click handlers to next/prev links	 
		function addClick(el, isNext)  {
			el.click(function() {
				if (el.hasClass(conf.disabledClass)) { return; }				
				
				// find the triggering link
				var trigger = links.eq(i = index + (isNext ? 1 : -1));			
					 
				// if found load it's href
				if (trigger.length) { load(trigger); }
			});				
		}

		// assign next/prev click handlers
		addClick(next, true);
		addClick(prev);


		// arrow keys
		$(document).keydown(function(evt) {
			if (!overlay.is(":visible") || evt.altKey || evt.ctrlKey) { return; }
			
			if (evt.keyCode == 37 || evt.keyCode == 39) {					
				var btn = evt.keyCode == 37 ? prev : next;
				btn.click();
				return evt.preventDefault();
			}	
			return true;			
		});		
		
		function showEls() {
			if (!overlay.is(":animated") && !animating) {
				els.show(); close.show(); info.slideDown();	
			}	
		}
		
		// autohide functionality
		if (conf.autohide) { 
			overlay.hover(showEls, function() { els.fadeOut(); /*info.slideUp();*/	close.hide(); }).mouseover(showEls);
		}		
		
		// load a proper gallery image when overlay trigger is clicked
		var ret;
		
		this.each(function() {
			var el = $(this), api = el.overlay(), ret = api;
			
			api.onBeforeLoad(function() {
				load(el);
			});
			
			api.onClose(function() {
				links.removeClass(conf.activeClass);	
			});			
		});  		
		return conf.api ? ret : this;
	};


	// Diashow script by Franz Koch (2009)
	$.fn.diashow = function(options) {
		var defaults = {
			start: 0,
			delay: 10000,
			hide: 'fadeOut',
			show: 'fadeIn',
			speed: 'slow',
			animate: true,
			loop: true,
			animateAtSameTime: false,
			randomize: false,
			pauseOnHover:false,
			applyHeightToContainer:false,
			autoPlay:true,
			buttonNext:false,
			buttonPrev:false,
			swapTransitions:false,
			swapDepth:false,
			api:false
		},
			isAnimating = false,
			stopped = false,
			lastSlide = null,
			timer = null,
			self = this;
	
		$.extend(self,{
			getItems: function() {
				return $this.children();
			},
			getSize: function() {
				return self.getItems().size();
			},
			addItem: function(item) {
				item = $(item);
				$this.append(item);
				slideStack.push(self.getSize());
				return self;
			},
			getNextSlide: function() {
				var size = self.getSize();
				if(options.randomize && size > 2) {
					if(slideNo >= size-1) {
						slideNo = 0;
						slideStack = $.shuffle(slideStack);
					} else {
						slideNo++;	
					}
					var oldSlide = slide;
					slide = slideStack[slideNo];
					if(slide == oldSlide) {
						slide = slideStack[++slideNo];
					}
				} else if (options.loop && slide+1 == size) {
					slide = 0;
				} else {
					slide++;	
				}
			},
			getPrevSlide: function() {
				if (options.loop && slide-1 < 0) {
					slide = self.getSize()-1;
				} else {
					slide--;	
				}
			},
			startTimer: function() {
				if((options.loop || (slide+1 < self.getSize() && slide > -1)) && !hovered && !stopped && options.autoPlay) {
					timer = setTimeout(self.next,options.delay);
				}
			},
			stopTimer: function() {
				clearTimeout(timer);
			},
			stop: function() {
				self.stopTimer();
				stopped = true;
			},
			play: function() {
				stopped = false;
				self.startTimer();
			},
			gotoSlide: function(no) {
				if(no >= 0 && no <= self.getSize()) {
					self.stopTimer();
					self.doTransition(function() {
						slide = no;
					});
				}
			},
			next: function() {
				if((options.loop || (slide+1 < self.getSize() && slide > -1)) && !isAnimating) {
					self.stopTimer();
					self.doTransition(self.getNextSlide);
				}
			},
			prev: function() {
				if((options.loop || slide-1 >= 0) && !isAnimating) {
					self.stopTimer();
					self.doTransition(self.getPrevSlide);
				}
			},
			doTransition: function(getSlideFunc) {
				var first = options.swapTransitions ? 'show' : 'hide',
					last = options.swapTransitions ? 'hide' : 'show';
				if(lastSlide) {
					self.getItems().eq(lastSlide).hide();
				}
				lastSlide = slide;
	
				isAnimating = true;
				if (options.animateAtSameTime) {
					self.animateSlide(slide,first);
					getSlideFunc();
					self.animateSlide(slide,last,self.onAfterTransition);
				} else {
					self.animateSlide(slide,first,function() {
						getSlideFunc();
						self.animateSlide(slide,last,self.onAfterTransition);
					});
				}
			},
			animateSlide: function(nr,transition,fn) {
				var $t = self.getItems().eq(nr),zindex = $t.css('z-index'), size = self.getSize();
				// until a good solution is found, hardcode a resouce friendly animation as fading at the same time is quite processor hungry
				if (transition == 'hide') {
					$t.css('z-index',0).toggleClass('active');
					self.transitionFinished(fn);
				} else {
					$t.css('z-index',Number(size))[options[transition]](options.speed,function() {
						$t.toggleClass('active');
						self.transitionFinished(fn);
					});
				}
	/*
				if (options.swapDepth) {
					$t.css({'z-index': (transition == 'hide' ? null : Number(size))});
				}
				if(!options.animate) {
					$t.toggleClass('active')[transition]();
					transitionFinished(fn);
				} else if(options[transition] == null) {
					zindex = (transition == 'hide' ? / *size *-1* /0 : Number(size))/ *(zindex != 'auto' ? Number(zindex) : 0) +* /;
					$t.css({'z-index':zindex}).toggleClass('active');
						transitionFinished(fn);
				} else if(options[transition] == 'animate') {
					$t.animate(options[transition+'Params'],options.speed,options[transition+'Easing'],function() {
						$.toggleClass('active');
						transitionFinished(fn);
					});
				} else {
					$t[options[transition]](options.speed,function() {
						$t.toggleClass('active');
						transitionFinished(fn);
					});
				}
	*/
			},
			onAfterTransition: function() {
				self.getItems().eq(lastSlide).hide().css('z-index',0);
				self.startTimer();
			},
			transitionFinished: function(fn) {
				if(fn != null) { fn.call() }
				isAnimating = false;
			}
		});

		function _init() {
			if(self.getSize() > 1) {
				if(options.buttonNext) {
					options.buttonNext.click(function() {self.next();return false;});	
				}
				if(options.buttonPrev) {
					options.buttonPrev.click(function() {self.prev();return false;});	
				}

				classes = $this.attr('class').split(' ');
				$(classes).each(function() {
					var strParts = this.split('-');
					if(strParts[0] == 'opt') {
						options[strParts[1]] = strParts[2];	
					}
				});

				if(options.applyHeightToContainer) {
					if($this.height() > 10) {
						$this.css('height',$this.height());
					} else {
						var heightTimer = setInterval(function($this) {
							var h = $this.children().height();
							if(h > 10) {
								$this.css('height',h);
								clearInterval(heightTimer);
							}
						},200,$this);
					}
				}
				$this.addClass('slideshowActive');

				for(var i=0; i < self.getSize(); i++) {
					slideStack.push(i);
				}
				if(options.randomize) {
					slideStack = $.shuffle(slideStack);
				}
				self.getItems().removeClass('active').addClass(selector).eq(slide).addClass('active');
				if(options.pauseOnHover) {
					$this.hover(
						function() {
							self.stopTimer();
							hovered = true;
						},
						function() {
							hovered = false;
							self.startTimer();
						}
					);
				}
				self.startTimer();
			}
		}
		
		options = jQuery.extend(defaults, options);
		var $this = $(this),
			selector = 'slideShowItem',
			timer = null,
			slide = options.start,
			slideStack = new Array(),
			slideNo = 0,
			hovered = false,
			classes = new Array();
		
		$this.load(_init());
		return options.api ? self : $this;
	};


	/*
	 * jQuery shuffle
	 *
	 * Copyright (c) 2008 Ca Phun Ung <caphun at yelotofu dot com>
	 * Dual licensed under the MIT (MIT-LICENSE.txt)
	 * and GPL (GPL-LICENSE.txt) licenses.
	 *
	 * http://yelotofu.com/labs/jquery/snippets/shuffle/
	 *
	 * Shuffles an array or the children of a element container.
	 * This uses the Fisher-Yates shuffle algorithm <http://jsfromhell.com/array/shuffle [v1.0]>
	 */

	$.fn.shuffle = function() {
		return this.each(function(){
			var items = $(this).children();
			return (items.length) ? $(this).html($.shuffle(items)) : this;
		});
	}
	
	$.shuffle = function(arr) {
		for(var j, x, i = arr.length; i; j = parseInt(Math.random() * i), x = arr[--i], arr[i] = arr[j], arr[j] = x);
		return arr;
	}
})(jQuery); // Call and execute the function immediately passing the jQuery object



/**************
* CUSTOM SCRIPTS FOR WEBSITE
***************/
(function($) {
	// General methods
	var base = $('base').attr('href'),
		$closeButton = $('<span class="close"></span>');
	$.enet = {};
	$.enet.baseUrl = base.substr(-1) != '/' ? base+'/' : base;
	$.enet.protocol = (document.location.protocol == 'https:' ? 'https:' : 'http:')+'//';
	$.enet.templatePath = 'templates/schultz/';
	$.enet.absTemplatePath = $.enet.baseUrl+$.enet.templatePath;
	$.enet.locale = typeof(locale) != 'undefined' ? locale : 'de';


/**************
* LOCALIZATION
***************/
	$.enet.lll = {
		'default' : {
			// general
			'error'						:	'Error',
			'attention'					:	'Attention',
			'close'						:	'Close',
			// lightbox
			'showNextImage'				:	'next Image',
			'showPrevImage'				:	'previous Image',
			'image'						:	'Image',
			'of'						:	'of',
			// form validation
			'pleaseSelect'				:	'Please select',
			'evalMsgValidEmail'			:	'Please enter a valid e-mail address',
			'evalMsgFillRequiredFields' :	'Please fill a marked fields',
			'evalMsgInteger'			:	'Please enter a valid number for ${label}',
			'evalMsgRepeat'				:	'The repeated input did not match the first one',
			// ajax
			'errorMessageAjaxRequest' 	:	'An error occured during your request. Please try again later.'
		},
		'de' : {
			// general
			'error'						:	'Fehler',
			'attention'					:	'Achtung',
			'close'						:	'Schließen',
			// lightbox
			'showNextImage'				:	'nächstes Bild',
			'showPrevImage'				:	'vorheriges Bild',
			'image'						:	'Bild',
			'of'						:	'von',
			// form validation
			'pleaseSelect'				:	'Bitte wählen',
			'evalMsgValidEmail'			:	'Geben Sie eine gültige E-Mail-Adresse an',
			'evalMsgFillRequiredFields' :	'Bitte füllen Sie alle markierten Felder aus.',
			'evalMsgInteger'			:	'Geben Sie bei ${label} eine gültige Zahl ein',
			'evalMsgRepeat'				:	'Die wiederholte Eingabe stimmt leider nicht mit der ersten überein',
			// ajax
			'errorMessageAjaxRequest' 	:	'Bei der Verarbeitung Ihrer Anfrage ist leider ein Fehler aufgetreten. Bitte versuchen Sie es erneut.'
		}
	};
	
	$.enet.l18n = function (k) {
		try {
			return $.enet.lll[$.enet.locale][k];
		} catch(e) {
			try {
				return $.enet.lll['default'][k];
			} catch(e) {
				return '';
			}
		}
	}

/**************
* HELPER FUNCTIONS
***************/

	$.enet.absoluteUrl = function(url) {
		if (!url.match(/^(http|https|ftp):\/\/.*/)) {
			url = $.enet.baseUrl+(url.substr(0,1) == '/' ? url.substr(1) : url);
		}
		return url;
	}

	$.enet.extendImageRotator = function(selector,url) {
		$t = $(selector);
		if($t.hasClass('diashow')) {
			$.get(url,function(data,status) {
				if(status == 'success' || status == 'notmodified') {
					var $d = $(data),
						$items = $d.children('li').removeClass('first'),
						current = $t.children('li').removeClass('last').children('img').attr('src');
					$d.hide();
	
					if($items.length > 1) {
						$items.each(function() {
							if($(this).children('img').attr('src') == current) {
								$(this).remove();
							}
						});
						$items.appendTo(selector);
						$.enet.enableDiaShow($t);
					}
					$d.remove();
				}
			},'html');
		}
	}
	$.enet.enableDiaShow = function(t) {
		if(t.children().length > 1) {
/*
			var $m = $('<ul class="slideShowNavi"><li class="nextImage"><a href="'+$.enet.baseUrl+'#">'+$.enet.l18n('next')+'</a></li><li class="prevImage"><a href="'+$.enet.baseUrl+'#">'+$.enet.l18n('prev')+'</a></li></ul>').hide(),
				api = t.diashow({delay:4000,speed:1000,randomize:false,api:true,animateAtSameTime:true,pauseOnHover:true,buttonNext:$m.find('.nextImage a'),buttonPrev:$m.find('.prevImage a')});
			t.wrap('<div class="slideShowContainer"></div>').after($m);
			$m.hover(function() {api.stop()},function() {api.play()}).fadeIn(600);
*/
			t.diashow({delay:4000,speed:1000,randomize:false,api:true,animateAtSameTime:true,applyHeightToContainer:true,pauseOnHover:true});
		}
	}

	$.enet.enrichContent = function(selector) {
		var $s = $(selector);

		// slideshows
		$s.find('.diashow').each(function() {
			$.enet.enableDiaShow($(this));
		});

		// scroller
		$s.find('.scrollable').each(function() {
			var $scroller = $(this), $childs = $scroller.children(), $container='',$menu='', w=$scroller.outerWidth(), h=0, count = Math.round(w / $childs.eq(0).outerWidth()), mT = $scroller.css('margin-top'), mB = $scroller.css('margin-bottom');
			if($childs.outerWidth() * $childs.length > w) {
				$container = $scroller.wrap('<div class="scrollerContainer"></div>').parent();
				h = $scroller.css({'margin-top':0,'margin-bottom':0}).outerHeight();
				$container.css( {'width':w, 'height':h, 'margin-top':mT, 'margin-bottom':mB});
				$menu = $('<ul class="scrollerNavi"></ul>');
				$menu.append('<li class="prev"><a title="'+$.enet.l18n('showPrevImage')+'"><span><dfn title="'+$.enet.l18n('showPrevImage')+'">‹</dfn>&nbsp;</span></a></li><li class="next"><a title="'+$.enet.l18n('showNextImage')+'"><span>&nbsp;<dfn title="'+$.enet.l18n('showNextImage')+'">›</dfn></span></a></li>');
				//$navi = $('<div class="navi"/>');
				//$scroller.diashow({applyHeightToContainer:false,animateAtSameTime:true,autoPlay:false,buttonNext:$menu.find('.next a'),buttonPrev:$menu.find('.prev a')});
				var api = $container.append($menu).scrollable({items:$scroller,size:count,clickable:false,api:true});

				// show/hide all images at once
				if ($scroller.hasClass('imageStrip')) {
					$container.addClass('imageStripContainer');
					var $open = $('<a href="#" class="toggle-open"><span>Alle anzeigen</span></a>').click(function(e) {
						$open.hide();
						$menu.fadeOut();
						api.seekTo(0,0);
						api.getConf().keyboard = false;
						$container.addClass('showAll').animate({'height':$scroller.outerHeight()},function() {
							$close.fadeIn();
						});
						return e.preventDefault();
					}).hide(),
					$close = $('<a href="#" class="toggle-close">Weniger anzeigen</a>').click(function(e) {
						$close.hide();
						$container.animate({'height':h},function() {
							$container.removeClass('showAll');
							$open.fadeIn();
							$menu.fadeIn();
							api.getConf().keyboard = true;
						});
						return e.preventDefault();
					}).hide();
					$container.append($open,$close);
					$open.fadeIn();
				}
			}
		});	

		// tabs
		var $tab = $s.find('.tabs');
		if ($tab.find('.pane').length) {
			var $m = $('<ul class="tabNavi"></ul>');
			$tab.children('.pane').each(function(){
				var $t = $(this), h = $t.find('.itemTitle:first').hide().html(), loc = document.location.toString();
				if (h != null && h.length) {
					$m.append('<li><a href="' + loc.substr(0, loc.indexOf('#')) + '#'+$t.attr('id')+'">'+h+'</a></li>');
				}
			});
			$m.children(':first').addClass('first');
			$m.children(':last').addClass('last');
			$tab.wrapInner('<div class="tabContent"></div>');
			$tab.find('.tabContent').append('<span class="clearFix"></span>');
			$tab.prepend($m);
			$m.tabs($m.next().children('.pane'),{effect:'fade'});
		}

		// accordeon
		$s.find('.accordeon').each(function() {
			var $t = $(this).addClass('jsEnhanced');
			$t.children('.itemTitle:first').addClass('current');
			$t.children('.pane:first').css('display','block');
			$t.children('.itemTitle').append('<em class="icon"></em>');
			$t.tabs($t.children('.pane'), {tabs: '.itemTitle', effect: 'slide', initialIndex: null});
		});

		// faq
		$s.find('.faq').each(function() {
			var $t = $(this).addClass('faqJsEnhanced');
			$t.children('.pane').hide();
			$t.children('.itemTitle').click(function() {
				var $b = $(this), $p = $b.next('.pane');
				if ($p.length) {
					$p.slideToggle(function(){
						$b.removeClass('toggle-close').removeClass('toggle-open').addClass($p.css('display') == 'block' ? 'toggle-close' : 'toggle-open');
					});
				}
			}).append('<em class="icon"></em>').eq(0).addClass('first');
		});

		$s.find('table.sortable').each(function() {
			$(this).tablesorter(); 
		});
		// equal height of multicolumn FCEs and make columns clickable if needed
		// this has to be called BEFORE tabs or accordeons are built in order to get the correct heights
		$s.find('div.multicolumn').each(function(){
			var $fceCol = $(this), h = $fceCol.innerHeight();
			if ($fceCol.children('[class*=framed]').length) {
				$fceCol.children('div').css('height',h);
				// make teasers on frontPage clickable
				if ($('#pageMargins').hasClass('striking')) {
					$fceCol.children().each(function() {
						$.enet.makeClickable(this);
					});
				}
			}
		});

		// lightbox
		if($s.find('a[rel*=lightbox]').length) {
			var $lB = $('<div class="lightbox" id="imageLightbox"><div class="image"><div class="navItems"><a class="prev" title="'+$.enet.l18n('showPrevImage')+'"><strong><dfn title="'+$.enet.l18n('showPrevImage')+'">‹</dfn></strong></a><a class="next" title="'+$.enet.l18n('showNextImage')+'"><strong><dfn title="'+$.enet.l18n('showNextImage')+'">›</dfn></strong></a></div></div><div class="info"></div><div class="loader"></div></div>').hide().append($closeButton).hide().appendTo('body');
			$s.find('a[rel*=lightbox]').overlay({
				target: '#imageLightbox',
				expose: {color:'#333', zIndex:9999},
				oneInstance: false
			}).gallery({
				speed:800,
				opacity: null,
				minWidth: 200,
				autohide: false,
				template: '<div class="description">${title}</div><span class="imageCount">'+$.enet.l18n('image')+' ${index} '+$.enet.l18n('of')+' ${total}</span>',
				useAsTitle: '(el.attr(\'name\') && $(\'#\'+el.attr(\'name\')).length) ? $(\'#\'+el.attr(\'name\')).html() : el.children(\'img\').attr(\'title\')'
			});
		};

		// search forms
		$s.find('.searchForm').each( function() {
			var sf = $(this).find('input.searchField'),
				dt = sf.val();
			if(dt != '' && dt != undefined && !sf.hasClass('dontEnhance')) {
				$(this).submit(function() {
					if(sf.val() != dt || (sf.hasClass('matchTitle') && sf.attr('title') != sf.val())) {
						return true;	
					}
					return false;
				});
				sf.focus(function() {
					if($(this).val() == dt) {
						$(this).val('');					
					}
				})
				.blur(function() {
					if($(this).val() == '') {
						$(this).val(dt);	
					}
				});
			}
		});	

		// special form fields
		$s.find('input.clearOnFocus').each( function() {
			var $t = $(this), dv = $t.attr('title');
			if ($t.val() == '') {
				$t.val(dv);	
			}
			$t.focus(function() {
				if ($t.val() == dv) {
					$t.val('');	
				}
			}).blur(function() {
				if ($t.val() == '') {
					$t.val(dv);	
				}
			});
		});


		// apply autosubmit after change in certain dropdown fields
		$s.find('.submitOnChange').change(function() {
			var $sel = $(this);
			if($sel.val() !== '-') {
				$sel.closest('form').submit();
			}
		}).closest('form').find(':submit').not('.alwaysVisible').hide();

		// form validation
		$s.find('form.mailForm').submit( function() {
			return $.enet.validateForm(this, false);	
		});
	}

	// form validation
	$.enet.validateForm = function(form,inlineValidation) {
		var $form = $(form),
			$validateFields = $form.find(".f-required, *[class*='eval-']"),
			errors = new Array();
		$('#overlay').hide().remove();

		//remove existing error messages from serverside validation
		$form.find('.validationMessage, #formValidationErrorMessage').remove();
		$form.find('.validationError').removeClass('validationError');
		
		function addError($field,msg) {
			var label = $('label[for='+$field.attr('id')+']').html() || '';
			msg = msg.replace('${label}',label);
			errors.push(Array($field,msg));
			if(typeof(inlineValidation) != 'undefined' && inlineValidation) {
				if($field.parent().find('.validationMessage').length) {
					$field.parent().find('.validationMessage').append('<br />'+msg);
				} else {
					$field.parent().append('<span class="validationMessage">'+msg+'</span>');	
				}
			}
		}
		
		// if fields got marked as required or require validation set via a special CSS class, proccess those for validation rules.
		if($validateFields.length) {
			$validateFields.each(function() {
				var $field = $(this), msg = $field.attr('title'), val = $field.val(), type = $field.attr('type');
				//$field.removeClass('validationError');
				switch (type) {
					default:
						if(!val && $field.hasClass('f-required')) {
							if (msg == null || typeof(msg) == 'undefined' || msg.length == 0) { msg = $.enet.l18n('evalMsgFillRequiredFields') }
							addError($field,msg);
						} else if(val) {
							if($field.hasClass('eval-email') && !val.match(/^[-!#$%&\`*+\.\/0-9=?A-Z^_´a-z{|}~]+@[-!#$%&\`*+\.\/0-9=?A-Z^_´a-z{|}~]+\.[A-Za-z]{2,4}$/)) {
								addError($field,$.enet.l18n('evalMsgValidEmail'));
							}
							if($field.hasClass('eval-integer') && isNaN(val)) {
								addError($field,$.enet.l18n('evalMsgInteger'));
							}
							if($field.hasClass('eval-quantity') && !val.match(/^[1-9][0-9]*$/)) {
								addError($field,$.enet.l18n('evalMsgValidQuantity'));
							}
							if($field.hasClass('eval-repeat')) {
								var $repeat = $('#'+$field.attr('id')+'-repeat');
								if(val && val != $repeat.val()) {
									addError($repeat,$.enet.l18n('evalMsgRepeat'));
								}
							}
						}
						break;
					case 'checkbox':
					case 'radio':
						if(type == 'checkbox' && !$field.attr('class').match(' *eval-.*') && !$field.attr('checked') && $field.hasClass('f-required')) {
							errors.push(Array($field,msg));
						}

						// evaluation
						if($field.hasClass('eval-atLeastOne')) {
							var na = $field.attr('name'), l = Math.round(na.length -2), n = na.substr(0,l);
							if(! $form.find('[name^="'+n+'"]:checked').length ) {
									errors.push(Array($field,msg));
							}
						}
						break;
				}
			});
			if(errors.length) {
				var msg = '',
					items='',
					focused = false,
					offset = $form.offset(),
					msgCache = new Array();
				$(errors).each(function() {
					$(this[0]).parent().addClass('validationError');
					if(!focused) {
						this[0].focus();
						focused = true;
					}
					if($.inArray(this[1],msgCache) == -1) {
						msgCache.push(this[1]);
						items += '<li>'+this[1]+'</li>';
					}
				});
				msg = '<ul>'+items+'</ul>';
				return $.enet.displayError($.enet.l18n('attention'),msg,{offset:offset.top});
			}
		}
		return true;
	}

	$.enet.displayError = function(headline,message){
		var $messageContainer = $('<div class="infoMessage layout-error" id="errorMessage"></div>');
		$('body').append($messageContainer);
		$messageContainer.html('<h3>'+headline+'</h3>'+message).hide().overlay({
			api:true,
			expose:'#333',
			onLoad: function() {$messageContainer.fadeIn()},
			onBeforeClose: function() {$messageContainer.fadeOut()},
			onClose:function() {$messageContainer.remove()}
		}).load();
		return false;
	}


/**************
* ENRICH USEREXPERIENCE
***************/
	// add extra functionality to the content
	$.enet.enrichContent('body');

	// call methods in onJQueryReady stack. The stack get's filled from inline JS or some other external scripts
	if(typeof(onJQueryReady) == 'object') {
		$(onJQueryReady).each(function() {
			this.fn.call(this.p);
		});
	}


/**************
* NAVIGATION
***************/
	$.enet.foldout = function($nav, selector, show, hide) {
		var navT, cur;
		$nav.children().each(function() {
			var $t = $(this), $i = $t, $m = $t.children(selector);
			if ($m.length) {
				$t.hover(
					function() {
						if (typeof(cur) == 'object' && cur != $t) {
							cur.removeClass('hover').children(selector).stop(true,true).hide();//.slideUp(0);
						}
						if (typeof(navT) != 'undefined') {
							clearTimeout(navT);
						}
						if (cur != $t) {
							cur = $t;
							$m.hide()[show](300);
						}
						$t.addClass('hover');
					},
					function() {
						clearTimeout(navT);
						navT = setTimeout(function() {
							$m.stop(true,true)[hide](300, function() {$t.removeClass('hover');});
							cur = false;
						},500);
					}
				);
			}
		});
	}

	$.enet.foldout($('#mainMenu ul'), 'ul', 'slideDown', 'slideUp');
})(jQuery);
