var Corine = {
	init: function() {
		var thisObj = this;
		this.name = "Corine";
		this.elContainer = $('container');
		this.elWrapper = $('contentWrapper');
		this.elScrollbar = $('contentScrollbar');
		this.elHandle = $('scrollbarHandle');
		this.checkWinSize();		// adjust Layout
		this.initScrollbar();		// create Scrollbar -> aufruf jetzt direkt nach content
		this.attachTargetBlanks();	// neues Fenster bei A.blank
		this.initLogobar();			// create Logobar Rollover
		this.initZoomImage();		// create ImageZooms
		this.initSlideShow();		// create SlideShow
		window.onresize = thisObj.checkWinSize;
	},
	writeJsDependedStyles: function() {
		// Styles die nur von Javascript-abhängigen Elementen benützt werden
		var jsStyles = '<link type="text/css" href="' + PATH;
		jsStyles 	+= '/inc/css/js.css" rel="stylesheet" media="screen, projection" />';
		document.writeln(jsStyles);
	},
	initScrollbar:  function() {
		if (this.elWrapper == null) return; // intro hat keinen wrapper
		var containerH = this.elContainer.getSize().y;
		var steps = this.elWrapper.getScrollSize().y - this.elWrapper.getSize().y;
		var content = this.elWrapper;
		if (steps > 0) {
			var slider = new Slider(this.elScrollbar, this.elHandle, {	
				steps: steps,
				range: new Array(0,steps),
				wheel: true,
				mode: 'vertical',
				onChange: function(steps){
					// Scrolls the content element in x or y direction.
					var x = 0;
					var y = steps;
					content.scrollTo(x,y);
				}
			}).set(0);
			// Stops the handle dragging process when the mouse leaves the document body.
			$(document.body).addEvent('mouseleave',function(){slider.drag.stop()});
			// Attach Mousewheel-Listener to Slider
			document.addEvent('mousewheel', function(e) {
				e = new Event(e).stop();
				var step = slider.step - e.wheel * 20;
				slider.set(step);
			});
			
			
		} else {
			// hide the handle	
			this.elHandle.setStyle('display','none');
		}
	},
	initLogobar: function() {
		this.elLogobar = $('logobar');
		this.elLogobarImg = $$('#logobar IMG');
		if (!this.elLogobarImg) return;
		var logobar = this.elLogobarImg;
		var elSrc = this.elLogobarImg.getProperty('src').toString();
		var hoverSrc = elSrc.replace(/.gif/, "_hl.gif");
		// preload
		var elHighlightImg = new Image();
		elHighlightImg.src = hoverSrc;
		// attach event
		this.elLogobar.addEvents({
			'mouseover': function() { 
				$('logobarimg').src = hoverSrc; },
			'mouseout': function() { 
				$('logobarimg').src = elSrc }
		});
	},
	checkWinSize: function() {
		return; /* Safari trouble */
		// Changes styles if viewport to small
		var elContainer = $('container');
		var winH = Window.getHeight().toInt();
		var elH = elContainer.getHeight().toInt();
		if(winH <= elH) {
			elContainer.setStyles({
				'margin-top': 0,
				'top': 0
			})
		} else {
			elContainer.setStyles({
				'margin-top': -(elH / 2),
				'top': '50%'
			})	
		}
	},
	initZoomImage: function() {
		var el = $$('A.zoomImage');
		if (el == 0) return;
		var thisObj = this;
		var dropZone = new Element('div', {
			'id': 'zoomDropZone'
		});
		dropZone.inject('contentContainer');
		this.dropZone = dropZone;
		el.addEvent('click',function() {
			thisObj.zoomImage(this.href);
			return false;
		});
	},
	zoomImage: function(zoomUri) {
		var thisObj = this;
		var dropZone = this.dropZone;
		var zoomImg = new Element('img', {
			'src': zoomUri,
			'events': {
				'click': function(){ thisObj.closeZoomImage(); }
			}
		});
		dropZone.empty();
		zoomImg.inject(dropZone);
		dropZone.setStyle('opacity',0);
		zoomComplete = function() {
			zoomImg.addEvent('click',function() {
				thisObj.closeZoomImage();								  
			})
		}
		zoomImg.onload = function() {
			dropZone.setStyle('display','block');
			var myFx = new Fx.Tween(dropZone, {
				'complete': zoomComplete()					
			});
			myFx.start('opacity', 0, 1);
		}
	},
	closeZoomImage: function() {
		var dropZone = this.dropZone;
		var myFx = new Fx.Tween(dropZone, {
			'complete': function() {
				dropZone.setStyle('display','none');
				dropZone.empty();
			}
		});
		myFx.start('opacity', 1, 0);
	},
	initSlideShow: function() {
		// create Elements
		var el = $$('DIV.slideShow A');
		if (el == 0) return;
		var thisObj = this;
		this.slidesShowImages = new Array();
		this.slidesShowTexts = new Array();
		this.dropZone = new Element('div', {
			'id': 'slideShowZone'
		});
		this.dropZone.inject('contentContainer');
		this.dropText = new Element('p', {
			'id': 'slideShowText'
		});
		this.dropText.inject('contentContainer');
		
		el.each(function(item,index) {
			thisObj.slidesShowImages.push(item.href);
			thisObj.slidesShowTexts.push(item.getElement('IMG').alt);
			item.addEvent('click',function() {
				thisObj.startSlideShow(index);
				return false;
			})
		});
		// preload the images
		var slideImages = new Asset.images(this.slidesShowImages, {
			'onComplete': function() {
				// do nothing
			}								   
		});
		// add close Button
		this.slideShowCloseBtn = new Element('a', {
			'id': 'slideShowCloseBtn',
			'href': '#',
			'html': 'Zur Übersicht',
			'events' : {
				'click' : function() {
					thisObj.slideShowClose();
					return false;
				}	
			}
		});
		this.slideShowCloseBtn.inject('contentContainer');
	},
	startSlideShow: function(index) {
		if (this.slidesShowImages[index] == '#') return; // if empty Href -> return
		var thisObj = this;
		var dropZone = this.dropZone;
		this.slideIndex = parseInt(index);
		this.dropText.innerHTML = this.slidesShowTexts[this.slideIndex];
		this.dropText.setStyle('display','block');
		this.slideShowCloseBtn.setStyle('display','block');
		this.slideImage = new Element('img', {
			'src': this.slidesShowImages[this.slideIndex],
			'alt': this.slidesShowTexts[this.slideIndex],
			'events': {
				'click': function(e) {
					thisObj.slideShowNext();
					return false;
				}	
			}
		});
		this.slideImage.inject(this.dropZone,'top');
		this.dropZone.setStyles( {
			'opacity': 0,
			'display': 'block'
		});
		this.slideShowFx = new Fx.Tween(this.dropZone).start('opacity', 0, 1);
	},
	slideShowNext: function() {
		var thisObj = this;
		var thisImg = this.slideImage;
		var thisText = this.dropText;
		var nextIndex = (this.slideIndex < this.slidesShowImages.length-1) ? this.slideIndex + 1 : 0 ;
		var nextImgSrc = this.slidesShowImages[nextIndex];
		this.slideShowCloseBtn.setStyle('display','block');
		this.slideImage.removeEvents();
		this.slideFx = new Fx.Tween(this.slideImage, {
			'onComplete': function() {
				thisObj.slideIndex = nextIndex;
				thisImg.src = nextImgSrc;
				thisImg.alt = thisObj.slidesShowTexts[thisObj.slideIndex];
				thisFx.onComplete = function() {};
				thisFx.start('opacity', 0, 1);
				thisText.innerHTML = thisObj.slidesShowTexts[thisObj.slideIndex];
				thisImg.addEvent('click',function() {
					thisObj.slideShowNext();
					return false;						  
				});
			}
		});
		var thisFx = this.slideFx;
		thisFx.start('opacity', 1, 0);
	},
	slideShowClose:function() {
		this.slideShowFx.start('opacity', 1, 0);
		this.slideImage.destroy();
		this.dropText.setStyle('display','none');
		this.slideShowCloseBtn.setStyle('display','none');
	},
	attachTargetBlanks: function() {
		var thisObj = this;
		$$('A.blank').addEvent('click',function(e) {
			var thisEvent = new Event(e).stop();
			thisObj.openWin(this.href,"menubar=yes,location=yes,status=yes,toolbar=yes");
			return false;
		});
	},
	openWin: function(url,features) {
		var newWin = window.open(url,'corinePopup',features);
		newWin.focus();
	},
	fadeIn: function() {
		this.fadeInEl = $('fadeElement');
		this.fadeInFx = new Fx.Tween(this.fadeInEl, {
			'onComplete': function() {
				$('fadeElement').destroy();
			}
		}).start('opacity', 1, 0);
	}
}



