function panView( e , name ){

	this.name = 'panView';
	this.version = '1.1';
	this.lastchangedate = '2009-07-20';
	this.author = 'Marcin Kita';
	
	this.stoped = true;
	this.mouseMoving = false;
	this.imageName = name;
	this.direction=1;
	this.movingSpeed=10;
	this.maxFactor=4;

	this.afterImagesLoading = function afterImagesLoading(){		// call back function // 
		var i=$(this);
		var pV = i.data('panView');

		// pobranie oryginalnych wymiarów obrazka
		pV.orgWidth = i.width();
		pV.orgHeight = i.height();

		// ustawienie wysokości
		pV.zoomFactor( pV.boxHeight / pV.orgHeight );
		pV.jImg.fadeIn('slow', pV.afterFadingIn);
	}

	this.afterFadingIn = function afterFadingIn(){		// call back function //
		var pV=$(this).data('panView');
		pV.jImg2.show();
		pV.startMoving();
		pV.jMainElement.css('background','none');
	}

	this.loopMoving = function loopMoving(){			// call back function  or normal(object) function //
		var pV = (this.name=='panView')?(this):($(this).data('panView'));

		if (pV)	{
			if (pV.direction==1){ // rotacja w prawo
				pV.jImg.css('margin-left','0px');
				pV.jImg.animate({'marginLeft': (pV.realWidth * -1) + 'px'},pV.realWidth * pV.movingSpeed,'linear'); //, pV.loopMoving);
			} else if(pV.direction==-1){ // rotacja w lewo
				pV.jImg.css('margin-left', (pV.realWidth * -1) + 'px');
				pV.jImg.animate({'marginLeft': '0px'}, pV.realWidth * pV.movingSpeed,'linear'); //,  pV.loopMoving);
			}
		}
	}

	this.afterMouseUp = function afterMouseUp(){		// call back function //

		var pV = $(this).data('panView'); 
		if (pV.mouseMoving) {
			pV.mouseMoving = false;
			$(this).css('cursor','default');

	//		if (!pV.stoped) pV.startMoving(true);
			if (!pV.stoped) pV.stopMoving();

			// clear selection - required by FireFox
			if(document.selection && document.selection.empty){
				document.selection.empty() ;
			} else if(window.getSelection) {
				var sel=window.getSelection();
				if(sel && sel.removeAllRanges) sel.removeAllRanges() ;
			}
		}
	}

	this.stopMoving = function stopMoving( ){
		this.jImg.stop();
		this.stoped = true;
	}

	this.startRotate = function startRotate(dir){
		if (dir=='left') this.direction=-1;
		if (dir=='right') this.direction=1;
		this.stopMoving();
		this.startMoving();
	}

	this.startMoving = function startMoving( opt ){ 
		if (this.stoped || (opt===true)){ 
			if (this.direction==1){ // rotacja w prawo
				var rest = (this.realWidth + parseInt(this.jImg.get(0).style.marginLeft)) * this.movingSpeed; 
				this.jImg.animate({'marginLeft': (this.realWidth * -1) + 'px'},rest,'linear', this.loopMoving);
			} else if(this.direction==-1){  // rotacja w lewo
				var rest = - parseInt(this.jImg.get(0).style.marginLeft) * this.movingSpeed;
				if (rest>0){
					this.jImg.animate({'marginLeft': '0px'},rest,'linear', this.loopMoving);
				} else {
					this.loopMoving();
				}
			}
			this.stoped = false;
		}
	}

	this.zoomFactor = function zoomFactor( factor ) {

		if (typeof factor == 'undefined'){
			return this.actualFactor;
		} else {
			if (factor<this.boxHeight / this.orgHeight) factor = this.boxHeight / this.orgHeight;
			if (factor>this.maxFactor) factor = this.maxFactor;

			this.jImg.stop();
			var x = this.cameraPositionX();
			var y = this.cameraPositionY();

			this.realWidth = this.orgWidth * factor;
			this.realHeight = this.orgHeight * factor;

			this.jImg.width( this.realWidth); 
			this.jImg2.width( this.realWidth);

			this.actualFactor = factor;
			this.cameraPositionX( x ); 
			this.cameraPositionY( y ); 

			if (!this.stoped) this.startMoving(true);
		}
	}

		this.zoomPlus = function zoomPlus( f ){ 
		this.zoomFactor( this.actualFactor * f );
	}

	this.zoomMinus = function zoomMinus( f ){ 
		this.zoomFactor( this.actualFactor * ( 1 / f ) );
	}

	this.cameraPositionX = function cameraPositionX( x ){
		if (typeof x == 'undefined'){
			var x=((this.boxWidth/2)-parseFloat(this.jImg.get(0).style.marginLeft))/this.realWidth;
			return (x>1)?x-1:x;
		} else {
			if (!isNaN(x)) this.setMarginLeft( (this.boxWidth/2)-(x*this.realWidth) );
		}
	}

	this.cameraPositionY = function cameraPositionY( y ){
		if (typeof y == 'undefined'){
			var y=((this.boxHeight/2)-parseFloat(this.jImg.get(0).style.marginTop))/this.realHeight;
			return (y>1)?y-1:y;
		} else {
			if (!isNaN(y)){
				this.setMarginTop( (this.boxHeight/2) - (y*this.realHeight) );
			}
		}
	}

	this.setMarginTop = function setMarginTop( top ) {
		if (top > 0) top = 0;
		if (top < this.boxHeight - this.realHeight) top = this.boxHeight - this.realHeight;
		this.jImg.css( 'margin-top', top + 'px');
		this.jImg2.css( 'margin-top', top + 'px' );
	}

	this.setMarginLeft = function setMarginLeft( left ) {
		if (left > 0) left = left - this.realWidth;
		if (left < -this.realWidth) left=left + this.realWidth;
		this.jImg.css( 'margin-left', left + 'px' );
	}

	this.destroy = function destroy() {
		this.jMainElement.empty().attr('style','');
		this.stopMoving();
	}

	this.jMainElement = e.eq(0);
	this.boxWidth = this.jMainElement.width();
	this.boxHeight = this.jMainElement.height();
		
	this.jImg = $(document.createElement("img"));
	this.jImg2 = $(document.createElement("img"));
	this.innerDIV =	$(document.createElement("div"));
	this.eventDIV =	$(document.createElement("div"));

	this.jMainElement.css('position','relative');
	this.eventDIV.appendTo( this.jMainElement ).css({'background-color':'white','width':this.jMainElement.width()+'px','height':this.jMainElement.height()+'px','z-index':'10','position':'absolute'}).fadeTo(100, 0);
	this.innerDIV.appendTo( this.jMainElement ).css('width','60000px');

	this.jImg.appendTo( this.innerDIV );
	this.jImg2.appendTo( this.innerDIV );

	this.jImg.data('panView',this);
	this.jImg.attr( 'src',name ).css({'margin-left':'0px','margin-top':'0px', 'display':'none', 'float':'left'}).load(this.afterImagesLoading);
	this.jImg2.attr( 'src',name ).css({'margin-top':'0px','display':'none', 'float':'left'});

	this.eventDIV.data('panView',this).mousedown(function( event ){	// call back function //
		var pV = $(this).data('panView'); 
		pV.jImg.stop();
		pV.mouseMoving = true;
		pV.lastMouseX = event.pageX;
		pV.lastMouseY = event.pageY;
		$(this).css('cursor','move');
	}).mousemove(function( event ){	// call back function //
		var pV = $(this).data('panView'); 
		var deltaX = pV.lastMouseX - event.pageX;		
		var deltaY = pV.lastMouseY - event.pageY;		
		pV.lastMouseX = event.pageX;
		pV.lastMouseY = event.pageY;

		if (pV.mouseMoving)	{
			var mt = parseFloat( pV.jImg.get(0).style.marginTop ) - deltaY;
			var ml = parseFloat( pV.jImg.get(0).style.marginLeft) - deltaX;
			pV.setMarginLeft( ml );
			pV.setMarginTop( mt );
		}
	}).mouseup(this.afterMouseUp).mouseout(this.afterMouseUp);
}