// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// emailadressen entschlüsseln
function entschluesseln(mail){
	mail = mail.split(",");
	d='';
	for(i=0;i<mail.length;i++){
		d+="&#"+mail[i]+";";
	}
	return d;
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Standardfuktion Dreamweaver
function tmt_findObj(n){
	var x,t; if((n.indexOf("?"))>0&&parent.frames.length){t=n.split("?");
	x=eval("parent.frames['"+t[1]+"'].document.getElementById('"+t[0]+"')");
	}else{x=document.getElementById(n)}return x;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_validateForm() { //v3.0 
	var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments; 
	for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]); 
	if (val) { nm=val.name; if ((val=val.value)!="") { 
	if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@'); 
	if (p<1 || p==(val.length-1)) errors+='- '+nm+' muss eine gültige eMail adresse enthalten.\n'; 
	} else if (test!='R') { num = parseFloat(val); 
	if (val!=''+num) errors+='- '+nm+' muss eine Nummer enthalten.\n'; 
	if (test.indexOf('inRange') != -1) { p=test.indexOf(':'); 
	min=test.substring(8,p); max=test.substring(p+1); 
	if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n'; 
	} } } else if (test.charAt(0) == 'R') errors += '- '+nm+' fehlt.\n'; } 
	} if (errors) alert('Folgende Fehler wurden festgestellt:\n'+errors); 
	document.MM_returnValue = (errors == ''); 
} 
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

(function() {
	if (typeof MooTools == 'undefined') {
		if ("console" in window) console.error('MooTools is required but missing...');
		return;
	}
	(function($, undefined) {
		window.addEvent('domready', function() {
			
			var currentIndex	= 0,
				images			= $$("#claimContainer > img"),
				container		= $('claimContainer'),
				effect			= 'fade',
				timer			= 5500,
				clickLock		= false,
				slideInterval	= null;
			
			if (images.length <= 1) return;
			
			var effects = {
				fade: function(image) {
					image.fade('hide');
					image.fade('in');
				},
				slide: function(image, mode) {
					var startX;
					switch (mode) {
						case 'forward':
							startX = container.getSize().x;
							break;
						case 'backward':
							startX = container.getSize().x*-1;
							break;
					}
					
					var slideComplete = function() {
						clickLock = false;
						this.removeEvent('complete', slideComplete);
						container.fireEvent('s2:rotator:effect:complete', arguments);
					}
					
					image.get('tween').addEvent('complete', slideComplete);
					
					image.setStyle('left', startX);
					image.tween('left', 0);
					
					var imageTween = function() {
						
					}
					
					container.fireEvent('s2:rotator:effect:start', arguments);
				}
			};
			
			var slide = function(mode) {
				var previousImage		= images[currentIndex];
				
				switch (mode) {
					case 'forward':
						currentIndex++;
						if (currentIndex > images.length-1) currentIndex = 0;
						break;
					case 'backward':
						currentIndex--;
						if (currentIndex < 0) currentIndex = images.length-1;
						break;
					default:
						return;
				}
				
				var currentImage	= images[currentIndex],
					highestZIndex	= 0;
					
				clickLock = true;
				
				if (effect in effects) effects[effect](currentImage, mode);
				else effects.fade(currentImage);
				
				images.each(function(image) {
					var zIndex = parseInt(image.getStyle('z-index'));
					if (zIndex > highestZIndex) highestZIndex = zIndex;
				});
				
				currentImage.setStyle('z-index', highestZIndex+1);
			}
			
			// Set InitStyles
			container.setStyles({
				overflow: 'hidden',
				position: 'relative',
				width: images[0].getSize().x,
				height: images[0].getSize().y
			});
			
			images.each(function(image, i) {
				image.setStyles({
					position: 'absolute',
					left: 0,
					top: 0,
					'z-index': images.length - i
				});
				
				image.set('tween', {duration: 2000, transition: Fx.Transitions.Quart.easeInOut});
			});
			
			var setupSlideInterval = function() {
				if (slideInterval !== null) return;
				slideInterval = slide.periodical(timer, this, ['forward']);
			}
			
			var clearSlideInterval = function() {
				clearInterval(slideInterval);
				slideInterval = null;
			}
			
			setupSlideInterval();
			
			container.addEvents({
				's2:rotator:effect:start': clearSlideInterval,
				's2:rotator:effect:complete': setupSlideInterval,
				'mouseenter': clearSlideInterval,
				'mouseleave': setupSlideInterval
			});
		});
	})(document.id);
})();
