/**
 *
 */
var Api = new Class
({
	/**
	 * Klassenvariablen
	 */
	options:			null,		//  Wird durch Mootools gesetzt - durch setOptions()
	
	initialize: function(options) {
		this.setOptions(this.getOptions(), options);
		
		window.addEvent('domready', function() {
			Ajax = new Ajax();
		});
	},
	
	getOptions: function() {
		return {
			//  Keine Standartwerte fürs übergebene Objekt
		};
	},
	
	openNewWindow: function(width, height, url, name, features)
	{
		var left = (screen.availWidth - width) / 2;
		var top = (screen.availHeight - height) / 2;
	
		var settings = 'height=' + height + ',' + 'width=' + width + ',' + 'top=' + top + ',' + 'left=' + left + ',';
		settings += features;
	
		whandle = window.open(url, name, settings);
		whandle.focus();
	},
	
	encode: function(value) {
		return encodeURIComponent ? encodeURIComponent(value) : escape(value);
	},
	
	showMsg: function(msg) {
		alert(msg)		
	},
	
	submitSuche: function(input_std_value) {
		var form = $('frm_suche');
		var input_suchbegriff = $('suchbegriff');

		if (input_suchbegriff.value != '' && input_suchbegriff.value != input_std_value) {
			form.submit();
		}
		else {
			this.focusInput(input_suchbegriff);
		}
	},
	
	focusInput: function(el) {
		$(el.id).addClass('onfocus_input_class');
		$(el).focus();
	},
	
	onFocusBlurInput: function(el)
	{
		$(el.id).toggleClass('onfocus_input_class');
		
		var info_div = $(el.id + '_info')
		
		//  Wenn Info vorhanden
		if ( $defined(info_div) )
		{
			var fx = new Fx.Style(info_div, 'opacity');
			
			//  Einblenden
			if ( info_div.getStyle('visibility') == 'hidden' ) {
				fx.start(0, 1);
			}
			//  Ausblenden
			else {
				fx.start(1, 0);
			}
		}		
	},
	
	openPrintPopup: function(page_url) {
		this.openNewWindow(800, 600, page_url, 'print', 'scrollbars=yes');
	},
	
	printPage: function() {
		window.addEvent('domready', function()
		{
			print();
		});
	},
	
	changeBranche: function(selectbox, land_sprache)
	{
		if ( selectbox.selectedIndex > 0 )
		{
			var branche_param = selectbox.options[selectbox.selectedIndex].value;
			window.location.href = '/' + land_sprache + '/industries/?industry=' + branche_param;
		}
	},
	
	toNumber: function(el) {		
		if (el.value.toInt()) {
			el.value = el.value.toInt();
		}
		else {
			el.value = '';
		}
	}
});

Api.implement(new Options);
Api.implement(new Events);


/**
 *
 */
var Ajax = new Class
({
	options:			null,			//  Wird durch Mootools gesetzt - durch setOptions()
	
	initialize: function(options)
	{
		this.setOptions(this.getOptions(), options);
	},
	
	getOptions: function() {
		return {
			//  Keine Standartwerte fürs übergebene Objekt
		};
	},
	
	merkzettelAddPage: function(pageTitle)
	{
		pageTitle = Api.encode(pageTitle);

		mooRemote.RPC.merkzettelAddPage({id: 'ajax_seite_merken', update: 'anz_merkzettel_seiten', std_ajax_loader: false, params: [pageTitle]}).addEvent('onSuccess', function(result)
		{
			if (result !== false) {
				$('seite_merken_link').setStyle('display', 'none');
				$('seite_loeschen_link').setStyle('display', 'block');
			}
		});
	},
	
	merkzettelDelPage: function()
	{
		mooRemote.RPC.merkzettelDelPage({id: 'ajax_seite_merken', update: 'anz_merkzettel_seiten', std_ajax_loader: false}).addEvent('onSuccess', function(result)
		{
			if (result !== false) {
				$('seite_merken_link').setStyle('display', 'block');
				$('seite_loeschen_link').setStyle('display', 'none');
			}
		});
	},
	
	merkzettelDelPageFromUebersicht: function(page_url)
	{
		mooRemote.RPC.merkzettelDelPageFromUebersicht({id: 'merkzettel_uebersicht', update: 'merkzettel_uebersicht', std_ajax_loader: true, params: [page_url]}).addEvent('onSuccess', function(result)
		{
			if (result !== false) {
				$('anz_merkzettel_seiten').setHTML(result);
			}
		});
	},
	
	ladeAnsprechpartnerAusland: function(laenderkuerzel)
	{
		mooRemote.RPC.ladeAnsprechpartnerAusland({id: 'ajax-loader', update: 'ansprechpartner_ausland', std_ajax_loader: false, params: [laenderkuerzel]}).addEvent('onSuccess', function(result)
		{			
		});
	},

	/**
	 *	Ersatzteile-Shop	
	 */
	eshopAddProdukt: function(produktID, anzahl)
	{
		mooRemote.RPC.eshopAddProdukt(
			{
				id: 'produkt_add_'+produktID,
				update: 'eshop_warenkorbanzahl',
				std_ajax_loader: false,
				params: [produktID,anzahl]
			}
			).addEvent('onSuccess', function(result)
		{
			if (Number(anzahl))
			{
				if (result !== false)
				{
					if ($('preis_'+produktID))
						$('preis_'+produktID).setHTML(result);
				}
			}
			else
			{
				//	Seite neu laden
				location.href = '';
			}
		});
	}
	

});

