//
// pagescriptor.js v1.5.4 05.11.2010 by Gerd Franke franke@sitescriptor.de
// Library for dynamic effects showing, hiding, moving content
// depends on prototype.js V1.63 and scriptaculous V1.8.3
//
// ToDos
// 		Alle: AJAX einführen
//
// PROBLEME:
// 		Effects mit Queue sequenziell ausfuehren
//		Slider-in-Slider: Next/Prev nicht im Viewport suchen!
//
// DONE:
// 		Slider: vor- zurueck Buttons
//		Slider: pruefen ob viewport schon absolute
//		Slider: suche nach Links im ganzen container
//		Slider: aktiven Link mit Klassse markieren
// 
//------------------------------------------------------------------------------------------

//--- toggle content -------------------------
/*
<div class="ps-toggle">
	<div>Preview</div>
	<div>
		Content
		<a href="#" class="ps-close">X</a>
	</div>
</div>
*/
		
	var PStoggle = Class.create({
			// internal variables, donīt change!
			groupHash: 0,
			// functions
			initialize: function( el ) 
				{
				this.groupHash = new Hash()
				this.groupHash.set( 'test', true );
				$$('div.ps-toggle').each( function(el)
					{ 
			//		alert('Toggle el:' + el );
					var newt = new PStog( el );	
					if( newt.tGroupName )
						{
						var g = newt.tGroupName;
			//			alert('Toggle g:' + g );
						if( !this.groupHash.get( g ))
							{
			//				alert('Toggle neuer Hasheintrag' );
							this.groupHash.set( g, [] );
			//				var queue = new
							}
						var gh = this.groupHash.get( g );
			//			gh.push( el );
						gh.push( newt );
			//			alert('PStoggle gh:' + gh.inspect() );
						}
					}, this );
		//		alert('PStoggle groupHash:' + this.groupHash.inspect() );
				},
			open: function( gr, tobj ) 
				{
		//		alert( 'Toggle open Group:"' + gr + '"; \nElement:"' + tobj + '";');
		//		alert('Toggle open  groupHash:' + this.groupHash.inspect() );
				if( this.groupHash.get( gr ) )
					{
					var garr = this.groupHash.get( gr );
			//		alert('Toggle open  garr:' + garr.inspect() );
					garr.each( function(te)
						{ 
			//			alert('Toggle te.status:' + te.status );
						if( te.status )
							{
							te._hide();
							}
						});
					}
				},
 			});
			
	var PStog = Class.create({
			// user defineable
			closeSelector: 	'a.ps-close',
			centerClass: 	'ps_center',
			zoomClass: 		'ps_zoom',
			downClass: 		'ps_down',
			blendClass: 	'ps_blend',
			// internal variables, donīt change!
			unit: 			'px',
			tGroupName: 	'',
			status: 		0,
			containerEl: 	0,
			preview: 		0,
			contentEL: 		0,
			// functions
			initialize: function( el ) 
				{
				var classarr = $w(el.className);
				var regex = RegExp(/^ps-group-(.*)$/);
				classarr.each( function(cl)
						{
			//			alert('Toggle search:' + cl );
						if( !this.tGroupName )
							{  
							var val = regex.exec(cl);
							if( val != null && val[1] )
								{
								this.tGroupName = val[1];
			//					alert( 'Toggle Groupname found:"' + cl + '"; tGroupName:"' + this.tGroupName + '";');
								//return;
								}						
							}
						else 
							{ 
			//				alert('Toggle Groupname set!'); 
							}
						}, this );
			//	alert( 'Toggle Groupname is:"' + this.tGroupName + '";');
								
 				this.containerEl = el;
				this.containerEl.setStyle( 'position:relative;' );				
				var parts 		= this.containerEl.childElements();
				this.preview 	= parts[0];
				this.contentEL 	= parts[1];
	//			this.contentEL.setStyle( 'z-index:10000;border-color:blue;' );

				this.ltoggle = this.ltoggle.bind( this );
				this.preview.observe( 'click',  this.ltoggle );

	//			alert( 'PStoggle.ltoggle(before):' + this.ltoggle );
				$(this.contentEL).select( this.closeSelector ).each(  
						function(elem)
							{
	//						alert( 'PStoggle.initialize(close:link)' + this.ltoggle );
							elem.observe( 'click',  this.ltoggle );
							}, this );
				this.contentEL.hide();
				
				},
			ltoggle: function( ev )
				{
				if( this.status == 0 )
					{		// show contentEL
					this._show();
					}
				else
					{		// remove contentEL
					this._hide();
					}
				Event.stop( ev );
				},
				
			_show: function ()
				{
				if( this.tGroupName ){ Toggler.open( this.tGroupName, this ); }
				this._screencenter();
				if( this.containerEl.hasClassName( this.zoomClass ) )
					{
					//alert('ltoggle: ' + this.zoomClass );
					Effect.Grow( this.contentEL, { direction: 'center' } );
					}
				else if( this.containerEl.hasClassName( this.downClass ) )
					{
		//			alert('ltoggle: ' + this.downClass );
					Effect.BlindDown( this.contentEL );
					}
				else if( this.containerEl.hasClassName( this.blendClass ) )
					{
		//			alert('ltoggle: open ' + this.blendClass );
					//this.contentEL.Opacity({ duration: 0.5, from: 0, to: 1 });
		//			this.contentEL.show();
					Effect.toggle( this.contentEL, 'appear',{ duration: 0.5, queue: 'end' } );
//					new Effect.Opacity( this.contentEL, { duration: 0.5, from: 0, to: 1, beforeStart: function(el){ Element.show(el);} } );
//					new Effect.Opacity( this.contentEL, { duration: 0.5, from: 0, to: 1, queue: 'end' } );
					}
				else if( this.containerEl.hasClassName( this.centerClass ) )
					{
					this.contentEL.appear({ duration: 0.5, from: 0, to: 1 });
					}
				else
					{
				//	alert('_show: default' );
					Effect.BlindDown( this.contentEL, { duration: 0.4 } );
					}
//				this.contentEL.show();
				this.status = 1;
				},
				
			_hide: function ()
				{
	//			alert( 'PStoggle.ltoggle(off)' );
				if( this.containerEl.hasClassName( this.zoomClass ) )
					{
					Effect.Shrink( this.contentEL, { direction: 'center' } );
					}
				else if( this.containerEl.hasClassName( this.downClass ) )
					{
					Effect.BlindUp( this.contentEL );
					}
				else if( this.containerEl.hasClassName( this.blendClass ) )
					{
	//				alert('ltoggle: close ' + this.blendClass );
//					new Effect.Opacity( this.contentEL, { duration: 0.5, from: 1, to: 0, afterFinish: function(el){ Element.hide(el);} } );
					Effect.toggle( this.contentEL, 'appear',{ duration: 0.5, queue: 'end' } );
					//this.contentEL.hide();
					}
				else if( this.containerEl.hasClassName( this.centerClass ) )
					{
					this.contentEL.fade({ duration: 0.5, from: 1, to: 0 });
					}
				else
					{   
				//	alert('_hide: default' );
					Effect.BlindUp( this.contentEL, { duration: 0.4 } );
					}
				this.status = 0;
				},
				
			_screencenter: function ()
				{
				if( !this.containerEl.hasClassName( this.centerClass ) ){ return; }
 				var cposition = this.containerEl.viewportOffset();			
// 				alert( 'screencenter:cposition.inspect \n' + cposition.inspect() );
				var deltaleft = ( document.viewport.getWidth() - this.contentEL.getWidth() )/2 - cposition[0];
				var deltatop = ( document.viewport.getHeight() - this.contentEL.getHeight() )/2 - cposition[1];
				//alert( 'screencenter:delta.left/top \n' + deltaleft + ' / ' + deltatop );
				this.contentEL.setStyle( 'position:absolute;top:' + deltatop + 'px;left:' + deltaleft + 'px;' );
				//new Effect.Move( this.contentEL, { x: deltaleft, y: deltatop, mode: 'relative' });
				},
			});
			
