//
// lightSCMS - Galeriedarstellung für das SCMS
//
// partiell abgeguckt von lightwindow.js - http://www.stickmanlabs.com


// Das ganze benötigt scriptaculous

if (typeof Effect == "undefined")
	throw("scriptaculuous' effects library not loaded");
	
// This will stop image flickering in IE6 when elements with images are moved
try {
	document.execCommand("BackgroundImageCache", false, true);
} catch(e) {}
Object.extend(Prototype.Browser, {
    IE6:     Prototype.Browser.IE && (typeof window.XMLHttpRequest == "undefined")
});



Object.extend(Array.prototype,{
	contains:function(item){
		for(var i=0; i<this.length;++i){
			if(this[i] == item) return true;
		}
		return false;
	}
});
Object.extend(String.prototype,{
	stripPX: function(){
		if(this.indexOf('px') == -1) return this;
		return parseInt(this.substr(0,this.indexOf("px")).replace("/\ /g",""));
	},
	getSchema: function(){
		var s;
		s = this.startsWith($$('base')[0].getAttribute('href')) ? this.replace($$('base')[0].getAttribute('href'),'') : this;
		if(s.startsWith('http://')){
			return s.split('/')[3]._checkSchema();
		}
		if(s.startsWith('/upl/')){
			return s.split('/')[2]._checkSchema();
		}
		if(s.startsWith('upl/')){
			return s.split('/')[1]._checkSchema();
		}
		if(s.startsWith('/')){
			return s.split('/')[1]._checkSchema();
		}
		return s.split('/')[0]._checkSchema();
	},
	toSrc: function(){
		var t =  this;
		if (t.indexOf('?') > -1)
			t = t.substr(0,t.indexOf('?'));
		if (t.indexOf('#') > -1)
			t = t.substr(0,t.indexOf('#'));
		return t.replace('a','a');
	},
	_checkSchema: function(){
		if(['dinschede','bruderschaft','ssg','gloesingen','oeventrop'].contains(this.toLowerCase())){
			return this;
		}
		else return false;
	}
});