Ajax.implement(new Options);
Ajax.implement(new Events);


/**************************************************************
	Script		: Slider
	Version		: 0.1
	Authors		: Sven Haselböck
	Desc		: 
**************************************************************/
var Slider = new Class
({
	anz_moves	:	0,
	
	getOptions: function()
	{
		return {
			duration:			1000,
			transition:			Fx.Transitions.sineInOut,
			quad_class_name:	'slider_outline',
			padding:			{top:0, right:0, bottom:0, left:0}			
		};
	},

	/**
	 * 
	 */
	initialize: function(element, Options)
	{
		this.setOptions(this.getOptions(), Options);
		
		this.element = $(element);

		var pos = this.element.getCoordinates();
		var obj = {};
		
		this.quad = new Element('div').setProperty('id', 'slider_' + new Date().getTime()).injectInside(document.body);
		obj.top = (pos.top-this.options.padding.top)+'px';
		obj.left = (pos.left-this.options.padding.left)+'px';
		obj.height = (pos.height+this.options.padding.top+this.options.padding.bottom)+'px';
		obj.width = (pos.width+this.options.padding.left+this.options.padding.right)+'px';
		this.quad.setStyles(obj);

		if (this.options.quad_class_name) {
			this.quad.addClass(this.options.quad_class_name);	
		}
				
		this.effects = new Fx.Styles(this.quad, {duration: this.options.duration, transition: this.options.transition});
	},
	
	/**
	 * 
	 */
	setStart: function() {
		this.move(this.last_x, this.last_y, this.last_width, this.last_height);
	},
	
	/**
	 * 
	 */
	move: function(x, y, width, height)
	{
		this.last_x = x;
		this.last_y = y;
			
		this.last_width = width;
		this.last_height = height;			
		
		this.effects.stop();
		
		var pos = this.element.getCoordinates();
				
		var obj = {};		
		obj.top = (pos.top - this.options.padding.top + parseInt(y) ) + 'px';
		obj.left = (pos.left - this.options.padding.left + parseInt(x) ) + 'px';
		obj.width = width;
		obj.height = height;
		
		this.effects.start(obj);
	}

});
Slider.implement(new Options);
Slider.implement(new Events);



/**************************************************************

	Script		: Background Slider
	Version		: 1.1
	Authors		: Samuel Birch
	Desc		: Slides a layer to a given elements position and dimensions.

**************************************************************/

var BackgroundSlider = new Class({

	getOptions: function(){
		return {
			duration: 300,
			wait: 0,
			transition: Fx.Transitions.sineInOut,
			className: false,
			fixHeight: false,
			fixWidth: false,
			id: false,
			padding: {top:0,right:0,bottom:0,left:0},
			onClick: this.setStart,
			mouseOver: true
		};
	},

	initialize: function(elements, options)
	{
		var Options = {
			width:		50,
			height:		50
		}
		
		this.setOptions(this.getOptions(), options);
		
		if (this.options.slider == true) {
			this.slider = new Slider('img_container', Options);
		}
		
		this.elements = $$(elements);
		this.timer = 0;
		
		if(this.options.id){
			this.bg = $(this.options.id);
		}else{
			this.bg = new Element('div').setProperty('id','BgSlider_'+new Date().getTime()).injectInside(document.body);
			if(this.options.className){
				this.bg.addClass(this.options.className);	
			}
		}
		
		this.effects = new Fx.Styles(this.bg, {duration: this.options.duration, transition: this.options.transition});
		
		this.elements.each(function(el,i){
			if(this.options.mouseOver){
				el.addEvent('mouseover', this.move.bind(this,el));
				el.addEvent('mouseout', this.reset.bind(this));
			}
			el.addEvent('click', this.thumbClicked.bind(this, el))
			if(el.hasClass('bgStart')){
				this.set(el);
			}
		},this);
		
		window.addEvent('resize',function(){
			this.move(this.startElement);
			this.slider.setStart();
		}.bind(this));
		
	},
	
	thumbClicked: function(el)
	{
		var bilder_text_divs = $('bilder_texte').getElements('div');
		bilder_text_divs.each(function(el) {
			el.addClass('hidden');
		});
		
		$(el.id + '_text').removeClass('hidden');
		
		if (this.options.slider == true)
		{
			var data = (el.getProperty('rel')).split("###");
			
			this.slider.quad.setStyle('opacity', 1);
			this.slider.move(data[0], data[1], data[2], data[3]);
			this.setStart(el);
		}		
	},
	
	setStart: function(el)
	{
		if (this.options.slider == true)
		{
			var data = (el.getProperty('rel')).split("###");
			
			for (var i = 0; i < data.length; i++)
			{
				if (data[i] == '')
				{
					switch (i)
					{
						case 0:
						case 1:
							data[i] = 0;
						break;
						
						case 2:
							data[2] = this.slider.element.width;
						break;
						
						case 3:
							data[3] = this.slider.element.height;
						break;
					}
				}
			}
			
			this.slider.options.width = data[2];
			this.slider.options.height = data[3];
				
			this.slider.move(data[0], data[1], data[2], data[3]);
			this.startElement = el;
		}
	},
	
	set: function(el){
		this.setStart(el);
		var pos = el.getCoordinates();
		
		if(this.options.id){
			this.options.padding.top = this.bg.getStyle('paddingTop').toInt();
			this.options.padding.right = this.bg.getStyle('paddingRight').toInt();
			this.options.padding.bottom = this.bg.getStyle('paddingBottom').toInt();
			this.options.padding.left = this.bg.getStyle('paddingLeft').toInt();
			this.bg.setStyle('padding','0px');
		}
		
		var obj = {};
		obj.top = (pos.top-this.options.padding.top)+'px';
		obj.left = (pos.left-this.options.padding.left)+'px';
		if(!this.options.fixHeight){obj.height = (pos.height+this.options.padding.top+this.options.padding.bottom)+'px'};
		if(!this.options.fixWidth){obj.width = (pos.width+this.options.padding.left+this.options.padding.right)+'px'};
		
		this.bg.setStyles(obj);
	},
	
	reset: function(){
		if(this.options.wait){
			this.timer = this.move.delay(this.options.wait, this, this.startElement);
		}
	},
	
	move: function(el)
	{		
		$clear(this.timer);
		var pos = el.getCoordinates();
		
		this.effects.stop();
		
		var obj = {};
		obj.top = pos.top-this.options.padding.top;
		obj.left = pos.left-this.options.padding.left;
		obj.height = pos.height+this.options.padding.top+this.options.padding.bottom;
		obj.width = pos.width+this.options.padding.left+this.options.padding.right;
		
		this.effects.start(obj);		
	}

});
BackgroundSlider.implement(new Options);
BackgroundSlider.implement(new Events);



