

Fx.Height = new Class({
     Extends: Fx.CSS,
	initialize: function(el, options){
		this.parent(el, 'height', options);
	    this.element = $(el);
	 if (this.options.initialize) this.options.initialize.call(this);
	},

	toggle: function(){

		if (this.element.offsetHeight > 0)
			 return this.custom(this.element.offsetHeight, 0);

		else
			return this.custom(0, this.element.scrollHeight);

	},

	show: function(){
		  return this.set(this.element.scrollHeight);
	}

});


var ownSlide=new Class({

	Implements: [Events, Options],
    Extends: Fx.Elements,
    options:{
			fxTransition: Fx.Transitions.linear,
			SlideIn: 500,
			StayAlive: 3000,
			loop:false,
			processing:true,
			showControls:true,
			showHoverText:true,
			animation:{'opacity':[0,1]},
		    animationOut:{'opacity':[1,0]}
			},

     initialize: function(container,elementClass,options){
        this.setOptions(options);

        this.elementIt={};
		this.HoverIt={};
        this.elementClass=$$(elementClass);
        this.AnzahlElements=this.elementClass.length;

		this.processing=this.options.processing;
		this.effects = {};
		this.SlideIn=this.options.SlideIn;
		this.StayAlive=this.options.StayAlive;
		this.fxTransition=this.options.fxTransition;
		this.loop=this.options.loop;
		this.animation=this.options.animation;
		this.animationOut=this.options.animationOut;
		this.NowPos=0;
		this.myControlsDiv=null;
		this.container=$(container);
		this.startlink=null;
		this.stoplink=null;

        var i=0;

         this.elementClass.each(function(elem){



			tempElem=new Element('div', {
				  'styles': {
						'position':'absolute',
						'top':'0px',
						'left':'0px',
						'clear':'both',
						'display':'inline',
                        'opacity':'0',
				        'width':'100%',
				        'height':(elem.getCoordinates().height)+'px'
			        }
				 	});

			elem.setStyles({'position':'absolute','display':'block','width':'100%','visibility':'visible','z-Index':'3'});
            elem.inject(tempElem);
			if(this.options.showHoverText && elem.getProperty('title')!=null){

				elem.HoverText=elem.getProperty('title');
				elem.removeProperty('title');

				hoverDiv=new Element('div', {
			        'html':elem.HoverText,
					'class':'myHoverText'
		    	});

               hoverDiv.inject(elem,'after');

			}


			tempElem.inject(this.container);

			this.elementIt[i]=new Fx.Morph(tempElem, {duration:this.SlideIn,transition: this.fxTransition, wait: false});
	  		i++;
	    }.bind(this));

		  if(this.options.showControls){

			   this.showControls();

			   this.container.addEvent('mouseenter',function(){

	                this.myControlsDiv.setStyle('display','block');

	        	 }.bind(this));

	           this.container.addEvent('mouseleave',function(){

	                 this.myControlsDiv.setStyle('display','none');
	              ;

	        	}.bind(this));
		 }

 		if (this.options.initialize) this.options.initialize.call(this);
     },
   showControls:function(){

		     this.myControlsDiv = new Element('div', {
		        'class':'myControlDiv',
				'styles': {
					'top':(this.container.getCoordinates().height/2)-13+'px',
					'left':(this.container.getCoordinates().width/2)-50+'px',
			        'width':'100px',
			        'height':'26px',
			        'display':'none'
		        }
		    });

			this.backlink=new Element('a',{
						'html':'<img src="images/slide/back.gif" border="0" title="Back" />&nbsp;',
						'styles': {
							'text-decoration':'none',
							'cursor':'pointer'
						},
						'events': {
					        'click': function(){
					           this.getPreviousItem();
					        }.bind(this)
						}
					});
			this.backlink.inject(this.myControlsDiv);


				this.startlink=new Element('a',{
						'html':'<img src="images/slide/loop.gif" border="0" title="Loop" />',
						'styles': {
							'text-decoration':'none',
							'cursor':'pointer'
						},
						'events': {
					        'click': function(){
					           this.StartManuell(1);
					        }.bind(this)
						}
					});

            if(!this.processing){
				this.startlink.setStyle('display','inline');
			}else{
				this.startlink.setStyle('display','none');
			}

			this.startlink.inject(this.myControlsDiv);


				this.stoplink=new Element('a',{
					'html':'<img src="images/slide/pause.gif" border="0" title="pause" />',
					'styles': {
							'text-decoration':'none',
							'cursor':'pointer'
						},
					'events': {
				        'click': function(){
				           this.StopManuell();
				        }.bind(this)
					}
				});
             if(this.processing){
			 	this.stoplink.setStyle('display','inline');
			}else{
				this.stoplink.setStyle('display','none');
			}

			this.stoplink.inject(this.myControlsDiv);

			this.forwardlink=new Element('a',{
						'html':'&nbsp;<img src="images/slide/forward.gif" border="0" title="Forward" />',
						'styles': {
							'text-decoration':'none',
							'cursor':'pointer'
						},
						'events': {
					        'click': function(){
					           this.getNextItem();
					        }.bind(this)
						}
					});

		   	this.forwardlink.inject(this.myControlsDiv);


		   this.myControlsDiv.inject($('container'));

   },

   startAnim:function(IndexIt){

              this.NowPos=IndexIt;

			  this.elementIt[IndexIt].start(this.animation).wait(this.StayAlive).chain(function(){
                   if(this.processing){
						this.getNextAnim((IndexIt+1));
				   }

				}.bind(this));
   },

   getNextAnim:function(indexIt){

        this.NowPos=indexIt;

		if(indexIt==this.AnzahlElements){
            if(this.loop){
				this.elementIt[(indexIt-1)].start(this.animationOut).chain(function(){
					this.startAnim(0);
				}.bind(this));
			}
		}else{
            if(this.processing){

				this.elementIt[(indexIt-1)].start(this.animationOut).chain(function(){

					this.elementIt[indexIt].start(this.animation).wait(this.StayAlive).chain(function(){
						this.getNextAnim1((indexIt+1));
					}.bind(this));

				}.bind(this));
		  }
		}

	},
	getNextAnim1:function(indexIt){

		 this.NowPos=indexIt;
		if(indexIt==this.AnzahlElements){
			if(this.loop){
				this.elementIt[(indexIt-1)].start(this.animationOut).chain(function(){
					this.startAnim(0);
				}.bind(this));
			}
		}else{
			if(this.processing){

				this.elementIt[(indexIt-1)].start(this.animationOut).chain(function(){
					this.elementIt[indexIt].start(this.animation).wait(this.StayAlive).chain(function(){
						this.getNextAnim((indexIt+1));
					}.bind(this));

				}.bind(this));
		    }
		}

	},

	StartManuell:function(Loop){
				  if(Loop==0)this.loop=false;
				  else{this.loop=true;}

				  if(this.startlink!=null){
				  	this.startlink.setStyle('display','none');
				  }
				  if(this.stoplink!=null){
				     this.stoplink.setStyle('display','inline');
				  }

				  this.processing=true;
				  this.elementIt[this.NowPos].start(this.animationOut);

				  this.startAnim(0);


	},
	StopManuell:function(Loop){

				  this.processing=false;
				  if(this.startlink!=null){
				  	this.startlink.setStyle('display','inline');
				  }

				  if(this.stoplink!=null){
				  	this.stoplink.setStyle('display','none');
				  }

	},

	getNextItem:function(){
				   this.processing=false;

				   this.elementIt[this.NowPos].start(this.animationOut).chain(function(){

			           	if (this.NowPos==(this.AnzahlElements-1)){
			           	 this.NowPos = 0;
			           	 }else{
			           	 this.NowPos+=1;
			           	 }

			            this.elementIt[this.NowPos].start(this.animation);

				   }.bind(this));
	},

   getPreviousItem:function(){

	   this.processing=false;

	   this.elementIt[this.NowPos].start(this.animationOut).chain(function(){

           	if (this.NowPos==0){
           	 this.NowPos = (this.AnzahlElements-1);
           	 }else{
           	 this.NowPos-=1;
           	 }

            this.elementIt[this.NowPos].start(this.animation);

	   }.bind(this));
	}


});