// Klasse LightSCMS
var LightSCMS = Class.create({
	check:'check',
// Optionen
	
	options:{
		diashow:{
			showImgScaled:true,
			additionalYOffset:60
		},
		gallery:{
			showImgScaled:true
		},
		newwin:{
			additionalYPadding:100,
			additionalXPadding:100,
			additionalXOffset:50,
			additionalYOffset:50
		},
		// Padding und Border des Anzeige-Containers
		border:13,
		defaults:{
			width:.333,
			height:.666,
			modus:'gallery'
		},
		// Breite und Höhe des Anzeige-Containers zu Beginn 
		loader_src:'http://schuetzen-oeventrop.de/templates/green/gr/icons/loading.gif',
		iconpath:'http://schuetzen-oeventrop.de/templates/green/gr/icons/',
		populate:true,
		opacity:1
	},
// HTML-Konstrukte

	layout:{
		darkener:'<div id="LightSCMS_darkener" class="LightSCMSInitial"></div><div id="LightSCMS_Info" class="LightSCMSInitial"></div>',
		loader :'<div id="LightSCMS_loading" class="LightSCMSInitial"><img src="{substitue_loader_src}"><span>Ladevorgang...</span></div>',
		main:	'<div id="LightSCMS_main" class="LightSCMSInitial">'+
			'	<div id="LightSCMS_titlebar">'+
			'		<span id="LightSCMS_close_internal">× schließen</span>'+
			'		<span id="LightSCMS_title"></span>'+
			'	</div>'+
			'<div id="LightSCMS_wrap">'+
			'		<div id="LightSCMS_content"></div>'+
			'		<div id="LightSCMS_overlaynav_prev"></div>'+
			'		<div id="LightSCMS_overlaynav_next"></div>'+			
			'	</div>'+
			'	<div id="LightSCMS_footer">'+
			'		<div id="LightSCMS_footer_wrap">'+
			'			<div id="LightSCMS_footer_naviwrap">'+
			//'				<img src="{substitute_iconpath}zurueck3.png" width="16" height="16" />'+			
			//'				<img src="{substitute_iconpath}uebersicht.png" width="16" height="16" />'+
			//'				<img src="{substitute_iconpath}speichern.png" width="16" height="16" />'+
			//'				<img src="{substitute_iconpath}link.png" width="16" height="16" />'+
			//'				<img src="{substitute_iconpath}grossansicht.png" width="16" height="16" />'+
			//'				<img src="{substitute_iconpath}hilfe.png" width="16" height="16" />'+
			//'				<img src="{substitute_iconpath}vor3.png" width="16" height="16" />'+
			'				<div id="LightSCMS_footer_prev"></div>'+
			'				<div id="LightSCMS_footer_next"></div>'+
			'			</div>'+
			'			<div id="LightSCMS_caption"></div>'+
			'			<div id="LightSCMS_footer_counter"></div>'+
			'		</div>'+
			'	</div>'+
			'</div>'+
			'<div id="LightSCMS_preload_wrap"></div>',
		gallery:'',
		diashow:'<div id="LightSCMS_diashow_nav" class="LightSCMSDiashowNavigation LightSCMSInitial">'+
			'	<span id="LightSCMS_diashow_prev" class="LightSCMS_diashownav_item"><img src="{substitute_iconpath}dia-zurueck.png" width="69" height="28"/></span>'+
			'	<span id="LightSCMS_diashow_stop" class="LightSCMS_diashownav_item"><img src="{substitute_iconpath}dia-stopp.png" width="48" height="28"/></span>'+
			'	<span id="LightSCMS_diashow_speed_minus" class="LightSCMS_diashownav_item"><img src="{substitute_iconpath}dia-minus.png" width="29" height="28"/></span>'+
			'	<span id="LightSCMS_diashow_speed_anzeige" class="LightSCMS_diashownav_item">{substitute_diashowtime} Sekunden</span>'+
			' 	<span id="LightSCMS_diashow_speed_plus" class="LightSCMS_diashownav_item"><img src="{substitute_iconpath}dia-plus.png" width="29" height="28"/></span>'+
			'	<span id="LightSCMS_diashow_play" class="LightSCMS_diashownav_item"><img src="{substitute_iconpath}dia-start.png" width="47" height="28"/></span>'+
			'	<span id="LightSCMS_diashow_next" class="LightSCMS_diashownav_item"><img src="{substitute_iconpath}dia-vor.png" width="69" height="28"/></span>'+
			'</div>',
		newwin:	'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'+
			'<html xmlns="http://www.w3.org/1999/xhtml">'+
			'<head>'+
			'<title>{substitute_title}</title>'+
			'<script type="text/javascript">'+
			'var zaehler = {substitute_curr};'+
			'var sources = new Array();'+
			'{substitute_sources}'+
			'function vor(){'+
			'if(zaehler < sources.length-1) ++zaehler;upd();'+
			'}'+
			'function zurueck(){'+
			'if(zaehler > 0) --zaehler;upd();'+
			'}'+
			'function anfang(){'+
			'zaehler =0;upd();'+
			'}'+
			'function ende(){'+
			'zaehler =sources.length-1;upd();'+
			'}'+
			'function upd(){'+
			'document.anzeige.src=sources[zaehler];document.forms[0].count.value="Bild "+(zaehler+1)+" von "+sources.length;'+
			'}'+			
			'</script>'+
			'</head>'+
			'<body align="center" style="background-color:#999;padding:0px;">'+
			'<div align="center"><form style="background-color:#fff;padding:.2em;border:thin solid #336600">'+
			'<input type="button" style="margin-right:5px" onClick="anfang()" value="&lt;&lt; Anfang" />'+
			'<input type="button" style="margin-right:5px" onClick="zurueck()" value="&lt; Bild" />'+
			'<input type="button" style="margin-right:5px" onClick="vor()" value="Bild &gt;" />'+
			'<input type="button" style="margin-right:5px" onClick="ende()" value="Ende &gt;&gt;" />'+
			'<input type="text" style="font-size:80%;border:none;text-align:center" name="count" value="Bild {substitute_count} von {substitute_max}" />'+
			'<input type="button" style="margin-left:5px" onClick="self.close()" value="Schlie&szlig;en" />'+
			'</form></div>'+
			'<div align="center"><img style="border:thin solid white" name="anzeige" src="{substitute_curr_src}" /></div>'+
			'</body>'+
			'</html>'
	},
	
// Interna
	effects: [],
	effectParams:[],
	items: [],
	active: false,
	animating:false,
	modus: null,
	current: null,
	startItem: null,
	diatimer: null,
	diashowRunning: false,
	diashowTime: 5,
	parent: false,
	dimensions:{
		avail:{
			main:{W:null,H:null},
			content:{W:null,H:null}
		},
		target:{
			main:{W:null,H:null},
			content:{W:null,H:null}
		},
		curr:{
			main:{W:null,H:null},
			content:{W:null,H:null}
		},
		X:null,Y:null
	},
// Funktionen

// Konstruktor
//
// Fügt das Standard-HTML-Konstrukt ein
// Erstellt wenn gewünscht die einzelnen Links

	initialize: function(){
		this.insertDefaultHTML();
		this.populateHTML();
	},
	
/************************************************************
/*
/* steuernde Funktionen
/*
/************************************************************/
	
	// start(Klick-Event, [id des Elements mit den Infos, Modus]):
	//	Startet LightSCMS
	//	wird auf Klick auf einen Link aufgerufen.
	
	start: function(event){

		event.stop();
		var id = arguments[1] || Event.element(event).identify();
		this.modus = arguments[2] || this.options.defaults.modus;
		var e = $(id);
		if(e.hasClassName('LightSCMSgallery')){
			if(Event.element(event).hasClassName('LightSCMSdiashowStarter')){
				this.modus = 'diashow';
			}
			if(Event.element(event).hasClassName('LightSCMSnewwinStarter')){
				this.modus = 'newwin';
			}
			this.__addItems(e.select('a'));		
			this.title = e.getAttribute('title');
			if(e.select('a[rev=top]').length > 0){
				this.parent=e.select('a[rev=top]')[0].href;
			}
		} else {
			// Es wurde auf einen einzelnen Link geklickt.
			
			// e kann nun auch ein <img> o.ä. sein...
			while(e.tagName.toUpperCase() != 'A') e=e.parentNode;
			if(e.getAttribute('rel')=='LightSCMS'){
				// Als einzelnes Item...
				this.__addItems([e]);
				
			} else {
				// Mehrere...
				var it = $$('a[rel="'+e.getAttribute('rel')+'"]');
				this.__addItems(it);
				var i=0;
				while(it[i] != e) ++i;
				this.startItem = i;
			}
		}
		this.showInitial();
		
		return false;
	},
	
	// function next
	//	Zeigt das nächste Item an
	next: function(){
		if(this.animating) return;
		this.showContent(
			this.current + 1 < this.items.length ? this.current+1 : 0
		);
	},
	// function prev
	//	Zeigt das vorherige Item an
	prev: function(){
		if(this.animating) return;
		this.showContent(
			this.current > 0 ? this.current-1 : this.items.length-1
		);
	},
	// close
	//	schließt das ganze...
	close: function(){
		// Effekte stoppen
		Effect.Queues.get('LightSCMS_Anim').each(function(e){e.cancel();});
		// Alle Event-Handler aufräumen...
		$$('*[id*="LightSCMS"]').each(function(e){e.stopObserving();});

		// diashow stoppen
		this.diashowRunning = false;
		window.clearTimeout(this.diatimer);
		// items löschen
		this.items = [];
		this.current = null;
		this.modus = null;
		this.title = null;
		this.parent=false;
		// Inhalte entfernen
		$('LightSCMS_content').select('*').each(function(e){e.remove();});
		$('LightSCMS_preload_wrap').select('*').each(function(e){e.remove();});

		this.effects=[];
		this.effectParams=[];
		this.animating=false;
		this.startItem = null;
		this.dimensions={
			avail:{
				main:{W:null,H:null},
				content:{W:null,H:null}
			},
			target:{
				main:{W:null,H:null},
				content:{W:null,H:null}
			},
			curr:{
				main:{W:null,H:null},
				content:{W:null,H:null}
			},
			X:null,Y:null
		};
		if($('LightSCMS_diashow_nav')) $('LightSCMS_diashow_nav').remove();
		$('LightSCMS_main').hide();		
		$('LightSCMS_darkener').hide()
		$('LightSCMS_footer_counter').update().show();
		$('LightSCMS_caption').update().show();
		
		// Seltsamerweise fehlen nach dem Ansehen einer Diashow die Event-Listener auf den eingefügten Links
		// Also nochmal setzen
		// TODO: Warum ist das so?
	
		// Sicherheitshalber erstmal alle stoppen
		$$('a[rel^="LightSCMS"]','a.LightSCMSnewwinStarter','a.LightSCMSdiashowStarter').each(function(e){e.stopObserving();});
		
		// Und neue einfügen
		$$('a[rel^="LightSCMS"]').each(this.__insertLinkObserver.bind(this));
		
		$$('.LightSCMSnewwinStarter','.LightSCMSdiashowStarter').each(function(e){
			e.observe('click',this.start.bindAsEventListener(this,e.parentNode.nextSibling.identify()));
		}.bind(this));
		
	},
/************************************************************
/*
/* Anzeigefunktionen
/*
/************************************************************/
	
	// showInitial()
	//	Blendet modusabhängig die ersten, ggf. leeren Elemente ein
	
	showInitial: function (){
		if(this.modus=='diashow')
			this.showInfo('In vielen Browsern kann mit der Taste <strong>F11</strong> in einen Vollbildmodus gewechselt werden.',2000);
		this.calcInitialPos();
		var cont;
		switch (this.modus){
			case 'newwin':
				this.newwinref = window.open('','LightSCMS_gallery_win',
					'resizable=yes,scrollbars=yes'+
					',top='+this.dimensions.Y+
					',left='+this.dimensions.X+
					',innerWidth='+this.dimensions.target.main.W+
					',innerHeight='+this.dimensions.target.main.H
				);
				this.newwinref.document.open();
				this.newwinref.document.write(
					this.layout.newwin.replace('{substitute_title}',this.title)
						.replace('{substitute_count}',this.startItem+1)
						.replace('{substitute_curr}',this.startItem!==null ? this.startItem : 0)
						.replace('{substitute_max}',this.items.length)
						.replace('{substitute_curr_src}',this.items[this.startItem!==null ? this.startItem:0].params.src)
						.replace('{substitute_sources}',function(){
							var s = '';
							for(var i=0;i<this.items.length;++i){
								s+='sources['+i+']="'+this.items[i].params.src+'";'+"\n";
							}
							return s;
						}.bind(this))
				
				);
				this.newwinref.document.close();
				this.newwinref.focus();
				// Besser aufräumen...
				this.close();
			break;
			case 'diashow':
				this.insertDiashowNav();
				
			case 'gallery':
				$('LightSCMS_darkener').show();
				$('LightSCMS_content').setStyle({
					width:this.dimensions.target.content.W+'px',
					height:this.dimensions.target.content.H+'px'
				});
				$('LightSCMS_main').setStyle({
					left:this.dimensions.X+'px',	
					top:this.dimensions.Y+'px',
					width:this.dimensions.target.main.W+'px',
					height:this.dimensions.target.main.H+'px',
					display:'block'
				});
				if (this.title){
					$('LightSCMS_title').update(this.title);
					$('LightSCMS_title').show();
				}
				this.__updateCurrDim();
				$('LightSCMS_close_internal').observe('click',
					this.close.bindAsEventListener(this)
				);
				if(this.startItem!==null)
					this.showContent(this.startItem);
				else this.showContent(0);
				break;

			break;
		}
		if (this.modus=='diashow'){
			this.diashowRunning = true;
			this.__registerDiashowEvents();
			window.setTimeout(this.__startDiaShowTimer.bind(this),10000);
		}
	},
	
	// showContent(idx)
	// 	Zeigt den über idx referenzierten Inhalt an
	
	showContent: function(idx){
		if (idx !== null)
			this.items[idx].load();
		if(this.current !== null){
			// alten Inhalt ausblenden
			$('LightSCMS_footer_naviwrap').hide();
			$('LightSCMS_caption').hide();
			$('LightSCMS_overlaynav_prev').hide();
			$('LightSCMS_overlaynav_next').hide();
			this.__registerEffect(function(){
				new Effect.BlindUp('LightSCMS_footer_wrap',{
					duration:.75,
					queue:{scope:'LightSCMS_Anim',position:'end'}
				});
			});
			this.playEffects();
			this.__registerEffect(
				this.items[this.current].getDisappearEffect() || function(){
					$(this.items[this.current].params.id).hide();
					this.items[this.current].remove();		
				}.bind(this)
			);
		}

		this.__registerEffect($('LightSCMS_loading').show.bind($('LightSCMS_loading')));
		this.playEffects();
		this.__showItemIfLoaded(idx);
		this.current=idx;
		if(this.current < this.items.length-1)
			this.items[idx+1].load();
		else 
			this.items[0].load();
		
	},
	unscale: function(){
		$('LightSCMS_content').setStyle({
			width:this.items[this.current].params.width+'px',
			height:this.items[this.current].params.height+'px'
		});
		$('LightSCMS_main').setStyle({
			width:(2*this.options.border+this.items[this.current].params.width)+'px',
			height:(2*this.options.border+this.items[this.current].params.height)+'px',
			left:((this.dimensions.X-(Math.round(this.items[this.current].params.width-this.dimensions.curr.main.W)/2)) > 0 ? 
					(this.dimensions.X-(Math.round(this.items[this.current].params.width-this.dimensions.curr.main.W)/2)) : 0)+'px' 
		});
		this.items[this.current].scaleTo(this.items[this.current].params);
	},
	// updateFooter
	//	Passt den Footer an
	updateFooter: function() {
		$('LightSCMS_footer_wrap').hide();
		if(this.items.length > 1)
			$('LightSCMS_footer_counter').update('Bild '+(this.current+1)+' von '+this.items.length).show();
		else {
			$('LightSCMS_footer_counter').hide().update();
		}
		if(this.items[this.current].params.caption){
			$('LightSCMS_caption').update(this.items[this.current].params.caption).show();
		} else {
			$('LightSCMS_caption').hide().update();
		}
		$('LightSCMS_footer_naviwrap').hide();
		$('LightSCMS_footer_naviwrap').select('*').each(function(e){
			e.stopObserving();
			e.remove();
		});
		if(!this.diashowRunning && this.items.length > 1){
			var prev = new Element('img',{title:'vorheriges Bild',style:'cursor:pointer',src:this.options.iconpath+'zurueck3.png',width:16,height:16});
			$('LightSCMS_footer_naviwrap').insert(prev);
			prev.observe('click',this.prev.bindAsEventListener(this));
		}
		if(this.items[this.current].getParent() || this.parent ){
			var parent = new Element('img',{style:'border:none',src:this.options.iconpath+'uebersicht.png',width:16,height:16});
			
		}
		if(this.items[this.current].getParent()){
			$('LightSCMS_footer_naviwrap').insert(new Element('a',{href:this.items[this.current].getParent(),title:'Zur Übersicht'}).insert(parent));
		} else if(this.parent){
			$('LightSCMS_footer_naviwrap').insert(new Element('a',{href:this.parent,title:'Zur Übersicht'}).insert(parent));
			
		}
		if(this.items[this.current].getDownloadSrc()){
			var download = new Element('img',{src:this.options.iconpath+'speichern.png',width:16,height:16,style:'border:none;'});
			$('LightSCMS_footer_naviwrap').insert(new Element('a',{href:this.items[this.current].getDownloadSrc(),title:'[Rechtsklick:] Speichern unter...'}).insert(download));
		}
		if(this.items[this.current].getLink()){
			var link = new Element('img',{src:this.options.iconpath+'link.png',width:16,height:16,style:'border:none;'});
			$('LightSCMS_footer_naviwrap').insert(new Element('a',{href:this.items[this.current].getLink(),title:'direkter Link zum Bild'}).insert(link));
		}
		if(this.items[this.current].isScaled() && !this.diashowRunning){
			var full = new Element('img',{src:this.options.iconpath+'grossansicht.png',width:16,height:16,title:'Bild in Originalgröße darstellen',style:'cursor:pointer'});
			$('LightSCMS_footer_naviwrap').insert(full);
			full.observe('click',this.unscale.bindAsEventListener(this) );
		}
		if(!this.diashowRunning && this.items.length > 1){
			var next = new Element('img',{title:'nächstes Bild',style:'cursor:pointer',src:this.options.iconpath+'vor3.png',width:16,height:16});
			$('LightSCMS_footer_naviwrap').insert(next);
			next.observe('click',this.next.bindAsEventListener(this));
		}
		new Effect.BlindDown('LightSCMS_footer_wrap',{
			duration:.5,
			afterFinish:$('LightSCMS_footer_naviwrap').show.bind($('LightSCMS_footer_naviwrap'))
			
		});
		if(!this.diashowRunning && this.items.length > 1){
			if($('LightSCMS_overlaynav_prev').select('a') > 0) $('LightSCMS_overlaynav_prev').show();
			else {
				var prevlink = new Element('a');
				$('LightSCMS_overlaynav_prev').insert(prevlink);
				prevlink.observe('click',this.prev.bindAsEventListener(this));
			}
			if($('LightSCMS_overlaynav_next').select('a') > 0) $('LightSCMS_overlaynav_next').show();
			else {
				var nextlink = new Element('a');
				$('LightSCMS_overlaynav_next').insert(nextlink);
				nextlink.observe('click',this.next.bindAsEventListener(this));
			}
			//$('LightSCMS_overlaynav_next').show();
		}
		//this.playEffects();
	},
	
	playEffects: function(){
		if(this.effects.length == 0) return false;

		if (this.animating === true){
			// Wenn noch eine Ani mation im gange ist, warte ab...
			window.setTimeout(this.playEffects.bind(this),50);
		} else {

			this.animating=true;

			var eff = [], funcs = [];

			while(this.effects.length > 0){

				if(Object.isFunction(this.effects[0])){
					if (eff.length == 0){
				
						// Wenn noch keine Effekte gespeichert sind werden die Funktionen sofort ausgeführt
						if(Object.isUndefined(this.effectParams[0])){
							this.effects.shift()();
							this.effectParams.shift();
						} else {
							this.effects.shift()(this.effectParams.shift());
						}
					} else {
						if(Object.isUndefined(this.effectParams[0])){
							funcs.push({f:this.effects.shift(),p:null});
							this.effectParams.shift();
						} else {
							funcs.push({f:this.effects.shift(),p:this.effectParams.shift()});
						}
					}
				} else {
					// Die alten Funktionen einfügen
					
					if (eff.length > 0 && funcs.length > 0){
						eff[eff.length-1].p.afterFinish = function(effect){
							for(var i=0; i<arguments[0].length; ++i){
								with (arguments[0][i]){
									if(p)	f(p);
									else	f();
								}
							}
						}.bind(this,funcs.clone());
						funcs.clear();
					}

					eff.push(this.effects.shift());
					eff[(eff.length-1)].p.queue={scope:'LightSCMS_Anim',position:'end'};
				}
			}

			if(funcs.length > 0 && eff.length > 0){
				eff[eff.length-1].p.afterFinish = function(effect){
					for(var i=0; i<arguments[0].length; ++i){
						with (arguments[0][i]){
							if(p)	f(p);
							else	f();
						}
					}
					this.animating=false;
				}.bind(this,funcs.clone());
			} else if(eff.length > 0) {
				eff[eff.length-1].p.afterFinish = function(effect){
					this.animating=false;
				}.bind(this);
			} else {
				this.animating = false;
			}

			// Die Effekte abspielen...
			for (var i = 0; i<eff.length; ++i){
				with(eff[i]) {new e(id,p);}
			}
		}
	},
	showInfo : function(info,t){
		
		$('LightSCMS_Info').update(info).setOpacity(.7).show();
		this.infoFadeTimer=window.setTimeout(this.__infoFade.bind(this,.65),t);
		//$('LightSCMS_Info').hide();
	},
	__infoFade: function(){
		var opacity = arguments[0];
		//alert(opacity);
		if(opacity > 0.2){
			$('LightSCMS_Info').setOpacity(opacity);
			this.infoFadeTimer = window.setTimeout(this.__infoFade.bind(this,opacity-.05),200);
		} else {
			$('LightSCMS_Info').hide();
		}
	},
	slower : function(){
		if(this.diashowTime < 99){
			this.diashowTime++;
			this.updateTimeControl();
		}
	},
	faster : function(){
		if(this.diashowTime > 3){
			this.diashowTime--;
			this.updateTimeControl();
		}
	},
/************************************************************
/*
/* Funktionen für Berechnungen
/*
/************************************************************/
	
	// calcInitialPos
	// 	Berechnet die Position des ersten, leeren Anzeigefensters
	
	calcInitialPos: function(){
		this.calcTargetDimens(null);
	},
	
	// calcTargetDimens(item-idx)
	// 	Berechnet die Dimensionen und Positionen des items, das über
	//	item-idx referenziert wird. Wenn null wird die Standardbreite/-höhe benutzt
	// TODO: Wirkliche Berechnung...
	
	calcTargetDimens: function(idx){
		this.calcAvailDimens(idx);
		if(idx === null){
			if(this.modus=='newwin'){
				function getMax(list){
					var w=-1,h=-1;
					for(var i=0;i<list.length;++i){
						if(list[i].params.width && list[i].params.width > w) w=list[i].params.width;
						if(list[i].params.height && list[i].params.height > h) h=list[i].params.height;
					}
					return {W:-(-w-(self.outerWidth-Math.min(document.documentElement.clientWidth,document.body.clientWidth))),
						H:-(-h-(self.outerHeight-Math.min(document.documentElement.clientHeight,document.body.clientHeight)))
					};
				}//.bind(this);
				this.dimensions.target.main.W = Math.min(getMax(this.items).W,this.dimensions.avail.main.W);
				this.dimensions.target.main.H = Math.min(getMax(this.items).H,this.dimensions.avail.main.H);
			} else {
				this.dimensions.target.main.W = Math.round(this.options.defaults.width * this.dimensions.avail.main.W);
				this.dimensions.target.main.H = Math.round(this.options.defaults.height * this.dimensions.avail.main.H);
				this.dimensions.target.content.W = this.dimensions.target.main.W - this.calcInfoElementDimens(idx).W;
				this.dimensions.target.content.H = this.dimensions.target.main.H - this.calcInfoElementDimens(idx).H;
			}

		} else {

			var w = this.items[idx].params.width, h = this.items[idx].params.height;

			var r = Math.min(1,Math.min(this.dimensions.avail.content.W/w,this.dimensions.avail.content.H/h));
			
			this.dimensions.target.content.W = Math.round(r*w);
			this.dimensions.target.content.H = Math.round(r*h);
			
			this.dimensions.target.main.H = this.dimensions.target.content.H + this.calcInfoElementDimens(idx).H;
			this.dimensions.target.main.W = this.dimensions.target.content.W + this.calcInfoElementDimens(idx).W;
			//alert(this.dimensions.target.main.W +' ' +this.dimensions.target.main.H );
		}
		var tmp = (this.modus == 'newwin') ? {left:0,top:0} : document.viewport.getScrollOffsets();
		this.dimensions.X = tmp.left -(-1* Math.round((this.dimensions.avail.main.W-this.dimensions.target.main.W)/2));
		this.dimensions.Y = tmp.top - (-1*Math.round((this.dimensions.avail.main.H-this.dimensions.target.main.H)/2));
		return !isNaN(this.dimensions.X) && !isNaN(this.dimensions.Y) && !isNaN(this.dimensions.target.main.W) && !isNaN(this.dimensions.target.main.H) && !isNaN(this.dimensions.target.content.W) && !isNaN(this.dimensions.target.main.H);
	},
	
	// calcAvailDimens(item)
	//	Berechnet die verfügbaren Dimensionen
	// 	Als Parameter bekommt es den Index des anzuzeigenden Items
	
	calcAvailDimens: function(item){
		if(this.modus=='newwin'){
			this.dimensions.avail.main.W=screen.availWidth;
			this.dimensions.avail.main.H=screen.availHeight;
		} else {
			this.dimensions.avail.main.W=document.viewport.getDimensions().width;
			this.dimensions.avail.main.H=document.viewport.getDimensions().height;
		}
		// optionale Abstände berücksichtigen
		if(this.options[this.modus] && this.options[this.modus].additionalXOffset)
			this.dimensions.avail.main.W-=this.options[this.modus].additionalXOffset;
		if(this.options[this.modus] && this.options[this.modus].additionalYOffset)	
			this.dimensions.avail.main.H-=this.options[this.modus].additionalYOffset;
			
		// height bezieht die Rahmen und Padding mit ein.
		// Für den Inhalt verfügbar ist also entsprechend weniger
		this.dimensions.avail.content.W = this.dimensions.avail.main.W; 
		this.dimensions.avail.content.H = this.dimensions.avail.main.H;
		
		if(this.modus!='newwin'){
			this.dimensions.avail.content.W -= this.calcInfoElementDimens(item).W;
			this.dimensions.avail.content.H -= this.calcInfoElementDimens(item).H;
		}
	},
	
	// calcInfoElementDimens
	//	Berechnet die Höhe/Breite der Info-HTML-Elemente (Titel etc.)
	// 	Bekommt als optionalen Parameter den Index des Items
	// 	Ohne Parameter liefert die Funktione die "Sollhöhen"
	// TODO: Wirkliche Berechnung 
	calcInfoElementDimens: function(){
		var item = arguments[0] || null, w=2*this.options.border,h=20+24+2*this.options.border;
//		if(this.items.length > 1) h+=11;
		
		
		if (item === null){
			return {H:h,W:w} 
		} else {
			if(this.items[item].params.caption){
			 	h += 16; 
			}
			return {H:h,W:w} 
		}
	},
	
/************************************************************
/*
/* HTML-verändernde Funktionen
/*
/************************************************************/

	// insertDefaultHTML:
	//	Fügt das Standard-HTML-Konstrukt ein

	insertDefaultHTML: function(){
		var b = $$('body')[0];
		b.innerHTML += this.layout.main.replace(/{substitute_iconpath}/g,this.options.iconpath)+this.layout.darkener;
		$('LightSCMS_main').hide();
		$('LightSCMS_darkener').hide();
		$('LightSCMS_darkener').setOpacity(this.options.opacity);
		$('LightSCMS_wrap').innerHTML=this.layout.loader.replace('{substitue_loader_src}',this.options.loader_src)
			+$('LightSCMS_wrap').innerHTML;
		$('LightSCMS_loading').hide();
		$('LightSCMS_footer_wrap').hide();
		$('LightSCMS_Info').hide();
		
	},
	
	// insertDiashowNav:
	//	Fügt die Navigation für die Diasow ein
	// TODO : EventListener etc...
	
	insertDiashowNav: function(){
		$$('body')[0].innerHTML += this.layout.diashow.replace(/{substitute_iconpath}/g,this.options.iconpath).replace('{substitute_diashowtime}',this.diashowTime);
	},
	// populateHTML:
	//	Setzt die Links zum Anzeigen der Galerie als Diashow etc...
	populateHTML: function(){
		// Zuerst die divs mit Klasse "LightSCMSgallery"
		$$('.LightSCMSgallery').each(this.__insertGalleryLinks.bind(this));
		if (!Prototype.Browser.IE6 && !Prototype.Browser.Opera) $$('a[rel^="LightSCMS"]').each(this.__insertLinkObserver.bind(this));
		if($('bildAnzeige') && !Prototype.Browser.IE6){
			if($('bildAnzeige').getAttribute('title')){
				var title = new Element('div',{id:'bildAnzeigeOverlaytitle'}).update("<a onClick=\"$('bildAnzeigeOverlaytitle').hide();\" style=\"float:right;cursor:pointer;font-weight:normal\" title=\"Bildbeschreibung ausblenden\">[×]</a>"+$('bildAnzeige').getAttribute('title'));
				$('bildAnzeige').getOffsetParent().insert({bottom:title});
				title.setStyle({
					position:'absolute',
					top:($('bildAnzeige').positionedOffset().top+13+20)+'px',
					width:($('bildAnzeige').offsetWidth-40-26)+'px',
					height:'auto',
					left:($('bildAnzeige').positionedOffset().left+13)+'px',
					padding:'10px 20px',
					opacity:.75,
					fontWeight:'bold',
					background:'#fff',
					fontSize:'14px',
					lineHeight:'14px',
					zIndex:100
				});
			}
			if($('picprevlink')){
				var l = new Element('a',{href:$('picprevlink').href,'class':'LightSCMSsimpleNav',id:'LightSCMSsimpleNavPrev'});
				if($('bildAnzeige').getOffsetParent().tagName.toUpperCase() == 'HTML')
					$$('body')[0].insert({bottom:l});			
				else
					$('bildAnzeige').getOffsetParent().insert({bottom:l});
				l.setStyle({
					height:$('bildAnzeige').offsetHeight+'px',
					width:Math.round($('bildAnzeige').offsetWidth/2)+'px',
					top:($('bildAnzeige').positionedOffset().top+13)+'px',
					left:$('bildAnzeige').positionedOffset().left+'px'
				});
			}
			if($('picpostlink')){
				var l = new Element('a',{href:$('picpostlink').href,'class':'LightSCMSsimpleNav',id:'LightSCMSsimpleNavNext'});
				if($('bildAnzeige').getOffsetParent().tagName.toUpperCase() == 'HTML')
					$$('body')[0].insert({bottom:l});			
				else
					$('bildAnzeige').getOffsetParent().insert({bottom:l});
				l.setStyle({
					height:$('bildAnzeige').offsetHeight+'px',
					width:Math.round($('bildAnzeige').offsetWidth/2)+'px',
					top:($('bildAnzeige').positionedOffset().top+13)+'px',
					left:(Math.round($('bildAnzeige').offsetWidth/2)+$('bildAnzeige').positionedOffset().left)+'px'
				});
			}
			if($$('.LightSCMSstarterWrap').length == 1){
				var l = new Element('a',{href:$('bildAnzeige').src.toSrc(),'class':'LightSCMSLinkToDownload'}).update('Speichern');
				$$('.LightSCMSstarterWrap')[0].insert({bottom:l});
			}
		}
	},
	updateTimeControl: function(){
		$('LightSCMS_diashow_speed_anzeige').update(this.diashowTime+' Sekunden');
		if(this.diashowTime == 99){
			$('LightSCMS_diashow_speed_plus').firstChild.src=this.options.iconpath+'dia-plus-off.png'
		} else {
			$('LightSCMS_diashow_speed_plus').firstChild.src=this.options.iconpath+'dia-plus.png'
		}
		if(this.diashowTime == 3){
			$('LightSCMS_diashow_speed_minus').firstChild.src=this.options.iconpath+'dia-minus-off.png'
		} else {
			$('LightSCMS_diashow_speed_minus').firstChild.src=this.options.iconpath+'dia-minus.png'
		}
	},
	
/************************************************************
/*
/* interne Funktionen
/*
/************************************************************/

	// __addItems(Array Item-Liste)
	//	Fügt die Items aus der Liste hinzu.
	
	__addItems: function(items){
		for(var i=0; i< items.length; ++i){
			switch (this.__detectType(items[i].href)){
				case 'JPG':
				case 'JPEG':
				case 'PNG':
				case 'GIF':
					this.items.push(new LightSCMS.Item.IMG(items[i]));

				break;
				case 'PDF':
					this.items.push(new LightSCMS.Item.PDF(items[i]));

				break;
			}
			if(items[i].getAttribute('rev') && items[i].getAttribute('rev')=='start'){
				this.startItem=this.items.length-1;
				
			}
		}
	},
	// __registerDiashowEvents()
	//	Setzt die Events für die Diashow etc. pp.
	
	__registerDiashowEvents: function(){
		$('LightSCMS_diashow_speed_minus').stopObserving();
		$('LightSCMS_diashow_speed_plus').stopObserving();
		$('LightSCMS_diashow_speed_minus').observe('click',this.faster.bindAsEventListener(this));
		$('LightSCMS_diashow_speed_plus').observe('click',this.slower.bindAsEventListener(this));
		if(this.diashowRunning){
			$('LightSCMS_diashow_prev').firstChild.src=this.options.iconpath+'dia-zurueck-off.png';
			$('LightSCMS_diashow_prev').stopObserving();
			$('LightSCMS_diashow_next').firstChild.src=this.options.iconpath+'dia-vor-off.png';
			$('LightSCMS_diashow_next').stopObserving();
			$('LightSCMS_diashow_play').firstChild.src=this.options.iconpath+'dia-start-off.png';
			$('LightSCMS_diashow_play').stopObserving();
			$('LightSCMS_diashow_stop').firstChild.src=this.options.iconpath+'dia-stopp.png';
			$('LightSCMS_diashow_stop').observe('click',function(e){
				this.diashowRunning = false;
				window.clearTimeout(this.diatimer);
				this.showInfo("Stopp", 500);
				this.__registerDiashowEvents();
			}.bindAsEventListener(this));
			$('LightSCMS_overlaynav_next').select('a').each(function(e){e.remove();});
			$('LightSCMS_overlaynav_prev').select('a').each(function(e){e.remove();});
		} else {
			$('LightSCMS_diashow_prev').firstChild.src=this.options.iconpath+'dia-zurueck.png';
			$('LightSCMS_diashow_prev').observe('click',function(e){
				this.showInfo('Zurück',100);
				this.prev();
			}.bindAsEventListener(this));
			$('LightSCMS_diashow_next').firstChild.src=this.options.iconpath+'dia-vor.png';
			$('LightSCMS_diashow_next').observe('click',function(e){
				this.showInfo('Vor', 100);
				this.next();
			}.bindAsEventListener(this));
			$('LightSCMS_diashow_play').firstChild.src=this.options.iconpath+'dia-start.png';
			$('LightSCMS_diashow_play').observe('click',function(e){
				this.diashowRunning=true;
				this.showInfo("Abspielen", 500);
				this.next();
				this.__startDiaShowTimer.bind(this);
				this.__registerDiashowEvents();
			}.bindAsEventListener(this));
			$('LightSCMS_diashow_stop').firstChild.src=this.options.iconpath+'dia-stopp-off.png';
			$('LightSCMS_diashow_stop').stopObserving();
			var next = new Element('a');
			next.observe('click',function(e){this.next();}.bindAsEventListener(this));
			var prev = new Element('a');
			prev.observe('click',function(e){this.prev();}.bindAsEventListener(this));
			$('LightSCMS_overlaynav_next').insert(next);
			$('LightSCMS_overlaynav_prev').insert(prev);
		}
	},
	// function __insertGalleryLinks
	//	Fügt die Start-Links für ganze Galerien ein	
	
	__insertGalleryLinks : function(e){
		var l,m,n;
		if(e.hasClassName('LightSCMSnewwinLink')){
			m = new Element('a',{'class':'LightSCMSnewwinStarter'});
			m.update(
				e.hasClassName('LightSCMSusetitle') && e.getAttribute('title') ?
					'Galerie »' + e.getAttribute('title') + '« in eigenem Fenster öffnen' : 
					'Fenster'
			);
			m.observe('click',this.start.bindAsEventListener(this,e.identify()));
		}
		if(e.hasClassName('LightSCMSdiashowLink')){
			n = new Element('a',{'class':'LightSCMSdiashowStarter'});
			n.update(
				e.hasClassName('LightSCMSusetitle') && e.getAttribute('title') ?
					'Galerie »' + e.getAttribute('title') + '« als Diashow ansehen' : 
					'Diashow'
			);
			n.observe('click',this.start.bindAsEventListener(this,e.identify()));
		}	
		l = new Element((e.tagName.toUpperCase() == 'DIV') ? 'div' : 'span',{'class':'LightSCMSstarterWrap'});
		if(m) l.insert(m);
		if(n && !Prototype.Browser.IE6 && !Prototype.Browser.Opera) l.insert(n);
		if(!l.empty()){
			l.insert({
				top: '<h4>Anzeigeoptionen:</h4>'
			});
			e.insert({before:l});
			if($('galerienavigation'))$('galerienavigation').scrollTo();
		}
	},
	
	// function __insertLinkObserver
	//	Überwacht die mit entsprechendem "rel" ausgestatteten Links
	
	__insertLinkObserver: function(e){
		e.observe('click',this.start.bindAsEventListener(this));
	},
	// function __startDiaShowTimer
	//	startet den DiaShow-Timer, :-)
	
	__startDiaShowTimer: function(){
		if(!this.diashowRunning) return;
		if(this.animating!==true){
			this.next();
			window.clearTimeout(this.diatimer);
			this.diatimer = window.setTimeout(function(){this.__startDiaShowTimer()}.bind(this),this.diashowTime*1000+3000);
		} else {
			this.diatimer = window.setTimeout(function(){this.__startDiaShowTimer()}.bind(this),50);
		}
	},	
	// __registerEffect(effect/function-call[,function-Parameter-Objekt])
	//	Fügt einen Effect bzw. Funktionsaufruf in die Effekt-Kette
	//	effect ist ein Objekt mit den drei Parametern
	//		e: Effect-Klasse, bspw. Effect.Fade
	//		id:Element-Id oder Objekt,
	//		p: Parameter-Objekt
	// 
	__registerEffect: function(effect){
		this.effects.push(effect);
		if(Object.isFunction(effect))
			this.effectParams.push(arguments[1]);
	},
	// __updateCurrDim
	//	Kopiert die target-Dimensionen in current
	// TODO: Ob das überhaupt gebraucht wird...
	__updateCurrDim: function(){
		with(this.dimensions){
			curr.main.W = target.main.W;
			curr.main.H = target.main.H;
			curr.content.W = target.content.W;
			curr.content.H = target.content.H;
		}
	},	
	// __detectType(href-String)
	//	Liefert die Dateieindung in Großbuchstaben zurück
	__detectType: function(href){
		if (href.indexOf('?') > -1)
			href = href.substr(0,href.indexOf('?'));
		if (href.indexOf('#') > -1)
			href = href.substr(0,href.indexOf('#'));
		return href.substr(href.lastIndexOf('.')+1).toUpperCase();
	},
	
	//__showItemIfLoaded(idx)
	//	Wartet, bis items[idx] geladen ist und zeigt dann den Inhalt
	
	__showItemIfLoaded: function(idx){

		if(this.items[idx].loaded==1){
			this.calcTargetDimens(idx);
			with(this.dimensions){
				
				if((target.main.W-curr.main.W) != 0 || (target.main.H-curr.main.H) != 0 ||
				   (target.content.W-curr.content.W) != 0 ||  (target.content.H-curr.content.H) != 0){
					
					this.__registerEffect({
						e: Effect.Parallel,
						id: [
							new Effect.Morph('LightSCMS_main',
								{style:'height:'+this.dimensions.target.main.H+'px;top:'+this.dimensions.Y+'px;'}),
							new Effect.Morph('LightSCMS_content',
								{style:'height:'+this.dimensions.target.content.H+'px'})
						],
						p:{}
					});
					this.playEffects();

					this.__registerEffect({
						e: Effect.Parallel,
						id: [
							new Effect.Morph('LightSCMS_main',
								{style:'width:'+this.dimensions.target.main.W+'px;left:'+this.dimensions.X+'px;'}),
							new Effect.Morph('LightSCMS_content',
								{style:'width:'+this.dimensions.target.content.W+'px'})
						],
						p:{}
					});
					this.playEffects();
				 }
			}
			// Aus dem Preloader holen...
			
			this.__registerEffect(function(){	
  				if(isNaN(this.dimensions.target.content.W) || this.dimensions.target.content.H){
					var tmp = 0;
					while(!this.calcTargetDimens(idx) && tmp < 10000){tmp++};
				}
				this.items[idx].scaleTo({
					width:this.dimensions.target.content.W,
					height:this.dimensions.target.content.H
				});
				if(Object.isFunction(this.items[idx].insert)){
					this.items[idx].insert();
				} else {
					$('LightSCMS_content').insert({top:$(this.items[idx].params.id)});
				}
				$('LightSCMS_loading').hide();
			}.bind(this));
			if(!Object.isFunction(this.items[idx].insert))
					this.__registerEffect($(this.items[idx].params.id).show.bind($(this.items[idx].params.id)));
			this.__registerEffect(this.items[idx].getAppearEffect() || {
				e: Effect.Opacity,
				id:this.items[idx].params.id,
				p:{from:.5,to:1}
			});
			

			this.__registerEffect(this.updateFooter.bind(this));
			
			
			if(!this.diashowRunning){
				this.__registerEffect(function (){
					if($('LightSCMS_overlaynav_prev')) $('LightSCMS_overlaynav_prev').show();
					if($('LightSCMS_overlaynav_next')) $('LightSCMS_overlaynav_next').show();
				}
			);
			}
			this.__registerEffect(function(){
				if($('LightSCMS_footer_naviwrap'))
						$('LightSCMS_footer_naviwrap').show();
				});
			this.playEffects();
			this.__updateCurrDim();
		} else {
			window.setTimeout(this.__showItemIfLoaded.bind(this,idx),1);
		}
	}
});

