
N = (document.all) ? 0 : 1;
var ob;
var over = false;



function MD(e) {
	if (over)
	{
		if (N) {
			ob = document.getElementById("myimage");
			var pElement = document.getElementById("PicturePanel").offsetParent
			
			X=e.layerX + (pElement.offsetLeft);
			Y=e.layerY + (pElement.offsetTop);
			return false;
		}
		else {
			ob = document.getElementById("myimage");
			ob = ob.style;
			
			var pElement = document.all.PicturePanel.offsetParent
			X=event.offsetX + (pElement.offsetLeft + 2);
			Y=event.offsetY + (pElement.offsetTop + 2);
			
			//window.alert(event.offsetX+" _ "+event.offsetY)
		}
	}
}

function MM(e) {
	if (ob) {
		if (N) {
			getPictureSize();
			
			//ob.style.top = e.pageY-Y;
			//ob.style.left = e.pageX-X;
			
			
			if( (e.clientX-X+document.body.scrollLeft) <= 0 && (e.clientY-Y+document.body.scrollTop) <= 0 &&
				(X-(MyImageWidth-ScreenWidth)) <= (e.clientX+document.body.scrollLeft) && (Y-(MyImageHeight-ScreenHeight)) <= (e.clientY+document.body.scrollTop) )
			{
				ob.style.left = e.clientX-X + document.body.scrollLeft;
				ob.style.top = e.clientY-Y + document.body.scrollTop;
			}
			else if( (e.clientX-X+document.body.scrollLeft) > 0 )
			{
				ob.style.left = 0;
				if( (e.clientY-Y+document.body.scrollTop) <= 0 && (Y-(MyImageHeight-ScreenHeight)) <= (e.clientY+document.body.scrollTop) )
					ob.style.top = e.clientY-Y + document.body.scrollTop;
			}
			else if( (e.clientY-Y+document.body.scrollTop) > 0 )
			{
				if( (e.clientX-X+document.body.scrollLeft) <= 0 && (X-(MyImageWidth-ScreenWidth)) <= (e.clientX+document.body.scrollLeft) )
					ob.style.left = e.clientX-X + document.body.scrollLeft;
				ob.style.top = 0;
			}
			else if( (X-(MyImageWidth-ScreenWidth)) > (e.clientX+document.body.scrollLeft) )
			{
				ob.style.left = ScreenWidth-MyImageWidth;
				if( (e.clientY-Y+document.body.scrollTop) <= 0 && (Y-(MyImageHeight-ScreenHeight)) <= (e.clientY+document.body.scrollTop) )
					ob.style.top = e.clientY-Y + document.body.scrollTop;
			}
			else if( (Y-(MyImageHeight-ScreenHeight)) > (e.clientY+document.body.scrollTop) )
			{
				if( (e.clientX-X+document.body.scrollLeft) <= 0 && (X-(MyImageWidth-ScreenWidth)) <= (e.clientX+document.body.scrollLeft) )
					ob.style.left = e.clientX-X + document.body.scrollLeft;
				ob.style.top = ScreenHeight-MyImageHeight;
			}
			return false;
			
			
		}
		else 
		{
			getPictureSize();
			
			if( (event.clientX-X+document.body.scrollLeft) <= 0 && (event.clientY-Y+document.body.scrollTop) <= 0 &&
				(X-(MyImageWidth-ScreenWidth)) <= (event.clientX+document.body.scrollLeft) && (Y-(MyImageHeight-ScreenHeight)) <= (event.clientY+document.body.scrollTop) )
			{
				ob.pixelLeft = event.clientX-X + document.body.scrollLeft;
				ob.pixelTop = event.clientY-Y + document.body.scrollTop;
			}
			else if( (event.clientX-X+document.body.scrollLeft) > 0 )
			{
				ob.pixelLeft = 0;
				if( (event.clientY-Y+document.body.scrollTop) <= 0 && (Y-(MyImageHeight-ScreenHeight)) <= (event.clientY+document.body.scrollTop) )
					ob.pixelTop = event.clientY-Y + document.body.scrollTop;
			}
			else if( (event.clientY-Y+document.body.scrollTop) > 0 )
			{
				if( (event.clientX-X+document.body.scrollLeft) <= 0 && (X-(MyImageWidth-ScreenWidth)) <= (event.clientX+document.body.scrollLeft) )
					ob.pixelLeft = event.clientX-X + document.body.scrollLeft;
				ob.pixelTop = 0;
			}
			else if( (X-(MyImageWidth-ScreenWidth)) > (event.clientX+document.body.scrollLeft) )
			{
				ob.pixelLeft = ScreenWidth-MyImageWidth;
				if( (event.clientY-Y+document.body.scrollTop) <= 0 && (Y-(MyImageHeight-ScreenHeight)) <= (event.clientY+document.body.scrollTop) )
					ob.pixelTop = event.clientY-Y + document.body.scrollTop;
			}
			else if( (Y-(MyImageHeight-ScreenHeight)) > (event.clientY+document.body.scrollTop) )
			{
				if( (event.clientX-X+document.body.scrollLeft) <= 0 && (X-(MyImageWidth-ScreenWidth)) <= (event.clientX+document.body.scrollLeft) )
					ob.pixelLeft = event.clientX-X + document.body.scrollLeft;
				ob.pixelTop = ScreenHeight-MyImageHeight;
			}
			return false;
		}
   }
}

function MU() {
	ob = null;
}

if (N) {
	document.captureEvents(Event.MOUSEDOWN | Event.MOUSEMOVE | Event.MOUSEUP);
}
document.onmousedown = MD;
document.onmousemove = MM;
document.onmouseup = MU;






