sj_resource = new Object();
sj_resource.getResource  = function(inString){
var res = inString;
	for (var key in this) {
		if (typeof key == 'string') {
			var old;
			do {
				old = res
				res = res.replace('%' + key + '%', this[key]);
			} while (old != res);
		}
	}

	return res;
} 


sj_resource.NOT_FOUND = "Not found";
sj_resource.INVALID_PARAMETER = "Invalid parameter";
sj_resource.IMAGE_IS_NOT_SPECIFIED = "image is not specified";
sj_resource.CONTEXT_PROCESSING_FAILED = "context processing FAILED";
sj_resource.ERROR = "Error";
sj_resource.THERE_WAS_A_PROBLEM_RETRIEVING_DATA = "There was a problem retrieving data";
sj_resource.ERROR_LOADING_CONTEXT = "Error loading context";
sj_resource.PROBLEMS = "Problems";
sj_resource.HANDLER_COULD_NOT_BE_ATTACHED = "Handler could not be attached";
sj_resource.HANDLER_COULD_NOT_BE_REMOVED = "Handler could not be removed";


function S7ConfigObject(inVersion,inViewerRoot,inRoot)
{
	this.isVersion		= inVersion || "2.8";
	this.isViewerRoot	= inViewerRoot || "/is-viewers";
	this.isRoot		= inRoot || "/is/image/";
}

var S7Config		= new S7ConfigObject();

var sjroot		= S7Config.isViewerRoot;
var sjimageServer	= S7Config.isRoot;




function SjDetectBrowser() {
   var ua = navigator.userAgent.toLowerCase(); 

   // browser engine name
   this.isGecko       = (ua.indexOf('gecko') != -1 && ua.indexOf('safari') == -1);
   this.isAppleWebKit = (ua.indexOf('applewebkit') != -1);

   // browser name
   this.isKonqueror   = (ua.indexOf('konqueror') != -1); 
   this.isWebTV       = (ua.indexOf('webtv') != -1); 
   this.isSafari      = (ua.indexOf('safari') != - 1);
   this.isOmniweb     = (ua.indexOf('omniweb') != - 1);
   this.isOpera       = (ua.indexOf('opera') != -1); 
   this.isIcab        = (ua.indexOf('icab') != -1); 
   this.isAol         = (ua.indexOf('aol') != -1); 
   this.isIE          = (ua.indexOf('msie') != -1 && !this.isOpera && (ua.indexOf('webtv') == -1) ); 
   this.isMozilla     = (this.isGecko && ua.indexOf('gecko/') + 14 == ua.length);
   this.isFirebird    = (ua.indexOf('firebird/') != -1);
   this.isNS          = ( (this.isGecko) ? (ua.indexOf('netscape') != -1) : 
                        ( (ua.indexOf('mozilla') != -1) && 
				!this.isOpera && 
				!this.isSafari && 
				(ua.indexOf('spoofer') == -1) 
				&& (ua.indexOf('compatible') == -1) 
				&& (ua.indexOf('webtv') == -1) 
				&& (ua.indexOf('hotjava') == -1) ) );
   
   // spoofing and compatible browsers
   this.isIECompatible = ( (ua.indexOf('msie') != -1) && !this.isIE);
   this.isNSCompatible = ( (ua.indexOf('mozilla') != -1) && !this.isNS && !this.isMozilla);
   
   // rendering engine versions
   this.geckoVersion = ( (this.isGecko) ? ua.substring( (ua.lastIndexOf('gecko/') + 6), (ua.lastIndexOf('gecko/') + 14) ) : -1 );
   this.equivalentMozilla = ( (this.isGecko) ? parseFloat( ua.substring( ua.indexOf('rv:') + 3 ) ) : -1 );
   this.appleWebKitVersion = ( (this.isAppleWebKit) ? parseFloat( ua.substring( ua.indexOf('applewebkit/') + 12) ) : -1 );
   
   // browser version
   this.versionMinor = parseFloat(navigator.appVersion); 
   
   // correct version number
   if (this.isGecko && !this.isMozilla) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('/', ua.indexOf('gecko/') + 6) + 1 ) );
   }
   else if (this.isMozilla) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('rv:') + 3 ) );
   }
   else if (this.isIE && this.versionMinor >= 4) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('msie ') + 5 ) );
   }
   else if (this.isKonqueror) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('konqueror/') + 10 ) );
   }
   else if (this.isSafari) {
      this.versionMinor = parseFloat( ua.substring( ua.lastIndexOf('safari/') + 7 ) );
   }
   else if (this.isOmniweb) {
      this.versionMinor = parseFloat( ua.substring( ua.lastIndexOf('omniweb/') + 8 ) );
   }
   else if (this.isOpera) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('opera') + 6 ) );
   }
   else if (this.isIcab) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('icab') + 5 ) );
   }
   
   this.versionMajor = parseInt(this.versionMinor); 
   
   // dom support
   this.isDOM1 = (document.getElementById);
   this.isDOM2Event = (document.addEventListener && document.removeEventListener);
   
   // css compatibility mode
   this.mode = document.compatMode ? document.compatMode : 'BackCompat';

   // platform
   this.isWin    = (ua.indexOf('win') != -1);
   this.isWin32  = (this.isWin && ( ua.indexOf('95') != -1 || ua.indexOf('98') != -1 || ua.indexOf('nt') != -1 || ua.indexOf('win32') != -1 || ua.indexOf('32bit') != -1 || ua.indexOf('xp') != -1) );
   this.isMac    = (ua.indexOf('mac') != -1);
   this.isUnix   = (ua.indexOf('unix') != -1 || ua.indexOf('sunos') != -1 || ua.indexOf('bsd') != -1 || ua.indexOf('x11') != -1)
   this.isLinux  = (ua.indexOf('linux') != -1);
   
   // specific browser shortcuts
   this.isNS4x = (this.isNS && this.versionMajor == 4);
   this.isNS40x = (this.isNS4x && this.versionMinor < 4.5);
   this.isNS47x = (this.isNS4x && this.versionMinor >= 4.7);
   this.isNS4up = (this.isNS && this.versionMinor >= 4);
   this.isNS6x = (this.isNS && this.versionMajor == 6);
   this.isNS6up = (this.isNS && this.versionMajor >= 6);
   this.isNS7x = (this.isNS && this.versionMajor == 7);
   this.isNS7up = (this.isNS && this.versionMajor >= 7);
   
   this.isIE4x = (this.isIE && this.versionMajor == 4);
   this.isIE4up = (this.isIE && this.versionMajor >= 4);
   this.isIE5x = (this.isIE && this.versionMajor == 5);
   this.isIE55 = (this.isIE && this.versionMinor == 5.5);
   this.isIE5up = (this.isIE && this.versionMajor >= 5);
   this.isIE6x = (this.isIE && this.versionMajor == 6);
   this.isIE6up = (this.isIE && this.versionMajor >= 6);
   
   this.isIE4xMac = (this.isIE4x && this.isMac);

   this.hasAll					= (document.all)		     ? true : false;	// document.all
   this.hasAnchors				= (document.anchors)		 ? true : false;	// document.anchors
   this.hasCookies				= (document.cookie)			 ? true : false;	// cookies enabled
   this.hasDocumentElement		= (document.documentElement) ? true : false;	// document.documentElement
   this.hasForms				= (document.forms)			 ? true : false;	// document.forms
   this.hasFrames	   			= (window.frames)			 ? true : false;	// window.frames
   this.hasGetElementById  		= (document.getElementById)	 ? true : false;	// document.getElementById
   this.hasGetElementsByTagName	= (document.getElementsByTagName) ? true : false;	// document.getElementsByTagName
   this.hasImages	   			= (document.images)			 ? true : false;	// document.images
   this.hasJava		   			= navigator.javaEnabled();						// Java enabled
   this.hasLayers	   			= (document.layers)			 ? true : false;	// document.layers
   this.hasLinks	   			= (document.links)		     ? true : false;	// document.links
   this.hasOption	   			= (window.Option)		     ? true : false;	// window.Option
   this.hasRegexp	   			= (window.RegExp)		     ? true : false;	// window.RegExp
   this.hasScreen	   			= (window.screen)		     ? true : false;	// window.screen
   
}

// utility function called by getCookie( )
SjDetectBrowser.prototype.getCookieVal=function(offset){
   var endstr = document.cookie.indexOf (";", offset);
    if (endstr == -1) {
        endstr = document.cookie.length;
    }
    return unescape(document.cookie.substring(offset, endstr));
}

SjDetectBrowser.prototype.fixCookieDate=function(date){
   var base=new Date(0);
   var skew=base.getTime();
   if(skew>0)date.setTime(date.getTime()-skew);
}

// primary function to retrieve cookie by name
SjDetectBrowser.prototype.getCookie=function(name){
  var arg = name + "=";
    var alen = arg.length;
    var clen = document.cookie.length;
    var i = 0;
    while (i < clen) {
        var j = i + alen;
        if (document.cookie.substring(i, j) == arg) {
            return this.getCookieVal(j);
        }
        i = document.cookie.indexOf(" ", i) + 1;
        if (i == 0) break; 
    }
    return "";
}