/**************************************************************

	Script		: SlideShow
	Version		: 1.3
	Authors		: Samuel Birch
	Web			: http://www.phatfusion.net/slideshow/index.htm

**************************************************************/

var SlideShow = new Class(
{
	initialize: function(container, images, options)
	{
		this.setOptions(this.getOptions(), options);
		
		this.container = $(container);
		this.container.setStyles({
			position: 'relative',
			overflow: 'hidden'
		});
		
		if (this.options.onClick){
			this.container.addEvent('click', function(){
				this.options.onClick(this.imageLoaded);
			}.bind(this));
		}
		
		this.imagesHolder = new Element('div').setStyles({
			position: 'absolute',
			overflow: 'hidden',
			top: this.container.getStyle('height'),
			left: 0,
			width: '0px',
			height: '0px',
			display: 'none'
		}).injectInside(this.container);
		
		if($type(images) == 'string' && !this.options.thumbnails){
			var imageList = [];
			$$('.'+images).each(function(el){
				imageList.push(el.src);
				el.injectInside(this.imagesHolder);
			},this);
			this.images = imageList;
			
		}else if($type(images) == 'string' && this.options.thumbnails){
			var imageList = [];
			var srcList = [];
			this.thumbnails = $$('.'+images);
			
			this.thumbnails.each(function(el,i){
				srcList.push(el.href);
				imageList.push(el.getElement('img'));
				el.href = 'javascript:;';
				el.addEvent('click',function(){					
					this.play(i);
				}.bind(this,el,i));
			},this);
			this.images = srcList;
			
			this.thumbnailImages = imageList;
			
			if(this.options.backgroundSlider){
				this.bgSlider = new BackgroundSlider(
					this.thumbnailImages,
					{
						mouseOver: false,
						duration: this.options.duration,
						className: this.options.thumbnailCls,
						padding:{top:0,right:-2,bottom:-2,left:0},
						slider: this.options.slider
					}
				);
				this.bgSlider.set(this.thumbnailImages[0]);
			}
		
		}else{
			this.images = images;
		}
		
		this.loading = new Element('div').addClass(this.options.loadingCls).setStyles({
			position: 'absolute',
			top: 0,
			left: 0,
			zIndex: 3,
			display: 'none',
			width: this.container.getStyle('width'),
			height: this.container.getStyle('height')
		}).injectInside(this.container);
		
		this.oldImage = new Element('div').setStyles({
			position: 'absolute',
			overflow: 'hidden',
			top: 0,
			left: 0,
			opacity: 0,
			width: this.container.getStyle('width'),
			height: this.container.getStyle('height')
		}).injectInside(this.container);
		
		this.newImage = this.oldImage.clone();
		this.newImage.injectInside(this.container);		
		
		this.timer = 0;
		this.image = -1;
		this.imageLoaded = 0;
		this.stopped = true;
		this.started = false;
		this.animating = false;
	},
	
	getOptions: function(){
		return {
			effect: 'fade', //fade|wipe|slide|random
			duration: 2000,
			transition: Fx.Transitions.linear,
			direction: 'right', //top|right|bottom|left|random
			color: false,
			wait: 5000,
			loop: false,
			thumbnails: false,
			thumbnailCls: 'slider_outline',
			backgroundSlider: false,
			loadingCls: 'ajax-loading',
			onClick: false,
			slider: true
		};
	},
	
	load: function(){
		$clear(this.timer);
		this.loading.setStyle('display','block');
		this.image++;
		var img = this.images[this.image];
		delete this.imageObj;
		
		doLoad = true;
		this.imagesHolder.getElements('img').each(function(el){
			var src = this.images[this.image];
			if(el.src == src){
				this.imageObj = el;
				doLoad = false;
				this.add = false;
				this.show();
			}
		},this);
		
		if(doLoad){
			this.add = true;
			this.imageObj = new Asset.image(img, {onload: this.show.bind(this)});
		}
		
	},

	show: function(add){		
		if(this.add){
			this.imageObj.injectInside(this.imagesHolder);
		}
		
		this.newImage.setStyles({
			zIndex: 1,
			opacity: 0
		});
		var img = this.newImage.getElement('img');
		if(img){
			img.replaceWith(this.imageObj.clone());
		}else{
			var obj = this.imageObj.clone();
			obj.injectInside(this.newImage);
		}
		this.imageLoaded = this.image;
		this.loading.setStyle('display','none');
		if(this.options.thumbnails){
			
			if(this.options.backgroundSlider){
				var elT = this.thumbnailImages[this.image];
				this.bgSlider.move(elT);
				this.bgSlider.setStart(elT);
			}else{
				this.thumbnails.each(function(el,i){
					el.removeClass(this.options.thumbnailCls);
					if(i == this.image){
						el.addClass(this.options.thumbnailCls);
					}
				},this);
			}
		}
		this.effect();
	},
	
	wait: function(){
		this.timer = this.load.delay(this.options.wait,this);
	},
	
	play: function(num){
		if(this.stopped){
			if(num > -1){this.image = num-1};
			if(this.image < this.images.length){
				this.stopped = false;
				if(this.started){
					this.next();
				}else{
					this.load();
				}
				this.started = true;
			}
		}
	},
	
	stop: function(){
		$clear(this.timer);
		this.stopped = true;
	},
	
	next: function(wait){
		var doNext = true;
		if(wait && this.stopped){
			doNext = false;
		}
		if(this.animating){
			doNext = false;
		}
		if(doNext)
		{
			this.cloneImage();
			$clear(this.timer);
				if(this.image < this.images.length-1){
					if(wait){
						//  geaendert S.H. damit der BackgroundSlider nicht automatisch ständig läuft
						//  this.wait();
						this.stop();
					}else{
						this.load();	
					}
				}else{
					if(this.options.loop){
						this.image = -1;
						if(wait){
							this.wait();
						}else{
							this.load();	
						}
					}else{
						this.stopped = true;
					}
				}
		}
	},
	
	previous: function(){
		if(this.imageLoaded == 0){
			this.image = this.images.length-2;	
		}else{
			this.image = this.imageLoaded-2;
		}
		this.next();
	},
	
	cloneImage: function(){
		var img = this.oldImage.getElement('img');
		if(img){
			img.replaceWith(this.imageObj.clone());
		}else{
			var obj = this.imageObj.clone();
			obj.injectInside(this.oldImage);
		}
		
		this.oldImage.setStyles({
			zIndex: 0,
			top: 0,
			left: 0,
			opacity: 1
		});
		
		this.newImage.setStyles({opacity:0});
	},
	
	
	effect: function(){
		this.animating = true;
		this.effectObj = this.newImage.effects({
			duration: this.options.duration,
			transition: this.options.transition
		});
		
		var myFxTypes = ['fade','wipe','slide'];
		var myFxDir = ['top','right','bottom','left'];
		
		if(this.options.effect == 'fade'){
			this.fade();
			
		}else if(this.options.effect == 'wipe'){
			if(this.options.direction == 'random'){
				this.setup(myFxDir[Math.floor(Math.random()*(3+1))]);
			}else{
				this.setup(this.options.direction);
			}
			this.wipe();
			
		}else if(this.options.effect == 'slide'){
			if(this.options.direction == 'random'){
				this.setup(myFxDir[Math.floor(Math.random()*(3+1))]);
			}else{
				this.setup(this.options.direction);
			}
			this.slide();
			
		}else if(this.options.effect == 'random'){
			var type = myFxTypes[Math.floor(Math.random()*(2+1))];
			if(type != 'fade'){
				var dir = myFxDir[Math.floor(Math.random()*(3+1))];
				if(this.options.direction == 'random'){
					this.setup(dir);
				}else{
					this.setup(this.options.direction);
				}
			}else{
				this.setup();
			}
			this[type]();
		}
	},
	
	setup: function(dir){
		if(dir == 'top'){
			this.top = -this.container.getStyle('height').toInt();
			this.left = 0;
			this.topOut = this.container.getStyle('height').toInt();
			this.leftOut = 0;
			
		}else if(dir == 'right'){
			this.top = 0;
			this.left = this.container.getStyle('width').toInt();
			this.topOut = 0;
			this.leftOut = -this.container.getStyle('width').toInt();
			
		}else if(dir == 'bottom'){
			this.top = this.container.getStyle('height').toInt();
			this.left = 0;
			this.topOut = -this.container.getStyle('height').toInt();
			this.leftOut = 0;
			
		}else if(dir == 'left'){
			this.top = 0;
			this.left = -this.container.getStyle('width').toInt();
			this.topOut = 0;
			this.leftOut = this.container.getStyle('width').toInt();
			
		}else{
			this.top = 0;
			this.left = 0;
			this.topOut = 0;
			this.leftOut = 0;
		}
	},
	
	fade: function(){
		this.effectObj.start({
			opacity: [0,1]
		});
		this.resetAnimation.delay(this.options.duration+90,this);
		if(!this.stopped){
		this.next.delay(this.options.duration+100,this,true);
		}
	},
	
	wipe: function(){
		this.oldImage.effects({
			duration: this.options.duration,
			transition: this.options.transition
		}).start({
			top: [0,this.topOut],
			left: [0, this.leftOut]
		})
		this.effectObj.start({
			top: [this.top,0],
			left: [this.left,0],
			opacity: [1,1]
		},this);
		this.resetAnimation.delay(this.options.duration+90,this);
		if(!this.stopped){
		this.next.delay(this.options.duration+100,this,true);
		}
	},
	
	slide: function(){
		this.effectObj.start({
			top: [this.top,0],
			left: [this.left,0],
			opacity: [1,1]
		},this);
		this.resetAnimation.delay(this.options.duration+90,this);
		if(!this.stopped){
		this.next.delay(this.options.duration+100,this,true);
		}
	},
	
	resetAnimation: function(){
		this.animating = false;
	}
	
});

