jQuery(document).ready(function($){
	var filters = [];
	var used = []

	if($("#filterReference").length){
		$('.listDefaultReference .listEntry a[rel="reference"]').each(function(){
			var revOptions = $(this).attr("rev");
			revOptions = revOptions.split(";");
			if(revOptions.length){
				for(i=0; i<revOptions.length; i++){
					if(revOptions[i]){
						used.push({
							filter: revOptions[i],
							obj: $(this)
						});
					}
				}
			}
		});

		$('#filterReference a[rel="filterReference"]').each(function(){
			$('#filterReference a[href="#reset"]').hide();
			$(this).hide();
			$(this).parents("li").hide();
			$(this).click(function(){
				var filter = $(this).attr("rev");
				$('#filterReference li').removeClass("on");
				$($(this).parents("li")).addClass("on");
				$('#filterReference a[href="#reset"]').show();
				$('.listDefaultReference .listEntry').each(function(){
					if($($(this).find('a[rev*="'+filter+'"]')).length){
						if(!$(this).is(":visible")) $(this).fadeIn("fast");
					}else{
						if($(this).is(":visible")) $(this).hide();
					}
				});
				return false;
			});
		});

		
		$('#filterReference a[href="#reset"]').click(function(){
			$(this).hide();
			$('#filterReference li').removeClass("on");
			$('.listDefaultReference .listEntry').each(function(){
				if(!$(this).is(":visible")) $(this).fadeIn("fast");
			});
			return false;
		});

		var url = location.href;
		url = url.split("#");
		if(url.length == 2){
			var param = "#"+url[1];
			if(param.length > 2){
				if($('#filterReference a[href="'+param+'"]').length){
					$('#filterReference a[href="'+param+'"]').click();
				}
			}
		}

		var sumUsed = [];
		$(used).each(function(i, use){
			if(!sumUsed[use.filter] || typeof sumUsed[use.filter] == "undefined") sumUsed[use.filter] = 1;
			else sumUsed[use.filter]++;
		});

		$(used).each(function(i, use){
			if(sumUsed[use.filter] && sumUsed[use.filter] > 0){
				if($('#filterReference a[rev="'+use.filter+'"]').length){
					$('#filterReference a[rev="'+use.filter+'"]').show();
					$('#filterReference a[rev="'+use.filter+'"]').parents("li").show();
					$('#filterReference a[rev="'+use.filter+'"] .count').html("("+sumUsed[use.filter]+")");
				}
			}
		});
	}
});

Object.extend(Prototype.Browser, {
    IE6:     Prototype.Browser.IE && (typeof window.XMLHttpRequest == "undefined"),
    IE7:     Prototype.Browser.IE && (typeof window.XMLHttpRequest == "object")
});

Shadowbox.init( {
	language :"de-DE",
	players : [ "img", "html", "iframe", "qt", "wmp", "swf", "flv" ]
});

document.observe("dom:loaded", function() { 
    Shadowbox.setup('a.pictureDetails', {});
    Shadowbox.setup('a[rel=shadowbox]', {});
	
	// IE6 Workarrounds
	if(Prototype.Browser.IE6){
		$$("#references .item img, #Tooltip img, #locations .item img, #locations_Tooltip img").each(function(item){
			src = item.src;
			src = src.replace(/\.png/, ".gif");
			item.src = src;
		});

		if($("backLink")) $("backLink").addClassName("noPNG");
		if($("bwdLink")) $("bwdLink").addClassName("noPNG");
		if($("fwdLink")) $("fwdLink").addClassName("noPNG");
	}
	if($("portal")) mapEffect = new MapEffect();
	if($("locations")) locationsWidget = new LocationsWidget();
	quicklinks = new Quicklinks();
	content = new Content();

	$$('a[rel="ajaxContent"]').each(function(item){
		item.observe("click", function(event){
			eval("if(Object.isFunction(" + item.readAttribute("rel")
					+ ")){ new " + item.readAttribute("rel")
					+ "(item, event) }");
			item.blur();
			Event.stop(event);
		});
	});

	$$('.listCompactNews .trigger').each( function(item) {
		item.observe("click", function(event) {
			if (!item.up().select(".teaser")[0].visible()) {
				item.up().addClassName("on");
				item.up().select(".teaser")[0].appear( {
					duration :0.5
				});
			} else {
				item.up().removeClassName("on");
				item.up().select(".teaser")[0].fade( {
					duration :0.5
				});
			}
			item.blur();
			Event.stop(event);
		});
	});
});