var ImageMenu = new Class({

	Implements: [Events, Options],
    options:{

			onOpen: false,
			onClose: Class.empty,
			openWidth: 200,
			transition: Fx.Transitions.Sine.easeInOut,
			duration: 400,
			open: null,
			border: 0
				 },
        initialize: function(elements,options){
        this.setOptions(options);

		this.elements = $$(elements);

		this.widths = {};
		this.widths.closed = this.elements[0].getStyle('width').toInt();
		this.widths.openSelected = this.options.openWidth;
		this.widths.openOthers = Math.round(((this.widths.closed*this.elements.length) - (this.widths.openSelected+this.options.border)) / (this.elements.length-1))


//		this.fx  = new Fx.Morph(this.elements, {duration: this.options.duration, transition: this.options.transition});
		this.fx = new Fx.Elements(this.elements, {wait: false, duration: this.options.duration, transition: this.options.transition});

		this.elements.each(function(el,i){

			el.addEvent('mouseenter', function(){
				this.reset(i);

			}.bind(this));

			el.addEvent('mouseleave', function(){

				this.reset(this.options.open);

			}.bind(this));

			var obj = this;

			el.addEvent('click', function(){

				if(obj.options.onOpen){

					if(obj.options.open == i){
						obj.options.open = null;
						obj.options.onClose(this.href, i);
					}else{
						obj.options.open = i;
						obj.options.onOpen(this.href, i);
					}


				}

			})

		}.bind(this));

		if(this.options.open){
			if($type(this.options.open) == 'number'){
				this.reset(this.options.open);
			}else{
				this.elements.each(function(el,i){
					if(el.id == this.options.open){
						this.reset(i);
					}
				},this);
			}
		}

	},

	reset: function(num){
		if($type(num) == 'number'){
			var width = this.widths.openOthers;
			if(num+1 == this.elements.length){
				width += this.options.border;
			}
		}else{
			var width = this.widths.closed;
		}

		var obj = {};
		this.elements.each(function(el,i){
			var w = width;
			if(i == this.elements.length-1){
				w = width+5
			}
			obj[i] = {'width': w};
		}.bind(this));

		if($type(num) == 'number'){
			obj[num] = {'width': this.widths.openSelected};
		}

		this.fx.start(obj);
	}

});