SlideShow.implement(new Options);
SlideShow.implement(new Events);



/*
	Slimbox v1.41 - The ultimate lightweight Lightbox clone
	by Christophe Beyls (http://www.digitalia.be/software/slimbox) - MIT-style license.
	Inspired by the original Lightbox v2 by Lokesh Dhakar.
*/

var Lightbox = {
	init: function(options){
		this.options = $extend({
			resizeDuration: 400,
			resizeTransition: false,	// default transition
			initialWidth: 250,
			initialHeight: 250,
			animateCaption: true,
			showCounter: true
		}, options || {});

		this.anchors = [];
		$each(document.links, function(el){
			if (el.rel && el.rel.test(/^lightbox/i)){
				el.onclick = this.click.pass(el, this);
				this.anchors.push(el);
			}
		}, this);
		this.eventKeyDown = this.keyboardListener.bindAsEventListener(this);
		this.eventPosition = this.position.bind(this);

		/* height = 0px fÃ¼r IE eingefÃ¼gt, da sonst ein Absatz unter dem Footer ist */
		this.overlay = new Element('div', {'id': 'lbOverlay', 'styles': {'height': '0px'}}).injectInside(document.body);
		this.bottomContainer = new Element('div', {'id': 'lbBottomContainer', 'styles': {'display': 'none'}}).injectInside(document.body);
		this.bottom = new Element('div', {'id': 'lbBottom'}).injectInside(this.bottomContainer);		

		this.center = new Element('div', {'id': 'lbCenter', 'styles': {'width': this.options.initialWidth, 'height': this.options.initialHeight, 'marginLeft': -(this.options.initialWidth/2), 'display': 'none'}}).injectInside(document.body);
		
		if (!Window.ie6) {
			this.rahmen = new Element('div', {'id': 'rahmen'}).injectInside(this.center);
			this.close_link = new Element('a', {'id': 'lbCloseLink', 'href': '#'}).injectInside(this.rahmen).onclick = this.overlay.onclick = this.close.bind(this);
			this.image = new Element('div', {'id': 'lbImage'}).injectInside(this.rahmen);
		}
		else {
			this.overlay.onclick = this.close.bind(this)
		}
		
		this.image = new Element('div', {'id': 'lbImage'}).injectInside(this.center);
		
		this.prevLink = new Element('a', {'id': 'lbPrevLink', 'href': '#', 'styles': {'display': 'none'}}).injectInside(this.image);
		this.nextLink = this.prevLink.clone().setProperty('id', 'lbNextLink').injectInside(this.image);
		this.prevLink.onclick = this.previous.bind(this);
		this.nextLink.onclick = this.next.bind(this);
		
		this.caption = new Element('div', {'id': 'lbCaption'}).injectInside(this.bottom);
		this.number = new Element('div', {'id': 'lbNumber'}).injectInside(this.bottom);
		new Element('div', {'styles': {'clear': 'both'}}).injectInside(this.bottom);

		var nextEffect = this.nextEffect.bind(this);
		this.fx = {
			overlay: this.overlay.effect('opacity', {duration: 500}).hide(),
			resize: this.center.effects($extend({duration: this.options.resizeDuration, onComplete: nextEffect}, this.options.resizeTransition ? {transition: this.options.resizeTransition} : {})),
			image: this.image.effect('opacity', {duration: 500, onComplete: nextEffect}),
			bottom: this.bottom.effect('margin-top', {duration: 400, onComplete: nextEffect})
		};

		this.preloadPrev = new Image();
		this.preloadNext = new Image();
	},

	click: function(link){
		if (link.rel.length == 8) return this.show(link.href, link.title);

		var j, imageNum, images = [];
		this.anchors.each(function(el){
			if (el.rel == link.rel){
				for (j = 0; j < images.length; j++) if(images[j][0] == el.href) break;
				if (j == images.length){
					images.push([el.href, el.title]);
					if (el.href == link.href) imageNum = j;
				}
			}
		}, this);
		return this.open(images, imageNum);
	},

	show: function(url, title){
		return this.open([[url, title]], 0);
	},

	open: function(images, imageNum){
		this.images = images;
		this.position();
		this.setup(true);
		this.top = 121;
		//  this.top = window.getScrollTop() + (window.getHeight() / 15);
		this.center.setStyles({top: this.top, display: ''});
		this.fx.overlay.start(0.8);
		return this.changeImage(imageNum);
	},

	position: function(){
		this.overlay.setStyles({'top': window.getScrollTop(), 'height': window.getHeight()});
	},

	setup: function(open){
		var elements = $A(document.getElementsByTagName('object'));
		elements.extend(document.getElementsByTagName(window.ie ? 'select' : 'embed'));
		elements.each(function(el){
			if (open) el.lbBackupStyle = el.style.visibility;
			el.style.visibility = open ? 'hidden' : el.lbBackupStyle;
		});
		var fn = open ? 'addEvent' : 'removeEvent';
		window[fn]('scroll', this.eventPosition)[fn]('resize', this.eventPosition);
		document[fn]('keydown', this.eventKeyDown);
		this.step = 0;
	},

	keyboardListener: function(event){
		switch (event.keyCode){
			case 27: case 88: case 67: this.close(); break;
			case 37: case 80: this.previous(); break;	
			case 39: case 78: this.next();
		}
	},

	previous: function(){
		return this.changeImage(this.activeImage-1);
	},

	next: function(){
		return this.changeImage(this.activeImage+1);
	},

	changeImage: function(imageNum){
		if (this.step || (imageNum < 0) || (imageNum >= this.images.length)) return false;
		this.step = 1;
		this.activeImage = imageNum;

		this.bottomContainer.style.display = this.prevLink.style.display = this.nextLink.style.display = 'none';
		this.fx.image.hide();
		this.center.className = 'lbLoading';

		this.preload = new Image();
		this.preload.onload = this.nextEffect.bind(this);
		this.preload.src = this.images[imageNum][0];
		return false;
	},

	nextEffect: function(){
		switch (this.step++){
		case 1:
			this.center.className = '';
			this.image.style.backgroundImage = 'url('+this.images[this.activeImage][0]+')';
			this.image.style.width = this.bottom.style.width = this.preload.width+'px';
			this.image.style.height = this.prevLink.style.height = this.nextLink.style.height = this.preload.height+'px';

			this.caption.setHTML(this.images[this.activeImage][1] || '');
			this.number.setHTML((!this.options.showCounter || (this.images.length == 1)) ? '' : 'Image '+(this.activeImage+1)+' of '+this.images.length);

			if (this.activeImage) this.preloadPrev.src = this.images[this.activeImage-1][0];
			if (this.activeImage != (this.images.length - 1)) this.preloadNext.src = this.images[this.activeImage+1][0];
			if (this.center.clientHeight != this.image.offsetHeight){
				this.fx.resize.start({height: this.image.offsetHeight});
				break;
			}
			this.step++;
		case 2:
			if (this.center.clientWidth != this.image.offsetWidth){
				this.fx.resize.start({width: this.image.offsetWidth, marginLeft: -this.image.offsetWidth/2});
				break;
			}
			this.step++;
		case 3:
			this.bottomContainer.setStyles({top: this.top + this.center.clientHeight, height: 0, marginLeft: this.center.style.marginLeft, display: ''});
			this.fx.image.start(1);
			break;
		case 4:
			if (this.options.animateCaption){
				this.fx.bottom.set(-this.bottom.offsetHeight);
				this.bottomContainer.style.height = '';
				this.fx.bottom.start(0);
				break;
			}
			this.bottomContainer.style.height = '';
		case 5:
			if (this.activeImage) this.prevLink.style.display = '';
			if (this.activeImage != (this.images.length - 1)) this.nextLink.style.display = '';
			this.step = 0;
		}
	},

	close: function(){
		if (this.step < 0) return;
		this.step = -1;
		if (this.preload){
			this.preload.onload = Class.empty;
			this.preload = null;
		}
		for (var f in this.fx) this.fx[f].stop();
		this.center.style.display = this.bottomContainer.style.display = 'none';
		this.fx.overlay.chain(this.setup.pass(false, this)).start(0);
		return false;
	}
};

