
function Page() {
	
	//--------------------------------------------------------------------
	
	var _self;
	var subNavigation;
	var contentBackGround;
	var contentContainer;
	var overflowContainer;
	var content;
	var hideButton;
	var pageCounter;
	var scrollCount;
	var activeScrollPage;
	var isScrolling;
	var activeLinkColor;
	var scrollSpacer;
	
	//--------------------------------------------------------------------
	
	/**
	 * 
	 * @param string a_background
	 * @param string a_overflow
	 * @param string a_content
	 * @param string a_button
	 * @param string a_pageCounter
	 * @return void
	 */
	this.__construct = function ( a_background, a_contentContainer, a_overflow, a_content, a_button, a_pageCounter ) {
		_self				= this;
		subNavigation		= $('subNavigation');
		contentBackGround	= $(a_background);
		contentContainer	= $(a_contentContainer);
		overflowContainer	= $(a_overflow);
		content				= $(a_content);
		hideButton			= $(a_button);
		pageCounter			= $(a_pageCounter);
		scrollCount			= 0;
		activeScrollPage	= 0;
		isScrolling			= false;
		activeLinkColor		= '#666666';
		scrollSpacer		= 60;
		init();
	}
	
	//--------------------------------------------------------------------
	
	function init() {
		contentBackGround.setOpacity(0.86);
		hideButton.defLeft = hideButton.offsetLeft;
		hideButton.onclick = function() {
			_self.hide();
		}
	}
	
	//--------------------------------------------------------------------
	
	/**
	 * 
	 * @return void
	 */
	this.setHeight = function () {
		var winHeight = window.getSize().y;
		contentBackGround.style.height = winHeight + 'px';
		overflowContainer.style.height = winHeight - 100 + 'px';
		hideButton.style.top = Math.round( (winHeight/2) - (hideButton.offsetHeight/2) ) + "px";
		this.setPageCounter();
		this.scrollToPart(0);
	}
	
	//--------------------------------------------------------------------
	
	/**
	 * 
	 * @return void
	 */
	this.setPageCounter = function () {
		content.style.height = 'auto';
		setTimeout(function(){
			scrollCount = Math.ceil(content.offsetHeight / ( overflowContainer.offsetHeight - scrollSpacer ));
			var aNodes = subNavigation.getChildren('a');
			subNavigation.className = ( scrollCount > 1 || gallery !== null || movie !== null || aNodes.length > 0 ) ? 'borderTop' : '';
			
			pageCounter.innerHTML = '';
			if(scrollCount > 1) {
				var textContent = ( LANG == 'de' ) ? 'Seite ' : 'Page ';
				var text = document.createTextNode(textContent);
				pageCounter.appendChild(text);
				for(i=0;i<scrollCount;i++) {
					var a = document.createElement('a');
					a.id = 'scrollButton_' + i;
					a.href = '#';
					a.innerHTML = i+1;
					a.className = 'pageStep';
					a.style.color = (i===0) ? activeLinkColor : ''; 
					a.scrollId = i;
					a.onclick = function() {
						_self.scrollToPart( this.scrollId );
						return false;
					}
					pageCounter.appendChild(a);
				}
				content.style.height = (overflowContainer.offsetHeight * scrollCount) + 'px';
				setWheel(true);
			} else {
				scrollCount = 0;
				setWheel(false);
			}
		},20);
	}
	
	//--------------------------------------------------------------------
	
	/**
	 * 
	 * @param {boolean} use
	 */
	function setWheel( use ) {
		if ( use === true ) {
			content.addEvent("mousewheel", function(e) {
				if (e.wheel > 0) {_self.scrollToPart(activeScrollPage-1);}
				else {_self.scrollToPart(activeScrollPage+1);}
			});
		} else {content.removeEvent("mousewheel");}
	}
	
	//--------------------------------------------------------------------
	
	/**
	 * 
	 * @return void
	 */
	this.hide = function () {
		hideButton.src = '/pix/main/arrowRight.gif';
		
		contentBackGround.set('morph', {duration: 500, transition: Fx.Transitions.Sine.easeOut});
		contentContainer.set('morph', {duration: 500, transition: Fx.Transitions.Sine.easeOut});
		hideButton.set('morph', {duration: 500, transition: Fx.Transitions.Sine.easeOut});
		
		contentBackGround.morph({left: -470});
		contentContainer.morph({left: -470});
		hideButton.morph({left: 10});
		
		hideButton.onclick = function() {_self.show();}
	}
	
	//--------------------------------------------------------------------
	
	/**
	 * 
	 * @return void
	 */
	this.show = function () {
		
		if( (gallery !== null && gallery.isActive() === true) ) {
			gallery.hide();
			return;
		}
		if( (movie !== null && movie.isActive() === true) ) {
			movie.stop();
			return;
		}
		
		hideButton.src = '/pix/main/arrowLeft.gif';
		contentBackGround.set('morph', {duration: 500, transition: Fx.Transitions.Sine.easeOut});
		contentContainer.set('morph', {duration: 500, transition: Fx.Transitions.Sine.easeOut});
		hideButton.set('morph', {duration: 500, transition: Fx.Transitions.Sine.easeOut});
		
		contentBackGround.morph({left: 0});
		contentContainer.morph({left: 0});
		hideButton.morph({left: hideButton.defLeft});
		hideButton.onclick = function() {_self.hide();}
	}
	
	//--------------------------------------------------------------------
	
	/**
	 * 
	 * @param integer id
	 * @return void
	 */
	this.scrollToPart = function ( id ) {
		if( isScrolling === true ) return;
		isScrolling = true;
		if ( scrollCount === 0 || id < 0 ) {id = 0;}
		else if( id > scrollCount-1 ) id = scrollCount-1;
		
		if($('scrollButton_' + activeScrollPage)) {$('scrollButton_' + activeScrollPage).style.color = '';}
		if($('scrollButton_' + id)) {$('scrollButton_' + id).style.color = activeLinkColor;}
		activeScrollPage = id;
		
		var scrollHeight = (overflowContainer.offsetHeight-scrollSpacer) * id;
		content.set('morph', {duration: 300, transition: Fx.Transitions.Sine.easeOut, onComplete: function(){
			isScrolling = false;
		}});
		content.morph({marginTop:scrollHeight*-1});
	}

	//--------------------------------------------------------------------
		
}
