/* (c) 2006, 2007 Patrick Gerdsmeier */

var MOUSEX = 0;
var MOUSEY = 0;
var zoomer;


initZoomer = function( zoomList ) {
	
	zoomer = new Zoomer( zoomList );

	document.onmousemove = function(e) {
		
		MOUSEX = ( document.all ) ? window.event.x + document.body.scrollLeft : e.pageX; 
		MOUSEY = ( document.all ) ? window.event.y + document.body.scrollTop : e.pageY;
		zoomer.zoom();
	};
};

zoomover = function(id) { if( typeof( zoomer ) == 'object' ) zoomer.setActiveBlock(id); }
zoomout  = function() { if( typeof( zoomer ) == 'object' ) zoomer.setActiveBlock(-1) };


/*
	Initialisierung mit einer Liste der X-Positionen fuer alle Elemente
	Aendert <li#zoomer+id> in Position und <span#zoomblock+id> in der Groesse.
 
*/
function Zoomer( blocklist ) {

	$ = function( id ) { return document.getElementById( id ); }

	// Fixum	
	this.BLOCKWIDTH = 5;
	this.BLOCKHEIGHT = 50;
	this.BLOCKMAXHEIGHT = 170;
	this.MINDISTANCE = 100;
	this.MININNER = 30;

	this.zoomList = blocklist;
	this.activeBlock = -1;
	
	for( var id = 0; id < this.zoomList.length; id++ )
		$( "zoomblock" + id ).style.display = "block";

	this.zoom = function() {
		
		var mymousey = MOUSEY - document.body.clientHeight / 2 + 100;
		var mymousex = MOUSEX - document.body.clientWidth  / 2 + 120;
	
		// <+)))><
		if( mymousey < - 50 - this.MINDISTANCE || mymousey > 130 + this.MINDISTANCE ) {

			// Reset aller Elemente
			for( var id = 0; id < this.zoomList.length; id++ )
				this.setBlock( id, this.zoomList[id] - this.BLOCKWIDTH / 2, this.BLOCKWIDTH, this.BLOCKHEIGHT );
				
		} else {
			
			for( var id = 0; id < this.zoomList.length; id++ ) {
	
				var x = this.zoomList[id];
				var y = Math.abs( mymousey - this.MINDISTANCE + 125 );
				
				var y_f = 0;
				
				if( y < this.MINDISTANCE && y >= this.MININNER ) 
					y_f = 1 - ( 1 / ( this.MINDISTANCE - this.MININNER ) ) * ( y - this.MININNER );
				
				if( y < this.MININNER )
					y_f = 1;

				var distance = x - mymousex;
				var f = ( Math.abs(distance) < 100  ) 
					? 
					( ( ( Math.sin( ( distance * 180 / this.MINDISTANCE + 90 )
					/ 180 * Math.PI ) * 0.25 ) + 0.25 ) * y_f + 1 )
					: 
					1 ;	
					
				var x1 = mymousex - ( mymousex - x + this.BLOCKWIDTH / 2 ) * f;
				var x2 = mymousex - ( mymousex - x - this.BLOCKWIDTH / 2 ) * f;

				var y1 = 0;
				var y2 = this.BLOCKHEIGHT * f;
				
				var w = ( x2 - x1 ) * f;
				var h = ( this.activeBlock != id ) ? ( y2 - y1 ) * f : this.BLOCKMAXHEIGHT;

				this.setBlock( id, x1, w, h );
			}
		}
	}


	this.setActiveBlock = function( id ) { this.activeBlock = id; }
	

	this.setBlock = function( id, left, width, height ) {

		try {
			$( "zoomer" + id ).style.left      = left + "px";
			$( "zoomblock" + id ).style.width  = width + "px";
			$( "zoomblock" + id ).style.height = height + "px";

			$( "zoomblock" + id ).style.marginLeft = "0";
		} catch(e) {}
	}
}