window.addEvent('domready', Lightbox.init.bind(Lightbox));



/**************************************************************

	Script		: google maps
	Version		: 0.2
	Authors		: Sven Haselböck
	Desc		: 
	Example		: 
		PHP + Javascript
		$logo = array(
					'image'		=>	'/media/images/gmaps_logo.png',					//  Firmen-Logo
					'shadow'	=>	'/media/images/gmaps_logo_schatten.png',		//	Schatten zum Firmen-Logo
					'anchor'	=>	array(6, 20),									//	Pixel-Koordinaten des Logos relativ (top, left) zum Icon. worauf das Logo gemappt wird
					'w_anchor'	=>	array(20, 5),									//	Pixel-Koordinaten des Info-Fensters relativ (top, left) zum Icon
					'info'		=>	'Mein HTML'										//  HTML-Text für das Info-Fenster
				);
		
		G_Maps.init("map", 51.280548, 9.508721, <?php echo json_encode($logo);?>);
		
		OR
		
		Javascript
		var logo = {image: '/media/images/gmaps_logo.png', shadow: '/media/images/gmaps_logo_schatten.png', anchor: [6,20], w_anchor: [20,5], info: 'test html'}
		G_Maps.init("map", 51.280548, 9.508721, logo);

**************************************************************/

G_Maps2 =
{
	gmap:					null,
	gdir:					null,
	gclientgeocoder:		null,
	
	map:					null,
	
	logo:					null,
	lat:					null,
	lng:					null,
	
	marker_icon:			null,
	marker_icon_shadow:		null,
	marker_icon_info_txt:	null,
	
	locale:					null,
	route_txt:				null,
	error_msg:				null,
	
	
	init: function(map_id, lat, lng) {
		this.map = document.getElementById(map_id);
		this.lat = lat;
		this.lng = lng;
		
		this.gmap = new GMap2(this.map);
		this.gclientgeocoder = new GClientGeocoder();
		
		this.gmap.addControl(new GMapTypeControl());
		this.gmap.addControl(new GLargeMapControl());
		
		this.gmap.setCenter(new GLatLng(lat, lng), 13);
		this.gmap.enableContinuousZoom();
		this.initMouseWheel();
	},
	
	setFirmLogoMarker: function(logo)
	{
		var img_logo = new Image();
		img_logo = logo.image.src;
			
		var baseIcon = new GIcon();
		baseIcon.image = logo.image.src;
		baseIcon.shadow = logo.shadow;
		baseIcon.iconSize = new GSize(logo.image.width, logo.image.height);
		baseIcon.shadowSize = new GSize(50, 34);
		baseIcon.iconAnchor = new GPoint(logo.anchor[0], logo.anchor[1]);
		baseIcon.infoWindowAnchor = new GPoint(logo.w_anchor[0], logo.w_anchor[1]);
		
		this.addMarkerByPoint(new GLatLng(this.lat, this.lng), baseIcon, logo.info);
	},
	
	setFirmMarker: function() {
		this.addMarkerByPoint(new GLatLng(this.lat, this.lng));
	},	
	
	initRoute: function(route_id)
	{
		this.route_txt = document.getElementById(route_id);
		
		this.gdir = new GDirections(this.gmap, this.route_txt);
		
		GEvent.bindDom(this.gdir, "error", this, function(event)
		{
			/*
			var reasons=[];
				reasons[G_GEO_SUCCESS]				= "Success";
				reasons[G_GEO_MISSING_ADDRESS]		= "Missing Address:The address was either missing or had no value.";
				reasons[G_GEO_UNKNOWN_ADDRESS]		= "Unknown Address: No corresponding geographic location could be found for the specified address.";
				reasons[G_GEO_UNAVAILABLE_ADDRESS]	= "Unavailable Address: The geocode for the given address cannot be returned due to legal or contractual reasons.";
				reasons[G_GEO_BAD_KEY]				= "Bad Key: The API key is either invalid or does not match the domain for which it was given";
				reasons[G_GEO_TOO_MANY_QUERIES]		= "Too Many Queries: The daily geocoding quota for this site has been exceeded.";
				reasons[G_GEO_SERVER_ERROR]			= "Server error: The geocoding request could not be successfully processed.";
				reasons[G_GEO_BAD_REQUEST]			= "A directions request could not be successfully parsed.";
				reasons[G_GEO_MISSING_QUERY]		= "No query was specified in the input.";
				reasons[G_GEO_UNKNOWN_DIRECTIONS]	= "The GDirections object could not compute directions between the points.";
			
			var code = G_Maps.gdir.getStatus().code;
			var reason="Code " + code;
			
			if (reasons[code]) {
				reason = reasons[code]
			}
			*/ 
			
			alert(G_Maps2.error_msg);
		});
	},
	
	setRouteLocale: function(locale) {
		this.locale = locale;
	},
	
	setRouteErrorMsg: function(error_msg) {
		this.error_msg = error_msg;
	},
	
	setMarkerIcon: function(path, info_txt) {
		this.marker_icon = new Image();
		this.marker_icon.src = path;
		this.marker_icon_info_txt = info_txt;
	},
	
	setMarkerIconShadow: function(path) {
		this.marker_icon_shadow = new Image();
		this.marker_icon_shadow.src = path;
	},
	
	initMouseWheel: function()
	{
		//  Firefox, Opera
		GEvent.bindDom(this.map, "DOMMouseScroll", this, function(event)
		{
			//  scrolling verhindern
			if (event.preventDefault) {
				event.preventDefault();
			}
			
			if (event.detail < 0) {
				this.gmap.zoomIn();
			}
			else if (event.detail > 0) {
				this.gmap.zoomOut();
			}
		});
		
		//  IE
		GEvent.bindDom(this.map, "mousewheel", this, function(event)
		{
			//  scrolling verhindern
			event.returnValue = false;
			
			if (event.wheelDelta > 0) {
				this.gmap.zoomIn();
			}
			else if (event.wheelDelta < 0) {
				this.gmap.zoomOut();
			}
		});
	},
	
	startRoute: function(from)
	{
		var from = document.getElementById(from).value;
		this.gclientgeocoder.getLatLng(from, this.getLatLng_Callback);
	},
	
	getLatLng_Callback:function(point)
	{
		if (!point) {
			alert(G_Maps2.error_msg);
		}
		else
		{			
			//  Alte Route löschen
			G_Maps2.gdir.clear();
			
			var query = "from: " + point.lat() + "," + point.lng() + " to:" + G_Maps2.lat + "," + G_Maps2.lng;
			G_Maps2.gdir.load(query, {locale: G_Maps2.locale});
			G_Maps2.route_txt.style.display = 'block';
		}		
	},
		
	addMarkerByAddress: function (address, icon, info_text)
	{
		this.gclientgeocoder.getLatLng(address, function(point)
		{
			if (!point) {
				alert(address + " nicht gefunden");
			}
			else
			{
				var marker = new GMarker(point, icon, {title: address});		
				
				GEvent.addListener(marker, "click", function() {
					marker.openInfoWindowHtml(info_text);
				});
				
				this.gmap.addOverlay(marker);
				this.arr_markers[this.arr_markers.length] = marker;
				this.arr_marker_texts[this.arr_marker_texts.length] = info_text;
			}
		});	
	},
	
	addMarkerByPoint: function(point, icon, info_txt)
	{
		var marker = null;
		
		if (icon != null && (typeof(icon) != "undefined") ) {
			marker = new GMarker(point, icon);
		}
		else {
			marker = new GMarker(point);			
		}
					
		//  Info-Text für das Popup wurde gesetzt
		if (info_txt != null && (typeof(info_txt) != "undefined"))
		{
			GEvent.addListener(marker, "click", function() {
				marker.openInfoWindowHtml(info_txt);
			});
		}
		
		this.gmap.addOverlay(marker);
	}
};