//--- ReplaceContent -------------------------
/*
<a class="ps-multi" href="#multi1" rel="viewport_id">first</a>
<a class="ps-multi" href="#multi2" rel="viewport_id">second</a>
<div id="viewport_id">
	<div id="multi1" class="ps_default">
		default content1
	</div>
	<div id="multi2">
		content2
		<a class="ps-multi" href="#multi1" rel="viewport_id">zeige content1</a>
	</div>
</div>
*/
//--------------------------------

	var PSmulti = Class.create({
			// Element classes (user defineable)
			linkSelector: 'a.ps-multi[rel="',
			// Status classes (user defineable)
			defaultClass: 'ps_default',
			activeClass: 'ps_active',
			visibleClass: 'ps_visible',
			unit: 'px',
			// internal variables, donīt change!
			defaultSet: 0,
			viewportID: '',
			viewportEl: 0,
			containerEl: 0,
  			queue: 0,
			contentHash: 0,
			contentNodeH: new Hash(),
			contentStatusH: new Hash(),
			// functions
			initialize: function( el ) 
				{
		//		alert('OPmulti.initialize(Hallo onepage 06 )');
				var defaultSet = 0;
  	  			//-----------			
				this.viewportEl = el;
  				this.viewportID = this.viewportEl.readAttribute('id');
				if( this.viewportEl.getStyle('position') != 'absolute' ){ this.viewportEl.relativize(); }
				
  				this.linkSelector = this.linkSelector + this.viewportID + '"]';
		 		//-----------			
				var parts 	= this.viewportEl.childElements();
				this.contentHash = new Hash();
		//		alert('OPmulti.initialize( contentHash:' + this.contentHash + '; childs)');
				parts.each( function(el)
						{
		//				alert('OPmulti.initialize(hashing)');
						if( el.readAttribute('id') )
							{
 							var vpID = el.readAttribute('id');
 		//					alert('OPmulti.initialize.found( vpID: ' + vpID + '; childs)');
							el.setStyle('position:absolute;top:0px;');
							this.contentNodeH.set( vpID, el );
 					//		el.setStyle( 'border-color:green;' ); 
							if( el.hasClassName( this.defaultClass ) && !defaultSet )
								{
								defaultSet = 1;
								this.contentStatusH.set( vpID, 1 );
								el.show();
								}
							else
								{
								this.contentStatusH.set( vpID, 0 );
								el.hide();
								}
							}
						}, this );
 			//	alert('OPmulti.initialize( contentNodeH.inspect: ' + this.contentNodeH.inspect(true) + ' )');
 			//	alert('OPmulti.initialize( contentStatusH.inspect: ' + this.contentStatusH.inspect(true) + ' )');
  		//-----------			
				$$( this.linkSelector ).each( function(al)
						{ 
						//----------
						var contentID = al.readAttribute('href');
						var regex = RegExp(/^#(.*)/);
						var val = regex.exec(contentID);
						contentID = val[1];
			//			alert('OPmulti.initialize.links(found: viewport: ' + this.viewportID + '; content: '+ contentID + ';)');
						//----------
						if( !this.contentNodeH.get( contentID ) )
							{ 
							al.setStyle( 'text-decoration: line-through;' );
			//				alert('OPmulti.initialize.links(failed: tar: ' + contentID + ';)');
							return;
							}
				//		al.setStyle( 'text-decoration:none;color: green;' );
			//			alert('OPmulti.initialize.links(sethandler: _swap)'  ); 
						al.observe( 'click', this._swap.bindAsEventListener( this, contentID ) );
						//----------
						}, this );
  				//-----------			
	 		//	alert('OPmulti.initialize( contentHash.keys: "' + this.contentHash.keys() + '" )');
				if( this.defaultSet ){this._activate( this.viewportEl, this.activeClass );}
				},

			_activate: function( container, clas )
				{
				// alle childs von ps-slider erhalten die Klasse active
		//		alert('PSslider._activate( container: "' + container + '" clas: "' + clas + '" )');
				var parts 	= $(container).childElements();
				parts.each( function( el )
						{
						el.addClassName( clas )
						//alert('PSslider._activate( el: "' + el + '"  class: "' + el.readAttribute('class') + '" )');
						}, this );
				this.defaultSet	= 1;	
				},
				
			_swap: function( ev, showid )
				{
				var closeId;
				var openId;
 		//		alert('OPmulti._swap( starts: ev: "' + ev + '" showid: "' + showid + '" )'); 
		//		alert('OPmulti._swap( contentNodeH.inspect: ' + this.contentNodeH.inspect(true) + ' )');
		//		alert('OPmulti._swap(1 contentStatusH.inspect: ' + this.contentStatusH.inspect(true) + ' )');
				if( !this.defaultSet )
					{
					this._activate( this.viewportEl, this.activeClass );
					this.defaultSet = 1;
					}
				this.contentNodeH.each( function( item )
						{
						if( this.contentStatusH.get( item.key ) )
							{
							closeId = item.key;
							}
						else if( this.contentNodeH.get( showid ) )
							{
							openId = showid;
							}
						else 
							{
							//alert('OPmulti._swap( failed: ev: "' + ev + '" showid: "' + showid + '" )'); 
							}
  						//-----------			
						}, this );
	//			alert('OPmulti._swap( queue: "' + this.viewportID + '"; closeId: "' + closeId + '"; openId: "' + openId + '"; )'); 
				//-----------			
				if( closeId != openId )
					{
					if( closeId )
						{
						//item.value.hide(); 
						$(closeId).fade({ duration: 1.0, from: 1, to: 0 });
						//new Effect.SlideUp( closeId, { queue: 'end' } );							
						this.contentStatusH.set( closeId, 0 );
						$(closeId).removeClassName( this.visibleClass )
						}
					//-----------			
					//item.value.show();
					$(openId).appear({ duration: 2.0, from: 0, to: 1 });
					//new Effect.SlideDown( openId, { queue: 'end' } );
// 							new Effect.SlideUp( closeId, { queue: { position: 'end', scope: this.viewportID } });							
// 							new Effect.SlideDown( openId, { queue: { position: 'end', scope: this.viewportID } });
					$(openId).addClassName( this.visibleClass )
					this.contentStatusH.set( openId, 1 );
					}
	//			alert('OPmulti._swap(2 contentStatusH.inspect: ' + this.contentStatusH.inspect(true) + ' )');
				//-----------			
				Event.stop( ev );
				},
			});

//--------------------------------
//--- dynamic slider -------------------------
/*
<div class="ps-slider">
	<div>
		<div>
			<div id="slider1"  title="Titel 1">content1</div>
			<div id="slider2"  title="Titel 2">content2</div>
		</div>
	</div>
	<ul>
		<li>content 1<a href="#slider1" class="ps-goto">first</a></li>
		<li>content 2<a href="#slider1" class="ps-goto">second</a></li>
	</ul>
</div>
*/
//--------------------------------
	var PSslider = Class.create({
			// Element classes (user defineable)
  			sliderClass: 	'ps-slider',
			viewportClass: 	'ps-viewport',
			naviClass: 		'ps-navi',
			linkClass: 		'ps-goto',
			// Options classes (user defineable)
			prevClass: 		'ps-previous',
			nextClass: 		'ps-next',
			defaultClass: 	'ps_default',
			aroundClass: 	'ps_around',
			// Status classes (user defineable)
			activeClass: 	'ps_active',
			// internal variables, donīt change
  			linkSelector: 	'a.',
			unit: 'px',
			viewportWidth: 0,
			viewportHeight: 0,
			contentVisibleId: 0,
			wrapperWidth: 0,
			defaultSet: 0,
			aroundSet: 0,
			// elements
			containerEl: 0,
				linkH: 0,
				viewportEl: 0,
					nextEl: 0,
					nextElarr: 0,
					previousEl: 0,
					previousElArr: 0,
					wrapperEl: 0,
						contentNodeH: 0,
						contentIdArr: 0,
				naviEl: 0,
			// functions
			initialize: function( el ) 
				{
				this.contentNodeH = new Hash()
 		//		alert('PSslider.initialize( BEGIN contentNodeH.inspect: ' + this.contentNodeH.inspect(true) + ' )');
		//		alert('PSslider.initialize( Hallo onepage 06 )');
  	  			//-----------			
				this.containerEl = el;
 				this.containerEl.setStyle( 'border: 0px;' );
		 		//-----------	find viewport, optional navigation
				// lookup by classes
				var parts 	= this.containerEl.childElements();
				//---- suche viewport-box
				parts.each( function( el )
						{
						if( el.hasClassName( this.viewportClass ) && !this.viewportEl )
							{
							this.viewportEl = el;
							return;
							}
						}, this );
						
				//---- suche optionale navi-box
				parts.each( function( el )
						{
						if( el.hasClassName( this.naviClass ) && this.viewportEl )
							{
							this.naviEl = el;
							return;
							}
						}, this );
				
				//---- oder altes modell: viewport > navi
				if( !this.viewportEl && !this.naviEl )
					{
					var parts 	= this.containerEl.childElements();
					if( parts[0] )
						{
						this.viewportEl = parts[0];
						if( parts[1] )
							{ 
							this.naviEl = parts[1] ; 
			//				alert('PSslider.initialize( navigation found! )');
							}
						}
					else {alert('Fatal Error: no viewport found');return;}
					}
					
				if( this.viewportEl.getStyle('position') != 'absolute' )
					{
		//			alert( this.viewportEl.getStyle('position') );
					this.viewportEl.relativize(); 
					}
				if( this.viewportEl.hasClassName( this.aroundClass ) ){ this.aroundSet = 1; }
				this.viewportWidth = this.viewportEl.getWidth();
				this.viewportHeight = this.viewportEl.getHeight();
				this.viewportEl.setStyle( 'overflow:hidden;' ); 
		//		alert('PSslider.initialize.found( viewportWidth: ' + this.viewportWidth + '; )');
		//		alert('PSslider.initialize.found( viewportHeight: ' + this.viewportHeight + '; )');
				
		 		//-----------	viewport untersuchen	
				parts = this.viewportEl.childElements();
				
		 		//-----------	wrapper im viewport untersuchen	
				if( parts[0] ){ this.wrapperEl = parts[0]; } 
				else {alert('Fatal error: wrapper not found!');return;}
				
		 		//-----------	contents	
				this.defaultSet = 0;
		//		var wsum = 0;
				this.contentIdArr = new Array();
				parts 	= this.wrapperEl.childElements();
				parts.each( function(el)
						{
						var vpID = el.readAttribute('id');
						this.contentIdArr.push( vpID );
		//				alert('PSslider.initialize.found( vpID: ' + vpID + '; childs)');
						this.contentNodeH.set( vpID, el );
						if( el.hasClassName( this.defaultClass ) && !this.defaultSet )
							{
							this.defaultSet = 1;
							this.contentVisibleId = vpID;
							}
						else
							{
							this.contentVisibleId = this.contentVisibleId ? this.contentVisibleId : vpID;
							}
						el.setStyle( 'float:left;margin:0px;padding:0px;width:' 
								+ this.viewportWidth + 'px;height:' + this.viewportHeight + 'px;' ); 
						}, this );
						
				if( !this.contentIdArr.size() ){ alert('Fatal error: wrapper is empty!');return; }
				this.wrapperWidth = this.contentIdArr.size() * this.viewportWidth;
		//		alert('PSslider.initialize.found( wrapperWidth: ' + this.wrapperWidth + '; )');
				
				this.wrapperEl.setStyle( 'position:absolute;left:0px;margin:0px;padding:0px;width:' 
										+ this.wrapperWidth + 'px;border:0px;height:' + this.viewportHeight + 'px;' ); 
						
		//		alert('PSslider.initialize.found( contentVisibleId: ' + this.contentVisibleId + '; defaultSet: ' + OPslider + ';)');
				// Slider 		
 		//		alert('PSslider.initialize( contentNodeH.inspect: ' + this.contentNodeH.inspect(true) + ' )');
  		//		alert('PSslider.initialize( contentIdArr.inspect: ' + this.contentIdArr.inspect(true) + ' )');
				
 		 		//----------- construct navigation
 				if( !this.naviEl )
 					{
 					var navi = '\n<div class="' + this.naviClass + ' auto"><ul>\n';    //20100524
 					var aclass = this.linkClass;
					this.contentNodeH.each( function( item )
							{
							navi += '<li><a href="#';
							navi += item.key;
							navi += '" class="';
							navi += aclass;
							navi += '">';
							navi += item.value.readAttribute('title');
							navi += '</a></li>\n';
 							});
 					navi += '</ul></div><!-- ende auto navi -->\n';
 		//			alert('PSslider.initialize( navigation: ' + navi + ' )');
 		//			alert('PSslider.initialize( viewportEl.inspect: ' + this.viewportEl.inspect(true) + ' )');
 					$(this.viewportEl).insert( {after: navi} );   //20100524
 					this.naviEl = $(this.viewportEl).next();
 		//			alert('PSslider.initialize( Inserted navigation: naviEl.inspect: ' + this.naviEl.inspect(true) + ' )');
					}

 		 		//----------- eventhandler to navigation
				this.linkH = new Hash()
 		 		this.linkSelector += this.linkClass ;
  		// 		alert('PSslider.initialize( linkSelector: ' + this.linkSelector + ' )');
				$(this.containerEl).select( this.linkSelector ).each( function(elt)
 						{ 
 		//				alert('PSslider.initialize( Set eventhandler:' + elt.inspect(true) + '  )');
 						//----------
 						var contentID = elt.readAttribute('href');
 						var regex = RegExp(/^#(.*)/);
 						var val = regex.exec(contentID);
 						contentID = val[1];
 						
						this.linkH.set( contentID, elt );
 						
 						
			//			alert('PSslider.initialize.links(found: viewport: ' + this.viewportID + '; content: '+ contentID + ';)');
 						//----------
 						if( !this.contentNodeH.get( contentID ) )
 							{ 
 							elt.setStyle( 'text-decoration: line-through;' );
 			//				alert('PSslider.initialize.links(failed: tar: ' + contentID + ';)');
 							return;
 							}
 			//			elt.setStyle( 'text-decoration:none;' );		// mod: 20100528 fc2010
 			//			elt.setStyle( 'text-decoration:none;color: green;' );
 			//			alert('PSslider.initialize.links(sethandler: _move)'  ); 
 						elt.observe( 'click', this._move.bindAsEventListener( this, contentID ) );
 						//----------
 						}, this );

 		 		//----------- eventhandler to next-button
				$(this.containerEl).select( 'a.' + this.nextClass ).each( function(elt)
 						{ 
 		//				alert('PSslider.initialize.links(sethandler: _next)'  ); 
  		//			elt.setStyle( 'color:orange;' );
						//----------
 						this.nextEl = elt;
 						elt.observe( 'click', this._next.bindAsEventListener( this ) );
 						//----------
 		//				elt.setStyle( 'color: green;' );
						elt.addClassName( this.activeClass ); 					
 						}, this );

 		 		//----------- eventhandler to previous-button
				this.previousElArr = new Array();
				$(this.containerEl).select( 'a.' + this.prevClass ).each( function(elt)
 						{ 
 		//				alert('PSslider.initialize.links(sethandler: _prev)'  ); 
  						//----------
						this.previousElArr.push( elt );
						this.previousEl = elt;
 						elt.observe( 'click', this._prev.bindAsEventListener( this ) );
 						//----------
 		//				elt.setStyle( 'color: green;' );
						elt.addClassName( this.activeClass ); 					
 						}, this );
						
				//-----------	auf erstes Bild bewegen		
 				// locallink in URL?
//  				var urlregex = RegExp(/^(.*?)#(.*)$/);
//  				var pid = urlregex.exec(window.location.href);
// 				if( pid[2] != 0 && this.contentNodeH.get( pid[2] ) )
//  						{ 
// 						//alert( 'ID known:3:' + pid[2] );
// 						// set as default slider
// 						this.contentVisibleId = pid[2];
// 						this.defaultSet = 1;
// 						var ind = - this.contentIdArr.indexOf( this.contentVisibleId ) * $( this.contentVisibleId ).getWidth();
//  					this.wrapperEl.setStyle( 'left:' + ind + 'px;' );
//  					this._button( this.contentVisibleId );
// 						}
				if( this.defaultSet )
					{
					this._activate( this.containerEl, this.activeClass );
					// first move
					var ind = - this.contentIdArr.indexOf( this.contentVisibleId ) * $( this.contentVisibleId ).getWidth();
 					this.wrapperEl.setStyle( 'left:' + ind + 'px;' );
					}
 				this._button( this.contentVisibleId );
				this._navilinks( null, this.contentVisibleId );
				// end of initialization
 				},

			_navilinks: function( lastid, nextid )
				{
				if(this.linkH.get(lastid)){this.linkH.get(lastid).removeClassName( this.activeClass );}
				if(this.linkH.get(nextid)){this.linkH.get(nextid).addClassName( this.activeClass );}
				
				},
				
			_activate: function( container, clas )
				{
				// alle childs von ps-slider erhalten die Klasse active
		//		alert('PSslider._activate( container: "' + container + '" clas: "' + clas + '" )');
				var parts 	= $(container).childElements();
				parts.each( function( el )
						{
						el.addClassName( clas )
						//alert('PSslider._activate( el: "' + el + '"  class: "' + el.readAttribute('class') + '" )');
						}, this );
				this.defaultSet	= 1;
				},

			_next: function( ev )
				{
				//-----------
				var ind = this.contentIdArr.indexOf( this.contentVisibleId );
				ind++;
				if( ind >= this.contentIdArr.size() && this.aroundSet ){ ind = 0; }
				var id = this.contentIdArr[ind];
				//-----------		
				
		//		alert('PSslider._next( next button triggerd: size:"' + this.contentIdArr.size() + '"; ind:"' + ind + '"; id:' + id  +  '"; )');
				//-----------			
				this._move( ev, id );
 				Event.stop( ev );
				return false;
				},

			_prev: function( ev )
				{
				//-----------			
				var ind = this.contentIdArr.indexOf( this.contentVisibleId );
				ind--;
				if( ind < 0  && this.aroundSet ){ ind = this.contentIdArr.size() - 1; }
				var id = this.contentIdArr[ind];
		//		alert('PSslider._next( previous button triggerd: size:"' + this.contentIdArr.size() + '"; ind:"' + ind + '"; id:' + id  +  '"; )');
				//-----------			
				this._move( ev, id );
				Event.stop( ev );
				return false;
				},
				
			_button: function( openId )
				{
				if( this.aroundSet || !this.nextEl || !this.previousEl ){ return;}
				//-----------			
				var ind = this.contentIdArr.indexOf( this.contentVisibleId );
				ind--;
				if( ind < 0  && this.aroundSet ){ ind = this.contentIdArr.size() - 1; }
				var id = this.contentIdArr[ind];
		//		alert('PSslider._button( previous button triggerd: size:"' + this.contentIdArr.size() + '"; ind:"' + ind + '"; id:' + id  +  '"; )');
					
				if( this.contentIdArr.size() == ( 1 + this.contentIdArr.indexOf( openId ) ) )
					{ 
					this.nextEl.removeClassName( this.activeClass ); 
					this.previousEl.addClassName( this.activeClass ); 					
					}
				else if( this.contentIdArr.indexOf( openId ) == 0 )
					{ 
					this.nextEl.addClassName( this.activeClass ); 					
					this.previousEl.removeClassName( this.activeClass ); 
					}
				else 
					{ 
					this.nextEl.addClassName( this.activeClass ); 					
					this.previousEl.addClassName( this.activeClass ); 
					}
										  

				},
				
			_move: function( ev, showid )
				{
				var closeId = 0;
				var openId = 0;
 	//			alert('PSslider._move( starts: ev: "' + ev + '" showid: "' + showid + '" )'); 
	//			alert('PSslider._move( contentNodeH.inspect: ' + this.contentNodeH.inspect(true) + ' )');
				if( !this.defaultSet ){this._activate( this.containerEl, this.activeClass );}
				if( this.contentNodeH.get( this.contentVisibleId ) )
					{ closeId = this.contentVisibleId; }
				else 
					{ alert('PSslider._move( failed: closeId unknown: "' + closeId + '"; )'); }
				if( this.contentNodeH.get( showid ) )
					{ openId = showid; }
				else 
					{ /* alert('PSslider._move( failed: openId unknown: "' + openId + '"; )'); */ }
		//		alert('PSslider._move( closeId: "' + closeId + '"; openId: "' + openId + '"; )'); 
				//-----------			
				if( (closeId && openId) )
					{
					var viewportWidth = $(closeId).getWidth();
					var ind = this.contentIdArr.indexOf( openId );
					var x_openId = ind * viewportWidth;
					//
		//			alert('PSslider._move( \n closeId: "' + closeId + '";\n openId: "' + openId + '";\n x_openId: "' + '";\n wrapperPos: "' + wrapperPos + '";  )'); 
					new Effect.Move( this.wrapperEl, { x: -x_openId, y: 0, mode: 'absolute', 
										//				transition: Effect.Transitions.linear, 
										//				transition: Effect.Transitions.spring, 
														transition: Effect.Transitions.sinoidal, 
														duration:  0.5
													});
					this.contentVisibleId = openId;
					this._navilinks( closeId, openId );
					this._button( openId );
					}
 				//-----------			
 				Event.stop( ev );
			return false;
				},
			});
 
 //----------------------------------------------------------------------
	var Toggler;
	document.observe("dom:loaded", function() 
		{
		Toggler = new PStoggle();
		$$('div.ps-multi').each( function(el){ new PSmulti( el );});
		$$('div.ps-slider').each( function(el){ new PSslider( el );  } );
		});	