var ajaxContent = {}
ajaxContent = Class.create();
ajaxContent.prototype = {
	initialize : function(element, event) {
		this.element = element;
		this.event = event;
		this.itemLoader = new Element("div", {
			"id" :"loader"
		});
		this.options = Object.extend( {
			loader :true,
			relAttribute :element.readAttribute("rel"),
			revOptions :Object.extend( {
				insertion :"replace",
				cutTarget :true
			}, this.parseRevOptions(this.element.readAttribute("rev"))),
			none :true
		}, arguments[2] || {});

		this.update();
	},

	showLoader : function() {
		if (this.options.revOptions.insertion == "replace") {
			$(this.options.revOptions.destination).update(this.itemLoader);
		} else {
			$(this.options.revOptions.destination).insert( {"top" :this.itemLoader});
		}
	},

	hideLoader : function() {
		this.itemLoader.remove();
	},

	update : function() {
		this.stopEvent();

		if (this.options.revOptions.destination
				&& $(this.options.revOptions.destination)) {
			url = this.element.readAttribute("href");

			url += "?ajax=true";
			new Ajax.Request(
					url,
					{ evalJS: false,
						method :'get',
						onCreate : function(tranport) {
							$(this.options.revOptions.destination).childElements().each(Element.hide);
							this.showLoader();
						}.bind(this),
						onSuccess : function(transport) {
							this.hideLoader();
							text = transport.responseText.stripScripts();
						
							if (this.options.revOptions.cutTarget) {
								tmp = new Element('div');
								tmp.update(text);	
								instance = this; 
								tmp.select("div").each(function(item) {
									if(typeof instance.options.revOptions.origin != "undefined"){
										if (item.id == instance.options.revOptions.origin) text= item.innerHTML;
									}else{
										if (item.id == instance.options.revOptions.destination) text= item.innerHTML;
									}
								}
								)
								 
							}
							
							if (this.options.revOptions.insertion == "replace") {

								$(this.options.revOptions.destination).update(text);
							} else {
								$(this.options.revOptions.destination)
										.insert(
												text,
												{
													position :this.options.revOptions.insertion
												});
							}
							 
							if (typeof content == "object") {
								content.setup();
							}
           //   et_eC_Wrapper( etCode, url, '', 0, '', '', 0, 0, 0, 0, 0, 0, 0);	
						}.bind(this)
					});
		}
	},

	stopEvent : function() {
		Event.stop(this.event);
	},

	parseRevOptions : function(str) {
		if (!str)
			return {};
		var quotes = [], match, rex = /`([^`]*?)`/g;
		while ((match = rex.exec(str)))
			quotes.push(match[1]);
		if (quotes.length)
			str = str.replace(rex, '``');
		str = str.replace(/\s*[:=]\s*/g, ':');
		str = str.replace(/\s*[;&]\s*/g, ' ');
		str = str.replace(/^\s+|\s+$/g, '');
		var pairs = {}, aVars = str.split(' '), i = aVars.length;
		while (i--) {
			var aThisVar = aVars[i].split(':'), name = aThisVar[0], value = aThisVar[1];
			if (typeof value === 'string') {
				if (!isNaN(value))
					value = +value;
				else if (value === 'true')
					value = true;
				else if (value === 'false')
					value = false;
			}
			if (value === '``')
				value = quotes.pop() || '';
			pairs[name] = value;
		}
		return pairs;
	},

	none : function() {
	}
}

var Quicklinks = {}
Quicklinks = Class.create();
Quicklinks.prototype = {
	initialize : function() {
		this.options = Object.extend( {
			itemQuicklink :".quicklink",
			none :true
		}, arguments[0] || {});
		this.showEvent = this.show.bindAsEventListener(this);
		this.hideEvent = this.hide.bindAsEventListener(this);
		$$(this.options.itemQuicklink).each( function(item) {
			Event.observe(item, "mouseover", this.showEvent);
			Event.observe(item, "mouseout", this.hideEvent);
			if (item.select(".active")[0])
				item.select(".active")[0].hide();
		}.bind(this));
	},

	show : function(e) {
		eItem = Event.element(e);
		if (!eItem.hasClassName("item"))
			eItem = Event.element(e).up(".item");

		if (eItem.select(".passive")[0])
			eItem.select(".passive")[0].hide();
		if (eItem.select(".active")[0])
			eItem.select(".active")[0].show();
		eItem.addClassName("quicklinkOn");
	},

	hide : function(e) {
		eItem = Event.element(e);
		if (!eItem.hasClassName("item"))
			eItem = Event.element(e).up(".item");

		if (eItem.select(".passive")[0])
			eItem.select(".passive")[0].show();
		if (eItem.select(".active")[0])
			eItem.select(".active")[0].hide();
		eItem.removeClassName("quicklinkOn");
	},

	none : function() {
	}
}

var Teaser = {}
Teaser = Class.create();
Teaser.prototype = {
	initialize : function() {
		this.items = [];
		this.options = Object.extend( {
			itemTeaser :"#teaser .teaser",
			itemImage :"#mappoints .item",
			classSlideshow: "slideshow"
				
		}, arguments[0] || {});

		$$(this.options.itemTeaser).each( function(item, i) {
			name = item.readAttribute("id");
			name = name.replace(/_teaser/, "");  
			this.items[i] = {
				name :name,
				text :item,
				image :$(name + "_image") ? $(name + "_image") : false
			};
		}.bind(this));

		this.shown = this.items.first().name; 
		
		
		if($("bwdLink")) $("bwdLink").appear();
		this.bwdEvent = this.bwd.bindAsEventListener(this);
		$$("#bwdLink a").each( function(item) {
			Event.observe(item, "click", this.bwdEvent);
		}.bind(this));
		
		
		if($("fwdLink")) $("fwdLink").appear();
		this.fwdEvent = this.fwd.bindAsEventListener(this);
		$$("#fwdLink a").each( function(item) {
			Event.observe(item, "click", this.fwdEvent);
		}.bind(this));		
	},
	
	
	prev : function() {
		key = null;
		this.items.each( function(item, i) {
			if (item.name == this.shown) {
				if (this.items[i - 1]) {
					key = this.items[i - 1].name;
					cur = this.items[i-1].text;
				} else {
					key = this.items.last().name;
					cur = this.items.last().text;
				}
				if(! cur.hasClassName(this.options.classSlideshow)) this.shown = key;
				return;
			}
		}.bind(this));
		return key;
	},

	next : function() {
		key = null;
		this.items.each( function(item, i) {
			if (item.name == this.shown) {
				if (this.items[i + 1]) {
					key = this.items[i + 1].name;
					cur = this.items[i+1].text;
				} else {
					key = this.items.first().name;
					cur = this.items.first().text;
				}
				if(! cur.hasClassName(this.options.classSlideshow)) this.shown = key;
				return;
			}
		}.bind(this));
		return key;
	},

	getItem : function(key) {
		ret = null;
		this.items.each( function(item, i) {
			if (item.name == key) {
				ret = item;
			}
		}.bind(this));
		return ret;
	},
	
	
	bwd : function(e){
		this.rotate("stop");
		
		new PeriodicalExecuter( function(pe) {
			this.delay = false;
			pe.stop();
		}.bind(this), 2);
		
		if(this.delay) {
			Event.stop(e);
			return;
		}
		this.delay = true;

		if (this.getItem(this.prev()).text.hasClassName("startTeaser") || ! this.getItem(this.prev()).image) {
			if (!$("map").visible()) {
				new Effect.Appear($("map"), {
					beforeStart : function(effect) {
						effect.element.setOpacity(0.0);
						effect.element.show();
						new Effect.Opacity('ToolTip',{ from: 0.0, to: 0.4,duration: 2});
					}
				});
				
			}
			if ($("backLink") && $("backLink").visible()) $("backLink").fade();
		 
			$("mappoints").setStyle( {
				zIndex :30
			});
		} else {
			if ($("backLink") && !$("backLink").visible()) $("backLink").appear();
				
			$("mappoints").setStyle( {
				zIndex :40
			});
			if ($("map").visible())
				new Effect.Fade($("map"), {
					afterFinish : function(effect) {
						$("ToolTip").fade();
						effect.element.hide();
					}
				});
		}
		this.show(this.prev(), "rotate");
		
		Event.stop(e);
	},
	fwd : function(e){
		this.rotate("stop");
		
		new PeriodicalExecuter( function(pe) {
			this.delay = false;
			pe.stop();
		}.bind(this), 2);
		
		if(this.delay) {
			Event.stop(e);
			return;
		}
		this.delay = true;
		
		if (this.getItem(this.next()).text.hasClassName("startTeaser") || ! this.getItem(this.next()).image) {
			if (!$("map").visible()) {
				new Effect.Appear($("map"), {
					beforeStart : function(effect) {
						effect.element.setOpacity(0.0);
						effect.element.show();
						new Effect.Opacity('ToolTip',{ from: 0.0, to: 0.4,duration: 2});
					}
				});
				
			}
			if ($("backLink") && $("backLink").visible()) $("backLink").fade();
		 
			$("mappoints").setStyle( {
				zIndex :30
			});
		} else {
			if ($("backLink") && !$("backLink").visible()) $("backLink").appear();
				
			$("mappoints").setStyle( {
				zIndex :40
			});
			if ($("map").visible())
				new Effect.Fade($("map"), {
					afterFinish : function(effect) {
						$("ToolTip").fade();
						effect.element.hide();
					}
				});
		}
		this.show(this.next(), "rotate");		
	
		Event.stop(e);
	},

	rotate : function() {
		if (arguments[0] == "stop") {
			if (this.peInit)
				this.peInit.stop();
			if (this.pe)
				this.pe.stop();
			return;
		}

		var fn = function(){
			if (this.getItem(this.next()).text.hasClassName("startTeaser") || ! this.getItem(this.next()).image) {
				if (!$("map").visible()) {
					new Effect.Appear($("map"), {
						beforeStart : function(effect) {
							effect.element.setOpacity(0.0);
							effect.element.show();
							new Effect.Opacity('ToolTip',{ from: 0.0, to: 0.4,duration: 2});
						}
					});
					
				}
				if ($("backLink") && $("backLink").visible()) $("backLink").fade();
			 
				$("mappoints").setStyle( {
					zIndex :30
				});
			} else {
				if ($("backLink") && !$("backLink").visible()) $("backLink").appear();
					
				$("mappoints").setStyle( {
					zIndex :40
				});
				if ($("map").visible())
					new Effect.Fade($("map"), {
						afterFinish : function(effect) {
							$("ToolTip").fade();
							effect.element.hide();
						}
					});
			}
			this.show(this.next(), "rotate");		
		}.bind(this);

		this.peInit = new PeriodicalExecuter( function(pe) {
			fn();
			pe.stop();
			this.peInit = null;
		}.bind(this), 5);


		this.pe = new PeriodicalExecuter( function(pe) {
			fn();
		}.bind(this), 13);	
	},
    _mapItemIdToKey : function(id) {
		ret = 0;
		this.items.each( function(item,index) {   
			if (id == item.name) ret =  index;
		});
		return ret;
	},
	show : function(key) {
		if (key == this.shown) {
			return;
		}

		temp = this.shown + "_teaser";
		this.items.each( function(item) {
			if (key == item.name) {
				this.shown = key;

				if (this.showEffect) this.showEffect.cancel();
				this.showEffect = new Effect.Appear(item.text, {
					beforeStart : function(effect) {
						effect.element.setOpacity(0.5);
						effect.element.show();
						effect.element.setStyle( {
							zIndex :20
						});
					},
					afterFinish : function(effect) {
						effect.element.show();
						this.showEffect = null;
					},
					from :0.5,
					to :1.0,
					duration :2.0
				});
				
				if (this.showImageEffect) this.showImageEffect.cancel();
				if (item.image)
					this.showImageEffect = new Effect.Appear(item.image, {
						beforeStart : function(effect) {
							$("mappoints").setStyle( {
								zIndex :40
							});
							effect.element.setOpacity(0.0);
							effect.element.show();
							effect.element.setStyle( {
								zIndex :20
							});
						},
						afterFinish : function(effect) {
							effect.element.show();
							this.showImageEffect = null;
						},
						from :0.0,
						to :1.0,
						duration :2.0
					});
			}
		}.bind(this));
		this.hide(temp);
	},

	hide : function() {
		key = arguments[0];
		effect = arguments[1];
		this.items.each( function(item) {
			if (!key || key == item.text.readAttribute("id")) {
				if (!key && this.shown == item.name) {
					return;
				}
				if (effect == "noEffect") {
					item.text.hide();
				} else {
					new Effect.Appear(item.text, {
						beforeStart : function(effect) {
							effect.element.setStyle( {
								zIndex :10
							});
						},
						afterFinish : function(effect) {
							effect.element.hide();
						},
						from :1.0,
						to :0.0,
						duration :2.0
					});
					if (item.image && item.image.visible()) {
						new Effect.Appear(item.image, {
							from :1.0,
							to :0.0,
							duration :2.0
						});
					}
				}
			}

		}.bind(this));
	}
}

var MapEffect = {};
MapEffect = Class.create();
MapEffect.prototype = {
	initialize : function() {
		this.options = Object.extend( {
			itemTeaser :"#teaser .teaser",
			itemMpAnim :"#map .item span",
			itemMp :"#map .item",
			none :true
		}, arguments[0] || {});

		new Effect.Opacity('ToolTip',{ from: 0.0, to: 0.4,duration: 2});

		this.showEvent = this.show.bindAsEventListener(this);
		this.hideEvent = this.hide.bindAsEventListener(this);
		this.clickEvent = this.click.bindAsEventListener(this);
		this.stopPEEvent = this.stopPE.bindAsEventListener(this);
		$$("#map .item .location").each( function(item) {

			if (!item.up().hasClassName('edit')) {
				Event.observe(item, "mouseover", this.showEvent);
				Event.observe(item, "mouseout", this.hideEvent);
				Event.observe(item, "click", this.clickEvent);
			} else {
				this.showEdit(item);
			}
		}.bind(this));

		this.backEvent = this.back.bindAsEventListener(this);
		$$("#backLink a, .refBackLink a").each( function(item) {
			Event.observe(item, "click", this.backEvent);
		}.bind(this));
		

		$$(".teaser .link a").each( function(item) {
			Event.observe(item, "click", this.stopPEEvent);
		}.bind(this));

		this.teaser = new Teaser();
		this.teaser.rotate();
		this.hideInitial();
	},

	stopPE : function(e) {
		this.teaser.rotate("stop");
	},

	show : function(e) {
		if(! $(Event.element(e).up().select("span")[0])) return;
		Event.element(e).up().select("span")[0].show();
		Event.element(e).up().select("span img")[0].setOpacity(0.0);
		new Effect.Appear(Event.element(e).up().select("span img")[0], {
			duration :6.0,
			from :0.0,
			to :0.5,
			transition :Effect.Transitions.pulse
		});
		this.mpPe = new PeriodicalExecuter( function(pe) {
			new Effect.Appear(Event.element(e).up().select("span img")[0], {
				duration :6.0,
				from :0.0,
				to :0.5,
				transition :Effect.Transitions.pulse
			});
		}.bind(this), 6);
		 
	},

	showEdit : function(el) {
		el.up().select("span img")[0].setOpacity(0.0);
		curElement = el;
		new PeriodicalExecuter( function(peEdit) {
			curElement.up().select("span")[0].show();
			new Effect.Appear(curElement.up().select("span img")[0], {
				duration :1.7,
				from :0.0,
				to :0.5,
				transition :Effect.Transitions.pulse
			});
		}, 2);
		curElement.setStyle( {
			cursor :'move'
		});
	 
	},

	makeEditPoint : function(el) {
		if($(el)){
		el.addClassName('edit');
		img = el.select('img:not(.h-inner)');
		this.showEdit(img[0]);
		dragInstance = new Draggable(el, {
			onStart : function(el) {
				dragInstance.options.revert = true;
			}
		});
		}
		$$("#map .item .location").each( function(item) {
			item.stopObserving('click', this.clickEvent);
		});
		mapEffect.teaser.rotate("stop");

	},

	back : function(e) {
		this.teaser.rotate("stop");

		this.teaser.show("mp0");
		$("backLink").fade();
		new Effect.Appear($("map"), {
			beforeStart : function(effect) {
				effect.element.setOpacity(0.0);
				effect.element.show();
			}
		});
		new Effect.Opacity('ToolTip',{ from: 0.0, to: 0.4,duration: 2});
		$("mappoints").setStyle( {
			zIndex :30 
		});
		 
		if($$('.refBackLink')[0]) {
			$$(content.options.detailView).each(function (item) {
				item.remove();
				
			});
			$("startContent").appear();
		} 
	
	},

	click : function(e) {
		this.teaser.show(Event.element(e).up().readAttribute("id"));
		this.teaser.rotate("stop"); 
		if ($("map").visible() && this.teaser.items[this.teaser._mapItemIdToKey(Event.element(e).up().readAttribute("id"))].image) {
			new Effect.Fade($("map"), {
				afterFinish : function(effect) {
					effect.element.hide();
				}
			});
			$("backLink").appear();
		} else {
			$("backLink").fade();
			if (!$("map").visible())new Effect.Appear($("map"), {
				beforeStart : function(effect) {
					effect.element.setOpacity(0.0);
					effect.element.show();
				}
			});
			$("mappoints").setStyle( {
				zIndex :30
			});
		}
		
	},

	hide : function(e) {
		if(! $(Event.element(e).up().select("span")[0])) return;
		Event.element(e).up().select("span")[0].hide();
		Event.element(e).up().select("span img")[0].setOpacity(0.0);
		if (this.mpPe)
			this.mpPe.stop();
	},

	hideInitial : function() {
		this.teaser.hide(false, "noEffect");

		$("backLink").hide();
		$$(this.options.itemMpAnim).each(Element.hide);
	},

	none : function() {
	}
};

var Content = {}
Content = Class.create();
Content.prototype = {
	initialize : function() {
		this.options = Object.extend( {
			refBackLink :".refBackLink a",
			detailView :".detailView",
			startContent :"startContent",
			none :true
		}, arguments[0] || {});

		this.setup();
	},

	show : function() {
	},

	setup : function() {
		if (typeof Shadowbox == "object"){
			Shadowbox.setup();
			Shadowbox.setup('a.pictureDetails', {});
			Shadowbox.setup('a[rel=shadowbox]', {});
		}

		this.clickBackLinkEvent = this.clickBackLink.bindAsEventListener(this);
		$$(this.options.refBackLink).each( function(item) {
			Event.observe(item, "click", this.clickBackLinkEvent);
		}.bind(this));
	},

	clickBackLink : function(e) {
		eItem = Event.element(e);
		eItem.up(this.options.detailView).remove();
		$("startContent").show();
		if(mapEffect) mapEffect.back();
		Event.stop(e);
	},

	none : function(item) {
	}
}

var LocationsWidget = {};
LocationsWidget = Class.create();
LocationsWidget.prototype = {
	initialize : function() {
		this.options = Object.extend( {
			itemContainer :"locations_detail",
			item :"#locations_detail_marginale .item",
			itemMpAnim :"#locations_map .item span",
			itemMp :"#locations_map .item",
			destination: "threeInner",
			none :true
		}, arguments[0] || {});

		new Effect.Opacity('locations_ToolTip',{ from: 0.0, to: 0.4,duration: 2});

		var test = $(this.options.itemContainer).innerHTML;
		$(this.options.itemContainer).update("");
		if($(this.options.destination)){
			$(this.options.destination).insert(
				new Element("div", { "id": this.options.itemContainer+"_marginale"}).update(test)
			);
		}
		$$(this.options.item).each( Element.hide );
		if($$(this.options.item) && $$(this.options.item)[0])
			$$(this.options.item)[0].appear();

		this.showEvent = this.show.bindAsEventListener(this);
		this.hideEvent = this.hide.bindAsEventListener(this);
		this.clickEvent = this.click.bindAsEventListener(this);
		$$("#locations_map .item .location").each( function(item) {
			Event.observe(item, "mouseover", this.showEvent);
			Event.observe(item, "mouseout", this.hideEvent);
			Event.observe(item, "click", this.clickEvent);
		}.bind(this));
	},

	show : function(e) {
		if(! $(Event.element(e).up().select("span")[0])) return;
		Event.element(e).up().select("span")[0].show();
		Event.element(e).up().select("span img")[0].setOpacity(0.0);
		new Effect.Appear(Event.element(e).up().select("span img")[0], {
			duration :6.0,
			from :0.0,
			to :0.5,
			transition :Effect.Transitions.pulse
		});
		this.mpPe = new PeriodicalExecuter( function(pe) {
			new Effect.Appear(Event.element(e).up().select("span img")[0], {
				duration :6.0,
				from :0.0,
				to :0.5,
				transition :Effect.Transitions.pulse
			});
		}.bind(this), 6);
		 
	},

	click : function(e) {
		$$(this.options.item).each( Element.hide );
		var ref = Event.element(e).up().readAttribute("id");
		if($("detail_"+ref)) $("detail_"+ref).appear();
	},

	hide : function(e) {
		if(! $(Event.element(e).up().select("span")[0])) return;
		Event.element(e).up().select("span")[0].hide();
		Event.element(e).up().select("span img")[0].setOpacity(0.0);
		if (this.mpPe)
			this.mpPe.stop();
	}
};

var Accordion = {}
Accordion = Class.create();
Accordion.prototype = {
	initialize: function(id){
		this.container = $(id);

		this.options = Object.extend({
			trigger: "h2.trigger"
		}, arguments[1] || {});

		this.container.select(this.options.trigger).first().addClassName("first");
		this.container.select("div.Accordion").first().addClassName("first");
		this.container.select(this.options.trigger).last().addClassName("last");
		this.container.select("div.Accordion").last().addClassName("last");


		this.container.select(this.options.trigger).each(function(item){
			item.next().hide();
		}.bind(this));

		this.observe();
	},

	observe: function(){
		this.clickEvent = this.click.bindAsEventListener(this);

		this.container.select(this.options.trigger).each(function(item){
			Event.observe(item, "click", this.clickEvent);
		}.bind(this));
	},

	click: function(e){
		var eItem = Event.element(e);
		this.container.select(this.options.trigger).each(function(item){
			if(item.next().visible() && item.next().readAttribute("id") != eItem.next().readAttribute("id") ){
				item.removeClassName("on");
				new Effect.toggle(item.next(), "blind", { duration: 0.5 });
			}
		}.bind(this));

		new Effect.toggle(eItem.next(), "blind", {
			afterFinish: function(effect){
				if(effect.element.previous().hasClassName("on")){
					effect.element.previous().removeClassName("on");
				}else{
					effect.element.previous().addClassName("on");
				}
			},
			duration: 0.5
		});
		Event.stop(e);
	}
};

var Tab = {}
Tab = Class.create();
Tab.prototype = {
	initialize: function(id){
		this.container = $(id);

		this.options = Object.extend({
			trigger: "h2.trigger"
		}, arguments[1] || {});

		this.ePanel = new Element("ul", { "class": "listDefaultTab" });

		this.container.select(this.options.trigger).each(function(item, i){
			if(i == 0){
				item.next().show();
			}else{
				item.next().hide();
			}

			this.ePanel.insert(
				new Element("li").insert(
					new Element("a", { "href": "#", "rel": "tab", "rev": this.container.readAttribute("id")+"_"+(i+1) }).update(item.innerHTML)
				)
			);

			item.remove();
		}.bind(this));

		this.ePanel.select("a").first().addClassName("on");
		this.ePanel.insert(new Element("div", { "class": "clearer" }));
		this.container.insert({ top: this.ePanel })

		this.observe();
	},

	observe: function(){
		this.clickEvent = this.click.bindAsEventListener(this);

		this.ePanel.select("a").each(function(item){
			Event.observe(item, "click", this.clickEvent);
		}.bind(this));
	},

	click: function(e){
		var eItem = Event.element(e);

		this.ePanel.select("a").each(function(item){
			item.up("li").removeClassName("on");
			item.removeClassName("on");
		}.bind(this));
		this.container.select("div.Tab").each(function(item){
			item.hide();
		}.bind(this));

		eItem.up("li").addClassName("on");
		eItem.addClassName("on");
		$(eItem.readAttribute("rev")).show();

		Event.stop(e);
	}
};
