		function mandelBrot() {
			this.hzoom_default=2.6; //zooms horizontally -- the smaller the factor the bigger the scale
			this.vzoom_default=2.4; //zooms vertically -- the smaller the factor the bigger the scale
			this.xorig_default=-2.05;
			this.yorig_default=-1.2; //setting the origin on the complex plane
							//These four parameters define the region of the complex plane we are going to explore
			this.hzoom_current=this.hzoom_default;
			this.vzoom_current=this.vzoom_default;
			this.xorig_current=this.xorig_default;
			this.yorig_current=this.yorig_default;

			this.hzoom_previous=this.hzoom_default;
			this.vzoom_previous=this.vzoom_default;
			this.xorig_previous=this.xorig_default;
			this.yorig_previous=this.yorig_default;

			this.xunit= function() {return this.hzoom_current/223;}
			this.yunit= function() {return this.vzoom_current/195;}
			
			this.get_str = function() {return "x="+this.xorig_current+"\&y="+this.yorig_current+"\&hz="+this.hzoom_current+"\&vz="+this.vzoom_current;}
			this.temparray= new Array();
			
			this.mode = null;
			
		}
		var MB_object = new mandelBrot();
		
		
		
		function MB_scale(e) {
			var x,y;
			if(!e) var e=event;
			if(e.cancelBubble) { e.cancelBubble(); e.returnValue=false;}
			else if(e.preventDefault) { e.preventDefault(); e.stopPropagation(); }

			if(e.offsetX) {
				x=e.offsetX;
				y=e.offsetY;
			} else { 
				x=e.clientX-(parseInt(e.target.style.left)+parseInt(getObject('mandeldiv').style.left));
				y=e.clientY-(parseInt(e.target.style.top)+parseInt(getObject('mandeldiv').style.top));	
			} 
			m=getObject("mbrot1");
		
			if(e.type=='mousedown') {
				if(document.addEventListener) {
					m.addEventListener("mousemove",MB_scale,true);
				} else if(document.attachEvent) {
					m.attachEvent("onmousemove",MB_scale);
				} else {
					m.onmousemove = MB_scale;
				}				
				MB_object.temparray = new Array();
				MB_object.temparray[0]=x;
				MB_object.temparray[1]=y;
			} else if(e.type=='mouseup') {
				if(document.removeEventListener) {
					m.removeEventListener("mousemove",MB_scale,true);
				} else if(document.detachEvent) {
					m.detachEvent("onmousemove",MB_scale);
				} else {
					m.onmousemove = document.onmousemove;
				}				
				if(MB_object.temparray[0]<=x) MB_object.temparray[2]=x;
				else { 
					MB_object.temparray[2]=MB_object.temparray[0];
					MB_object.temparray[0]=x;
					}
				if(MB_object.temparray[1]<=y) MB_object.temparray[3]=y;
				else { 
					MB_object.temparray[3]=MB_object.temparray[1];
					MB_object.temparray[1]=y;
					}
				getObject('zbutt').style.visibility = 'visible';
			}
				if(e.stopPropagation) e.stopPropagation();
				else e.cancelBubble=true;
				
				if(e.preventDefault) e.preventDefault();
				else e.returnValue = false;
		}
		
		function MB_zoom(npd) {

			if(npd=='default') {
				//assign current to previous			
				MB_object.xorig_previous=MB_object.xorig_current;
				MB_object.yorig_previous=MB_object.yorig_current;
				MB_object.hzoom_previous=MB_object.hzoom_current;
				MB_object.vzoom_previous=MB_object.vzoom_current;

				//assign default to current for get string
				MB_object.xorig_current=MB_object.xorig_default;
				MB_object.yorig_current=MB_object.yorig_default;
				MB_object.hzoom_current=MB_object.hzoom_default;
				MB_object.vzoom_current=MB_object.vzoom_default;
				MB_object.mode='default';
				
				document.mbrot.src="furniture/mb_fullset.<?= $png ? 'png' : 'jpg' ?>";
			
			} else {
				if(npd=='new') {
					//assign current to previous			
					MB_object.xorig_previous=MB_object.xorig_current;
					MB_object.yorig_previous=MB_object.yorig_current;
					MB_object.hzoom_previous=MB_object.hzoom_current;
					MB_object.vzoom_previous=MB_object.vzoom_current;

					//assign tmps to current for get string
					MB_object.xorig_current=MB_object.xorig_current+(MB_object.temparray[0]*MB_object.xunit());
					MB_object.yorig_current=MB_object.yorig_current+(MB_object.temparray[1]*MB_object.yunit());
					MB_object.hzoom_current=MB_object.xunit()*(MB_object.temparray[2]-MB_object.temparray[0]);
					MB_object.vzoom_current=MB_object.yunit()*(MB_object.temparray[3]-MB_object.temparray[1]);
					getObject('zbutt').style.visibility = 'hidden';
					MB_object.mode='new';
				}
				else if(npd=='previous') {
					//assign previous to current for get string
					MB_object.xorig_current=MB_object.xorig_previous;
					MB_object.yorig_current=MB_object.yorig_previous;
					MB_object.hzoom_current=MB_object.hzoom_previous;
					MB_object.vzoom_current=MB_object.vzoom_previous;
					MB_object.mode='previous';
				}
				
				MB_object.temparray = new Array();
				document.mbrot.src="furniture/mbrot.php?"+MB_object.get_str();
			}
		}

		function MB_load() {
			switch(MB_object.mode) {
				case 'default': getObject('zbutt').style.visibility = 'hidden';
							getObject('dbutt').style.visibility = 'hidden';
							getObject('pbutt').style.visibility = 'visible'; break;
				case 'new': getObject('zbutt').style.visibility = 'hidden'; 
							getObject('dbutt').style.visibility = 'visible';
							getObject('pbutt').style.visibility = 'visible'; break;
				case 'previous': getObject('pbutt').style.visibility = 'hidden';
							getObject('dbutt').style.visibility = 'visible';
			}
		}
			
