var webaMediaGallery = Class.create({
	initialize: function(elString,galleryString,numShowItems) {
		//set Elements
		this.el = $(elString);
		this.list = $(elString).down(galleryString);
		this.items = $(this.list).getElementsByTagName('li');
		//set numbers
		this.numShowItems = numShowItems;
		this.first = 0;
		this.last = this.numShowItems-1;
		var num = this.numShowItems;
		if(this.items.length<this.numShowItems){
			num = this.items.length;
			this.hideLink('.nextLink','none');
		} 	
		this.hideLink('.prevLink','none');
			
		//make elemts visible
		for(i = 0;i<num;i++){
			$(this.items[i]).setStyle({
				display:'block'
			});
		}	
	},
	hideLink: function(linkString,displayString){
		this.el.down(linkString).setStyle({
			display:displayString
		});	
	},
	next: function() {
		if(this.last<this.items.length-1){
			this.hideLink('.prevLink','block');
			$(this.items[this.first]).setStyle({
				display:'none'
			});
			this.first++;
			this.last++;
			$(this.items[this.last]).setStyle({
				display:'block'
			});
		} 
		if(this.last==this.items.length-1){
			this.hideLink('.nextLink','none');
		}		
	},
	prev: function() {
		if(this.first>0){
			this.hideLink('.nextLink','block');
			$(this.items[this.last]).setStyle({
				display:'none'
			});
			this.first--;
			this.last--;
			$(this.items[this.first]).setStyle({
				display:'block'
			});			
		} 
		
		if(this.first==0) {
			this.hideLink('.prevLink','none');
		}			
	}
});

var medGal;

document.observe('dom:loaded', function() {
    var element = $('webaMediagallery');
    if(element){
		medGal = new webaMediaGallery(element,'.gallery',4);
	}
});


//Hover Map

var HoverMap = Class.create({
	initialize: function(src, id) {
		this.src = src
		this.areaId = id
		this.mapId = this.src.ancestors()[0].id
		this.mapPic = $('tx_a4fe'+this.mapId).src

		this.src.observe('mouseover', this.showTip.bindAsEventListener(this));
		this.src.observe('mouseout', this.hideTip.bindAsEventListener(this));
	},
	showTip: function(evt) {
		Event.stop(evt);

		// Jetzt noch das Area einblenden
		img = $('areapic_'+ this.areaId);
		if(!img.src.endsWith('/'))
			$('tx_a4fe'+this.mapId).src = img.src
	},
	hideTip: function(evt) {
		$('tx_a4fe'+this.mapId).src = this.mapPic
	}
	
});