var MooRevolver = new Class({

	Implements: [Events, Options],
    options:{

			"pad":80,
			"border":0,
			"yRadius":10,
			"arrowLeft":null,
			"arrowRight":null,
			"fxDuration": 500,
			"fxTransition": Fx.Transitions.linear,
			"fade":false
				 },
     initialize: function(element,options){
        this.setOptions(options);
        this.Manuell=false;

		if($(element)){

			if($(this.options.arrowLeft)) {
				$(this.options.arrowLeft).addEvent("click", (function(e){
					this.getPrevious1();
				}).bind(this));
			}

			if($(this.options.arrowRight)) {
				$(this.options.arrowRight).addEvent("click", (function(e){
					this.getNext1();
				}).bind(this));
			}

 			this.processing = false;
			this.containerSize = $(element).getSize();


			this.xRadius = (this.containerSize.x / 2) - this.options.pad;
			this.yRadius = this.options.yRadius;
			this.centerX = (this.containerSize.x / 2);
			this.centerY = 35;

			this.items = $(element).getChildren();
			this.totalItems = this.items.length;

			this.points = [];
			this.positions = [];
			this.sizes = [];
			this.zIndexes = [];
			this.opacities = [];


			for(var i = 0; i < this.totalItems; i++){
				this.points.push(i * (360 / this.totalItems));
				var pt = this.getElipticalPoint(this.points[i]);

				this.items[i].setStyles({
					"left": pt.x,
					"top": pt.y
				});

          //this is new added by neo27

			 this.items[i].addEvent("mouseenter", (function(){

              		this.processing=true;



				}).bind(this));

             this.items[i].addEvent("mouseleave", (function(){

					this.processing=false;


				}).bind(this));
              //END NEW

			this.processItem(i, this.points[i]);



			}

			this.reposition();


		} else {
			return;
		}
	},
    startAnim:function(){
        this.processing=false;
        this.Manuell=false;

    },
    stopAnim:function(){
	    this.processing=true;
	    this.Manuell=true;

    },

    getNext1: function(){

			this.Manuell=true;
			this.rotate(true);


	},

	getPrevious1: function(){

			this.Manuell=true;
			this.rotate(false);


	},

	getNext: function(){
		if (!this.processing) {
			this.processing = true;
			this.rotate(true);
		}
	},

	getPrevious: function(){
		if (!this.processing) {
			this.processing = true;
			this.rotate(false);
		}
	},

	rotate: function(forward){
		if(!this.processing) return;

		if(forward){
			this.items.push(this.items.shift());
		} else {
			this.items.unshift(this.items.pop());
		}

		var fxArray = [];

		for(var i = 0; i < this.totalItems; i++){

			var myEffects = new Fx.Morph(this.items[i], {duration: this.options.fxDuration, transition: this.options.fxTransition});


			fxArray.push(myEffects);
			if(this.options.fade) {
				myEffects.start({"opacity": this.opacities[i], "top": this.positions[i].y, "left": this.positions[i].x, "width": this.sizes[i].x, "height": this.sizes[i].y});
			} else {
				myEffects.start({
				"top": this.positions[i].y,
				"left": this.positions[i].x,
				"width": this.sizes[i].x,
				"height": this.sizes[i].y
				 });

			}
			this.items[i].setStyle("z-index", this.zIndexes[i]);




		}

		var g = new Group(null);
		g.initialize.apply(g, fxArray);

			g.addEvent("onComplete", (function(){

			 if(this.Manuell==false){
			     this.processing = false;

			 }
			 if(this.Manuell==true){
			     this.processing = true;

			 }
			 }).bind(this));

	},

	reposition: function() {
		for (var _l = 0; _l < this.totalItems; _l++) {
			var pt = this.getElipticalPoint(this.points[_l]);
			this.positions.push({x: pt.x - ((this.items[_l].getSize().x + this.options.border) / 2), y: pt.y});

			this.items[_l].setStyles({
				"left": this.positions[_l].x,
				"top": this.positions[_l].y
			});
		}
	},

	getElipticalPoint: function(_d) {
		var rad = _d * (Math.PI / 180);
		var _x = this.centerX + this.xRadius * Math.sin(rad);
		var _y = this.centerY + this.yRadius * Math.cos(rad);
		return {x : _x, y : _y};
	},

	processItem: function(_i, deg) {
		var size = 1;

		if (deg >= 0 && deg < 180) {
			size = (180 - deg) / 180;
		} else if (deg >= 180 && deg <= 360) {
			size = (deg - 180) / 180;
		}
		this.scaleItem(_i, size);
		this.items[_i].setStyle("z-index", (size * 100).round());
		this.zIndexes.push((size * 100).round());
	},

	scaleItem: function(_i, percentage) {
		if(percentage == 0) percentage = 0.1;

		var _x = ((this.items[_i].getSize().x + this.options.border) * percentage);
		var _y = ((this.items[_i].getSize().y + this.options.border) * percentage);

		this.sizes.push({x: _x, y: _y});
		this.opacities.push(percentage);

		this.items[_i].setStyles({
			"width": _x,
			"height": _y,
			"opacity": this.options.fade ? percentage : 1
		});
	}
});



