























	/**
	*
	*	HISTORY STAGE
	*
	**/
	
	c_history_stage = Class.create({
	
		//
		//	initialize
		//
		initialize: function() {
		
			// settings
			this._history_stage_elmt = $('history-stage');
			this._slider_elmt = this._history_stage_elmt.down('ul');
			this._slide_step = 120;
			this._slide_item_width = 224;
			this._slide_item_rightmargin = 13;
			
			// system vars
			this._slider_item_count = this._slider_elmt.select('li.item').length;
			
			// initialize
			this.prepare_dom();
			this.set_event_handlers();
		
		},
		
		//
		//	prepare dom
		//
		prepare_dom: function() {
		
			this._history_stage_elmt.down('div#history-slider').insert({
				top: '<a href="#" id="btn-slide-left" style="display: none;">&nbsp;</a>',
				bottom: '<a href="#" id="btn-slide-right">&nbsp;</a>'
			});
		
		},
		
		//
		//	set event handlers
		//
		set_event_handlers: function() {
		
			$('btn-slide-left').observe('click', function(e) {
				e.stop();
				this.slide(-1);
			}.bind(this));
			
			$('btn-slide-right').observe('click', function(e) {
				e.stop();
				this.slide(1);
			}.bind(this));
			
			this._slider_elmt.select('li.item').each(function(a) {
			
				a.observe('click', function(e) {
					this.switch_content(a);
				}.bind(this));
				
				if(Browser.isMSIE6) {

					a.observe('mouseenter', function(e) {
						a.addClassName('item-hover');
					}.bind(this));
					
					a.observe('mouseleave', function(e) {
						a.removeClassName('item-hover');
					}.bind(this));

				}
				
			}.bind(this));
		
		},
		
		//
		//	slide
		//
		slide: function(_dir) {
		
			_dir = _dir * (-1);
		
			_current_left = parseInt(this._slider_elmt.getStyle('left'));
			_new_left = _current_left + (_dir * this._slide_step);
			
			_max_left = -((this._slider_item_count * (this._slide_item_rightmargin+this._slide_item_width)) - this._slide_item_rightmargin - 835);
			
			if(_new_left >= 0) { 
				_new_left = 0; 
				(Browser.isMSIE) ? $('btn-slide-left').hide() : $('btn-slide-left').fade({ duration: 0.3 });
			} else {
				(Browser.isMSIE) ? $('btn-slide-left').show() : $('btn-slide-left').appear({ duration: 0.3 });
			}
			
			if(_new_left <= _max_left) {
				_new_left = _max_left;
				(Browser.isMSIE) ? $('btn-slide-right').hide() : $('btn-slide-right').fade({ duration: 0.3 });
			} else {
				(Browser.isMSIE) ? $('btn-slide-right').show() : $('btn-slide-right').appear({ duration: 0.3 });
			}
		
			if(this._slide_effect) this._slide_effect.cancel();
			this._slide_effect = new Effect.Morph(this._slider_elmt, {
				duration: 0.4,
				transition: Effect.Transitions.Cubic,
				style: 'left: ' + _new_left + 'px;'
			});
		
		},
		
		//
		//	switch content
		//
		switch_content: function(_item) {
		
			this._slider_elmt.select('li.item-active').invoke('removeClassName', 'item-active');
			_item.addClassName('item-active');
			
			$$('div#history-stage-content div.content')[0].remove();
		
			_node = _item.down('div.content').cloneNode(true);
			_node.hide();
			$('history-stage-content').insert({ top: _node });
			_node.appear({ duration: 0.2 });
		
		}
	
	
	});













	/**
	*
	*	PODCAST STAGE
	*
	**/
	
	c_podcast_stage = Class.create({
	
		//
		//	initialize
		//
		initialize: function() {
		
			// settings
			this._stage_elmt = $('podcast-stage');
			this._slider_elmt = this._stage_elmt.down('ul#podcast-nav-list');
			this._slide_step = 90;
			
			// system vars
			this._slider_items = this._slider_elmt.select('li.item');
			this._slider_item_count = this._slider_items.length;
			this._slider_current_item = 0;
			this._overlay_effect = false;
			this._is_sliding = false;
			
			// initialize
			this.prepare_dom();
			this.set_event_handlers();
		
		},
		
		//
		//	prepare dom
		//
		prepare_dom: function() {
		
			this._stage_elmt.down('div#podcast-nav').insert({
				top: '<a href="#" id="btn-slide-left" style="display: none;">&nbsp;</a>',
				bottom: '<a href="#" id="btn-slide-right">&nbsp;</a>'
			});
		
		},
		
		//
		//	set event handlers
		//
		set_event_handlers: function() {
		
			$('btn-slide-left').observe('click', function(e) {
				e.stop();
				this.slide(-1);
			}.bind(this));
			
			$('btn-slide-right').observe('click', function(e) {
				e.stop();
				this.slide(1);
			}.bind(this));
			
			this._slider_elmt.select('li.item').each(function(a) {
			
				a.observe('click', function(e) {
					this.switch_content(a);
				}.bind(this));
				
				if(Browser.isMSIE6) {

					a.observe('mouseenter', function(e) {
						a.addClassName('item-hover');
					}.bind(this));
					
					a.observe('mouseleave', function(e) {
						a.removeClassName('item-hover');
					}.bind(this));

				}
				
			}.bind(this));
		
		},
		
		//
		//	slide
		//
		slide: function(_dir) {
		
			if(!this._is_sliding) {
			
				this._is_sliding = true;

				_dir = _dir * (-1);

				_current_left = parseInt(this._slider_elmt.getStyle('top'));
				_new_left = _current_left + (_dir * this._slide_step);			
				_max_left = -((this._slider_item_count * this._slide_step) - this._slide_step*3);			
				_current_item = this._slider_current_item + (_dir * (-1));

				if(_new_left >= 0) { 
					_new_left = 0; 
					_current_item = 0;
					(Browser.isMSIE) ? $('btn-slide-left').hide() : $('btn-slide-left').fade({ duration: 0.3 });
				} else {
					(Browser.isMSIE) ? $('btn-slide-left').show() : $('btn-slide-left').appear({ duration: 0.3 });
				}

				if(_new_left <= _max_left) {
					_new_left = _max_left;
					_current_item = this._slider_item_count-1;
					(Browser.isMSIE) ? $('btn-slide-right').hide() : $('btn-slide-right').fade({ duration: 0.3 });
				} else {
					(Browser.isMSIE) ? $('btn-slide-right').show() : $('btn-slide-right').appear({ duration: 0.3 });
				}
				
				

				this._slider_current_item = _current_item;

				if(this._slide_effect) this._slide_effect.cancel();
				this._slide_effect = new Effect.Morph(this._slider_elmt, {
					duration: 0.3,
					transition: Effect.Transitions.Cubic,
					style: 'top: ' + _new_left + 'px;',
					afterFinish: function() {
						this._is_sliding = false;
					}.bind(this)
				});
				
			}
		
		},
		
		//
		//	switch content
		//
		switch_content: function(_item) {
		
			this._slider_elmt.select('li.item-active').invoke('removeClassName', 'item-active');
			_item.addClassName('item-active');
			
			$$('div#podcast-player div.content')[0].remove();
		
			_node = _item.down('div.content').cloneNode(true);
			_node.hide();
			$('podcast-player').insert({ top: _node });
			_node.appear({ duration: 0.2 });
		
		}
	
	
	});



      














	/**
	*
	*	BELLA ITALIA STAGE
	*
	**/
	
	c_bella_italia_stage = Class.create({
	
		//
		//	initialize
		//
		initialize: function() {
		
			// settings
			this._stage_elmt = $('bella-italia-stage');
			this._slider_elmt = this._stage_elmt.down('ul#bella-italia-list');
			this._slide_step = 443;
			
			// system vars
			this._slider_items = this._slider_elmt.select('li.item');
			this._slider_item_count = this._slider_items.length;
			this._slider_current_item = 0;
			this._overlay_effect = false;
			this._is_sliding = false;
			
			// initialize
			this.prepare_dom();
			this.set_event_handlers();
			this.jump( Math.floor( Math.random() * this._slider_item_count ) );
			
		},
		
		//
		//	prepare dom
		//
		prepare_dom: function() {
		
			this._stage_elmt.down('div#bella-italia-slider').insert({
				top: '<a href="#" id="btn-slide-left" style="display: none;">&nbsp;</a>',
				bottom: '<a href="#" id="btn-slide-right">&nbsp;</a>'
			});
			
			$('wallpaper-list').select('a').each(function(a) {
				a.observe('click', function(e) {
					e.stop();
					this.jump(a.href.substring(a.href.indexOf('#')+1));
				}.bind(this));
			}.bind(this));
		
		},
		
		//
		//	set event handlers
		//
		set_event_handlers: function() {
		
			$('btn-slide-left').observe('click', function(e) {
				e.stop();
				this.slide(-1, false);
			}.bind(this));
			
			$('btn-slide-right').observe('click', function(e) {
				e.stop();
				this.slide(1, false);
			}.bind(this));
			
			this._slider_elmt.select('li.item').each(function(a, b) {

				a.observe('mouseenter', function(e) {
					this.show_overlay(a);
				}.bind(this));

				a.observe('mouseleave', function(e) {
					this.hide_overlay(a);
				}.bind(this));
				
				if(b == this._slider_item_count-1) {
					a.addClassName('last-item');
				}
				
			}.bind(this));
		
		},
		
		//
		//	slide
		//
		slide: function(_dir, _index) {
		
			if(!this._is_sliding) {
			
				this._is_sliding = true;

				_dir = _dir * (-1);

				_current_left = parseInt(this._slider_elmt.getStyle('left'));
				_new_left = _current_left + (_dir * this._slide_step);			
				_max_left = -((this._slider_item_count * this._slide_step) - this._slide_step);			
				_current_item = this._slider_current_item + (_dir * (-1));
				
				this._slider_items[this._slider_current_item].down('div.overlay').hide();
				
				// slide to hash index?
				if(!_dir && !isNaN(_index)) {
				
					_new_left = -(_index * this._slide_step);
					_current_item = parseInt(_index);
					if(_current_item < 0) _current_item = 0;
					if(_current_item >= this._slider_item_count) _current_item = (this._slider_item_count-1);

					this._slider_items[_current_item].down('div.overlay').show();
				
				}

				if(_new_left >= 0) { 
					_new_left = 0; 
					_current_item = 0;
					(Browser.isMSIE) ? $('btn-slide-left').hide() : $('btn-slide-left').fade({ duration: 0.3 });
				} else {
					(Browser.isMSIE) ? $('btn-slide-left').show() : $('btn-slide-left').appear({ duration: 0.3 });
				}

				if(_new_left <= _max_left) {
					_new_left = _max_left;
					_current_item = this._slider_item_count-1;
					(Browser.isMSIE) ? $('btn-slide-right').hide() : $('btn-slide-right').fade({ duration: 0.3 });
				} else {
					(Browser.isMSIE) ? $('btn-slide-right').show() : $('btn-slide-right').appear({ duration: 0.3 });
				}
				
				

				this._slider_current_item = _current_item;

				if(this._slide_effect) this._slide_effect.cancel();
				this._slide_effect = new Effect.Morph(this._slider_elmt, {
					duration: 0.4,
					transition: Effect.Transitions.Cubic,
					style: 'left: ' + _new_left + 'px;',
					afterFinish: function() {
						this._is_sliding = false;
					}.bind(this)
				});
				
			}
		
		},
		
		//
		//	show overlay
		//
		show_overlay: function(_item) {
		
			_pos = this._slider_items.indexOf(_item);

			if(_pos == this._slider_current_item) {
			
				if(this._overlay_effect) this._overlay_effect.cancel();
				this._overlay_effect = new Effect.Appear(_item.down('div.overlay'), {
					duration: 0.2
				});
			
			}
		
		},
		
		//
		//	hide overlay
		//
		hide_overlay: function(_item) {
		
			_overlay = _item.down('div.overlay');
			
			if(_overlay.visible()) {
			
				if(this._overlay_effect) this._overlay_effect.cancel();
				this._overlay_effect = new Effect.Fade(_overlay, {
					duration: 0.2
				});
			
			}
		
		},
		
		//
		//	jump to hash index
		//
		jump: function(_index) {
		
			this.slide(false, _index);
		
		}	
	
	});




















	/**
	*
	*	HASH NAVIGATION
	*
	**/
	c_location = Class.create({

		//
		//	initialize
		//
		initialize: function() {

			this.initlocation = this.getcleanlocation();
			//this.checkinterval = window.setInterval(function() { this.check(); }.bind(this), 100);
			this.check();
			this.handlers = new Hash();

		},

		//
		//	set
		//
		set: function(which) {

			window.location.href = this.initlocation = this.getcleanlocation() + '#' + which;

		},

		//
		//	get clean location
		//
		getcleanlocation: function() {

			return window.location.href.replace(/\#.+/,"");

		},

		//
		//	get identifier
		//
		getidentifier: function() {

			var locID;
			loc = window.location.href;
			hashPos = loc.indexOf('#');

			if(hashPos != -1) {

				tmpLocID = loc.substring((hashPos+1));
				locID = tmpLocID;

				}

			if(locID == '') { return false; }
			else { return locID; }

		},

		//
		//	check
		//
		check: function() {

			if(window.location.href != this.initlocation) {
				this.initlocation = window.location.href;
				this.call_function(this.getidentifier());
			}

		},
		
		//
		//	call function
		//
		call_function: function(_lid) {
		
			if($('bella-italia-stage')) _bella_italia_stage.jump(_lid);
		
		}

	});




















	/**
	*
	*	PIZZA STAGE
	*
	**/
	
	c_pizza_stage = Class.create({
	
		//
		//	initialize
		//
		initialize: function() {
		
			// settings
			this._pizza_stage_elmt = $('pizza-stage');
			
			this._item_width_medium = 143;
			this._item_width_max = 143;
			this._item_width_min = 95;
			this._item_padding_max = 252;
			this._img_width_max = 161;
			this._img_width_medium = 122;
			this._img_width_min = 82; 
			
			this._scale_effect_duration = 0.3;
			
			// system vars
			this._text_item = false;
			this._swap_is_running = false;
			this._current_item = false;
			this._last_body_classname = false;
			
			// initialize
			this.prepare_dom();
			this.set_event_handlers();
			this.set_zindex();
		
		},
		
		//
		//	prepare dom
		//
		prepare_dom: function() {
		
			this._pizza_stage_elmt.down('ul').insert({
				top: '<li class="text-item" style="display: none;">&nbsp;</li>'
			});
			
			this._text_item = this._pizza_stage_elmt.down('li.text-item');
			
			if(Browser.isMSIE6) {
			
				this._pizza_stage_elmt.select('div.image a img').each(function(a) {
				
					a.src = a.src.replace(/\.png/, '.gif');
				
				});
			
			}
		
		},
		
		//
		//	set event handlers
		//
		set_event_handlers: function() {
		
			this._pizza_stage_elmt.select('li.item a').each(function(a, b) {
			
				a.observe('click', function(e) {
					e.stop();
					this.enlarge_pizza(e, a, b);
				}.bind(this));
			
				if(Browser.isMSIE6) {
					a.observe('mouseover', function(e) {
						a.down('strong').show();
					});
					a.observe('mouseout', function(e) {
						a.down('strong').hide();
					});
				}
			
			}.bind(this));
		
		},
		
		//
		//	set z-index
		//
		set_zindex: function() {
		
			_z = 7;
			this._pizza_stage_elmt.select('li.item').each(function(a) {

				a.setStyle('z-index: '+(_z--));
			
			});
		
		},
		
		//
		//	enlarge pizza
		//
		enlarge_pizza: function(e, elmt, index) {
		
			if(!this._swap_is_running) {
			
				if(elmt == this._current_item) {
					this.reset_pizzas();
				}
				
				else {
				
					this._current_item = elmt;
					this._swap_is_running = true;

					_li = elmt.up('li.item');
					
					this.set_background(elmt);

					this.shrink_all_pizzas(_li);

					// left or right?
					_padding = (_li.hasClassName('left')) ? 'padding-right' : 'padding-left';

					// li.item
					new Effect.Morph(_li, {
						style: 'width: '+this._item_width_max+'px; '+_padding+': '+this._item_padding_max+'px; padding-top: 0px; margin-top: -30px;',
						duration: this._scale_effect_duration
					});

					// li.item img
					new Effect.Morph(_li.down('img'), {
						style: 'width: '+this._img_width_max+'px;',
						duration: this._scale_effect_duration,
						afterFinish: function() {
							this._swap_is_running = false;
						}.bind(this)
					});

					// copy and show text contents
					this.show_text_contents(_li, index);
					
				}
				
			}
		
		},
		
		//
		//	shrink all pizzas
		//
		shrink_all_pizzas: function(except) {
		
			this._pizza_stage_elmt.select('li.item').each(function(a) {
			
				if(a != except) {
				
					// li.item
					new Effect.Morph(a, {
						style: 'width: '+this._item_width_min+'px; padding-left: 0px; padding-right: 0px; padding-top: 30px; margin-top: 0px;',
						duration: this._scale_effect_duration
					});
					
					// li.item img
					new Effect.Morph(a.down('img'), {
						style: 'width: '+this._img_width_min+'px;',
						duration: this._scale_effect_duration
					});
				
				}
			
			}.bind(this));
		
		},
		
		//
		//	show text contents
		//
		show_text_contents: function(_item, index) {

			_left_offset = (index > 2) ? (index * this._item_width_min) : ((index * this._item_width_min) + this._item_width_max - 66);
		
			this._text_item.hide();
			this._text_item.id = 'text-item-'+_item.id;

			this._text_item.update(_item.down('div.text').innerHTML);
			this._text_item.appear({ duration: this._scale_effect_duration });
			new Effect.Morph(this._text_item, {

				style: 'left: '+_left_offset+'px;',
				duration: this._scale_effect_duration

			});
		
		},
		
		//
		//	reset pizzas
		//
		reset_pizzas: function() {
		
			if(!this._swap_is_running) {
			
				this._swap_is_running = true;
				
				this.set_background(false);
				
				this._pizza_stage_elmt.select('li.item').each(function(a) {

					// li.item
					new Effect.Morph(a, {
						style: 'width: '+this._item_width_medium+'px; padding-left: 0px; padding-right: 0px; padding-top: 0px; margin-top: 0px;',
						duration: this._scale_effect_duration,
						afterFinish: function() {
							this._swap_is_running = false;
							this._current_item = false;
						}.bind(this)
					});

					// li.item img
					new Effect.Morph(a.down('img'), {
						style: 'width: '+this._img_width_medium+'px;',
						duration: this._scale_effect_duration
					});

				}.bind(this));
				
				this._text_item.fade({
					duration: this._scale_effect_duration,
					afterFinish: function(a) {
						a.element.update('');
					}
				});
			
			}
		
		},
		
		//
		//	set background
		//
		set_background: function(_item) {
		
			// reset background
			$$('body')[0].removeClassName(this._last_body_classname);
			
			// set background
			if(_item) {
			
				_classname = _item.up('li.item').id;
				this._last_body_classname = _classname;
				$$('body')[0].addClassName(_classname);
			
			}
		
		}
	
	
	});







	/**
	*
	*	HOME SLIDESHOW
	*
	**/
	
	c_pizza_slideshow = Class.create({
	
		//
		//	initialize
		//
		initialize: function() {

			// settings
			this._slide_duration = 2;
			this._interval_duration = 5;
			this._img_elmts = $$('.slideshow-images .item'); 
			
			// system variables
			this._zindex = 1;
			this._current_img_index = -1;
			this._img_count = this._img_elmts.length;
			this._text_was_changed = false;
			
			// initialize
			this.prepare_dom();
         		this.start_slideshow();
         		
		}, 
		
		//
		//	prepare dom
		//
		prepare_dom: function() {
		
			this._img_elmts.invoke('setOpacity', 0);
		
		},
		
		//
		//	start slideshow
		//
		start_slideshow: function() {
		
			window.setTimeout(function() {
			
				this.slide_image();
			
				new PeriodicalExecuter(function(pe) {
					this.slide_image();
				}.bind(this), this._interval_duration);
				
			}.bind(this), 500);
		
		},
		
		//
		//	slide image
		//
		slide_image: function() {
		
			_next_index = (this._current_img_index+1 <= this._img_count-1) ? this._current_img_index+1 : 0;
			this._current_img_index = _next_index;
			this._zindex++;
			
			_img = this._img_elmts[_next_index];
			_img.setOpacity(0);
			_img.setStyle('z-index: '+this._zindex);
			_img.appear({
				duration: this._slide_duration
			});
			
			if(this._current_img_index == 4 && !this._text_was_changed) {
				$('slideshow').down('p.first').hide();
				$('slideshow').down('p.second').appear({
					duration: this._slide_duration
				});
				this._text_was_changed = true;
			}
			if(this._current_img_index == 0 && this._text_was_changed) {
				$('slideshow').down('p.second').hide();
				$('slideshow').down('p.first').appear({
					duration: this._slide_duration
				});
				this._text_was_changed = false;
			}
		
		}
		
	}); 


   
	/**
	*
	*	META LINKS
	*   make meta links strict valid external targets
	*
	**/
	
	c_meta_links = Class.create({
	
		//
		//	initialize
		//
		initialize: function()
		{                                                                                                                
		 	this.addBehaviour();
		},  
		
		addBehaviour: function()
		{
			// onclick="window.open(this.href, 'datenschutz', 'width=800, height=500, scrollbars=yes, top=100, left=100'); return false;"

			$$('#footer p.left a').each( function( element ) 
			{
				element.observe('click', function(e) {
					e.stop();                                   
					if( this.className == 'external') {        
					 	window.open( this.href, 'external', 'menubar=yes,statusbar=yes,toolbar=yes,scrollbars=yes, top=100, left=100');
					}else {                                                                      
						window.open( this.href, 'datenschutz', 'width=800, height=500, scrollbars=yes, top=100, left=100');                                                          
					}                                                                                                 
				});   
			});
			
			$$('a.btn-pizzabus').each( function( element ) 
			{
				element.observe('click', function(e) {
					e.stop();                                   
                    window.open( this.href, 'pizzabus', 'width=800, height=600, scrollbars=yes, top=100, left=100');                                                                                                                                                          
				});   
			});
			$$('.facebook a').each( function( element ) 
			{
				element.observe('click', function(e) {
					e.stop();                                   
                    window.open( this.href, 'facebook', 'menubar=yes,statusbar=yes,toolbar=yes,scrollbars=yes, top=100, left=100')                                                                                                                                                        
				});   
			});  
			
			                                                         
		}
		
		
	}); 




	/**
	*
	*	BROWSER DETECTION
	*
	**/

	var Browser = {
		detect: function() {
			var UA = navigator.userAgent;
			this.isKHTML = /Konqueror|Safari|KHTML/.test(UA);
			this.isGecko = (/Gecko/.test(UA) && !this.isKHTML);
			this.isOpera = /Opera/.test(UA);
			this.isMSIE = (/MSIE/.test(UA) && !this.isOpera);
			this.isMSIE7 = this.isMSIE && !(/MSIE 6\./.test(UA) && !this.isOpera);
			this.isMSIE6 = this.isMSIE && !this.isMSIE7;
			this.isIPHONE = /iPhone|iPod/.test(UA);
		}
	}
	Browser.detect();





















	/**
	*
	*	ON DOM LOADED
	*
	**/
	
	document.observe('dom:loaded', function() {
	                                                                
		if($('pizza-stage')) { _pizza_stage = new c_pizza_stage(); }  
		
		if($('slideshow')) { _pizza_slideshow = new c_pizza_slideshow(); }   
		
		if($('history-stage')) { _history_stage = new c_history_stage(); }
		                                                                                   
		if($('bella-italia-stage')) { _bella_italia_stage = new c_bella_italia_stage(); } 
		 
		if($('footer')) { _meta_links = new c_meta_links(); }  
		
		_location = new c_location();
	
	});