// store cookie value with optional details as needed
SjDetectBrowser.prototype.setCookie=function (name,value,expires,path,domain,secure){
   document.cookie = name + "=" + escape (value) +
        ((expires) ? "; expires=" + expires : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

// remove the cookie by setting ancient expiration date
SjDetectBrowser.prototype.deleteCookie=function (name,path,domain){
    if (this.getCookie(name)) {
        document.cookie = name + "=" +
            ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") +
            "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}

var sjIS = new SjDetectBrowser();
var sjDetectBrowserIncluded = true;


if(Array.prototype.push && ([0].push(true)==true))
	Array.prototype.push = null;

if(!Array.prototype.push) {
	function array_push() {
		for(var i=0;i<arguments.length;i++){
			this[this.length]=arguments[i]
		};
		return this.length;
	}
	Array.prototype.push = array_push;
}

if(!Array.prototype.pop) {
	function array_pop(){
	    lastElement = this[this.length-1];
		this.length = Math.max(this.length-1,0);
	    return lastElement;
	}
	Array.prototype.pop = array_pop;
}


String.prototype.doubleNewlines = function() { 
	return this.replace( /(\r?\n|\r){1,2}/g, '\n\n' ); 
}

function sjPBreak(str) {
	return( (str.indexOf("?")>=0?"&":"?") );
};

sjDelimList = [' ', '\n', '\r'];

function sjGetKeyValue(inS, inKey) {
	var keyIdx = inS.indexOf(inKey);
	if (keyIdx == -1) {
		return null;
	}
	var eqIdx = inS.indexOf('=', keyIdx + inKey.length);
	if (eqIdx == -1) {
		return null;
	}
	var valStartIdx = eqIdx + 1;
	while ((valEndIdx < inS.length) && (inS.charAt(valStartIdx) == ' ')) {
		valStartIdx ++;
	}
	if (valStartIdx >= inS.length - 1) {
		return null;
	}
	var valEndIdx = valStartIdx + 1;
	while ((valEndIdx < inS.length) && !sjIsLineDelim(inS.charAt(valEndIdx))) {
		valEndIdx ++;
	}
	return inS.substring(valStartIdx+1, valEndIdx);
};

function sjIsLineDelim(inChar) {
	for (var i = 0; i < sjDelimList.length; i ++) {
		if (inChar == sjDelimList[i]) {
			return true;
		}
	}
	return false;
};

function sjGetElement(name) {
   if(typeof(name)!='string') return name;
   if (document.getElementById) 
	   return document.getElementById(name);
   else if (document.all) 
	   return document.all[name];
   else if (document.layers) 
	   return document[name];
   else name=null;
   return name;
}

function sjGetElementDoc(name) {
   if (document.getElementById) 
	   return document.getElementById(name).ownerDocument;
   else if (document.all) 
	   return document.all[name].document;
   else if (document.layers) 
	   return document[name].document;
   else name=null;
   return name;
}

function sjGetElementStyle(name) {
   if (document.getElementById) 
	   return document.getElementById(name).style;
   if (document.all) 
	   return document.all[name].style;
   if (document.layers) 
	   return document[name];
}

function sjGetObj(name){
  if (document.getElementById){
  	this.obj = document.getElementById(name);
	this.style = document.getElementById(name).style;
  }else if (document.all){
	this.obj = document.all[name];
	this.style = document.all[name].style;
  }else if (document.layers){
   	this.obj = document.layers[name];
   	this.style = document.layers[name];
  }
}

function sjGetTextContent(inNode) {
	var s = '';
	var children = inNode.childNodes;
	for(var i = 0; i < children.length; i++) {
		var child = children[i];
		if (child.nodeType == 3 /*Node.TEXT_NODE*/) s += child.data;
		else s += sjGetTextContent(child);
	}
	return s;
}

function sjCreateDiv(parentId,divId) {
	var parentElm = null;
      if (parentId != null) 
	    parentElm = sjGetElement(parentId);
   if (document.all) {
      if (parentElm == null) 
		  parentElm = document.body;
		 parentElm.insertAdjacentHTML('afterBegin',' <div unselectable="on" id="' + divId + 
												'" style="position:absolute;text-align:left;overflow:hidden;">'+' '+'</div> ');
   }
   else if (document.layers) {
      if (parentElm == null){
			document.layers[divId] = new Layer(0);
         } else {
			parentElm.document.layers[divId] = new Layer(0,parentElm);
         }
   }
   else if (document.getElementById) {
      if (parentElm == null)
		  parentElm = document.body;
      var tempLayer = document.createElement('div');
      tempLayer.setAttribute('id',divId);
      tempLayer.setAttribute('style','position:absolute;text-align:left;overflow:hidden;');
      parentElm.appendChild(tempLayer);
   }
}

function sjGetWidth(name) {
   if (document.getElementById) 
	   return document.getElementById(name).style.width;
   if (document.all) 
	   return document.all[name].offsetWidth;
   if (document.layers) 
	   return document[name].document.width;
}

function sjGetHeight(name) {
   if (document.getElementById) 
	   return document.getElementById(name).style.height;
   if (document.all) 
	   return document.all[name].offsetHeight;
   if (document.layers) 
	   return document[name].document.height;
}


function sjGetX(layer) {
   layer=sjGetElementStyle(layer);
   if (document.getElementById) 
	   return parseInt(layer.left);
   if (document.all) 
	   return layer.pixelLeft;
   if (document.layers) 
	   return layer.x;
}

function sjGetY(layer) {
   layer=sjGetElementStyle(layer);
   if (document.getElementById) 
	   return parseInt(layer.top);
   if (document.all) 
	   return layer.pixelTop;
   if (document.layers) 
	   return layer.y;
}

function sjSetClip(layer,x,y,t,r,b,l) {
   layer=sjGetElementStyle(layer);
   if (document.getElementById) {
      //layer.clip='rect('+t+' '+r+' '+b+' '+l+')';
      layer.clip='rect('+t+'px '+r+'px '+b+'px '+l+'px)';
   } else if (document.all) {
      layer.clip='rect('+t+'px '+r+'px '+b+'px '+l+'px)';
      layer.pixelLeft=x;
      layer.pixelTop=y;
      layer.overflow='hidden';
   } else if (document.layers) {
      layer.clip.top=t;
      layer.clip.right=r;
      layer.clip.bottom=b;
      layer.clip.left=l;
      layer.moveTo(x,y);
   }
}

function sjSetWidth(layer,w) {
   layer=sjGetElementStyle(layer);
   if (document.getElementById)
      layer.width=parseInt(w)+'px';
   else if (document.all)
      layer.posWidth=parseInt(w)+'px';
   else if (layer.clip)
      layer.clip.width=w;
}

function sjSetHeight(layer,h) {
   layer=sjGetElementStyle(layer);
   if (document.getElementById)
      layer.height=parseInt(h)+'px';
   else if (document.all)
      layer.posHeight=parseInt(h)+'px';
   else if (layer.clip)
      layer.clip.height=h;
}

function sjZoomMap (inMapName, inXfactor, inYfactor) {
	if(inMapName){
	  if (document.all) {
		var map = document.all[inMapName];
		if (map){
			var areas = map.all.tags('AREA');
		}
	  } else if (document.getElementsByName) {
		var map = document.getElementsByName(inMapName)[0];
		if (map){
			var areas = map.getElementsByTagName('AREA');
		}
	  }
	  if (areas) {
		for (var a = 0; a < areas.length; a++) {
		  //var coords = areas[a].getAttribute('origcoords').split(/\s*,\s*/);
		  var coords = areas[a].getAttribute('coords').split(/\s*,\s*/);
		  if (areas[a].getAttribute('shape').toLowerCase() == 'rect' || areas[a].getAttribute('shape').toLowerCase() == 'poly') {
			for (var p = 0; p < coords.length; p += 2) {
			  coords[p] = Math.round(coords[p] * inXfactor);
			  coords[p + 1] = Math.round(coords[p + 1] * inYfactor);
			}
		  } else if (areas[a].getAttribute('shape').toLowerCase() == 'circle') {
			coords[0] = Math.round(coords[0] * inXfactor);
			coords[1] = Math.round(coords[1] * inYfactor);
			coords[2] = Math.round(coords[2] * (inXfactor < inYfactor ? inXfactor : inYfactor));
		  }
		  //areas[a].coords = coords.join(', ');
		  areas[a].setAttribute('coords',coords.join(', '));
		}
	  }
	}
}

function sjResetMap (inMapName) {
	if(inMapName){
	  if (document.all) {
		var map = document.all[inMapName];
		if (map){
			var areas = map.all.tags('AREA');
		}
	  } else if (document.getElementsByName) {
		var map = document.getElementsByName(inMapName)[0];
		if (map){
			var areas = map.getElementsByTagName('AREA');
		}
	  }
	  if (areas) {
		for (var a = 0; a < areas.length; a++) {
		  var coords = areas[a].getAttribute('origcoords').split(/\s*,\s*/);
		  areas[a].setAttribute('coords',coords.join(', '));
		}
	  }
	}
}

function sjSetLayerHTML(layer,html) {  
   if (navigator.userAgent.indexOf('MSIE 5.0') && navigator.userAgent.indexOf('Mac') != -1) html += '\n';
   if (document.getElementById){
      document.getElementById(layer).innerHTML=html;
   } else if (document.all) {
      layer=eval(layer);
      layer.innerHTML=html;
   } else if (document.layers) {
      var doc=sjGetElementDoc(layer);
      doc.open();
      doc.writeln(html);
      doc.close();
   }	
}

function sjGetLayerHTML(layer) {
   if (document.getElementById){
      return document.getElementById(layer).innerHTML;
   } else if (document.all) {
      layer=eval(layer);
      return layer.innerHTML;
   }
}

function sjSetXY(layer,x,y) {
   layer=sjGetElementStyle(layer)
   if (document.getElementById) {
      layer.left=parseInt(x)+'px';
      layer.top=parseInt(y)+'px';
   } else if (document.all) {
      layer.pixelLeft=parseInt(x)+'px';
      layer.pixelTop=parseInt(y)+'px';
   } else if (document.layers)
      layer.moveTo(x,y);
}

function sjCenter(layer,y) { 
	sjSetXY(layer,Math.round((width-getWidth(layer)-leftMargin-rightMargin)/2)+leftMargin,y); 
}

function sjSetCursor(curtype) { 
   var ua = navigator.userAgent.toLowerCase(); 
   var isIE = (ua.indexOf('msie') != -1); 
   var isMAC = (ua.indexOf('mac') != -1); 
	document.body.style.cursor = ((!isIE || isMAC) && curtype == 'hand')? 'pointer' : curtype;
	//if (document.all) document.body.style.cursor=curtype; 
}

// value must be "visible", "hidden", or "inherit".
function sjSetVisibility (layer, value){  
   layer=sjGetElementStyle(layer);
	if (document.layers) 
	  layer.visibility = value;
   else if (layer) 
	  layer.visibility = value;
}

// return values as strings "visible", "hidden", or "inherit".
function sjGetVisibility (layer){  
   layer=sjGetElementStyle(layer);
	if (document.layers){
	 var value = layer.visibility;
	 if (value == "show") 
		return "visible";
	 else if (value == "hide") 
	 	return "hidden";
	 else return value;
   }
   else if (layer) 
	 return layer.visibility;
}

function sjGetZIndex (layer){ 
   layer=sjGetElementStyle(layer);
  if (document.layers) 
	  return(layer.zIndex);
  else if (layer) 
	  return (layer.zIndex);
}

function sjSetZIndex (layer, z){ 
   layer=sjGetElementStyle(layer);
	if (document.layers) 
		layer.zIndex = z;
	else if (layer) 
		layer.zIndex = z;
}

function sjSetBackColor (layer, color){ 
   layer=sjGetElementStyle(layer);
	if(layer.background) 
		layer.background = color;
	else if (document.layers) 
		layer.bgColor = color;  
	else if(document.all || document.getElementById) 
		layer.backgroundColor = color;
}

sjSetBackImage = function (layer, imageURL) {
   layer=sjGetElementStyle(layer);
	if(layer.background) 
		layer.background.src = imageURL == 'none' ? null : imageURL;
	else if (document.layers)
		layer.background.src = imageURL == 'none' ? null : imageURL;
	else if (document.all || document.getElementById)
		layer.backgroundImage = imageURL == 'none' ? 'none' : 'url(' + imageURL + ')';
}

function sjSetBorder (layer, width,style,color){ 
   stl=sjGetElementStyle(layer);
	stl.borderWidth = width + "px" || 0;  
	stl.borderStyle = style || 'solid';
	stl.borderColor = color || 'black';
}

function sjOpacity (layer,inOpacity) {
	if (inOpacity != null) {
		stl=sjGetElementStyle(layer);
	    if(inOpacity < 0) inOpacity = 0; 
		if(inOpacity > 99) inOpacity = 99;
		stl.opacity = (inOpacity / 100);
		stl.MozOpacity = (inOpacity / 100);
		stl.KhtmlOpacity = (inOpacity / 100);
		stl.filter = "alpha(opacity=" + inOpacity + ")";
		return stl.opacity;
	}
}

function sjGetMouseXY(e){
  var mousePos = {x: 0, y: 0};
	if (document.all) {
		mousePos.x = event.clientX + document.body.scrollLeft;
	    mousePos.y = event.clientY + document.body.scrollTop;
	} else {
        mousePos.x = e.pageX;
   	    mousePos.y = e.pageY;
	}
  return mousePos;
}

function sjGetPageCoords (element) {
  var coords = {x: 0, y: 0};
  while (element) {
    coords.x += element.offsetLeft;
    coords.y += element.offsetTop;
    element = element.offsetParent;
  }
  return coords;
}

function sjGetOffsets (evt) {
 if(evt){
  if (typeof evt.offsetX != 'undefined')
    return { x: evt.offsetX, y: evt.offsetY }
  else if (evt.target) {
    if (window.opera)
      var element = evt.target;
    else
      var element = evt.target.nodeType == 1 ? evt.target : evt.target.parentNode;
    var eventCoords = {
      x: evt.clientX + window.pageXOffset,
      y: evt.clientY + window.pageYOffset
    };
    var elCoords = sjGetPageCoords(element);
    return {x: eventCoords.x - elCoords.x, y: eventCoords.y - elCoords.y};
  }
 }
}


function sjAddObjectEvent(inObject, evType, handler, useCapture){
 var  inObject = sjGetElement(inObject.getElementId());
  if (inObject.addEventListener){
		inObject.addEventListener(evType, handler, useCapture);
    return true;
  } else if (inObject.attachEvent){
    var res = inObject.attachEvent("on"+evType, handler);
    return res;
  } else {
		//alert("Handler could not be attached");
		alert(sj_resource.getResource('%HANDLER_COULD_NOT_BE_ATTACHED%'));
  }
} 

function sjRemoveObjEvent(inObject, evType, handler, useCapture){
 var  inObject = sjGetElement(inObject.getElementId());
  if (inObject.removeEventListener){
		inObject.removeEventListener(evType, handler, useCapture);
    return true;
  } else if (inObject.detachEvent){
    var res = inObject.detachEvent("on"+evType, handler);
    return res;
  } else {
		//alert("Handler could not be removed");
		alert(sj_resource.getResource('%HANDLER_COULD_NOT_BE_REMOVED%'));
  }
}

// usage :
//   addKeyHandler(document.body);
//     document.body.addKeyPress(32, function(){alert("You pressed Space");});
//or  document.body.addKeyDown(65, function(){alert('a pressed');})
//    document.body.removeKeyDown(65)
//or var counter = 0;
//   function increaseCounter() {
//     window.status = "counter = " + counter++;
//   }
//
//   document.body.addKeyPress(13, increaseCounter);document.body.addKeyPress(13, increaseCounter);
// or document.body.addKeyDown(67, function() {if (window.event.ctrlKey) alert("CTRL + C");});
// or 
//	var w, q;
//	document.body.addKeyDown(81, function() {q = true; if (q && w) window.status = "q and w is pressed";});
//	document.body.addKeyUp(81, function() {q = false; window.status = "";});
//	document.body.addKeyDown(87, function() {w = true; if (q && w) window.status = "q and w is pressed";});
//	document.body.addKeyUp(87, function() {w = false; window.status = "";});
sjAddKeyHandler = function sjAddKeyHandler(element) {
	element._keyObject = new Array();
	element._keyObject["keydown"] = new Array();
	element._keyObject["keyup"] = new Array();
	element._keyObject["keypress"] = new Array();
	
	element.addKeyDown = function (keyCode, action) {
		element._keyObject["keydown"][keyCode] = action;
	}
	
	element.removeKeyDown = function (keyCode) {
		element._keyObject["keydown"][keyCode] = null;
	}

	element.addKeyUp = function (keyCode, action) {
		element._keyObject["keyup"][keyCode] = action;
	}
	
	element.removeKeyUp = function (keyCode) {
		element._keyObject["keyup"][keyCode] = null;
	}
	
	element.addKeyPress = function (keyCode, action) {
		element._keyObject["keypress"][keyCode] = action;
	}
	
	element.removeKeyPress = function (keyCode) {
		element._keyObject["keypress"][keyCode] = null;
	}
	
	function handleEvent() {
		var type = window.event.type;
		var code = window.event.keyCode;
		
		if (element._keyObject[type][code] != null) 
			element._keyObject[type][code]();
	}
	
	element.onkeypress = handleEvent;
	element.onkeydown = handleEvent;
	element.onkeyup = handleEvent;
}

/////////////
function sjGetKey(obj,evt) {
	var key=document.all?event.keyCode:
		evt.keyCode?evt.keyCode:
		evt.charCode?evt.charCode:
		evt.which?evt.which:void 0;
  return key;
}

/////////////
//	reading the scrollBars width (depending on the OS settings).
function getScrollBarWidth (){
	try{
		var elem = document.createElement("DIV");
		elem.id = "asdf";
		elem.style.width = 100;
		elem.style.height = 100;
		elem.style.overflow = "scroll";
		elem.style.position = "absolute";
		elem.style.visibility = "hidden";
		elem.style.top = "0";
		elem.style.left = "0";
		document.body.appendChild (elem);
		scrollWidth = sjGetElement('asdf').offsetWidth - sjGetElement('asdf').clientWidth;
		document.body.removeChild (elem);
		delete elem;
	}catch (ex){
		return false;
	}
	return scrollWidth;
}
///////////
function getRowIndex (cell) {
  return document.all ? cell.parentElement.rowIndex : cell.parentNode.rowIndex;
}


function SjTextLoader() {
	this._id = SjTextLoader._cnt ++;
	this.req = null;
	this.tid=null;
	this.text=null;
	this.IFrameDoc=null;
	this.first = false;
	this.counter = 0;
	SjTextLoader.all[this._id] = this;
	if( document.childNodes && document.createElement ) {
		sjCreateDiv(null,"datadiv"+this._id);
		var dname="datadiv"+this._id;
		var lname="loader"+this._id;
		var str=' <div id='+dname+' style="position:absolute;visibility:hidden"><iframe src="about:blank" id='+lname+' name='+lname+' onload=""></iframe> </div> ';
		sjSetLayerHTML("datadiv"+this._id,str);
	}
}

SjTextLoader.prototype.load = function(inURL,firstLoading) {
	if (!firstLoading){
		if (window.XMLHttpRequest) {//native XMLHttpRequest object
			this.req = new XMLHttpRequest();
			eval('this.req.onreadystatechange = function() { SjTextLoader.all[' + this._id + ']._onLoadText(); }');
			this.req.open("GET", inURL, true);
			this.req.send(null);
		}/* else if ((window.ActiveXObject) && 
					(!(navigator.userAgent.indexOf('MSIE 5.0') && 
						navigator.userAgent.indexOf('Mac') != -1))){//IE/Windows ActiveX version
			this.req = new ActiveXObject("Microsoft.XMLHTTP");
			if (this.req) {
				eval('this.req.onreadystatechange = function() { SjTextLoader.all[' + this._id + ']._onLoadText(); }');
				this.req.open("GET", inURL, true);
				this.req.send();
			}
		}*/ else {
			var elm=sjGetElement("loader" + this._id);
			if (elm){
				if (typeof elm.src != 'undefined')
					elm.src = inURL;
				else if (typeof elm.location != 'undefined')
					elm.location = inURL;
				this.tid=setInterval(this+'.checkLoad()', 100);
			}
		} 
	}else{
		image = new Object;
		metadata = new Object;//for future
		protocol = new Object;//for future
		context = new Object;//for future
		this.first = true;
		document.write("<script language='javascript' src='" + inURL+  ",javascript'></" + "script>");
		this.tid=setInterval(this+'.checkLoad()', 100);
	}
};

SjTextLoader.prototype._onLoadText = function() {
	if (this.req.readyState == 4) {//"loaded";0 = uninitialized 1 = loading 2 = loaded 3 = interactive 4 = complete
		if (this.req.status == 200) {//"OK" Numeric code returned by server, such as 404 for "Not Found" or 200 for "OK"
			this.text = this.req.responseText;
			if (this.onLoadText){
				this.onLoadText();
			}
        } else {
            //alert("There was a problem retrieving data:\n" + this.req.statusText);
            alert(sj_resource.getResource("%THERE_WAS_A_PROBLEM_RETRIEVING_DATA%:\n") + this.req.statusText);
        }
    }
};

function dumpProps(obj,obj_name) {
	var str = "", i ="";
	for (i in obj)
	str += obj_name +"."+ i +" = "+ obj[i] +"\n";
	return str;
}

SjTextLoader.prototype.checkLoad = function() {
	if (this.first == true){
		if (image.rect) {
			this.text = dumpProps(image,"image");
			if (metadata){
				this.text += dumpProps(metadata,"metadata");
			}
			if (protocol){
				this.text += dumpProps(protocol,"protocol");
			}
			if (context){
				this.text += dumpProps(context,"context");
			}
			if (this.onLoadText){
				this.onLoadText();
			}
			this.counter = 0;
			clearInterval(this.tid);
		}else{
			if (this.counter < 100){
				this.counter++;
				//window.status = 'Loading context...'+this.counter+' attempt.';
			}else{
				//window.status = 'Error loading context!';
				//alert('Error loading context!');
				alert(sj_resource.getResource('%ERROR_LOADING_CONTEXT%!'));
				this.counter = 0;
				clearInterval(this.tid);
			}
		}
	}else{
		var elm=sjGetElement("loader" + this._id);
		if (elm != null)
		if(document.frames){
		 if(document.frames[elm.name]) { this.IFrameDoc=document.frames[elm.name].document } // For IE5
		}else if (elm.contentDocument) { this.IFrameDoc=elm.contentDocument } //For NS6
		 else if (elm.contentWindow) { this.IFrameDoc=elm.contentWindow.document } //For IE5.5
		else{
			//alert('Problems.....');
			alert(sj_resource.getResource('%PROBLEMS%.....'));
			clearInterval(this.tid);
			return true;
		}
		var inf = sjGetTextContent(this.IFrameDoc);
		if (inf){
			this.text = inf;
			if (this.onLoadText){
				this.onLoadText();
			}
			clearInterval(this.tid);
		}
	}
}

SjTextLoader.prototype.clearText = function(txt) {
	var testText = txt;
	if ((testText != null) && (testText != '')) {
	    var result = testText;
	    var teg=testText.substring(testText.indexOf("<"),testText.indexOf(">")+1);
		var idx = testText.indexOf(teg);
		while (idx != -1) {
			result = result.substring(0, idx) + '' + result.substring(idx + teg.length);
			testText=result;
		    idx=-1;
			teg=testText.substring(testText.indexOf("<"),testText.indexOf(">")+1);
			if (teg!=''){
		     idx = testText.indexOf(teg);
			 result=testText;
			}
		}
 	    
		testText=testText.replace("&lt;","<"); 
		testText=testText.replace("&gt;",">"); 
		this.text = testText;
	}
	return this.text;
}

SjTextLoader.prototype.toString = function() {
	return 'SjTextLoader.all[' + this._id + ']';
};

SjTextLoader.all = [];
SjTextLoader._cnt = 0;


//String key, Object value
function SjHashtable(){
    this.hashtable = new Array();
}                

SjHashtable.prototype.clear = function (){
    this.hashtable = new Array();
	for (var key in this.hashtable){
		this.remove(key);
	}
}

SjHashtable.prototype.containsKey = function(key){
    var exists = false;
    for (var i in this.hashtable) {
        if (i == key && this.hashtable[i] != null) {
            exists = true;
            break;
        }
    }
    return exists;
}

SjHashtable.prototype.indexOfKey = function(key){
	var result = -1;
    var exists = false;
    for (var i in this.hashtable) {
		result++;
		if (i == key){
			if( this.hashtable[i] != null) {
				exists = true;
				break;
			}
        }
    }
    return exists ? result:-1;
};

SjHashtable.prototype.containsValue = function(value){
    var contains = false;
    if (value != null) {
        for (var i in this.hashtable) {
            if (this.hashtable[i] == value) {
                contains = true;
                break;
            }
        }
    }
    return contains;
}

SjHashtable.prototype.indexOfValue = function(value){
	var result = -1;
	var contains = false;
    if (value != null) {
        for (var i in this.hashtable) {
			result++;
            if (this.hashtable[i] == value) {
                contains = true;
                break;
            }
        }
    }
    return contains ? result : -1;
};

SjHashtable.prototype.get = function(key){
    return this.hashtable[key];
}

SjHashtable.prototype.isEmpty = function(){
    return (this.size == 0) ? true : false;
}

SjHashtable.prototype.keys = function(){
    var keys = new Array();
    for (var i in this.hashtable) {
        if (this.hashtable[i] != null) 
            keys.push(i);
    }
    return keys;
}

SjHashtable.prototype.put = function(key, value){
    if (key == null || value == null) {
        throw "NullPointerException {" + key + "},{" + value + "}";
    }else{
        this.hashtable[key] = value;
    }
}

SjHashtable.prototype.remove = function(key){
    var rtn = this.hashtable[key];
    this.hashtable[key] = null;
    return rtn;
}

SjHashtable.prototype.size = function(){
    var size = 0;
    for (var i in this.hashtable){
        if (this.hashtable[i] != null) 
            size ++;
    }
    return size;
}

SjHashtable.prototype.toString = function(){
    var result = "";
    for (var i in this.hashtable){      
        if (this.hashtable[i] != null) 
            result += "{" + i + "},{" + this.hashtable[i] + "}\n";   
    }
    return result;
}

SjHashtable.prototype.values = function(){
    var values = new Array();
    for (var i in this.hashtable) {
        if (this.hashtable[i] != null) 
            values.push(this.hashtable[i]);
    }
    return values;
}



function SjElement(inParent, inElementId) {
	if (arguments[0] == 'empty') {
		return;
	}
    this._parent = inParent || self;
    this.window = (inParent && inParent.window) || self;
    this.document = (inParent && inParent.document) || self.document;
	this.name=this._elementId = inElementId || 'SjElement'+parseInt(SjElement.Count++);
    this.tag = null;
	this._x = 0;
	this._y = 0;
	this._z = 0;
	this._width = 0;
	this._height = 0;
	this._visible = false;
	this._opacity = 100;
	this._fadeTime = 2000;
	this._color = '';
	this._backColor = '';
	this._backImage = '';
	this._tid = null;
	this._content = sjGetElement(this._elementId);
	if (this._content){
		this._content._draggable = false;
	}
	SjElement.all[this._elementId] = this;
}

SjElement.prototype.getParent = function() {
	return this._parent;
};

SjElement.prototype.getElementId = function() {
	return this._elementId;
};

SjElement.prototype.getElement = function() {
	return sjGetElement(this._elementId);
};

SjElement.prototype.toString = function () {
	return 	'SjElement.all["'+this._elementId+'"]';
};

SjElement.prototype.visible = function(inVisible) {
	var the_element = sjGetElementStyle(this._elementId);
	if (inVisible != null && the_element) {
		this._visible = inVisible;
		if (inVisible) {
			//the_element.visibility = 'visible';
			the_element.visibility = 'inherit';
		} else {
			the_element.visibility = 'hidden';
		}
	}
	return this._visible;
}

SjElement.prototype.pageXY = function() {
		return sjGetPageCoords (sjGetElement(this._elementId));
};

SjElement.prototype.left = function(inX) {
	if (inX == null) {
		return this._x;
	} else {
   if (document.getElementById) {
      this._content.style.left=parseInt(inX)+'px';
   } else if (document.all) {
      this._content.style.pixelLeft=parseInt(inX)+'px';
   } else if (document.layers)
      this._content.moveTo(parseInt(inX),parseInt(inY));
		this._x = parseInt(inX);
		return this._x;
	}
};

SjElement.prototype.top = function (inY) {
	if (inY == null) {
		return this._y;
	} else {
   if (document.getElementById) {
      this._content.style.top=parseInt(inY)+'px';
   } else if (document.all) {
      this._content.style.pixelTop=parseInt(inY)+'px';
   } else if (document.layers)
      this._content.moveTo(parseInt(inX),parseInt(inY));
		this._y = parseInt(inY);
		return this._y;
	}
};

SjElement.prototype.toXY = function(inX,inY) {
	var xy={x:this.left(inX),y:this.top(inY)};
	this.fireEvent('setXY');
	return xy;
}

SjElement.prototype.width = function (inWidth) {
	if (inWidth == null) {
		return this._width;
	} else {
	   if (document.getElementById)
		  this._content.style.width=inWidth+'px';
	   else if (document.all)
		  this._content.style.posWidth=inWidth+'px';
	   else if (layer.clip)
		  this._content.clip.width=inWidth;
		this._width = inWidth;
		return this._width;
	}
};

SjElement.prototype.height = function (inHeight) {
	if (inHeight == null) {
		return this._height;
	} else {
	   if (document.getElementById)
		  this._content.style.height=inHeight+'px';
	   else if (document.all)
		  this._content.style.posHeight=inHeight+'px';
	   else if (layer.clip)
		  this._content.clip.height=inHeight;
		this._height = inHeight;
		return this._height;
	}
};

SjElement.prototype.setSize = function (inWidth,inHeight) {
	var size={w:this.width(inWidth),h:this.height(inHeight)};
	this.fireEvent('setSize');
	return size;
};

SjElement.prototype.clip = function (inLeft,inTop,inRight,inBottom) {
		var the_element = sjGetElementStyle(this._elementId);
		var bw=parseInt(the_element.borderWidth);
		if (bw){
			sjSetClip(this._elementId,this._x,this._y,inTop,inRight+2*bw,inBottom+2*bw,inLeft);
		}else{
			sjSetClip(this._elementId,this._x,this._y,inTop,inRight,inBottom,inLeft);
		}
};

SjElement.prototype.setBorder = function (width,style,color){ 
   stl=sjGetElementStyle(this._elementId);
	stl.borderWidth = width || 0;  
	stl.borderStyle = style || 'solid';
	stl.borderColor = color || '#000000';
}

SjElement.prototype.getBorder = function (){ 
   stl=sjGetElementStyle(this._elementId);
	return parseInt(stl.borderWidth);  
}

SjElement.prototype.opacity = function (inOpacity) {
	if (inOpacity != null) {
		var e = sjGetElement(this._elementId);
	    if(inOpacity < 0) inOpacity = 0; 
		if(inOpacity > 99) inOpacity = 99;
		e.style.opacity = (inOpacity / 100);
		e.style.MozOpacity = (inOpacity / 100);
		e.style.KhtmlOpacity = (inOpacity / 100);
		e.style.filter = "alpha(opacity=" + inOpacity + ")";
		this._opacity = inOpacity;
	}
}

SjElement.prototype.zIndex = function (inZ) {
	if (inZ == null) {
		return this._z;
	} else {
		sjSetZIndex(this._elementId,inZ);
		this._z = inZ;
		return sjGetZIndex(this._elementId);
	}
};

SjElement.prototype.setFadeTime = function(inFadeTime) {
	this._fadeTime = inFadeTime;
};

SjElement.prototype.fadeIn = function(inFadeTime){
    if (this._tid) {
		clearTimeout(this._tid);
		this._tid = null;
	}
	this._opacity=0;
	this.fadeStartTime = new Date().getTime();
	this.fadeStartOpacity = this._opacity;
	this.fadeTo(99,inFadeTime);
};

SjElement.prototype.fadeOut = function(inFadeTime){
    if (this._tid) {
		clearTimeout(this._tid);
		this._tid = null;
	}
	this._opacity=99;
	this.fadeStartTime = new Date().getTime();
	this.fadeStartOpacity = this._opacity;
	this.fadeTo(0,inFadeTime);
};

SjElement.prototype.fadeTo = function(inOpacity,inFadeTime){
	if(this._opacity==null) return;
	
	var dt = new Date().getTime() - this.fadeStartTime;
	if (dt >= inFadeTime) {
	    this.opacity(inOpacity);
	    this.visible((this._opacity > 0)? true:false);
		clearTimeout(this._tid);
		this._tid = null;
		if (this.afterFade){
			this.afterFade();
		}
		return;
	} else {
		var newOpacity = Math.round(this.fadeStartOpacity + (inOpacity - this.fadeStartOpacity) * dt / inFadeTime);
	    this.opacity(newOpacity);
	    this.visible((this._opacity > 0)? true:false);
		this._tid=setTimeout(this+'.fadeTo('+inOpacity+','+inFadeTime+')',5);
	}
};

SjElement.prototype.color = function (inColor) {
	if (inColor == null) {
		return this._color;
	} else {
		sjSetBackColor(this._elementId,inColor);
		this._color=inColor;
		return this._color;
	}
};

SjElement.prototype.background = function (inBackColor,inBackImage) {
    if (inBackColor)
		this._backColor = inBackColor;
    if (inBackImage)
		this._backImage = inBackImage;
};

//System Event
//event{type,x,y,button,keyCode,shiftKey,ctrlKey,altKey} 
SjElement.prototype.addEventHandler = function(eventName, handler){
	var obj = this;
	var x = 0;
	var y = 0;
	this._content = sjGetElement(this._elementId);
	this._content["on"+eventName.toLowerCase()] = function(event){ 
		if (!event) var event = window.event;
		var target = null;
		if (event.target) {
			target = (event.target.nodeType == 3) ? event.target.parentNode : event.target;
	    } else {
		    target = event.srcElement;
		}

		if (event.modifiers){
			event.shiftKey = ((event.modifiers & Event.SHIFT_MASK) != 0);
			event.altKey = ((event.modifiers & Event.ALT_MASK) != 0);
			event.ctrlKey = ((event.modifiers & Event.CONTROL_MASK) != 0);
			event.button	= event.which;
			event.keyCode	= event.which;
		}
		if (event.pageX || event.pageY){
			event.posx = event.pageX;
			event.posy = event.pageY;
		} else if (event.clientX || event.clientY){
			event.posx = event.clientX + document.body.scrollLeft;
			event.posy = event.clientY + document.body.scrollTop;
		}

            return handler(obj, event , target);
	}
}

SjElement.prototype.removeEventHandler = function(eventName, handler){
	if (document.layers){
		this.releaseEvents(Event[eventName.toUpperCase()]);
		delete this._content[Event[eventName.toUpperCase()]];
	}
	this._content["on"+eventName.toLowerCase()] = null;
}

//Event
SjElement.prototype.makeEventObject = function(inAarguments){
	var eventobject = new Object();
	eventobject["type"] = inAarguments[0];
	eventobject["target"] = this;
	for (i = 1; i < inAarguments.length; i+=2){
		eventobject[inAarguments[i]] = inAarguments[i+1];
	}
	return eventobject;
};

SjElement.prototype.addEventListener = function(inType, inHandler){
	inType = inType.toLowerCase();
	if (!this.hashtable_eventlisteners){
		this.hashtable_eventlisteners = new SjHashtable();
	}
	var arrListeners = this.hashtable_eventlisteners.get(inType);
	if (!arrListeners){
		arrListeners = new Array();
		this.hashtable_eventlisteners.put(inType, arrListeners);
	}
	var index = this.indexOfEventListener(inType, inHandler);
	if (index == -1){
		arrListeners.push(inHandler);
	}
};

SjElement.prototype.removeEventListener = function(inType, inHandler){
	inType = inType.toLowerCase();
	if (this.hashtable_eventlisteners){
		var arrListeners = this.hashtable_eventlisteners.get(inType);
		if (arrListeners){
			//arrListeners.remove(inHandler);
			var index = this.indexOfEventListener(inType, inHandler);
			if (index != -1){
				var arrListeners_temp = new Array();
				for (var i = 0; i < arrListeners.length; i++){
					if (arrListeners[i] != inHandler){
						arrListeners_temp.push(arrListeners[i]);
					}
				}
				this.hashtable_eventlisteners.put(inType, arrListeners_temp);
			}
		}
	}
};

SjElement.prototype.fireEventObject = function(inEvent){
	if (this.hashtable_eventlisteners && this.hashtable_eventlisteners.size() > 0){
		var arrListeners = this.hashtable_eventlisteners.get(inEvent.type.toLowerCase());
		if (arrListeners){
			var index;
			for (index = 0; index < arrListeners.length; index++){
				arrListeners[index](inEvent);
			}
		}
	}
};


SjElement.prototype.fireEvent = function(){
	var eventobject = this.makeEventObject(arguments);
	this.fireEventObject(eventobject);
};

SjElement.prototype.indexOfEventListener = function(inType, inHandler){
	var result = -1;
	inType = inType.toLowerCase();
	var index;
	if (this.hashtable_eventlisteners){
		var arrListeners = this.hashtable_eventlisteners.get(inType);
		if (arrListeners){
			//result = this.hashtable_eventlisteners.indexOfValue(inHandler);//arrListeners.indexOf(inListener);
			for (index = 0; index < arrListeners.length; index++){
				if (arrListeners[index] == inHandler){
					result = index;
					break;
				}
			}
		}
	}

	return result;
};
////

SjElement.Count = 0;
SjElement.all = [];


function SjLayer(inParent, inElementId) {
	if (arguments[0] == 'empty') {
		return;
	}
	this.SjElement = SjElement;
	this.SjElement(inParent, inElementId);
	if (this._parent && this._parent._elementId){
		sjCreateDiv(this._parent._elementId , this._elementId);
	}else{
		sjCreateDiv(null , this._elementId);
	}
	this._content = sjGetElement(this._elementId);
};

SjLayer.prototype = new SjElement('empty');


function SjPicture(inParent, inElementId,inWidth,inHeight) {
	if (arguments[0] == 'empty') {
		return;
	}
	this.SjElement = SjElement;
	this.SjElement(inParent, inElementId);
	if (this._parent && this._parent._elementId){
		sjCreateDiv(this._parent._elementId , this._elementId);
	}else{
		sjCreateDiv(null , this._elementId);
	}

	this._imageWidth = 0;
	this._imageHeight = 0;
	this._stretch = false;
	this.scale = 1;
	this.loaded = false;
	this.img = new Object();
	this.img._uId = this._elementId + '_img';
	this.img.src = "";
    this.img.str = ' <img';
	this.img.str += ' id=' + this.img._uId;
	this.img.str += ' name=' + this.img._uId;
	this.img.str += ' border=' + 0;
	this.img.str += ' style="position:absolute;left:0;top:0;"';
	this.img.str += '> ';
	//if (document.all) {
		//sjGetElement(this._elementId).insertAdjacentHTML('afterBegin',this.img.str);
	//}else{
	    sjSetLayerHTML(this._elementId,this.img.str);
	//}
	this._content = sjGetElement(this._elementId);
	this.imageElm = sjGetElement(this.img._uId);
	this.imageElm._parent = this;
	this.useMap='';
	this.imageElm.useMap='';
	this.img._parent = this;	
}

SjPicture.prototype = new SjElement('empty');

SjPicture.prototype.load = function(inURL) {
	this.loaded = false;
	if (inURL == this.img.src) {
		this.loaded = true;
	eval('document.' + this.img._uId + '.onload=this.onLoad;');//?????????/
		eval('document.' + this.img._uId + '.style.width=this._imageWidth;');
		eval('document.' + this.img._uId + '.style.height=this._imageHeight;');
		eval('document.' + this.img._uId + '.onload();');
		return;
	}
	if (document.all) {
		sjGetElement(this.img._uId).outerHTML=this.img.str;
		this.imageElm = sjGetElement(this.img._uId);
		this.imageElm._parent = this;
		this.img._parent = this;
	}else{
		eval('document.' + this.img._uId + '.style.width=null;');
		eval('document.' + this.img._uId + '.style.height=null;');
	}	
	this.img.src = inURL;
	eval('document.' + this.img._uId + '.onload=this.onLoad;');
	eval('document.' + this.img._uId + '.onerror=this.onError;');
	eval('document.' + this.img._uId + '.onabort=this.onAbort;');
    eval('document.' + this.img._uId + '.src = inURL;');
	this.imageElm.useMap = this.useMap;
};


SjPicture.prototype.onLoad = function() {
	this._parent.loaded = true;
	this._parent._imageWidth = this.width;
	this._parent._imageHeight = this.height;
	//this._parent.setSize(this.width,this.height);//set size of conteiner div !!!
	this._parent.stretch(this._parent.stretch());
	this._parent.fireEvent('load');
};

SjPicture.prototype.onError = function() {
	this._parent.loaded = false;
	this._parent.fireEvent('error');
};

SjPicture.prototype.onAbort = function() {
	this._parent.loaded = false;
	this._parent.fireEvent('abort');
};

SjPicture.prototype.stretch = function(inStretch) {
	if (inStretch != null) {
		this._stretch = inStretch;
		var w = this.width();
		var h = this.height();
		if (this._stretch) {
			sjSetWidth(this.img._uId, this._width);
			sjSetHeight(this.img._uId, this._height);
		} else {
			sjSetWidth(this.img._uId, this._imageWidth);
			sjSetHeight(this.img._uId, this._imageHeight);
		}
			sjZoomMap (this.imageElm.useMap.substring(1), this.width()/w, this.height()/h);
	}
	return this._stretch;
};

SjPicture.prototype.super_width = SjPicture.prototype.width;
SjPicture.prototype.width = function(inWidth) {
	var w = this.super_width();
	var h = this.super_height();
	var ret = this.super_width(inWidth);
	if (inWidth != null) {
			if (this._stretch) {
				sjSetWidth(this.img._uId, this._width);
				sjSetHeight(this.img._uId, this._height);
			}
			sjZoomMap (this.imageElm.useMap.substring(1), this.width()/w, this.height()/h);
	}
	return ret;
};

SjPicture.prototype.super_height = SjPicture.prototype.height;
SjPicture.prototype.height = function(inHeight) {
	var w = this.super_width();
	var h = this.super_height();
	var ret = this.super_height(inHeight);
	if (inHeight != null) {
			if (this._stretch) {
				sjSetWidth(this.img._uId, this._width);
				sjSetHeight(this.img._uId, this._height);
			}
			sjZoomMap (this.imageElm.useMap.substring(1), this.width()/w, this.height()/h);
	}
	return ret;
};

SjPicture.prototype.map = function(inMap) {
	if (inMap!= null){
	  this.imageElm.useMap=this.useMap='#'+inMap;
	}else
	return this.imageElm.useMap;
};

SjPicture.prototype.clearMap = function() {
	  this.imageElm.useMap=this.useMap='';
};


/////////////////////////////////SjZoomNav
function SjZoomNav(inObj,inWidth,inHeight,inPosition,inNav){
	this.SjElement = SjElement;
///////
	if ((typeof inNav == 'undefined')) {
		inNav = 'izNav';
	}
    if (sjGetElement(inNav)){
		this.SjElement(sjGetElement(inNav), null);
		if (this._parent){
			sjCreateDiv(sjGetElement(inNav), this._elementId);
		}else{
			sjCreateDiv(null , this._elementId);
		}
		this.elem=sjGetElement(this._elementId);
		this.elem._elementId = this._elementId;
		this._content		= sjGetElement(this._elementId);
		
		this.setSize(sjGetElement(inNav).offsetWidth || 50,sjGetElement(inNav).offsetHeight || 50);
		sjSetWidth(inNav, this.width());
		sjSetHeight(inNav, this.height());
	    this.toXY(0,0);
	}else{
		this.SjElement(inObj, null);
		if (this._parent && this._parent._elementId){
			sjCreateDiv(this._parent._elementId , this._elementId);
		}else{
			sjCreateDiv(null , this._elementId);
		}
		this.elem=sjGetElement(this._elementId);
		this.elem._elementId = this._elementId;
		this._content		= sjGetElement(this._elementId);
		
		this.setSize(inWidth || 50,inHeight || 50);
	}
/////////

	this.navObj = null;

	this.dblnavImage = new SjPicture(this.elem);
	this.dblnavImage.setSize(inWidth || 50,inHeight || 50);
	this.dblnavImage.visible(false);

	this.navImage = new SjPicture(this.elem);
	this.navImage.visible(false);
	sjSetBorder(this._elementId,1,'solid',"#666666");
	this.navImage.setSize(inWidth || 50,inHeight || 50);
	this.dragImage = new SjLayer(this.navImage);
	this.dragImage.zIndex(100);
	this.dragImage.visible(false);
	this.dragImage.setSize(inWidth || 50,inHeight || 50);
	this.borderWidth  = 2;
	this.borderColor = '#ff0000';
	//var str='<img id='+this.dragImage._elementId+'_img  src="../dhtml/images/blankimg.gif" style="left:2px;top:2px;width:'+this.dragImage.width()+';height:'+this.dragImage.height()+';">';
	var str='<img id='+this.dragImage._elementId+'_img  src="" style="left:2px;top:2px;width:'+this.dragImage.width()+'px;height:'+this.dragImage.height()+'px;">';
	sjSetLayerHTML(this.dragImage._elementId,str);
	sjGetElementStyle(this.dragImage._elementId+'_img').border='#ff0000 2px solid'; 
	this.visible(false);
	this.position = inPosition || 'absolute';
	if (this.position == 'absolute'){
		sjGetElementStyle(this._elementId).position='absolute'; 
	}else{ 
		//sjGetElementStyle(this._elementId).position ='relative';//relative - not work!
	}
	this.initialLoading	= true;
	//for future this.changingImage	= false;
}

SjZoomNav.prototype = new SjElement();

SjZoomNav.prototype.setViewer = function(inObj){
	this.navObj = inObj;
	if (this.navObj){
		this.navObj.navLayer = this;
		sjGetElement(this.dragImage._elementId+'_img').src = "/webart/spacer.gif";
		this.initHandlers();
		if ((this.navObj.navloadURL) && (this.navObj.imgServerWidth) && (this.navObj.imgServerHeight)){
			this.navObj.navDefaultScl = Math.max(Math.max(this.navObj.imgServerWidth / (this.width()-5), this.navObj.imgServerHeight / (this.height()-5)), 1.0);
			this.navObj.navloadURL +='&scl='+(this.navObj.navDefaultScl)+'&fmt=jpeg'+this.navObj.idStr;
			//??this.navImage.load(this.navObj.navloadURL);
			this.dblnavImage.load(this.navObj.navloadURL);
		}
	}
}

SjZoomNav.prototype.update = function(x,y,w,h){
	if(this.navObj){
		this.navObj.navigatorScl= Math.max(w/this.navImage.width(),h/this.navImage.height());
		var fixedX = Math.max(-x/this.navObj.navigatorScl,0);
		var fixedY = Math.max(-y/this.navObj.navigatorScl,0);
		this.dragImage.toXY(fixedX,fixedY);
		var fixedWidth = Math.min(this.navObj.width()/this.navObj.navigatorScl, this.navImage.width());
		var fixedHeight = Math.min(this.navObj.height()/this.navObj.navigatorScl, this.navImage.height());
		this.dragImage.setSize(fixedWidth,fixedHeight);
		sjGetElementStyle(this.dragImage._elementId+'_img').width = parseInt(((this.dragImage.width()-this.borderWidth*2)<1?1:(this.dragImage.width()-this.borderWidth*2)))+"px";
		sjGetElementStyle(this.dragImage._elementId+'_img').height = parseInt(((this.dragImage.height()-this.borderWidth*2)<1?1:(this.dragImage.height()-this.borderWidth*2)))+"px";
	}
}

SjZoomNav.prototype.moving=false;
SjZoomNav.prototype.startDrag=false;


SjZoomNav.prototype.initHandlers = function(){
	var obj = this;
	var objNav = this.navObj;
	this.dblnavImage.addEventListener("load", 
		function (){
			var scl = 1;//Math.min((obj.width()-5)/obj.dblnavImage._imageWidth,(obj.height()-5)/obj.dblnavImage._imageHeight);
			obj.dblnavImage.stretch(true);
			obj.dblnavImage.setSize(obj.dblnavImage._imageWidth*scl,obj.dblnavImage._imageHeight*scl);
			obj.dblnavImage.toXY((obj.width() - obj.dblnavImage.width())/2,(obj.height() - obj.dblnavImage.height())/2);
			obj.dblnavImage.visible(true);
			obj.navImage.load(obj.dblnavImage.img.src);//??
			return false;
		}
	);
	this.navImage.addEventListener("load", 
		function (){
			var scl = 1;//Math.min((obj.width()-5)/obj.navImage._imageWidth,(obj.height()-5)/obj.navImage._imageHeight);
			obj.navImage.stretch(true);
			obj.navImage.setSize(obj.navImage._imageWidth*scl,obj.navImage._imageHeight*scl);
			obj.navImage.toXY((obj.width() - obj.navImage.width())/2,(obj.height() - obj.navImage.height())/2);
			obj.dragImage.setSize(obj.navImage.width(),obj.navImage.height());
			var newx =(obj.navImage.width() - obj.dragImage.width())/2;
			var newy =(obj.navImage.height() - obj.dragImage.height())/2;
			obj.dragImage.toXY(newx,newy);
			sjGetElementStyle(obj.dragImage._elementId+'_img').width = parseInt(((obj.dragImage.width()-obj.borderWidth*2)<1?1:(obj.dragImage.width()-obj.borderWidth*2)))+"px";
			sjGetElementStyle(obj.dragImage._elementId+'_img').height = parseInt(((obj.dragImage.height()-obj.borderWidth*2)<1?1:(obj.dragImage.height()-obj.borderWidth*2)))+"px";
			obj.dragImage.visible(true);
			if(obj.navObj){
				if (!obj.initialLoading){
					if (obj.dblnavImage.loaded){
						obj.dblnavImage.fadeOut(obj.navObj.fadeTime/2);
					}
					obj.navImage.fadeIn(obj.navObj.fadeTime/2);
					obj.navImage.visible(true);
				}else{
					obj.navImage.visible(true);
					obj.dblnavImage.visible(false);
				}
			}
			obj.initialLoading	= false;
			return false;
		}
	);
	this.navImage.addEventHandler('mousedown',
		function (o,evt){
			objNav.storeImagesXY();
			ex = evt.posx;
			ey = evt.posy;
			obj.startDrag=true;
			sjSetCursor('hand');
			return false;
		}
	);
	this.navImage.addEventHandler('mousemove',
		function (o,evt){
			if (obj.startDrag){
				obj.moving=true;
				var diffX = evt.posx - ex;
				var diffY = evt.posy - ey;
				objNav.setPosition(objNav.backImage,objNav.bx - diffX*objNav.navigatorScl,objNav.by - diffY*objNav.navigatorScl,objNav.currentScl);
				objNav.foreImage.left(objNav.currentX-objNav.bx+objNav.fx);
				objNav.foreImage.top(objNav.currentY-objNav.by+objNav.fy);
			}
			return false;
		}
	);
	this.navImage.addEventHandler('mouseup',
		function (o,evt){
			if(obj.moving){
				obj.moving=false;
				objNav.updateForeImage();
			}else{
				if (evt.ctrlKey){
				} else {
				}
			}
			obj.startDrag=false;
			sjSetCursor('default');
			return false;
		}
	);
}

SjZoomNav.prototype.setBorder = function(sz,inColor) {	
	this.borderColor = inColor || "#ff0000";
	this.borderWidth = parseInt(sz) || 2;
	sjGetElementStyle(this.dragImage._elementId+'_img').border=""+this.borderColor+" "+parseInt(this.borderWidth)+"px solid"; 
	sjGetElementStyle(this.dragImage._elementId+'_img').width = parseInt(((this.dragImage.width()-this.borderWidth*2)<1?1:(this.dragImage.width()-this.borderWidth*2)))+"px";
	sjGetElementStyle(this.dragImage._elementId+'_img').height = parseInt(((this.dragImage.height()-this.borderWidth*2)<1?1:(this.dragImage.height()-this.borderWidth*2)))+"px";
}

/////////////////////////////////SjZoom

function SjZoom(inParent,inBaseImage,inWidth,inHeight,withNav,withMagnifier,inPosition){
	this.SjElement = SjElement;
	this.SjElement(inParent, null);
	if (this._parent && this._parent._elementId){
		sjCreateDiv(this._parent._elementId , this._elementId);
	}else{
		sjCreateDiv(null , this._elementId);
	}
	this._content		= sjGetElement(this._elementId);
	if (typeof tsj != 'undefined'){
		this.codePath		= tsj.path;
	}else if(typeof sj != 'undefined'){
		this.codePath		= sj.path;
	}else{
		this.codePath		= '../dhtml/';
	}
	this.imageID            = inBaseImage.substr(inBaseImage.lastIndexOf("/") + 1);
	this.mainURL		= inBaseImage || "/webart/spacer.gif";
	this.foreURL		= null;
	this.loadURL		= null;
	this.waitIconURL	= null;
	this.imgFolder		= this.codePath+"images/default/";
	// viewer arguments
	this.viewSize		= {width: inWidth || 200, height: inHeight || 200};
	this.currentX		= null;//x;
	this.currentY		= null;//y;
	this.initialScl		= 1;//s;
	this.defaultScl		= 1;//s;
	this.currentScl		= 1;//s;
	this.lastScl		= 1;//s;
	this.nextScl		= 1;//s;
	this.prevScl		= 1;//s;
	this.imgServerWidth	= null; //server image size
	this.imgServerHeight= null;
	this.prevImgServerWidth	= null; //previuos server image size
	this.prevImgServerHeight= null;
	this.initialLoading	= true;
	this.changingImage	= false;
	this.initRGNZone	= null;
	this.RGNtype		= "rgna";
	this.format			= "jpeg";			// jpeg
	this.cachingModel	= "on,off";	// server side caching off, client side caching on
	this.infotxt		= "";
	this.buttonSpace	= 0;
	this.buttonOffset	= 0;
	this.imgBorder		= 0;
	// tiled zoom viewer arguments
	this.tileSize		= {width:128,height:128};
	this.panStep		= 128;
	this.maxWait		= 15000;
	this.max_zoom		= 5;
	this.zoom_factor	= 2;
	this.transitionTime	= 500;//msec
	this.fadeTime		= 150;// msec
	this.magnifier		= {width:150,height:150,factor:2,st:true};
	this.navInfo		= {pos:1,x:5,y:5,width:75,height:75};
	this.spinnerCou=0;
	this.orig_max_zoom	= 5;
	this.totalzoom		= 1;
	this.zoom_factor_limit = 0.0;
	this.waitIconTimer	= {showDelay: 3000, hideDelay: 100};
	this.waitIconTimerId= null;
	this.panPercision	= 3;
	this.curZoomPower	= 0;
	//navigator
	this.navigatorScl;
	this.withNav		= withNav || false;
	this.withMagnifier	= withMagnifier || false;
//closebutton???????
	this.closebutton_w	= 20;
	this.closebutton_h	= 20;
	this.closebutton_x	= 5;
	this.closebutton_y	= 5;
	this.closebutton_pos = 0;
//resizing
	this.setSize(this.viewSize.width,this.viewSize.height);
	this.clip(0,0,this.viewSize.width+2,this.viewSize.height+2);
		this.navLayer = null;
	this.foreImage = new SjPicture(this,'foreImage'+this._elementId);
	this.foreImage.visible(false);
	this.foreImage.setSize(this.viewSize.width,this.viewSize.height);
	this.foreImage.stretch(true);
	this.foreImage.zIndex(this.zIndex()+1);
	//XXX01 avu 22.09.2005: fixed issue #4696 - DHTML generic zoom - clicking swatch sometimes doesn't update main image.
	this.foreImage.afterFade = function() {
		this._parent.checkPendingChangeContext();
	};

	this.backImage = new SjPicture(this,'backImage'+this._elementId);
	this.backImage.visible(false);
	this.backImage.setSize(this.viewSize.width,this.viewSize.height);
	this.backImage.stretch(true);

	this.mapImage = new SjPicture(this,'mapImage'+this._elementId);
	this.mapImage.visible(false);
	this.mapImage.setSize(this.viewSize.width,this.viewSize.height);
	this.mapImage.stretch(true);
	this.mapImage.zIndex(this.foreImage.zIndex()+1);
	this.mapImage.load("/webart/spacer.gif");
	this.waitIcon = new SjPicture(this,'waitIcon'+this._elementId);
	this.waitIcon.visible(false);
	this.waitIcon.zIndex(this.foreImage.zIndex()+1);
	this.waitIcon.setSize(10,10);
////////////////buttons
	this.closeButton = new SjPicture(this._parent,'closeButton'+this._elementId);
	this.plusButton = new SjPicture(this._parent,'plusButton'+this._elementId);
	this.minusButton = new SjPicture(this._parent,'minusButton'+this._elementId);
	this.resetButton = new SjPicture(this._parent,'resetButton'+this._elementId);
	this.infoButton = new SjPicture(this._parent,'infoButton'+this._elementId);
	this.threeDButton = new SjPicture(this._parent,'threed'+this._elementId);
	this.threeDButtonOver = new SjPicture(this._parent,'threedOver'+this._elementId);
	this.closeButton.zIndex(this.foreImage.zIndex()+10);
	this.plusButton.zIndex(this.foreImage.zIndex()+10);
	this.minusButton.zIndex(this.foreImage.zIndex()+10);
	this.resetButton.zIndex(this.foreImage.zIndex()+10);
	this.infoButton.zIndex(this.foreImage.zIndex()+10);
	this.threeDButton.zIndex(this.foreImage.zIndex()+10);
	this.threeDButtonOver.zIndex(this.foreImage.zIndex()+11);
	this.closeButton.setSize(20,20);
	this.plusButton.setSize(20,20);
	this.minusButton.setSize(20,20);
	this.resetButton.setSize(20,20);
	this.infoButton.setSize(20,20);
	this.threeDButton.setSize(70,49);
	this.threeDButtonOver.setSize(70,49);
	this.closeButton.visible(false);
	this.plusButton.visible(false);
	this.minusButton.visible(false);
	this.resetButton.visible(false);
	this.infoButton.visible(false);
	this.threeDButton.visible(false);
	this.threeDButtonOver.visible(false);
	
//??	this.color('#ffffff');
	this.visible(true);
	this.stack = null;
	this.state = "create";
	this.oldImage = null;
	this.currentRGN = null;
	//XXX01 avu 22.09.2005: fixed issue #4696 - DHTML generic zoom - clicking swatch sometimes doesn't update main image.
	this.pendingChangeContext = null;
/////////////////
	this.currentCrop = null;
	this.alignX = 0;
	this.alignY = 0;
	this.broshure = null;
	this.navloadURL	= null;
	this.navDefaultScl = 1;
/////////////////
	this.clickToZoom = true;
	this.zoomSclArray = new Array();
	this.zoomIdx = 0; //reset state
	this.zoomScl = false;
	this.enableZoom = true;

	this.checkFor3D(this.imageID);
}

SjZoom.prototype = new SjElement();

SjZoom.prototype.checkFor3D = function checkFor3D(imgID){
	
        if(imgID.indexOf('?') > -1)
		imgID = imgID.substring(0,imgID.indexOf('?'));
	if (this.valid360Product(imgID))
		this.show3DButton();
}

SjZoom.prototype.show3DButton = function show3DButton() {

	this.threeDButton.left(this.viewSize.width - 70 - 3);
	this.threeDButton.top(3);
	this.threeDButton.visible(true);
	// Removed image
	this.threeDButton.load('');
	this.threeDButtonOver.left(this.viewSize.width - 70 - 3);
	this.threeDButtonOver.top(3);
	this.threeDButtonOver.visible(false);
	// Removed image
	this.threeDButtonOver.load('');	
}


SjZoom.prototype.initialising = function (x,y,scale,defaultScl) {
	this.defaultScl = this.initialScl = Math.max(Math.max(this.imgServerWidth / this.viewSize.width, this.imgServerHeight / this.viewSize.height), 1.0);//ss
	 if (defaultScl != null){
		this.defaultScl = this.initialScl = defaultScl;
	  }
	 this.bgImgScl = this.defaultScl;
	 if (scale == null){
		this.currentScl = this.defaultScl;
	  } else {
		var resetScl = scl1 = Math.max(this.imgServerWidth / this.viewSize.width, 
										this.imgServerHeight / this.viewSize.height);
		var prevResetScl = scl0 = Math.max(this.prevImgServerWidth / this.viewSize.width, 
											this.prevImgServerHeight / this.viewSize.height);
		resetScl = Math.max(resetScl,1.0);
		prevResetScl = Math.max(prevResetScl,1.0);

		var maxScaleChange = Math.pow(this.zoom_factor , this.max_zoom);
		//minimum allowed scale value.
		var minScale = resetScl / maxScaleChange;
		var prevminScale = prevResetScl / maxScaleChange;
		scale = scale * minScale / prevminScale;
		this.currentScl = scale;
	 }

	//set position
	this.defaultX = (this.viewSize.width - this.imgServerWidth/this.defaultScl)/2;
	 if (x == null){
		this.currentX = (this.viewSize.width - this.imgServerWidth/this.currentScl)/2;
	  } else {
		this.currentX = x;
	 }
	this.defaultY = (this.viewSize.height - this.imgServerHeight/this.defaultScl)/2;
	 if (y == null){
		this.currentY = (this.viewSize.height - this.imgServerHeight/this.currentScl)/2;
	  } else {
		this.currentY = y;
	 }
	
	if (!this.zoomScl){
		this.zoomSclArray = new Array();
		for(var i=0;i<=this.max_zoom;i++){
			this.zoomSclArray.push(this.defaultScl/Math.pow(this.zoom_factor , i));
		}
	}
	//create url
		this.idStr="";
		if (this.imageVersion){
			this.idStr = '&id='+this.imageVersion;
		}
		this.loadURL = this.navloadURL = this.mainURL+sjPBreak(this.mainURL)+'rgn='+
							Math.round(0)+','+
							Math.round(0)+','+
							Math.round(this.imgServerWidth)+','+
							Math.round(this.imgServerHeight);
		this.loadURL +=	'&scl='+(this.bgImgScl)+'&fmt=jpeg'+this.idStr;
	//load image
		this.backImage.visible(false);
		this.backImage.load(this.loadURL);
		sjResetMap(this.pageId);////map
		sjZoomMap (this.pageId, 1/this.currentScl, 1/this.currentScl);
		this.mapImage.map(this.pageId);
		var obj = this;
		this.setMapper(this.pageId,
				function (){
					obj.enableZoom = false;
					return false;
				},
				function (){
					obj.enableZoom = true;
					return false;
				}
			);
		//setTimeout(this+'.focusing('+(0)+');',1000);

		if (this.navLayer){
			this.navDefaultScl = Math.max(Math.max(this.imgServerWidth / (this.navLayer.width()-5), this.imgServerHeight / (this.navLayer.height()-5)), 1.0);
			//this.navloadURL +=	'&scl='+(this.navDefaultScl)+'&op_sharpen=1&fmt=jpeg'+idStr;
			//this.navloadURL +=	'&scl='+(this.navDefaultScl)+'&fmt=jpeg'+idStr;
			this.navloadURL +=	'&scl='+(this.navDefaultScl)+'&fmt=jpeg'+this.idStr;
			//??if (this.navLayer.navImage.img.src){
			//??	this.navLayer.dblnavImage.load(this.navLayer.navImage.img.src);
			//??}
			//??this.navLayer.navImage.load(this.navloadURL);
			this.navLayer.navImage.visible(false);
			this.navLayer.dblnavImage.visible(false);
			this.navLayer.dblnavImage.load(this.navloadURL);
		}
}

SjZoom.prototype.changeContext = function (inURL,x,y,scale,defaultScl,imgWidth,imgHeight,imgVersion,pageId){
	this.oldImage = this.mainURL;
	this.currentHost = location.host;
	var tempURL=new SjURL(inURL);
	if (!this.initialLoading) {
		if (this.changingImage || (!this.foreImage.loaded) ||(this.foreImage._tid != null) || (this._fid)){
			//XXX01 avu 22.09.2005: fixed issue #4696 - DHTML generic zoom - clicking swatch sometimes doesn't update main image.
			this.pendingChangeContext = {
				url : inURL,
				x : x,
				y : y,
				scale : scale,
				defaultScl:defaultScl,
				width : imgWidth,
				height : imgHeight,
				version : imgVersion,
				pageId : pageId
			};
			return;
		}else{
			//same image - no change.
			if (inURL == this.mainURL) {
				return;
			}
			tTime = (new Date()).getTime();
			this.changingImage = true;
		}
	}
	//if((imgWidth)&&(imgHeight)&&(imgVersion)){
	if((imgWidth)&&(imgHeight)){
		this.prevImgServerWidth	= this.imgServerWidth; //previuos server image size
		this.prevImgServerHeight = this.imgServerHeight;
		this.imgServerWidth=imgWidth;
		this.imgServerHeight=imgHeight;
		if (imgVersion){
			this.imageVersion=imgVersion;
		}else{
			this.imageVersion=null;
		}
		if (pageId){
			this.pageId=pageId;
		}else{
			this.pageId='page0';
		}
		this.mainURL=mainURL=inURL;
		this.initialising(x,y,scale,defaultScl);
		this.state = "changeContext";
		this.fireEvent('endZoom');
	}else if ((this.currentHost != (tempURL.host+''+tempURL.port)) && (tempURL.host !='') && (!this.initialLoading)){
		this.prevImgServerWidth	= this.imgServerWidth; //previuos server image size
		this.prevImgServerHeight = this.imgServerHeight;
		if (imgVersion){
			this.imageVersion=imgVersion;
		}else{
			this.imageVersion=null;
		}
		if (pageId){
			this.pageId=pageId;
		}else{
			this.pageId='page0';
		}
		this.mainURL=mainURL=inURL;
		this.initialising(x,y,scale,defaultScl);
		this.state = "changeContext";
		this.fireEvent('endZoom');
	}else{
		if (pageId){
			this.pageId=pageId;
		}else{
			this.pageId='page0';
		}
		var ltURL = inURL+sjPBreak(inURL)+ 'req=ctx';
		var lt = null;
			lt = new SjTextLoader();
			lt.parent = this;
			lt.onLoadText = function() {
				if (lt.clearText(lt.text) != null) {
					var imageRectStr = sjGetKeyValue(lt.text, 'image.rect');
					var rectTokenList = imageRectStr.split(',');
					var imageWidth = rectTokenList[2];
					var imageHeight = rectTokenList[3];
					var imageVersion = sjGetKeyValue(lt.text, 'image.version');
					this.parent.prevImgServerWidth	= this.parent.imgServerWidth; //previuos server image size
					this.parent.prevImgServerHeight = this.parent.imgServerHeight;
					this.parent.imgServerWidth=imageWidth;
					this.parent.imgServerHeight=imageHeight;
					if (imageVersion){
						this.parent.imageVersion=imageVersion;
					}else{
						this.parent.imageVersion=null;
					}
					this.parent.mainURL=mainURL=inURL;
					this.parent.initialising(x,y,scale,defaultScl);
					this.parent.state = "changeContext";
					this.parent.fireEvent('endZoom');
				}
				return false;
			}
		if (this.initialLoading){
			lt.load(ltURL,true);
		}else{
			lt.load(ltURL,false);
		}
	}
}

SjZoom.prototype.checkPosition = function (x,y,scale){
	var newx = x;
	var newy = y;
	var shiftX = this.imgServerWidth/scale/2;
	var shiftY = this.imgServerHeight/scale/2;
	if (newx < (this.viewSize.width-this.imgServerWidth/scale)) 
		newx = (this.viewSize.width-this.imgServerWidth/scale);
	if (newy < (this.viewSize.height-this.imgServerHeight/scale)) 
		newy = (this.viewSize.height-this.imgServerHeight/scale);
	if (this.viewSize.width > this.imgServerWidth/scale){ 
		newx = (this.viewSize.width - this.imgServerWidth/scale)/2+(this.alignX*shiftX);
		if (newx+this.imgServerWidth/scale > this.viewSize.width){
			newx = (this.viewSize.width - this.imgServerWidth/scale);
		}
		if (newx < 0){
			newx = 0;
		}
	} else if (newx > 0) 
		newx=0;
	if (this.viewSize.height > this.imgServerHeight/scale){ 
		newy = (this.viewSize.height - this.imgServerHeight/scale)/2+(this.alignY*shiftY);
		if (newy+this.imgServerHeight/scale > this.viewSize.height){
			newy = (this.viewSize.height - this.imgServerHeight/scale);
		}
		if (newy < 0){
			newy = 0;
		}
	} else if (newy > 0) 
		newy=0;
	return ({nx:newx,ny:newy});
}

SjZoom.prototype.setPosition = function (img,x,y,scale){
	var oldx = img.left();
	var oldy = img.top();

	var newx = this.checkPosition(x,y,scale).nx;
	var newy = this.checkPosition(x,y,scale).ny;
	this.currentX = img.left(newx);
	this.currentY = img.top(newy);
	this.fireEvent('setPosition');
	
	//set navigator
	if (this.navLayer)
		this.navLayer.update(this.currentX,this.currentY,this.backImage.width(),this.backImage.height());

	sjResetMap(this.pageId);////map
	sjZoomMap (this.pageId, 1/this.currentScl, 1/this.currentScl);
	return ({ox:oldx,oy:oldy,nx:newx,ny:newy});
}

SjZoom.prototype._fid=null;
SjZoom.prototype.func=new Function();
SjZoom.prototype.animFix = function (img,x,y,inFinScale,inZoomTime,inAfterFn){
    if (this._fid){
		clearTimeout(this._fid);
		this._fid = null;
	}
	var startScale	= this.currentScl;
	var startPosX	= parseInt(this.currentX);
	var startPosY	= parseInt(this.currentY);
	var finPosX		= parseInt(this.checkPosition(x,y,inFinScale).nx);
	var finPosY		= parseInt(this.checkPosition(x,y,inFinScale).ny);
	this.zoomStartTime	= new Date().getTime();
	//if ((startPosX != finPosX) || (startPosY != finPosY) || (startScale != inFinScale)){
	if ((startPosX != finPosX) || (startPosY != finPosY) || (startScale != inFinScale) || (!this.foreImage.loaded)){//!!!!!!!!!
	    if (this.foreImage._tid) {
			clearTimeout(this.foreImage._tid);
			this.foreImage._tid = null;
			//XXX01 avu 22.09.2005: fixed issue #4696 - DHTML generic zoom - clicking swatch sometimes doesn't update main image.
			this.checkPendingChangeContext();
		}
		this.foreImage.visible(false);
		sjSetCursor('wait');
		this.requestShowWaitIcon();
		this.animFixTo(img,startPosX,startPosY,finPosX,finPosY,startScale,inFinScale,inZoomTime,inAfterFn);
	}else{
	    if (this.foreImage._tid) {
			clearTimeout(this.foreImage._tid);
			this.foreImage._tid = null;
			//XXX01 avu 22.09.2005: fixed issue #4696 - DHTML generic zoom - clicking swatch sometimes doesn't update main image.
			this.checkPendingChangeContext();
		}
		this.foreImage.visible(true);
		sjSetCursor('default');
		this.requestHideWaitIcon();
	}
}

SjZoom.prototype.animFixTo = function (img,startPosX,startPosY,finPosX,finPosY,startScale,finScale,inZoomTime,inAfterFn){
	var dt = new Date().getTime() - this.zoomStartTime;
	if (dt >= inZoomTime) {
		this.currentScl = finScale;
		this.setPosition(img,finPosX,finPosY,this.currentScl);
		img.setSize(this.imgServerWidth / this.currentScl,this.imgServerHeight / this.currentScl);
		if (this._fid){
			clearTimeout(this._fid);
			this._fid = null;
		}
		if (inAfterFn){
			this.updateForeImage();
			this.fireEvent('endZoom');
			this.fireEvent('setPosition');
		}
		sjSetCursor('default');
		this.requestHideWaitIcon();
		return;
	} else {
		var startZoom = 1 / startScale;
		var finZoom = 1 / finScale;
		var newZoom = startZoom + (finZoom - startZoom) * dt / inZoomTime;
		var newScl = 1 / newZoom;
		this.currentScl = newScl;
		var newx = (startPosX + (finPosX - startPosX) * dt / inZoomTime);
		var newy = (startPosY + (finPosY - startPosY) * dt / inZoomTime);
		this.currentX = newx;
		this.currentY = newy;
		img.setSize(this.imgServerWidth / newScl,this.imgServerHeight / newScl);			
		img.toXY(newx,newy);
		this.fireEvent('setPosition');
		//set navigator
		if (this.navLayer)
			this.navLayer.update(this.currentX,this.currentY,this.backImage.width(),this.backImage.height());
		sjResetMap(this.pageId);////map
		sjZoomMap (this.pageId, 1/this.currentScl, 1/this.currentScl);
		this._fid=setTimeout(this+'.animFixTo('+img+','+startPosX+','+startPosY+','+finPosX+','+finPosY+','+startScale+','+finScale+','+inZoomTime+','+this.func+')',25);
		return;
	}
}

SjZoom.prototype.ZoomAt = function (img,x,y,factor) {
//this.max_zoom				: max number of zoom levels
//this.defaultScl			: server scale at reset state
//this.currentScl			: current server scale
//this.zoom_factor			: step of zooming (by default = 2)
//this.zoom_factor_limit	: by default = 0(without restrictions) if >0 ,value in % of max zooming
//							1.0 ->> 100%,2.2 ->> 220%, 0.47 ->> 47%
//zoom		scl		zoom_factor_limit	
//25%		4		0.25				
//33%		3		0.33				
//100%		1		1					
//200%		0.5		2.0					
/*
if "factor" >1 - zoomOut "factor" <1 - zoomIn "factor" == 1 - may be "panning" 
*/
	var nothing = false;

	if (!this.zoomScl){
		nothing = false;
	}else{
		if (factor > 1){
				for (var i=this.zoomSclArray.length-1;i>=0;i--){
					if ((this.zoomSclArray[i] - this.currentScl)>0){
						factor = this.zoomSclArray[i] / this.currentScl;
						nothing = false;
						break;
					}else{
						nothing = true;
					}
				}
		}else if (factor < 1){
				for (var i=0;i<this.zoomSclArray.length;i++){
					if ((this.zoomSclArray[i] - this.currentScl)<0){
						factor = this.zoomSclArray[i] / this.currentScl;
						nothing = false;
						break;
					}else{
						nothing = true;
					}
				}
		}; 
	}

	var newScl = this.currentScl*factor;
	if (this.zoom_factor_limit != 0) {
		newScl = Math.max(newScl, 1 / this.zoom_factor_limit);
	}
	newScl = Math.min(this.defaultScl,newScl);
	//maximum relative scale change, starting from 'reset' state.
	var maxScaleChange = Math.pow(this.zoom_factor , this.max_zoom);
	//minimum allowed scale value.
	var minScale = this.defaultScl / maxScaleChange;
	newScl = Math.max(newScl, minScale);
	//check for scale changing and panning
		var newx = this.viewSize.width/2-x/(newScl/this.currentScl);
		var newy = this.viewSize.height/2-y/(newScl/this.currentScl);
		var neww=this.imgServerWidth/newScl;
		var newh=this.imgServerHeight/newScl;
//window.status = 'currentScl->'+this.currentScl+' factor->'+factor+' newScl->'+newScl+' zoomSclArray->'+this.zoomSclArray;
	if (!nothing){ 
			if ((newScl != this.currentScl) || (factor == 1) || (Math.round(newx) != Math.round(this.currentX)) || (Math.round(newy) != Math.round(this.currentY))){
			//this.state = "zoomAt";
			//this.fireEvent('zoomAt','image',img,'currentScl',this.currentScl,'newScl',newScl,'factor',factor);
			if (!this.initialLoading){
				this.animFix(img,newx,newy,newScl,this.transitionTime,this.updateForeImage);
			}else{
				this.animFix(img,newx,newy,newScl,0,this.updateForeImage);
			}
		}else{
			sjSetCursor('default');
		}
	}
//window.status = 'currentScl->'+this.currentScl+' factor->'+factor+' newScl->'+newScl+' zoomSclArray->'+this.zoomSclArray;
}

SjZoom.prototype.ZoomIn = function (img){
	var newx = this.viewSize.width/2-this.currentX;
	var newy = this.viewSize.height/2-this.currentY;
	this.ZoomAt(img,newx,newy,1/this.zoom_factor);
	this.state = "zoomIn";
	this.fireEvent('zoomIn','image',img,'currentScl',this.currentScl,'factor',1/this.zoom_factor);
}

SjZoom.prototype.ZoomOut = function (img){
	var newx = this.viewSize.width/2-this.currentX;
	var newy = this.viewSize.height/2-this.currentY;
	this.ZoomAt(img,newx,newy,this.zoom_factor);
	this.state = "zoomOut";
	this.fireEvent('zoomOut','image',img,'currentScl',this.currentScl,'factor',this.zoom_factor);
}

SjZoom.prototype.pan = function (img,directionX,directionY,amount){
	this.panStep = Math.sqrt(this.viewSize.width * this.viewSize.width + this.viewSize.height * this.viewSize.height) / 2 
	var newx = this.viewSize.width/2-this.currentX+directionX*amount*this.panStep;
	var newy = this.viewSize.height/2-this.currentY+directionY*amount*this.panStep;
	this.ZoomAt(img,newx,newy,1);
	this.state = "zoomPan";
	this.fireEvent('zoomPan','image',img,'directionX',directionX,'directionY',directionY,'amount',amount);
}
SjZoom.prototype.PanLeft = function (img){
	this.pan(img,-1,0,1);
}
SjZoom.prototype.PanUp = function (img){
	this.pan(img,0,-1,1);
}
SjZoom.prototype.PanDown = function (img){
	this.pan(img,0,1,1);
}
SjZoom.prototype.PanRight = function (img){
	this.pan(img,1,0,1);
}
SjZoom.prototype.PanLeftUp = function (img){
	this.pan(img,-1,-1,1);
}
SjZoom.prototype.PanRightUp = function (img){
	this.pan(img,1,-1,1);
}
SjZoom.prototype.PanLeftDown = function (img){
	this.pan(img,-1,1,1);
}
SjZoom.prototype.PanRightDown = function (img){
	this.pan(img,1,1,1);
}

SjZoom.prototype.ResetView = function (img){
	this.state = "reset";
	if(this.initRGNZone){
		this.ZoomSet(this.initRGNZone,this.RGNtype);
	}else{
		this.zoomIdx = 0;
		this.ZoomAt(img,this.defaultX,this.defaultY,this.defaultScl/this.currentScl);
	}
	this.fireEvent('zoomReset','image',img);
}

SjZoom.prototype.xImageToScreen = function (imgX){
	return imgX/this.currentScl+this.currentX;
}
SjZoom.prototype.yImageToScreen = function (imgY){
	return imgY/this.currentScl+this.currentY;
}
SjZoom.prototype.widthImageToScreen = function (imgW){
	return this.xImageToScreen(imgW) - this.xImageToScreen(0);
}
SjZoom.prototype.heightImageToScreen = function (imgH){
	return this.yImageToScreen(imgH) - this.yImageToScreen(0);
}

SjZoom.prototype.xScreenToImage = function (scrX){
	return (scrX-this.currentX) * this.currentScl;
}
SjZoom.prototype.yScreenToImage = function (scrY){
	return (scrY-this.currentY) * this.currentScl;
}
SjZoom.prototype.widthScreenToImage = function (scrW){
	return this.xScreenToImage(scrW) - this.xScreenToImage(0);
}
SjZoom.prototype.heightScreenToImage = function (scrH){
	return this.yScreenToImage(scrH) - this.yScreenToImage(0);
}

SjZoom.prototype.ZoomSet = function (rgn,type) {
	if (!this.changingImage){
     var rgnArray = rgn.split(",");
     if( rgnArray.length == 4 ) {
        var aspect = this.imgServerWidth/this.imgServerHeight;
        if( type=="rgnn" ) {
			rgnArray[0] = rgnArray[0] * this.imgServerWidth;
			rgnArray[1] = rgnArray[1] * this.imgServerHeight;
			rgnArray[2] = rgnArray[2] * this.imgServerWidth;
			rgnArray[3] = rgnArray[3] * this.imgServerHeight;
		}else if( type=="rgn" ){
			rgnArray[0] = rgnArray[0]/aspect*this.imgServerWidth;
			rgnArray[1] = rgnArray[1]*this.imgServerHeight;
			rgnArray[2] = rgnArray[2]/aspect*this.imgServerWidth;
			rgnArray[3] = rgnArray[3]*this.imgServerHeight;
		}
			var newx=this.xImageToScreen(rgnArray[0]);
			var newy=this.yImageToScreen(rgnArray[1]);
			var neww=this.widthImageToScreen(rgnArray[2]);
			var newh=this.heightImageToScreen(rgnArray[3]);
			var scl = Math.max(neww / this.viewSize.width, newh / this.viewSize.height);
		    if (this.foreImage._tid) {
				clearTimeout(this.foreImage._tid);
				this.foreImage._tid = null;
				//XXX01 avu 22.09.2005: fixed issue #4696 - DHTML generic zoom - clicking swatch sometimes doesn't update main image.
				this.checkPendingChangeContext();
			}
			var nx = newx+neww/2-this.currentX;
			var ny = newy+newh/2-this.currentY;
			this.currentRGN = rgnArray;
			this.state = "setRGN";
			this.ZoomAt(this.backImage,nx,ny,scl);
     };
	}else{
		this.state = "setRGN";
		var stack ={name:"ZoomSet",args:arguments};
		this.stack = stack;
	}
};

SjZoom.prototype.checkRect = function (x,y,w,h){
	var res={x:0,y:0,w:0,h:0,scl:null,url:null};
	var scl=this.currentScl;
		if (scl <= 1){
			scl=1;
		}
	res.x = Math.max(0,-x);
	res.w = Math.min(this.viewSize.width, w);
	res.y = Math.max(0,-y);
	res.h = Math.min(this.viewSize.height, h);
	if ((res.h <= 0) || (res.w <= 0)) {
		return null;
	} else {
	//fix tile coordinates so that it will always be align to tileSize.width.
	var tsize = this.tileSize.width*Math.ceil(Math.round(this.tileSize.width * this.currentScl)/this.tileSize.width);
	var img_x_old = res.x*this.currentScl;
	var img_y_old = res.y*this.currentScl;
	var img_w_old = res.w*this.currentScl;
	var img_h_old = res.h*this.currentScl;
	img_x = tsize * Math.floor(img_x_old / tsize);
	img_w = tsize * Math.ceil((img_x_old + img_w_old) / tsize) - img_x;
	img_y = tsize * Math.floor(img_y_old/ tsize);
	img_h = tsize * Math.ceil((img_y_old + img_h_old) / tsize) - img_y;
	//fix out of image bounds.
	img_x = Math.max(img_x, 0);
	img_y = Math.max(img_y, 0);

	if ((img_x + img_w) > this.imgServerWidth) {
		img_w = this.imgServerWidth - img_x;
	}
	if ((img_y + img_h) > this.imgServerHeight) {
		img_h = this.imgServerHeight - img_y;
	}

	//find shift screen position of the image.
		var c1x=img_x+img_w/2;
		var c1y=img_y+img_h/2;
		var c2x=img_x_old+img_w_old/2;
		var c2y=img_y_old+img_h_old/2;
		this.shiftX = (c2x - c1x);
		this.shiftY = (c2y - c1y);
		this.lastScl = scl;//s;
		res.url = this.mainURL;
		res.scl = scl;
		res.x =	Math.round(img_x);
		res.y =	Math.round(img_y);
		res.w =	Math.round(img_w);
		res.h =	Math.round(img_h);
		this.currentCrop = res;
		return res;
	}
}

SjZoom.prototype.getRect = function (x,y,w,h){
	var res={x:0,y:0,w:0,h:0,url:null};
	var scl=this.currentScl;
		if (scl <= 1){
			scl=1;
		}
	res.x = Math.max(0,-x);
	res.w = Math.min(this.viewSize.width, w);
	res.y = Math.max(0,-y);
	res.h = Math.min(this.viewSize.height, h);
	if ((res.h <= 0) || (res.w <= 0)) {
		return null;
	} else {
	//fix tile coordinates so that it will always be align to tileSize.width.
	var tsize = this.tileSize.width*Math.ceil(Math.round(this.tileSize.width * this.currentScl)/this.tileSize.width);
	var img_x_old = res.x*this.currentScl;
	var img_y_old = res.y*this.currentScl;
	var img_w_old = res.w*this.currentScl;
	var img_h_old = res.h*this.currentScl;
	img_x = tsize * Math.floor(img_x_old / tsize);
	img_w = tsize * Math.ceil((img_x_old + img_w_old) / tsize) - img_x;
	img_y = tsize * Math.floor(img_y_old/ tsize);
	img_h = tsize * Math.ceil((img_y_old + img_h_old) / tsize) - img_y;
	//fix out of image bounds.
	img_x = Math.max(img_x, 0);
	img_y = Math.max(img_y, 0);

	if ((img_x + img_w) > this.imgServerWidth) {
		img_w = this.imgServerWidth - img_x;
	}
	if ((img_y + img_h) > this.imgServerHeight) {
		img_h = this.imgServerHeight - img_y;
	}

	//find shift screen position of the image.
		var c1x=img_x+img_w/2;
		var c1y=img_y+img_h/2;
		var c2x=img_x_old+img_w_old/2;
		var c2y=img_y_old+img_h_old/2;
		this.shiftX = (c2x - c1x);
		this.shiftY = (c2y - c1y);
		this.lastScl = scl;//s;
		this.idStr="";
		if (this.imageVersion){
			this.idStr = '&id='+this.imageVersion;
		}
		res.url = this.mainURL+sjPBreak(this.mainURL)+'rgn='+
							Math.round(img_x)+','+
							Math.round(img_y)+','+
							Math.round(img_w)+','+
							Math.round(img_h)+
							'&scl='+(scl)+'&fmt=jpeg'+this.idStr;
		this.foreURL = this.mainURL+sjPBreak(this.mainURL)+'rgn='+
							Math.round(img_x)+','+
							Math.round(img_y)+','+
							Math.round(img_w)+','+
							Math.round(img_h)+
							//'&scl='+(scl)+'&op_brightness=100&fmt=jpeg'+'&id='+this.imageVersion;
							//'&scl='+(scl)+'&fmt=jpeg'+idStr;
							'&scl='+(scl)+'&fmt=jpeg'+this.idStr;
		this.foreMagURL = this.mainURL+sjPBreak(this.mainURL)+'rgn='+
							Math.round(img_x)+','+
							Math.round(img_y)+','+
							Math.round(img_w)+','+
							Math.round(img_h)+
							'&scl='+(scl/this.magnifier.factor)+'&fmt=jpeg'+this.idStr;
		return res;
	}
}

SjZoom.prototype.updateForeImage = function (inURL){
var res={x:0,y:0,w:0,h:0,scl:null,url:null};
	res=this.checkRect(this.backImage.left(),this.backImage.top(),this.backImage.width(),this.backImage.height());
	this.mapImage.toXY(this.backImage.left(),this.backImage.top());
	this.mapImage.setSize(this.backImage.width(),this.backImage.height());
	this.idStr="";
	if (this.imageVersion){
		this.idStr = '&id='+this.imageVersion;
	}
	var tempURL = res.url + sjPBreak(res.url)+'rgn='+(res.x)+','+(res.y)+','+(res.w)+','+(res.h)+
							'&scl='+(res.scl)+'&fmt=jpeg'+this.idStr;
//	if (((typeof inURL != 'undefined') && ((inURL != tempURL) || (inURL != this.foreURL))) || (tempURL != this.foreURL)){
		if (this.foreImage._tid) {
			clearTimeout(this.foreImage._tid);
			this.foreImage._tid = null;
			//XXX01 avu 22.09.2005: fixed issue #4696 - DHTML generic zoom - clicking swatch sometimes doesn't update main image.
			this.checkPendingChangeContext();
		}
		this.foreImage.visible(false);
		sjSetCursor('wait');
		this.requestShowWaitIcon();
		//??this.foreURL = tempURL;
		//06-02-2007//??		
		var offsetX = this.currentCrop.x/this.currentScl;
		var offsetY = this.currentCrop.y/this.currentScl;
		this.foreImage.toXY(this.backImage.left()+offsetX,this.backImage.top()+offsetY);
		//
	if (((typeof inURL != 'undefined') && ((inURL != tempURL) || (inURL != this.foreURL))) || (tempURL != this.foreURL)){
		this.foreImage.load(inURL || tempURL);
	}else{
		this.foreImage.load(this.foreURL);//??
	}
}

SjZoom.prototype.bx = 0;
SjZoom.prototype.by = 0;
SjZoom.prototype.fx = 0;
SjZoom.prototype.fy = 0;
SjZoom.prototype.ex = 0;
SjZoom.prototype.ey = 0;
SjZoom.prototype.moving=false;
SjZoom.prototype.startDrag=false;

SjZoom.prototype.storeImagesXY = function(){
	this.bx = this.backImage.left();
	this.by = this.backImage.top();
	this.fx = this.foreImage.left();
	this.fy = this.foreImage.top();
}

function sjCrossEvent(event){
	if (!event) var event = window.event;
	if (event.pageX || event.pageY){
		event.posx = event.pageX;
		event.posy = event.pageY;
	} else if (event.clientX || event.clientY){
		event.posx = event.clientX + document.body.scrollLeft;
		event.posy = event.clientY + document.body.scrollTop;
	}
   	event.returnValue = false;
   	//event.cancelBubble = true;
	//event.browserReturn=true;
	//event.bubble=true;
	return event;
}

SjZoom.prototype.initHandlers = function(){
	var obj = this;
	////////////////document

function toStandardMouse(){
	document.onmousemove=null; 
	document.onmouseup=null;
}

function initMouse(o,evt){
	obj.storeImagesXY();
	obj.ex = evt.posx;
	obj.ey = evt.posy;
	obj.startDrag=true;
	sjSetCursor('hand');
		document.onmousemove = function(event){
			moveMouse(o,sjCrossEvent(event));
			return false;
		}; 
		document.onmouseup = function(event){
			finishMouse(o,sjCrossEvent(event));
			return false;
		}; 
		//document.onmouseout = function(event){
		//	finishMouse(o,sjCrossEvent(event));
		//	return false;
		//}; 
	return false;
}

function moveMouse(o,evt){
	if (obj.startDrag){
		obj.moving=true;
		var diffX = evt.posx - obj.ex;
		var diffY = evt.posy - obj.ey;
		obj.setPosition(obj.backImage,obj.bx + diffX,obj.by + diffY,obj.currentScl);
		var x=obj.currentX-obj.bx+obj.fx;
		var y=obj.currentY-obj.by+obj.fy;
		obj.foreImage.toXY(x,y);
	}
	return false;
}

function finishMouse(o,evt){
	if(obj.moving){
		obj.moving=false;
		obj.state = "endPan";
		obj.fireEvent('endZoom');
		obj.updateForeImage();
	}else if (obj.startDrag){
		var x =sjGetPageCoords (sjGetElement(obj._elementId)).x;
		var y =sjGetPageCoords (sjGetElement(obj._elementId)).y;
		var newx=evt.posx-obj.currentX-x;
		var newy=evt.posy-obj.currentY-y;
		if ((obj.clickToZoom) && (obj.enableZoom)){
			if (evt.ctrlKey){
				obj.state = "zoomOut";
				obj.ZoomAt(obj.backImage,newx,newy,obj.zoom_factor)
			} else if (!evt.altKey){
				var minScale = Math.max(1 / obj.zoom_factor_limit, obj.defaultScl / Math.pow(obj.zoom_factor , obj.max_zoom));
				if (Math.abs(minScale - obj.currentScl) > 0.000001) {
					obj.state = "zoomIn";
					obj.ZoomAt(obj.backImage,newx,newy,1/obj.zoom_factor)
				}
			} else if (evt.altKey){
				obj.ResetView(obj.backImage);
			}
		}
	}
	obj.startDrag=false;
	sjSetCursor('default');
	toStandardMouse();
	return false;
}
	////////////////waitIcon
	this.waitIcon.addEventListener("load", 
		function (){
			obj.waitIcon.setSize(obj.waitIcon._imageWidth,obj.waitIcon._imageHeight);
			var newx =(obj.viewSize.width - obj.waitIcon.width())/2;
			var newy =(obj.viewSize.height - obj.waitIcon.height())/2;
			obj.waitIcon.toXY(newx,newy);
			return false;
		}
	);
	this.waitIcon.addEventHandler('mousedown',initMouse);
	//this.waitIcon.addEventHandler('mousemove',moveMouse);
	this.waitIcon.addEventHandler('mouseup',finishMouse);
	////////////////mapImage
	this.mapImage.addEventListener("load", 
		function (){
			obj.mapImage.visible(true);
			return false;
		}
	);
	this.mapImage.addEventHandler('mousedown',initMouse);
	//this.mapImage.addEventHandler('mousemove',moveMouse);
	this.mapImage.addEventHandler('mouseup',finishMouse);
	////////////////backImage
	this.backImage.addEventListener("load", 
		function (){
			obj.setPosition(obj.backImage,obj.currentX,obj.currentY,obj.currentScl);
			obj.backImage.setSize(obj.imgServerWidth / obj.currentScl,obj.imgServerHeight / obj.currentScl);
			obj.setPosition(obj.mapImage,obj.currentX,obj.currentY,obj.currentScl);
			obj.mapImage.setSize(obj.imgServerWidth / obj.currentScl,obj.imgServerHeight / obj.currentScl);
			//obj.backImage.fadeIn(obj.fadeTime);//?? memory leak!
			obj.backImage.visible(true);
			if(obj.initRGNZone){
				obj.changingImage=false;
				//XXX01 avu 22.09.2005: fixed issue #4696 - DHTML generic zoom - clicking swatch sometimes doesn't update main image.
				obj.checkPendingChangeContext();
				obj.ZoomSet(obj.initRGNZone,obj.RGNtype);
				if (!obj.initialLoading){
					obj.foreImage.fadeOut(obj.fadeTime/2);
					//setTimeout(obj+'.updateForeImage()',obj.fadeTime/2);
				}
			}else{
				if (!obj.initialLoading){
					obj.foreImage.fadeOut(obj.fadeTime/2);
					setTimeout(obj+'.updateForeImage()',obj.fadeTime/2);
				}else{
					obj.updateForeImage(obj.backImage.img.src);
				}
			}
					obj.initialLoading	= false;
			return false;
		}
	);

	////////////////foreImage
	this.foreImage.addEventListener("load", 
		function (){
		var offsetX = obj.currentCrop.x/obj.currentScl;
		var offsetY = obj.currentCrop.y/obj.currentScl;
			var scl=obj.currentScl;
			if (scl < 1){
				scl/=obj.lastScl; 
				obj.foreImage.height(obj.foreImage._imageHeight/scl);
				obj.foreImage.width(obj.foreImage._imageWidth/scl);
			}else{
				obj.foreImage.height(obj.foreImage._imageHeight);
				obj.foreImage.width(obj.foreImage._imageWidth);
			}
			//obj.foreImage.toXY(obj.backImage.left()+offsetX,obj.backImage.top()+offsetY);//??06-02-2007
			var fadeTime;
			if (obj.changingImage){
				fadeTime = obj.fadeTime/2;
				//XXX01 avu 22.09.2005: fixed issue #4696 - DHTML generic zoom - clicking swatch sometimes doesn't update main image.
				setTimeout(obj+'.changingImage=false;'+obj+'.checkPendingChangeContext();'+obj+'.callStack();',fadeTime);
			}else{
				fadeTime = obj.fadeTime;
			}
			if (!obj._fid){//??26-01-2007??issue 6476
				obj.foreImage.fadeIn(fadeTime);
			}
			sjSetCursor('default');
			obj.requestHideWaitIcon();
			//set navigator
			if (obj.navLayer){
				obj.navLayer.update(obj.currentX,obj.currentY,obj.backImage.width(),obj.backImage.height());
			}
			sjResetMap(obj.pageId);////map
			sjZoomMap (obj.pageId, 1/obj.currentScl, 1/obj.currentScl);
			obj.mapImage.visible(true);
			obj.state = "zoomForeImageLoad";
			//obj.fireEvent('zoomForeImageLoad','viewer',obj);
			obj.fireEvent('endZoom');
			//XXX01 avu 22.09.2005: fixed issue #4696 - DHTML generic zoom - clicking swatch sometimes doesn't update main image.
			obj.checkPendingChangeContext();
			return false;
		}
	);
	this.foreImage.addEventHandler('mousedown',initMouse);
	//this.foreImage.addEventHandler('mousemove',moveMouse);
	this.foreImage.addEventHandler('mouseup',finishMouse);
	////////////////buttons
	this.closeButton.addEventHandler('click',
		function (o,evt){
			//window.open( '../dhtml/window_closer.html','DHTMLZoomCloser','width=300,height=300');
		   var reply = confirm("The Web page you are viewing is trying to close the window" +
				"\n \nDo you want to close this DHTMLZoomViewer window?");
			if (reply) {
				top.close();
			}
			return false;
		}
	);


	this.threeDButtonOver.addEventHandler('click',
		function (o,evt){
		   //window.open( '');
		   return false;
		}
	);
	
	
	this.threeDButton.addEventHandler('mouseover',
		function (o,evt){
			obj.threeDButtonOver.visible(true);
			return false;
		}
	);	
	
	this.threeDButtonOver.addEventHandler('mouseout',
		function (o,evt){	
			obj.threeDButtonOver.visible(false);
			return false;
		}
	);		
	


	this.plusButton.addEventHandler('click',
		function (o,evt){
			obj.ZoomIn(obj.backImage);	
			return false;
		}
	);
	this.minusButton.addEventHandler('click',
		function (o,evt){
			obj.ZoomOut(obj.backImage);	
			return false;
		}
	);
	this.resetButton.addEventHandler('click',
		function (o,evt){
			obj.ResetView(obj.backImage);
			return false;
		}
	);
	this.infoButton.addEventHandler('click',
		function (o,evt){
			obj.showInformation();
			return false;
		}
	);
}

//////////////////////////////////
SjZoom.prototype.ZoomInit = function(rgn,type) {
	if(( type=="rgnn" ) || (type == 'rgna') || (type == 'rgn')){ 
		if( type == "rgnn" ){	
			this.RGNtype = "rgnn";
		}else if( type == "rgn" ){
			this.RGNtype = "rgn";
		}else  if( type == "rgna" ){
			this.RGNtype = "rgna";
		}
		this.initRGNZone = rgn;
	}
};

SjZoom.prototype.setMaxZoom = function(numZoomLevels, amount,limit) {
	if( ""+amount == "undefined" || amount==null ) amount=2;
	if( amount <= 1 ) amount = 1.1;
	if( amount > 3 ) amount = 3;
	this.zoom_factor = amount;
	this.max_zoom = numZoomLevels;
	this.orig_max_zoom = numZoomLevels;
	this.zoom_factor_limit = limit || 0.0;
};

SjZoom.prototype.advanced = function( zoomAmount,tiles,percision, transitionLoops, buf_size ) {
	this.zoom_factor = Math.max(1.1,zoomAmount);
	this.panPercision = Math.max(1,parseInt(percision));
	if( buf_size || buf_size == 0 ) this.tileSize.width = Math.max(0,buf_size);
};

SjZoom.prototype.enableNav = function(position,inX,inY,inWidth,inHeight) {
   if (this.navLayer == null){
		var tszoom_nav = new SjZoomNav(this._parent,null,null,'absolute');
		tszoom_nav.setViewer(this);
		//??tszoom_nav.initHandlers();
		//??tszoom_nav.navImage.load(this.navloadURL);
		if (this.navloadURL){
			tszoom_nav.dblnavImage.load(this.navloadURL);
		}
   }
	var x =this.left();
	var y =this.top();
	this.navInfo.width = inWidth || this.navInfo.width;
	this.navInfo.height = inHeight || this.navInfo.height;
	if( position >= 1 && position <= 4 ) {
		this.navInfo.pos = position;
		switch(position){
			case 1:	this.navInfo.x = x + 5; 
					this.navInfo.y = y  + 5; 
					break;
			case 2:	this.navInfo.x = x + this.width() - this.navLayer.width() - 5; 
					this.navInfo.y = y  + 5; 
					break;
			case 3:	this.navInfo.x = x + this.width() - this.navLayer.width() - 5; 
					this.navInfo.y = y  + this.height() - this.navLayer.height() - 5;
					break;
			case 4:	this.navInfo.x = x + 5; 
					this.navInfo.y = y  + this.height() - this.navLayer.height() - 5;
					break;
		}
	}else if( position > 4 ) {
		this.navInfo.x = x+inX || 0;
		this.navInfo.y = y+inY || 0;
	};

	if (this.navLayer){
		this.navLayer.setSize(this.navInfo.width,this.navInfo.height);
		this.navLayer.toXY(this.navInfo.x,this.navInfo.y);
		this.navLayer.visible(true);
		this.navLayer.zIndex(this.foreImage.zIndex()+10);
	}
}
    
SjZoom.prototype.NavigBox = function(){
	if (this.navLayer)
		this.navLayer.visible(!this.navLayer.visible());
}

SjZoom.prototype.setFormat = function(str) {
	this.format = str; 
};

SjZoom.prototype.setCachingModel = function(str) {	
	this.cachingModel = str; 
};

SjZoom.prototype.addInformation = function(str) {
	this.infotxt = "alert('"+str+"')";
};

SjZoom.prototype.showInformation = function() {
	if( this.infotxt.length != 0 )	{ 
		eval(this.infotxt); 
	}  
	else{
		window.open( '../dhtml/helppage.html','DHTMLZoomInfo','width=300,height=400' );
	};  
};

SjZoom.prototype.setHelpPage = function(str,w,h) {
	if( ""+str == "undefined" )  	
		this.infotxt = "window.open('../dhtml/helppage.html','DHTMLZoomInfo','width="+w+",height="+h+"')";
	else
		this.infotxt = "window.open('"+str+"','DHTMLZoomInfo','width="+w+",height="+h+"')";
};

SjZoom.prototype.enableUI = function(imgFolder,offset,spacing) {
	if( ""+this.imgFolder == "undefined" ) this.imgFolder= null;
	this.imgFolder	= imgFolder || "../dhtml/images/default/";
	if( this.imgFolder.substring(this.imgFolder.length-1,this.imgFolder.length) != "/" ) this.imgFolder+="/";
	if( ""+offset == "undefined" ) offset=0;
	if( ""+spacing == "undefined" ) spacing=0;

	this.buttonOffset = 0 || offset;
	this.buttonSpace = 0 || spacing;

		if( this.imgFolder != null ) {
			var infoShift = (this.infotxt!=""?1:0);
			var buttonSize = new Array(20,20);

			this.plusButton.toXY(this.viewSize.width-1-(3+infoShift)*(buttonSize[0]+this.buttonSpace),
								 this.viewSize.height-this.buttonOffset);
			this.minusButton.toXY( this.viewSize.width-1-(2+infoShift)*(buttonSize[0]+this.buttonSpace),
								this.viewSize.height-this.buttonOffset);
		 
			this.resetButton.toXY( this.viewSize.width-1-(1+infoShift)*(buttonSize[0]+this.buttonSpace),
								this.viewSize.height-this.buttonOffset);

			if( this.infotxt != "" ) {
				this.infoButton.toXY( this.viewSize.width-1-infoShift*(buttonSize[0]+this.buttonSpace),
									this.viewSize.height-this.buttonOffset);
			};
			
			//this.closeButton.load(this.imgFolder+'close.gif');
			this.plusButton.load(this.imgFolder+'zoomin.gif');
			this.minusButton.load(this.imgFolder+'zoomout.gif');
			this.resetButton.load(this.imgFolder+'reset.gif');
			this.infoButton.load(this.imgFolder+'info.gif');
			//this.closeButton.visible(false);
			this.plusButton.visible(true);
			this.minusButton.visible(true);
			this.resetButton.visible(true);
			if( this.infotxt != "" ) {
				this.infoButton.visible(true);
			}
		};
};

SjZoom.prototype.setWaitIconURL = function(inURL){
	if (this.waitIcon){
		this.waitIconURL = inURL || null;
		this.waitIcon.load(this.waitIconURL);
	}
}

SjZoom.prototype.setWaitIconTimer = function(inShowDelay, inHideDelay){
		this.waitIconTimer.showDelay = inShowDelay || 500;
		this.waitIconTimer.hideDelay = inHideDelay || 100;
}

SjZoom.prototype.requestHideWaitIcon = function(){
	if (this.waitIconTimerId){
		clearTimeout(this.waitIconTimerId);
		this.waitIconTimerId = null;
	}
	if (this.waitIconURL)
		this.waitIconTimerId = setTimeout(this+".waitIcon.visible(false)", this.waitIconTimer.hideDelay);
}

SjZoom.prototype.requestShowWaitIcon = function(){
		if (this.waitIconTimerId){
			clearTimeout(this.waitIconTimerId);
			this.waitIconTimerId = null;
		}
	if (this.waitIconURL)
	    this.waitIconTimerId = setTimeout(this+".waitIcon.visible(true)", this.waitIconTimer.showDelay);
}

SjZoom.prototype.enableCloseButton = function(position){
	this.closebutton_pos = position;
		if( this.closebutton_pos >= 1 && this.closebutton_pos <= 4 ) {
			this.closeButton.load(this.imgFolder+'close.gif');
			this.closebutton_x = 5; this.closebutton_y = 5;
			if( this.closebutton_pos == 2 || this.closebutton_pos == 3 ) this.closebutton_x = this.viewSize.width-this.closebutton_w-5; 
			if( this.closebutton_pos == 3 || this.closebutton_pos == 4 ) this.closebutton_y = this.viewSize.height-this.closebutton_h-5;
			this.closeButton.toXY(this.closebutton_x,this.closebutton_y);
			this.closeButton.visible(true);
		};
}

SjZoom.prototype.callStack = function(){
	if (this.stack){
		var str="";
		for (var i=0;i<this.stack.args.length;i++){
			if (i>0){
				str += ","+this+".stack.args["+i+"]";
			}else{
				str += this+".stack.args["+i+"]";
			}
		}
		eval(this+"."+this.stack.name+"("+str+")");
		this.stack = null;
	}
}

//XXX01 avu 22.09.2005: fixed issue #4696 - DHTML generic zoom - clicking swatch sometimes doesn't update main image.
SjZoom.prototype.checkPendingChangeContext = function(){
	if (this.pendingChangeContext != null) {
		var url = this.pendingChangeContext.url;
		var x = this.pendingChangeContext.x;
		var y = this.pendingChangeContext.y;
		var scale = this.pendingChangeContext.scale;
		var defaultScl = this.pendingChangeContext.defaultScl;
		var width = this.pendingChangeContext.width;
		var height = this.pendingChangeContext.height;
		var version = this.pendingChangeContext.version;
		var pageId = this.pendingChangeContext.pageId;
		this.pendingChangeContext = null;
		this.changeContext(url, x, y, scale,defaultScl,width,height,version,pageId);
	}
};

SjZoom.prototype.valid360Product = function(key) {
	for (i = 0; i < this.ProductTable360.length; i++)
		if (this.ProductTable360[i] == key)
			return true;
	return false;
}


///////////////
//range -1 .. 1
SjZoom.prototype.setAlign = function (inX,inY){
	this.alignX = inX || 0;
	this.alignY = inY || 0;
}

function SjEvent(inViewer){
	this.viewer = inViewer;
}

SjEvent.prototype.onEvent = function(inType,inHandler){
	this.viewer.addEventListener(inType,inHandler); 
}

SjEvent.prototype.onZoom = function(inType){
	this.viewer.addEventListener(inType,inHandler); 
}

///////////////
function SjURL(inURL){
	if(inURL.length==0) return null;
	this.url=inURL;
	this.port='';
	this.protocol='';
	this.host='';
	var protocolIdx=this.url.indexOf('://');
	if(protocolIdx>=0){
		this.protocol=this.url.substring(0,protocolIdx).toLowerCase();
		this.host=this.url.substring(protocolIdx+3);
		if(this.host.indexOf('/')>=0) this.host=this.host.substring(0,this.host.indexOf('/'));
		var atIdx=this.host.indexOf('@');
		if(atIdx>=0){
			var credentials=this.host.substring(0,atIdx);
			var colonIndex=credentials.indexOf(':');
			if(colonIndex>=0){
				this.username=credentials.substring(0,colonIndex);
				this.password=credentials.substring(colonIndex);
			}else{
				this.username=credentials;
			}
			this.host=this.host.substring(atIdx+1);
		}
		var portIdx=this.host.indexOf(':');
		if(portIdx>=0){
			this.port=this.host.substring(portIdx);
			this.host=this.host.substring(0,portIdx);
		}
		this.file=this.url.substring(protocolIdx+3);
		this.file=this.file.substring(this.file.indexOf('/'));
	}else{
		this.file=this.url;
	}
}

SjZoom.prototype.getImageWidth = function(){
	return (this.imgServerWidth); 
}

SjZoom.prototype.getImageHeight = function(){
	return (this.imgServerHeight);
}

////////
SjZoom.prototype.setClickToZoom = function(inState){
	return (this.clickToZoom = inState);
}

SjZoom.prototype.setZoomScl = function(inArray){
	if (typeof inArray != 'undefined'){
		this.zoomSclArray = new Array();
		this.zoomSclArray.sort();
		if (this.zoomSclArray[0] == 0){
			this.zoomScl = false;
		}else{
			this.zoomScl = true;
			for (var i=0;i<inArray.length;i++){
				this.zoomSclArray.push(inArray[i]);
			}
		}
	}else{
		this.zoomScl = false;
	}
}


SjZoom.prototype.setMapper = function(inMapName,inOver,inOut){
	if(inMapName){
	  if (document.all) {
		var map = document.all[inMapName];
		if (map){
			var areas = map.all.tags('AREA');
		}
	  } else if (document.getElementsByName) {
		var map = document.getElementsByName(inMapName)[0];
		if (map){
			var areas = map.getElementsByTagName('AREA');
		}
	  }
	  if (areas) {
		for (var a = 0; a < areas.length; a++) {
		  areas[a].onmouseover=inOver;
		  areas[a].onmouseout=inOut;
		  areas[a].onmousedown=function(){
								//alert("down");
								return false;
							  };
		  areas[a].onmouseup=function(){
								//alert("up");
								return false;
							  };
		}
	  }
	}
}

function ts_zoom(baseImage,width,height,isSecure,baseImage2,newWidth, newHeight, imgVersion){
	this.SjElement = SjElement;
	this.SjElement();

	var str="";
	str+=' <div id='+this._elementId+'_base';
	str+=' STYLE="position:relative;width:' + width + ';height:' + height + '">';
	str+=' <div  id='+this._elementId;
	str+=' STYLE="position:absolute;left:0;top:0;width:' + width + ';height:' + height + '">';
	str+=' </div> ';
	str+=' </div> ';
		document.write(str);

	this.elem=sjGetElement(this._elementId);
	this.elem._elementId = this._elementId;
	this.elem_base=sjGetElement(this._elementId+'_base');
	this.elem_base._elementId = this._elementId+'_base';
	this.x = 0;
	this.y = 0;
	this.zviewer = new SjZoom(this.elem,baseImage,width,height,true,true,true);
	//this.setBorder();
    this.zviewer.toXY(0,0);
	this.zviewer.initHandlers();
	//if (baseImage && ((newWidth)&&(newHeight)&&(imgVersion))){
	if (baseImage && ((newWidth)&&(newHeight))){
		this.zviewer.changeContext(baseImage,null,null,null,null,newWidth, newHeight, imgVersion);
	}else if (baseImage){
		this.zviewer.changeContext(baseImage,null,null,null,null);
	}
}

ts_zoom.prototype = new SjElement();

ts_zoom.prototype.addToPage = function(absolutePos) {
	if(absolutePos) {
		sjGetElementStyle(this.elem_base._elementId).position='absolute'; 
		sjSetXY(this.elem_base._elementId,this.x,this.y);
	}else{ 
		sjGetElementStyle(this.elem_base._elementId).position ='relative';
	    this.zviewer.toXY(0,0);
	}
};

ts_zoom.prototype.enableNav = function(position,inX,inY,inWidth,inHeight) {	
	this.zviewer.enableNav(position,inX,inY,inWidth || 50,inHeight || 50); 
};

ts_zoom.prototype.setBorderNav = function(sz,inColor) {	
	if (this.zviewer.navLayer){
		this.zviewer.navLayer.setBorder(sz,inColor); 
	}
};

ts_zoom.prototype.setBackground = function(bgColor) {
	if( ""+bgColor != "undefined" && ""+bgColor.length > 6 ) {
		this.zviewer.color("#"+bgColor.substr(bgColor.length-6)); 
		if (this.zviewer.navLayer){
			this.zviewer.navLayer.color("#"+bgColor.substr(bgColor.length-6)); 
		}
	} else {
		this.zviewer.color(bgColor); 
		if (this.zviewer.navLayer){
			this.zviewer.navLayer.color(bgColor.substr(bgColor.length-6)); 
		}
	};
};

ts_zoom.prototype.setImage = function(img, reset, newWidth, newHeight, imgVersion) { 
	if (reset || (this.zviewer.initialScl == this.zviewer.currentScl)){
		this.zviewer.changeContext(img,null,null,null,null,newWidth, newHeight, imgVersion);
	}else{
		this.zviewer.changeContext(img,this.zviewer.currentX,this.zviewer.currentY,this.zviewer.currentScl,null,newWidth, newHeight, imgVersion);
	}
};

ts_zoom.prototype.setFadeTime = function(inFadeTime) { 
	this.zviewer.fadeTime = inFadeTime; 
};

ts_zoom.prototype.setTurnTime = function(inTurnTime) { 
	this.zviewer.fadeTime = inTurnTime*1000; 
};

ts_zoom.prototype.setTransitionTime = function(inTransitionTime) { 
	this.zviewer.transitionTime = inTransitionTime; 
};

ts_zoom.prototype.setWaitIconTimer = function(inTimerStr){
	var tempStr = inTimerStr.split(",");
	this.zviewer.waitIconTimer.showDelay = (tempStr[0]-0)*1000;
	this.zviewer.waitIconTimer.hideDelay = (tempStr[1]-0)*1000;
}

ts_zoom.prototype.setMaxZoom = function(zoomLevels,amount,limit) {	
	this.zviewer.setMaxZoom(zoomLevels, amount,limit); 
};

ts_zoom.prototype.setZoomStep = function(amount) {	
	this.zviewer.setMaxZoom(this.zviewer.max_zoom, amount,this.zviewer.zoom_factor_limit); 
};

ts_zoom.prototype.zoomOut = function() {	
	this.zviewer.ZoomOut(this.zviewer.backImage); 
};

ts_zoom.prototype.zoomIn = function() {	
	this.zviewer.ZoomIn(this.zviewer.backImage);
};

ts_zoom.prototype.pan = function(direction,amount) {	
	var directionX=0;
	var directionY=0;
	switch(direction){
		case 'leftup':
			directionX=-1;directionY=-1;
			break;
		case 'up':
			directionX=0;directionY=-1;
			break;
		case 'rightup':
			directionX=1;directionY=-1;
			break;
		case 'left':
			directionX=-1;directionY=0;
			break;
		case 'right':
			directionX=1;directionY=0;
			break;
		case 'leftdown':
			directionX=-1;directionY=1;
			break;
		case 'down':
			directionX=0;directionY=1;
			break;
		case 'rightdown':
			directionX=1;directionY=1;
			break;
	}
	this.zviewer.pan(this.zviewer.backImage,directionX,directionY,amount); 
};

ts_zoom.prototype.reset = function() {			
	this.zviewer.ResetView(this.zviewer.backImage); 
};

ts_zoom.prototype.initialRGN = function(rgn) {		
	this.zviewer.ZoomInit(rgn,"rgn"); 
};

ts_zoom.prototype.initialRGNN = function(rgn) {
	this.zviewer.ZoomInit(rgn,"rgnn"); 
};

ts_zoom.prototype.initialRGNA = function(rgn) {		
	this.zviewer.ZoomInit(rgn,"rgna"); 
};

ts_zoom.prototype.setRGN = function(rgn) {		
	this.zviewer.ZoomSet(rgn,"rgn"); 
};

ts_zoom.prototype.setRGNN = function(rgn) {		
	this.zviewer.ZoomSet(rgn,"rgnn"); 
};

ts_zoom.prototype.setRGNA = function(rgn) {		
	this.zviewer.ZoomSet(rgn,"rgna"); 
};

ts_zoom.prototype.setBorder = function(sz,bgColor) {	
	var w =	parseInt(sjGetWidth(this.elem_base._elementId)) || GlobalImageWidth;
	var h =	parseInt(sjGetHeight(this.elem_base._elementId)) || GlobalImageHeight;
	var bgColor = bgColor || "#666666";
	var sz = sz || 0;
		if( ""+bgColor != "undefined" && ""+bgColor.length > 6 ) {
			sjSetBackColor(this.elem_base._elementId,"#"+bgColor.substr(bgColor.length-6));
			if (this.zviewer.navLayer)
				sjSetBorder(this.zviewer.navLayer._elementId,1,'solid',"#"+bgColor.substr(bgColor.length-6));
		} else {
			sjSetBackColor(this.elem_base._elementId,bgColor);
			if (this.zviewer.navLayer)
				sjSetBorder(this.zviewer.navLayer._elementId,1,'solid',bgColor);
		};
			sjSetWidth(this.elem_base._elementId, w+2*sz);
			sjSetHeight(this.elem_base._elementId, h+2*sz);
			sjSetXY(this.elem._elementId, sz,sz);
			this.zviewer.imgBorder = sz;
};

ts_zoom.prototype.setFormat = function(str) {		
	this.zviewer.setFormat(str); 
};

ts_zoom.prototype.setCachingModel = function(str) {	
	this.zviewer.setCachingModel(str); 
};

ts_zoom.prototype.addInformation = function(str) {	
	this.zviewer.addInformation(str); 
};

ts_zoom.prototype.setHelpPage = function(str,w,h) {	
	this.zviewer.setHelpPage(str,w,h); 
};

ts_zoom.prototype.initialRGN = function(rgn) {		
	this.zviewer.ZoomInit(rgn,"rgn"); 
};

ts_zoom.prototype.initialRGNN = function(rgn) {		
	this.zviewer.ZoomInit(rgn,"rgnn"); 
};

ts_zoom.prototype.initialRGNA = function(rgn) {		
	this.zviewer.ZoomInit(rgn,"rgna"); 
};

ts_zoom.prototype.advanced = function( zoomAmount,tiles,percision,transitionLoops,buf_size ) {
	this.zviewer.advanced( zoomAmount,tiles,percision,transitionLoops,buf_size );
};

////////////////////
ts_zoom.prototype.enableUI = function(imgFolder,offset,spacing) {
	var w =	parseInt(sjGetWidth(this.elem_base._elementId));
	var h =	parseInt(sjGetHeight(this.elem_base._elementId));
		sjSetHeight(this.elem_base._elementId,parseInt(sjGetHeight(this.elem_base._elementId))+20-Math.min(20,offset)+1);
		this.zviewer.enableUI(imgFolder,offset,spacing);
};

ts_zoom.prototype.enableCloseButton = function(position) {	
	this.zviewer.enableCloseButton(position); 
};

ts_zoom.prototype.showInformation = function() {
	this.zviewer.showInformation();
}


SjZoom.prototype.ProductTable360 = [];