var zoomfactor=0.15 //Enter factor (0.05=5%)
var ZoomCount=0;
var KeepState = '';
var clickStatus = '';
var ClickXPoint = 0, ClickYPoint = 0;

function zoomhelper(){

		TemWidth  = parseInt( whatcache.style.width ) * zoomfactor * prefix;
		TemHeight = parseInt( whatcache.style.height ) * zoomfactor * prefix;
		
		if( ZoomCount < 10 )
		{
			ZoomCount++;
			TemWidth /= 10;
			TemHeight /= 10;
			whatcache.style.width  = parseInt( whatcache.style.width )  + TemWidth;
			whatcache.style.height = parseInt( whatcache.style.height ) + TemHeight;
			
			
			
			if( whatcache.style.left == "" && whatcache.style.top == "" )
			{
				whatcache.style.left = TemWidth / 2;
				whatcache.style.top =  TemHeight / 2;
				//window.alert(KeepState);
			}
			else
			{
				if( KeepState == 'in' )
				{
					
					if( clickStatus == 'doubleClick' )
					{
						//window.alert(event.offsetX+" _ ")
						
						//FrontXPoint = ClickXPoint;
						//EndXPoint = ScreenWidth - ClickXPoint;
						XMoveTotal = ClickXPoint / parseInt( whatcache.style.width ) * TemWidth;
						//ClickXPoint -= XMoveTotal;
						
						//FrontYPoint = ClickYPoint;
						//EndYPoint = ScreenHeight - ClickYPoint;
						YMoveTotal = ClickYPoint / parseInt( whatcache.style.height ) * TemHeight;
						
						whatcache.style.left = parseInt( whatcache.style.left ) - parseInt( XMoveTotal );
						whatcache.style.top = parseInt( whatcache.style.top ) - parseInt( YMoveTotal );
						
					}
					else
					{
						//whatcache.style.left = parseInt( whatcache.style.left ) - parseInt( XMoveTotal );
						//whatcache.style.top = parseInt( whatcache.style.top ) - parseInt( YMoveTotal );
						whatcache.style.left = parseInt( whatcache.style.left ) - ( TemWidth / 2 );
						whatcache.style.top = parseInt( whatcache.style.top ) - ( TemHeight/2 );
					}
				}
				else if( KeepState == 'out' )
				{
					//window.alert(whatcache.style.left+" "+whatcache.style.width);
					PictureXPoint = parseInt( whatcache.style.left );
					PictureXLPoint = parseInt( whatcache.style.left ) + parseInt( whatcache.style.width );
					
					LeftWidth = 0 - PictureXPoint;
					RightWidth = PictureXLPoint - ScreenWidth;
					TotalWidth = LeftWidth + RightWidth;
					LeftMoveWidth = ( LeftWidth / TotalWidth ) * ( TemWidth );
					whatcache.style.left = parseInt( whatcache.style.left ) - LeftMoveWidth;
					
					
					PictureYPoint = parseInt( whatcache.style.top );
					PictureYLPoint = parseInt( whatcache.style.top ) + parseInt( whatcache.style.height );
					TopHeight = 0 - PictureYPoint;
					BottomHeight = PictureYLPoint - ScreenHeight;
					TotalHeight = TopHeight + BottomHeight;
					TopMovePoint = ( TopHeight / TotalHeight ) * ( TemHeight )
					whatcache.style.top = parseInt( whatcache.style.top ) - TopMovePoint;
				}
			}
			setTimeout( zoomhelper, 40 );
		}
		
		//window.alert(whatcache.style.width);
		
}

function zoom( what, state, obj, clickTime ){
	
	clickStatus = clickTime;
	configure();
	if(!document.all&&!document.getElementById)
		return

		whatcache=eval("document.images."+what)
		prefix=(state=="in")? 1 : -1
		KeepState = state;
		
	if( whatcache.style.width=="" || state=="restore" ) {
		whatcache.style.width=originalW
		whatcache.style.height=originalH
		
		if (state=="restore")
		{
			whatcache.style.top = 0
			whatcache.style.left = 0
			return
		}
	} 
	else {
		
		if( (parseInt( whatcache.style.width )  + parseInt( whatcache.style.width )  * zoomfactor * prefix) > parseInt( originalW ) &&
		    (parseInt( whatcache.style.height ) + parseInt( whatcache.style.height ) * zoomfactor * prefix) > parseInt( originalH ) )
		{
			ZoomCount = 0;
			if( clickStatus == 'doubleClick' )
			{
				ClickXPoint = event.offsetX;
				ClickYPoint = event.offsetY;
			}
			zoomhelper();
		}
		else
		{
			whatcache.style.width = parseInt( originalW )
			whatcache.style.height = parseInt( originalH )
			if( state=="out" )
			{
				whatcache.style.top=0
				whatcache.style.left=0
			}
		}
	}
}

function clearzoom(){
	if ( window.beginzoom )
		clearInterval( beginzoom )
}

function configure(){
	originalW = 396;
	originalH = 378;
	
	ScreenWidth = 396;
	ScreenHeight = 378;
}

function getPictureSize(){
	configure();
	MyImageWidth = document.getElementById("myimage").width;
	MyImageHeight = document.getElementById("myimage").height;
}



this.mouseCoords = function(ev) {
        if(ev.pageX || ev.pageY){
            return {x:ev.pageX, y:ev.pageY};
        }
        return {
            x:ev.clientX + document.body.scrollLeft - document.body.clientLeft,
            y:ev.clientY + document.body.scrollTop  - document.body.clientTop
        };
    }