var OwnTips = new Class({

	Implements: [Events, Options],
    options:{
	        maxTitleChars: 30,
			fxDuration: 1000,
			maxOpacity: 1,
			timeIn: 1000,
			timeOut: 5000,
			fixed:true,
			clickable:true,
			stayalive: true,
			takeajax:false,
			offsets: {'x': 16, 'y': 16},
			ajaxfile:'tooltext.php',
			ajaxoption:'action',
			className: 'tooltip'

  			 },
     initialize: function(elements,options){

        this.setOptions(options);
 		this.elements = elements;

		this.document = (elements.length) ? elements[0].ownerDocument : document;

		this.toolTip = new Element('div').addClass(this.options.className).setStyles({'position': 'absolute','top': '0px','left': '0px','visibility':'hidden'}).inject(document.body);
		if(this.options.stayalive){
			this.toolClose = new Element('div').setProperties({'id':'close'});
		    this.toolClose.set('html','schliessen').inject(this.toolTip);
		}
		if(!this.options.takeajax){
			this.toolTitle = new Element('H3').inject(this.toolTip);
			this.toolText = new Element('p').inject(this.toolTip);
		}else{
			this.toolText = new Element('div').setProperties({'id':'ajaxcontent'}).inject(this.toolTip);
		}

		this.toolDivImg = new Element('div').setProperties({'id':'imgdiv'}).inject(this.toolTip);
		this.toolImg = new Element('img').inject(this.toolDivImg);

		this.CoolFx = new Fx.Morph(this.toolTip, {duration: this.options.fxDuration});


		$A(elements).each(function(el){

			$(el).myText = el.title || false;
			if (el.myText) el.removeProperty('title');
			if (el.href){
				if (el.href.test('http://')) el.myTitle = el.href.replace('http://', '');
				if (el.href.length > this.options.maxTitleChars) el.myTitle = el.href.substr(0,this.options.maxTitleChars-3)+"...";
			}

		    if(!this.options.takeajax){
				if (el.myText && el.myText.test('::')){
					var dual = el.myText.split('::');
					el.myTitle = dual[0].trim();
					el.myText = dual[1].trim();

					if(dual.length==3){
					  el.myImg = dual[2].trim();
					}else el.myImg='blank.gif';

				}
			}

			if(this.options.clickable){

				el.addEvent('click', function(){
					this.show(el);
					if (!this.options.fixed) this.locate(event);
			    	else this.position(el);
				}.bind(this));

			}else{

				el.addEvent('mouseenter', function(){
					this.show(el);
					if (!this.options.fixed) this.locate.bind(this);
			    	else this.position(el);
				}.bind(this));
			}

			if(this.options.stayalive){

				$(this.toolClose).addEvent('click',function(){this.disappear();}.bind(this));

			}else{
                 var end = this.end.bind(this);
		         el.addEvent('mouseleave', end);
			}

			if (!this.options.fixed) el.addEvent('mousemove', this.locate.bind(this));

		}, this);

	 if (this.options.initialize) this.options.initialize.call(this);
	},
    end: function(event){
		$clear(this.timer);
		this.timer = this.disappear.delay(this.options.timeOut, this);
	},
    position: function(element){
		var pos = element.getPosition();
		this.toolTip.setStyles({
			'left': pos.x + this.options.offsets.x,
			'top': pos.y + this.options.offsets.y
		});
	},

	show: function(el){

		if(!this.options.takeajax){
			this.toolTitle.set('html', el.myTitle);
			this.toolText.set('html', el.myText);
			this.toolImg.setProperty('src',el.myImg);
		}else{
			this.ajaxload(this.options.ajaxfile,el.myText.trim(),this.toolText);
			this.toolImg.setProperty('src','images/blank.gif');
		}

		this.timer = $clear(this.timer);
		this.timer = this.appear.delay(this.options.timeIn, this);

	},

	appear: function(){
		this.CoolFx.start({'opacity': [0, this.options.maxOpacity]});
	},

    ajaxload: function(file,what,tooling){
	 	new Request.HTML({url:file, method:'post',data:this.options.ajaxoption+'='+encodeURIComponent(what),update:tooling,
			onFailure:function(){},
			onComplete:function(){}}).send();
		return this;
		 },

	locate: function(event){
		var doc = this.document.getSize();
		var scroll = this.document.getScroll();
		var tip = {'x': this.toolTip.offsetWidth, 'y': this.toolTip.offsetHeight};
		var prop = {'x': 'left', 'y': 'top'};
		for (var z in prop){
			var pos = event.page[z] + this.options.offsets[z];
			if ((pos + tip[z] - scroll[z]) > doc[z]) pos = event.page[z] - this.options.offsets[z] - tip[z];
			this.toolTip.setStyle(prop[z], pos);
		}
	},


	disappear: function(){
	  //  this.timer = this.disapear.delay(this.options.timeOut, this);
		this.CoolFx.start({'opacity': [this.options.maxOpacity, 0]});
	//	this.toolTip.destroy();
		//this.fireEvent('onHide', [this.toolTip]);
	}

});
OwnTips.implement(new Chain);
OwnTips.implement(new Events);
OwnTips.implement(new Options);