/*
File: mooremote.js
This file needs to be included after Mootools and before the JS generated by <MooRemote::getJavascript>.

License:
	MIT-style license

Author:
	Jan Kassens
	
Dependencies:
	- Mootools >= 1.2dev
	- Remote.XHR and Remote.Json
*/
var MooRemote = new Class
({
	options: null,
	
	initialize: function(functions, options)
	{
		MooRemote.options = options || {};
		
		var url = MooRemote.options.url || window.location.href;
		var self = this;
		
		functions.each(function(fn)
		{
			if (fn.klass)
			{
				self[fn.klass] = {};
				
				fn.methods.each(function(method)
				{
					self[fn.klass][method] = function() { 							
						return new MooRequest(url, [fn.klass, method], arguments[0]);
					}
				});
			}
			else
			{
				self[fn] = function() {
					return new MooRequest(url, fn, arguments[0]);
				}
			};
		});
	}

});
/*
Class: MooRequest
Any call with mooRemote.* returns an instance of this class. There are two events you can register with addEvent.

Events:
	onSuccess - is fired after a successful function call. The return value of the PHP function is passed as the first 
	argument of the event.
	onError - is fired if an error was triggered or an exception thrown in your PHP code. Argument is the error string.
*/

var MooRequest = XHR.extend
({
	id_ajax_loading:		null,
	result:					null,
	std_ajax_loader:		false,
	
	/**
	 * 
	 */
	initialize: function(url, fn, arguments)
	{
		this.parent();
		this.setHeader('X-Requested-With', 'MooRequest');
		
		if ( $defined(arguments.update) ) {
			this.result = $type(arguments.update) == 'string' ? $(arguments.update) : arguments.update; 
		}

		if ( $defined(arguments.id) ) {
			this.id_ajax_loading = $type(arguments.id) == 'string' ? $(arguments.id) : arguments.id;
		}
		
		if ( $defined(arguments.std_ajax_loader) )
		{
			this.std_ajax_loader = arguments.std_ajax_loader;
			
			if (arguments.std_ajax_loader) {
				this.id_ajax_loading.addClass('ajax-loading');
			}
			else {
				if ( this.id_ajax_loading !== null) {
					this.id_ajax_loading.removeClass('hidden');
				}			
			}
		}
		
		this.addEvent('onError', eval(MooRemote.options.onError));
		this.send(url, "call=" + encodeURIComponent(Json.toString({'method': fn, 'params': arguments.params})));
	},
	
	/**
	 * 
	 */
	onSuccess: function()
	{
		var response = Json.evaluate (this.transport.responseText);
				
		if (this.id_ajax_loading !== null)
		{
			if ( this.id_ajax_loading.id == this.result.id && this.std_ajax_loader)
			{
				this.id_ajax_loading.removeClass('ajax-loading');
			}
			else {
				this.id_ajax_loading.addClass('hidden');
			}
		}
		
		if ($defined(response.error)) {
			this.fireEvent('onError', response.error);
		}
		else
		{
			if ( $defined(response.result) )
			{
				if ( response.result !== false )
				{
					if ( $defined(this.result) )
					{
						if (response.html != "") {
							this.result.setHTML(response.html);
						}
					}
				}
			}
			return this.fireEvent('onSuccess', $defined(response.result) ? [response.result] : []);
		}
	},
	
	/*
	Method: callback
	callback is a shortcut for addEvent("onSuccess", fn)
	
	Parameters:
		fn - Callback function.
	
	Example:
	(code)
	function myCallback(result){
	    alert(result);
	}
	mooRemote.foobar().callback(myCallback);
	// which is the same as
	mooRemote.foobar().addEvent('onSuccess', myCallback);
	(end code)
	*/
	callback: function(fn) {
		return this.addEvent('onSuccess', fn);
	}

});
