/* (C) dfacts Network  //  pix-r.us

Description: dock style / fish eye  gallery
Version: 1.0
Author: Gerhard Koch

*/

function dockInit() { 
  		if (!document.getElementsByTagName){ return; }
		var imageTags = document.getElementsByTagName('img');
		var counter = 0;
		for (var i=0; i<imageTags.length; i++){
			var imageTag = imageTags[i];
			var relAttribute = String(imageTag.getAttribute('rel'));
			if (imageTag.src && (relAttribute.toLowerCase().match('dockgallery'))){
				counter++;
				dockRegExp = /^(.*)\[(.+)\|(\d.+)\|(\d.+)\]$/
				dockParams = dockRegExp.exec(relAttribute);

				imageTag.style.cursor = "pointer";
				imageTag.setAttribute('id', "img"+(counter));
				if(counter > 5)  {imageTag.style.display = 'none' } else  {imageTag.style.display = '' };
				
				imageTag.dockInstance = new dockGallery(counter, imageTag, dockParams);
				

		
			}
		}
	}


function dockGallery(index, tag, params)  {

	this.Visible 	= 5;
	this.Interval 	= null;

    this.initialize(index, tag, params);
  
}




dockGallery.prototype = {
	initialize : function(index, image, dockParams) {
   	 	this.originalWidth = image.offsetWidth?image.offsetWidth:image.width;
 		this.originalHeight =  image.offsetHeight?image.offsetHeight:image.height;
    	this.originalSource = image.src;
    	this.targetSource = dockParams[2];
    	this.zoomState = 0;
    	this.growState = 0;
    	this.index = index;
	    image.onmouseover = this.zoomin.bind(this);
    	image.onmouseout = this.zoomout.bind(this);
 	},

  
 	zoomin : function() {
 			if(this.zoomState == 0){
				this.zoomState = -2;

				$('img'+this.index).src = this.targetSource;


				image = 'img'+this.index; 
				grown = false;
			
	/*			rightNeighbor = 'img'+(this.index+1);
				if($(rightNeighbor) && !Element.visible(rightNeighbor)){
					outerLeft = 'img'+(this.index-(this.Visible-1));
					if($(outerLeft) && Element.visible(outerLeft)){
						new Effect.Grow($(rightNeighbor), { afterFinish: function(){
						new Effect.Shrink($(outerLeft));
						}});
					}
				}

				leftNeighbor = 'img'+(this.index-1);
				if($(leftNeighbor) && !Element.visible(leftNeighbor)){
					outerRight = 'img'+(this.index+(this.Visible-1));
					new Effect.Grow($(leftNeighbor), { afterFinish: function(){
					new Effect.Shrink($(outerRight));
					}});
				}
	*/		
				this.effect = new Effect.Scale(
								$('img'+this.index), 
								250, 
								{	scaleFromCenter: 	true, 
									originalHeight: 	this.originalHeight, 
									originalWidth: 		this.originalWidth, 
									afterFinish: 		this.zoomindone.bind(this)
									}
								);
								
				for(i=0; $('img'+i); i++){
					if(i!=this.index){
					
					}
				}
				
			
			}
					
			
			
	},

	zoomout : function() {
 			if(this.zoomState == 1){	
				this.zoomState = -1;
				imageHeight = this.originalHeight;
				imageWidth = this.originalWidth;
				imageSource = this.originalSource
				this.effect = new Effect.Scale(	
									$('img'+this.index),
									40, 
									{	scaleFromCenter: 	true, 
										originalHeight: 	this.originalHeight, 
										originalWidth: 		this.originalWidth,
										afterFinish: 		this.zoomoutdone.bind(this)

									}
								);
			} else if(this.zoomState == -2) { 
				originalFactor = this.effect.factor;
				this.zoomState = -3;
				imageHeight = this.originalHeight;
				imageWidth = this.originalWidth;
				imageSource = this.originalSource;
				this.effect.finish();
				this.effect.update();
				this.effect = new Effect.Scale(	
									$('img'+this.index),
									40, 
									{	scaleFromCenter: 	true, 
										originalHeight: 	this.originalHeight, 
										originalWidth: 		this.originalWidth,
										queue:				'end',
										afterFinish: 		this.zoomoutdone.bind(this)

									}
								);
			
			
			} 
			
	},
	
	zoomindone : function() {
 			this.zoomState = 1;
 			this.effect = null;
	},

	zoomoutdone : function() {
 			this.zoomState = 0;
 			this.effect = null;
 			$('img'+this.index).src = this.originalSource;
 			
	}

	
}