/**
/*
/* Klassendefinitionen für die einzelnen Medientypen
/*
/**/

// Pseudoklasse Item

LightSCMS.Item = Class.create({
	params: {
		src:null,
		width:null,
		height:null,
		caption:null,
		id:null
	},
	element:null,
	loaded:0,
	getAppearEffect: function(){return false;},
	getDisappearEffect: function(){return false;},
	remove: function(){return false;},
	lookForCaption:function(){
		var block;
		if(block = this.isInBlock()){
			if(block.select('.caption').length > 0){

				this.params.caption = block.select('.caption')[0].innerHTML.stripTags();
			}
		}
	},
	isInBlock:function(){
		return this.element.up('.block');
	},
	getParent: function(){return false;},
	getDownloadSrc: function(){return false;},
	getLink: function(){return false;},
	isScaled: function(){return false;}
});

// Klasse IMG für Bilder

LightSCMS.Item.IMG = Class.create(LightSCMS.Item,{
	initialize: function(e){
		this.element=e;
		this.params = e.href.toQueryParams();	
		this.params.src = e.href.toSrc();
		if(e.getAttribute('title')){
			this.params.caption=e.getAttribute('title');
		} else {
			this.lookForCaption();	
		}
	},
	load: function(){
		var img = new Element('img',{src:this.params.src});
		this.params.id=img.identify();
		img.observe('error',function(){
			window.clearInterval(this.loader);//.stop();
			alert(this.params.src+'Bild kann nicht geladen werden');
			this.params.src='http://www.oddcomments.com/lib/msc/404-quitYou.jpg';
			$(this.params.id).src='http://www.oddcomments.com/lib/msc/404-quitYou.jpg';
			
			this.loaded=1;
		}.bindAsEventListener(this));
		
		$('LightSCMS_preload_wrap').insert({bottom:img});
		img.setOpacity(0);
		this.loader = window.setInterval(function(){
			img = arguments[0];
			if(img.complete){//typeof img.naturalWidth != 'undefined' && img.naturalWidth > 0 && img.naturalHeight > 0){
				if(typeof img.naturalWidth != 'undefined' && img.naturalWidth > 0 && img.naturalHeight > 0){
					this.params.width=img.naturalWidth;
					this.params.height=img.naturalHeight;
				} else if(img.currentStyle){
					this.params.width=img.currentStyle.width.stripPX();
					this.params.height=img.currentStyle.height.stripPX();
				}
				if(!isNaN(this.params.width) && !isNaN(this.params.height)){
 					this.loaded=1;	
					window.clearInterval(this.loader);
				}
				//img.setOpacity(0);
			//	alert(this.params.src+' '+img.naturalHeight);
			} else {
				
			}
		}.bind(this,img),50);
	},
	scaleTo: function(to){
		$(this.params.id).setStyle({width:to.width+'px',height:to.height+'px'});
	},
	remove: function(){
		return $(this.params.id).remove();
	},
	getDownloadSrc: function(){return this.params.src},
	getLink: function(){
		if (!Object.isString(this.params.pid)) return false;
		return $$('base')[0].getAttribute('href')+'/'+(this.params.src.getSchema())+'/bilder/pic/_'+this.params.pid;
	},
	getParent: function(){
		if (!Object.isString(this.params.gid)) return false;
		return $$('base')[0].getAttribute('href')+'/'+(this.params.src.getSchema())+'/bilder/gal/_'+this.params.gid;
	},
	isScaled: function(){
		if ($(this.params.id).offsetWidth != this.params.width || $(this.params.id).offsetHeight != this.params.height)
				return true;
		return false;
	}
		
});
LightSCMS.Item.PDF = Class.create(LightSCMS.Item,{
	
	initialize: function(e){
	
		
		this.element = e;
		this.params = e.href.toQueryParams();
		//this.loaded = 1;
		this.params.width=Math.round(document.viewport.getDimensions().width * .8);
		this.params.height=Math.round(document.viewport.getDimensions().height * .8);
		this.params.src =e.href.toSrc();
		//alert('al0 '+this.params.src);
	},
	load: function(){
		
		if(this.loaded==1) return;
		this.loaded=1;
		this.wrapper = new Element('div',{style:'padding:0 5%'});
		this.params.id=this.wrapper.identify();
	},
	scaleTo:function(to){
		
		this.wrapper.setStyle({width:to.width+'px',height:to.height+'px'});
	},
	insert:function(){
		var iframe= new Element('iframe',{src:'about:blank',width:'90%',height:'90%',name:'LightSCMSiframe',id:'LightSCMSiframe',frameborder:0});
		
		//iframe.document.open();
		//iframe.document.write('<html><head></head><body onload="alert(\"foo\");"></body></html>');
		
		//if (this.params.id!=null)
		//	wrapper.id = this.params.id;
		//else 
		this.wrapper.select('*').each(function(e){e.remove();});
		//alert('al1 '+this.params.id+'|'+this.params.src);
		this.wrapper.insert(new Element('div',{style:'height:10%;background:#ff9;margin-left:-5%;width:100%'}).update('Die inline-Anzeige ist abhängig von einem Browser-Plugin. Statt des Inhalts der pdf-Datei wird möglicherweise eine Download-Bestätigung angezeigt. Öffnen Sie das pdf-Dokument dann mit Ihrem pdf-Betrachter.'));
		this.wrapper.insert(iframe);
		$('LightSCMS_content').insert({top:this.wrapper});
		//$('LightSCMS_preload_wrap').insert(wrapper);
		//alert(iframe+' '+iframe.contentWindow+' '+iframe.contentDocument);
		var src=this.params.src;
		var id = window.setTimeout(function(){
			iframe.contentWindow.document.open();
			iframe.contentWindow.document.write('<html><head></head><body onLoad=\'var tmp = self.setTimeout(function(){self.location.href="'+src+'";},5)\'>Sollte das pdf nicht innerhalb der nächsten Sekunden automatisch öffnen, <a href="'+src+'">laden Sie es hier herunter</a></body></html>');
			iframe.contentWindow.document.close();
		},5); 
		//iframe

		iframe.setStyle({zIndex:200});
		
	},
	getAppearEffect:function(){
		this.wrapper.show();
		window.setTimeout(function(){lscms.updateFooter()},1500);
		return function(){};
	},
	remove:function(){
		this.loaded = 0;
		return $(this.params.id).remove();
	},
	getDownloadSrc:function() {
		return this.params.src;
	}
});
document.observe("dom:loaded", function() {
	lscms = new LightSCMS();
});




