//**********************************************************************
// All the code below was written by David Frenkiel from the Beitar Jerusalem web site
// all this code is copyright (c) 2002 David Frenkiel (dfl@beitar-jerusalem.org.il)
// If you choose to use this code or portions of it you must keep the credit and comments in the source
// unchanged. If you modify the code please email the changes to the author.
//**********************************************************************

// change history

// version 1.2 - April 2002, modified for mozilla
// version 1.1 - september 2000, added clipping support
// version 1.0 - october 1998


// constants
var ns=1;
var ie=2;
var dom = 3;
var none=0;
var visibleString = "visible";
var hiddenString = "hidden";
var ImagesListName = 'images';
var FormsListName = 'forms';

// global vars
var debugLevel = 0;
var browser = none;
var topLevelString = "top"; // place from which objects are searched top-down
var myObjects = null;
var _isGecko = false;
var _bVersion = 0;
var browser = null;

var undefined;

function makeBrowser() {
// setup browser type
	var ua = navigator.userAgent.toLowerCase();
	this.isMac = 	(ua.indexOf("mac") >= 0);
	this.isGecko = (ua.indexOf('gecko') >= 0);
	this.isIE = (ua.indexOf("msie") >= 0);
	this.version = parseInt(navigator.appVersion);
	if (document.getElementById != null)
		this.type = dom;
	else if (this.version >= 4) {
		if (navigator.appName.toLowerCase().indexOf("netscape") != -1) {
			this.type = ns;
		} else {
			this.type = ie;
		}
	}
	return this;
}

browser = new makeBrowser();

//////////////// Initialization function - call once ////////////
function MyObjectArray() {
	this.objects = new Array();
	this.getObject = getObjectFunction;
	this.addObject = addObjectFunction;
}

function initDflApi() {
	if (myObjects== null)
		myObjects = new MyObjectArray();
	else
		debugAlert("init*x", 1);
}

function makeCapName(propname) {
	var ret = '';
	var len = propname.length;
	var capDiff = 'a'.charCodeAt(0) - 'A'.charCodeAt(0);
	for (i = 0; i < len; i++) {
		theChar = propname.charAt(i);
		if (theChar <= 'Z' && theChar >= 'A')
			theChar = String.fromCharCode(theChar.charCodeAt(0)) + '-'+capDiff;
		ret += theChar;
	}
	return ret;
}

function getEffectiveValueFunction(propname) {
  var value = null;
	if (document.defaultView != null && document.defaultView.getComputedStyle != null) {
		if (browser.isGecko)	{
		  switch(propname) {
			case 'clip':
				return this.iStyleObject[propname];
			case 'top':
				if (browser.isMac || (browser.version < 0.96 && this.iStyleObject.position == 'relative'))
					return this.iObject.offsetTop;
			case 'left':
				if (browser.isMac || (browser.version < 0.96 && this.iStyleObject.position == 'relative'))
					return this.iObject.offsetLeft;
			case 'width':
				if (browser.isMac)
					return this.iObject.scrollWidth;
			case 'height':
				if (browser.isMac)
					return this.iObject.scrollHeight;
		  }
		}
		cappropname = makeCapName(propname);
//		alert("searching for "+cappropname);
		value =  document.defaultView.getComputedStyle(this.iObject, '').getPropertyValue(cappropname);
	
		// xxxHack for Gecko:
		if (! value && this.iStyleObject[propname])
			value = this.iStyleObject[propname];
  	}
	else if (browser.isIE && browser.version > 4) {
	 // IE5+
	 value = this.iObject.currentStyle[propname];
	 if (! value)
		value = this.iStyleObject[propname];
	}
	else if (typeof(this.iStyleObject[propname]) == 'undefined') {
		debugAlert("undefined property "+propname, 2);
		value = 0;
	}
	else {
		value = this.iStyleObject[propname];
  	}
	return value;
}


function getObjectFunction(objName, listName) {
	var ret = null;
	if (listName) {
		if (this[listName] != null)
			ret = this[listName][objName];
	}
	else
		ret = this.objects[objName];
	return ret;
}

function addObjectFunction(obj, objName, listName) {
	if (listName) {
		if (this[listName] == null)
			this[listName] = new Array();
		this[listName][objName] = obj;
	}
	else
		this.objects[objName] = obj;
}

//////////  general utility ///////////

// make object search begin at current document level
function setTopLevelToDocument() {
	topLevelString = "document";
}

function setDebugLevel(newLevel) {
	debugLevel = newLevel;
}

// alerts only if current debugLevel is equal or higher than specified level
function debugAlert(str, level) {
	if (debugLevel >= level)
		alert(str);
}

////////////////////////
// general object methods 
////////////////////////

/////// accessors //////

function getClipRectFunction() {
	if (this.clipRect == null) {
		this.clipRect= new makeRect();
		getClipValues(this.iStyleObject, this.clipRect);
	}
	return this.clipRect;
}

function getWidthFunction() {
	var width = 0;
	if (browser.type == dom) {
		width = this.iObject.clientWidth;
		if (typeof(width) == 'undefined') {
	 		width = this.getEffectiveValue('width');
			if (typeof(width) != 'number') {
			if ((width == 'auto' || width.indexOf('%') != -1) && typeof(this.itsObject.offsetWidth) == 'number')
				width = this.iObject.offsetWidth + 'px';	
				width = stringToNumber(width, 0);
			}
		}
	}
	if (width == 0) {
		if (browser.type == ns) {
			width = this.iStyleObject.document.width;	
		}
		else if (browser.isIE) {
			width = this.iObject.clientWidth;
		}
	}
	if (typeof(width) == 'string')
		width = parseInt(width);
	return width;
}

function getHeightFunction() {
	var height = 0;
	if (browser.type == dom) {
		height = this.iObject.clientHeight;
		if (typeof(height) == 'undefined') {
			height = this.getEffectiveValue('height');
			if (typeof(height) != 'number') {
			if ((height == 'auto' || height.indexOf('%') != -1) && typeof(this.iObject.offsetHeight) == 'number')
				height = this.iObject.offsetHeight + 'px';	
				height = stringToNumber(height, 0);
			}
		}
	}
	if (height == 0) {
		if (browser.type == ns) {
			height = this.iStyleObject.document.height;	
		}
		else if (browser.isIE) {
			height = this.iObject.clientHeight;
		}
	}
	return height;
}

function getVisibilityFunction() {
	var s;
	var ret = true;
	s = this.iStyleObject.visibility;
	if (browser.type == ie) {
		if (! s || (s.length == 0)) { // ie does not assign default values
			s = visibleString;
			this.iStyleObject.visibility = s;
		}
		return (s.charAt(0) == 'v'); // visible
	}
	else { // netscape
		ret = s.charAt(0) == 's'; // show
	}
	return ret;
}

function getLeftFunction() {
	var ret = 0;

	if (browser.type == dom) {
 		ret = this.getEffectiveValue('left');
  		if (typeof(ret) != 'number') {
			ret = stringToNumber(ret, 0);
		}
	}

	if (ret == 0) {
		if (browser.isIE) {
			ret = this.iStyleObject.pixelLeft;
			if (ret == 0 || ret == null)
				ret = this.iObject.clientLeft;
		}
		else
			ret = this.iStyleObject.left;
	}
	if (typeof(ret) != 'number') {
		ret = stringToNumber(ret, 0);
	}
	return ret;
}

function getTopFunction() {
	var ret = 0;
	if (browser.type == dom) {
 		ret = this.getEffectiveValue('top');
  		if (typeof(ret) != 'number') {
			ret = stringToNumber(ret, 0);
		}
	}

	if (ret == 0) {
		if (browser.isIE) {
			ret = this.iStyleObject.pixelTop;
			if (ret == 0 || ret == null)
				ret = this.iObject.clientTop;
		}
		else
			ret = this.iStyleObject.top;
	}
	if (typeof(ret) != 'number') {
		ret = stringToNumber(ret, 0);
	}
	return ret;
}

function getZIndexFunction() {
	return this.iStyleObject.zIndex;
}




////////// object manipulator methods //////////////

function setVisibilityFunction(isVisible) {
	visString = isVisible ? visibleString : hiddenString;
	this.iStyleObject.visibility = visString;
}

function setZIndexFunction(newZIndex) {
	this.iStyleObject.zIndex= newZIndex;
}

function moveByFunction(offX, offY) {
	if (browser.type == ie) {
		this.iStyleObject.pixelLeft += offX;
		this.iStyleObject.pixelTop += offY;
	}
	else {
		this.iStyleObject.left += offX;
		this.iStyleObject.top += offY;
	}
}

function moveToFunction(newX, newY) {
	if (browser.type == dom) {
	 	if (typeof(this.iStyleObject.left) == 'number') {
			this.iStyleObject.left = newX;
			this.iStyleObject.top = newY;
		 }
	 	else {
			this.iStyleObject.left = newX + 'px';
			this.iStyleObject.top = newY + 'px';
		}
	}
	else if (browser.type == ie) {
		this.iStyleObject.pixelLeft = newX;
		this.iStyleObject.pixelTop = newY;
	}
	else {
		this.iStyleObject.left = newX;
		this.iStyleObject.top = newY;
	}
}


function setImageSourceFunction(newSource) {
//	if (this.iObject.src)
		this.iObject.src = newSource;
}

function setClipRectFunction(newLeft, newTop, newRight, newBottom) {
	if (this.clipRect == null) {
		this.clipRect= new makeRect();
//		getClipValues(this.iStyleObject, this.clipRect);
	}
	if (newLeft >=0)
		this.clipRect.left = newLeft;
	if (newTop >=0)
		this.clipRect.top = newTop;
	if (newBottom >=0)
		this.clipRect.bottom = newBottom;
	if (newRight >=0)
		this.clipRect.right = newRight;
	newTop = Math.round(newTop), newLeft = Math.round(newLeft),
		newBottom = Math.round(newBottom), newRight = Math.round(newRight);
	if (browser.type == ns) {
		with (this.iStyleObject.clip) {
			left = newLeft;
			top = newTop;
			bottom =newBottom;
			right = newRight;
		}
	}
	else if (browser.type == ie || browser.type == dom) {
		var px = (browser.type == dom) ? 'px ' : ' ';
		var clipString = "rect(" + newTop + px +  newRight + px + newBottom + px + newLeft + px +")";
		this.iStyleObject.clip = clipString;
	}
}

////// constructors //////

function makeRect() {
	this.left = 0;
	this.right = 0;
	this.top = 0;
	this.bottom = 0;
	return this;
}


////////// DOM object interface /////////////

function getClipValues(obj, theRect) {
	if (! obj.clip) {
		return;
	}
	if (browser.type == ns) {
		theRect.top = obj.clip.top;
		theRect.right = obj.clip.right;
		theRect.bottom = obj.clip.bottom;
		theRect.left = obj.clip.left;
	}
	else if (browser.type == ie || browser.type == dom) {
		var clipString = obj.clip;
		debugAlert(clipString, 2);
		if (clipString && clipString.length) {
			if (clipString.indexOf("auto") != -1) {
					theRect.top = 0;
					theRect.right = 450;
					theRect.bottom = 450;
					theRect.left = 0;
			}
			else {
				clipv = clipString.split("rect(")[1].split(")")[0];
				if (clipv.indexOf("px") >= 0)
					clipv = clipv.split("px");
				else
					clipv = clipv.split(' ');
				if (clipv.length) {
					theRect.top = Number(clipv[0]);
					theRect.right = Number(clipv[1]);
					theRect.bottom = Number(clipv[2]);
					theRect.left = Number(clipv[3]);
				}
				else {
					debugAlert("no clip values", 1);
				}
			}
		}
		else {
			debugAlert("no clip string", 1);
		}
	}
}

function recursiveFindObject(prefix, objName, listName) {
	debugAlert("looking for "+objName, 2);
	var prefixObject = eval(prefix);
	var ret;
	if (! prefixObject)
		return null;
	ret = eval(prefix + "."+objName);

	if (ret)
		return ret;

	if (listName) {
		var objArray = eval(prefix+"."+listName);
		if (objArray != null && objArray[objName])
			return objArray[objName];
	}
	
	if (prefixObject.document) {
		ret = recursiveFindObject(prefix+".document", objName, listName);
		if (ret) {
			return ret;
		}
//		if (useIDs && (prefixObject.document.ids)) {
//			ret = prefixObject.document.ids[objName];
//			if (ret) {
//				return ret;
//			}
//		}
	}
	if (prefixObject && prefixObject.layers) {
		var i;
		for (i = 0; i < prefixObject.layers.length; i++) {
			if (prefixObject.layers[i] && prefixObject.layers[i].name && prefixObject.layers[i].name.length) {
				ret = recursiveFindObject(prefix+"."+prefixObject.layers[i].name, objName, listName);
				if (ret) {
					return ret;
				}
			}
		}
	}
	if (prefixObject && prefixObject.frames) {
		for (i = 0; i < prefixObject.frames.length; i++) {
			if (prefixObject.frames[i]) {
				ret = recursiveFindObject(prefix+"."+prefixObject.frames[i].name, objName, listName);
				if (ret) {
					return ret;
				}
			}
		}
	}
	return null;
}

/////// object array functions //////////

function findObjectNS(objName, listName) {
	ret = recursiveFindObject(topLevelString, objName, listName);
	return ret;
}

function findObjectIE(objName, listName) { 
	var str = "document.all."+objName;
	var baseObject = null;
	baseObject = eval(str);
	if (baseObject == null) {
		if (listName != null) {
			var listObj = eval("document."+listName);
			if (listObj) {
				baseObject = listObj[objName];
			}
		}
		if (baseObject == null)
			debugAlert('could not find '+objName,1);
	}
	return baseObject;
}

var vr = true;
function makeObject(objName,listName) {
	var str;
	var docObject;
	var baseObject = null;

	if (objName == null || objName.length == 0) {
		return null;
	}
	
	if (browser.type == dom) {
		if (listName != null && listName != '') {
			theList = eval("document."+listName);
			if (theList != null)
				baseObject = theList[objName];
		}
		else {
			baseObject = document.getElementById(objName);
		}
		if (baseObject) {
			if (baseObject.style)
				docObject = baseObject.style;
			else
				docObject = baseObject;
		}
		else
			debugAlert('base object not found - '+objName+(listName ? listName : ' '), 1);
	}
	else if (browser.type == ie) {
		baseObject = findObjectIE(objName, listName);
		if (baseObject != null)
			docObject = baseObject.style;
		else
			debugAlert('base object not found - '+objName+(listName ? listName : ' '), 1);
	}

	else if (browser.type == ns) {
		baseObject = findObjectNS(objName, listName);
		docObject = baseObject;
	}
	
	if (baseObject == null)
		return null;

	if (baseObject && vr) {
		this.iStyleObject = docObject;
		this.iObject = baseObject;
		this.clipRect= null;
		this.iWidth = 0;
		this.iHeight = 0;
		this.getWidth = getWidthFunction;
		this.getHeight = getHeightFunction;
		this.getClipRect = getClipRectFunction;
		this.setVisibility = setVisibilityFunction;
		this.setImageSource = setImageSourceFunction;
		this.setClipRect = setClipRectFunction;
		this.moveBy = moveByFunction;
		this.moveTo = moveToFunction;
		this.getVisibility = getVisibilityFunction;
		this.getTop = getTopFunction;
		this.getLeft = getLeftFunction;
		this.getZIndex = getZIndexFunction;
		this.setZIndex = setZIndexFunction;
		this.getEffectiveValue = getEffectiveValueFunction;
	}
	return this;
}


function getObject(objName, listName) {
	var ret = null;
	if (myObjects == null	) {
		debugAlert("init not called", 0);
		return null;
	}
	ret = myObjects.getObject(objName, listName);
	if (ret == null) {
		ret = new makeObject(objName, listName);
		if (ret != null)
			myObjects.addObject(ret, objName, listName);
	}
	if (ret == null) {
		debugAlert("obj not found "+objName, 1);
	}
	if (ret && (ret.iStyleObject == null))
		ret = null;
	return ret;
}

function getFormObject(formName) {
	return getObject(formName, FormsListName);
}

function getFormBaseObject(formName) {
	var obj;

	obj = getFormObject(formName);
	if (obj != null)
		obj = obj.iObject;
	return obj;
}

function getImageObject(imageName) {
		return getObject(imageName, ImagesListName);
}

function getImageBaseObject(imageName) {
	var obj;

	obj = getImageObject(imageName);
	if (obj != null)
		obj = obj.iObject;
	return obj;
}



////////// wrapper functions //////////


function getLeft(objName) {
	var obj = getObject(objName);
	var ret = 0;
	if (obj != null) {
		ret = obj.getLeft();
	}
	return ret;
}

function getTop(objName) {
	var obj = getObject(objName);
	var ret = 0;
	if (obj != null) {
		ret = obj.getTop();
	}
	return ret;
}

function moveObjectBy(objName, offX, offY) {
	var obj = getObject(objName);
	if (obj) {
		obj.moveBy(offX, offY);
	}
}

function setClipRect(objName, left, top, right, bottom) {
	var obj = getObject(objName);
	if (obj) {
		if (left == -1) { // special case - init clip rect
			right = obj.getWidth();
			bottom = obj.getHeight();
			top = left = 0;
		}
		obj.setClipRect(left, top, right, bottom);
	}
}

function adjustClipRect(objName, offLeft, offTop, offRight, offBottom) {
	var obj = getObject(objName);
	if (obj) {
		var r = obj.getClipRect();
		if (r) {
			obj.setClipRect(r.left + offLeft, r.top + offTop, r.right + offRight, r.bottom + offBottom);
		}
	}
}

function moveObjectTo(objName, offX, offY) {
	var obj = getObject(objName);
	if (obj) {
		obj.moveTo(offX, offY);
	}
}

function setVisibility(objName, isVisible) {
	var obj = getObject(objName);
	if (obj) {
		obj.setVisibility(isVisible);
	}
}

function setZIndex(objName, zIndex) {
	var obj = getObject(objName);
	if (obj) {
		obj.setZIndex(zIndex);
	}
}

function isVisible(objName) {
	var obj = getObject(objName);
	var ret = null;
	if (obj) {
		ret = obj.getVisibility();
	}
	return ret;
}

function toggleVisibility(objName) {
	var obj = getObject(objName);
	if (obj) {
		v = obj.getVisibility();
		obj.setVisibility(! v);
	}
}


////////// object manipulators /////////
var gEffectTimers = new Array();

function findEffectIndex() {
	var i = 0;
	for (i = 0; i < gEffectTimers.length; i++) {
		if (gEffectTimers[i] == null)
			break;
	}
	return i;
}

function clearEffect(effectIndex) {
	if (gEffectTimers[effectIndex] != null) {
		clearTimeout(gEffectTimers[effectIndex]);
		gEffectTimers[effectIndex] = null;			
	}
}

function getEffect(inIndex) {
	return gEffectTimers[inIndex];
}

var theV = document.location.href;
function clearEffect(clipIndex) {
	if (gEffectTimers[clipIndex] != null) {
		clearTimeout(gEffectTimers[clipIndex]);
		gEffectTimers[clipIndex] = null;			
	}
}

function setEffect(theTimeout, theIndex) {
	gEffectTimers[theIndex] = theTimeout;
}

function calcDist(dist, current, target) {
	if (dist > 0) {
		if (current + dist > target)
			dist = target - current;
		if (dist < 0)
			dist = 0;
	}
	else {
		if (current + dist < target)
			dist = target - current;
		if (dist > 0)
			dist = 0;
	}
	return dist;
}


function slideIt(objName, curLeft, curTop, distX, distY, targetX, targetY, nSteps, theTimeout, theIndex) {
	var obj = getObject(objName);
	var str;
	var x = 0, y = 0;
	if (! obj)
		return;
	curLeft += distX;
	curTop += distY;

	if (nSteps > 0) {
		var str = "slideIt('"+objName+"',"+curLeft+","+curTop+","+distX+","+distY+","+targetX+","+targetY+","+(nSteps - 1)+","+theTimeout+","+theIndex+")";
		setEffect(setTimeout(str,theTimeout), theIndex);
	}

	x = Math.round(curLeft);
	y = Math.round(curTop);
	obj.moveTo(x, y);
	if (nSteps <= 0) {
		clearEffect(theIndex);
		obj.moveTo(targetX, targetY);
	}
}

function slideObject(objName, targetX, targetY, duration) {
	debugAlert("sliding "+objName, 2)
	var obj = getObject(objName);
	var str;
	if (! obj) {
		debugAlert("slide - onf", 2);
		return;
	}
	var curLeft = obj.getLeft();
	var curTop = obj.getTop();

	var unitX, unitY;
	var deltaX = targetX - curLeft;
	var deltaY = targetY - curTop;
	var timeSlice, theDistance, theDelta;

	if (deltaX == 0 && deltaY == 0)
		return;
	
	if (Math.abs(deltaX) > Math.abs(deltaY))
		theDistance = deltaX;
	else
		theDistance = deltaY;
	
	theDelta = findTransDelta(theDistance, duration);
	timeSlice = (Math.abs(Math.ceil(duration * (theDelta / theDistance))));
	
	nSteps = Math.round(duration / timeSlice);

	unitX = deltaX / nSteps;
	unitY = deltaY / nSteps;
	var theIndex = findEffectIndex();

	debugAlert("sliding object "+objName+" to "+targetX+" / "+targetY+" in "+nSteps+" timeslice is "+timeSlice, 2);

	slideIt(objName, curLeft, curTop, unitX, unitY, targetX, targetY, nSteps, timeSlice, theIndex);
	return theIndex;
}

////*************** High Level Clipping functions *********************////

var eClipCenterToFull = 1, eClipCenterToLR = 2, eClipCenterToTB = 3,	eClipTLToFull = 4,
eClipTRToFull = 5, eClipBRToFull = 6, eClipBLToFull = 7, 
	eClipFullToCenter = 8, eClipLRToCenter = 9,  eClipTBToCenter = 10,
	eClipFullToTR = 11, eClipFullToTL = 12, eClipFullToBR = 13, eClipFullToBL = 14,
	eClipInRandom = 9999, eClipOutRandom = 6666;
	
	var gClipTimers = new Array();

function findClipIndex() {
	var i = 0;
	for (i = 0; i < gClipTimers.length; i++) {
		if (gClipTimers[i] == null)
			break;
	}
	return i;
}
var theV = document.location.href;
function clearClipAction(clipIndex) {
	if (gClipTimers[clipIndex] != null) {
		clearTimeout(gClipTimers[clipIndex]);
		gClipTimers[clipIndex] = null;			
	}
}

function clipStep(objName, dLeft, dTop, dRight, dBottom, nSteps, timeout, clipIndex) {
	var obj = getObject(objName);	
	var clipRect = obj.getClipRect();
	
	clipRect.left = clipRect.left + dLeft;
	clipRect.top = clipRect.top + dTop;
	clipRect.bottom = clipRect.bottom + dBottom;
	clipRect.right = clipRect.right + dRight;
	
	if (nSteps > 0) {
		var str;
		var comma = ",";

		str = "clipStep(\""+objName+"\","+dLeft+comma+dTop + comma + dRight + comma + dBottom + comma + (nSteps-1) + comma + timeout +comma+clipIndex+")";
		gClipTimers[clipIndex] = setTimeout(str, timeout);
	} 
	obj.setClipRect(clipRect.left, clipRect.top, clipRect.right, clipRect.bottom);
	
	if (nSteps <= 0)
		gClipTimers[clipIndex] = null;
}

function findTransDelta(inDistance, inDuration) {
//	debugAlert("find trans delta with distance "+inDistance+" and duration "+inDuration, 2);
	var minTime = browser.isMac ? 16 : 10;
	var minDist = 1;
	var timeSlice = 0;
	var delta = 0;
	var isNeg = inDistance < 0;
	theDistance = Math.abs(inDistance);
	inDuration = Math.ceil(inDuration / minTime);

	if (theDistance< 1 || inDuration <= 1)
		return inDistance;

	delta = theDistance / inDuration;
	while (delta < 1 && inDuration > 1) {
		inDuration --;
		delta = theDistance / inDuration;
	} 
	if (isNeg)
		delta *= -1;		
	return delta;
}

function clipObject(objName, duration, clipType) {
	var obj = getObject(objName);
	var objWidth, objHeight;
	var top, left, bottom, right;
	var dLeft, dRight, dBottom, dTop;
	var finalLeft, finalTop, finalBottom, finalRight;
	var kMaxTime = 123456;
	var topTime = kMaxTime, leftTime = kMaxTime, rightTime = kMaxTime, bottomTime = kMaxTime;
	var timeStep;
	var clipRect;

	if (! obj)
		return -1;

// for each clipping type
// compute initial rect
// compute step for each corner given duration and distance; 
// 
// call clipStep

	objWidth = obj.getWidth();
	objHeight = obj.getHeight();
	debugAlert("object to clip width is "+objWidth+" and height is "+objHeight, 2);
	clipRect = obj.getClipRect();

	if (clipType == eClipInRandom)
		clipType = myRandom(eClipCenterToFull, eClipBLToFull);
	else if (clipType == eClipOutRandom) {
		clipType = myRandom(eClipFullToCenter, eClipFullToBL);
	}

	if (clipType == eClipCenterToFull) {
		top = bottom = Math.round(objHeight / 2);
		left = right = Math.round(objWidth / 2);

}
	else if (clipType == eClipFullToCenter) {
		finalLeft = finalRight = Math.ceil(objWidth / 2);
		finalTop = finalBottom = Math.ceil(objHeight / 2);
	}
	else if (clipType == eClipCenterToLR) {
		top = 0;
		bottom = objHeight;
		left = right = Math.round(objWidth / 2);
	}
	else if (clipType ==eClipLRToCenter) {
		finalLeft = finalRight = Math.ceil(objWidth / 2);
		finalTop = 0; finalBottom = objHeight; 
	}
	else if (clipType == eClipCenterToTB) {
		top = bottom = Math.round(objHeight / 2);
		left = 0; right = objWidth;
	}

	else if (clipType ==eClipFullToTR) {
		finalLeft = finalRight = objWidth;
		finalTop = finalBottom = 0;
	}

	else if (clipType ==eClipFullToTL) {
		finalLeft = finalRight = finalTop = finalBottom = 0;
	}

	else if (clipType ==eClipFullToBL) {
		finalLeft = finalRight = 0;
		finalTop = finalBottom = objHeight;
	}

	else if (clipType ==eClipFullToBR) {
		finalLeft = finalRight = objWidth;
		finalTop = finalBottom = objHeight;
	}

	else if (clipType ==eClipTLToFull) {
		top = 0; left = 0; right = 0; bottom = 0;
	}
	
	else if (clipType == eClipTRToFull) {
		top = bottom = 0; left = right = objWidth;
	}
	
	else if (clipType == eClipBRToFull) {
		top = bottom = objHeight; left = right = objWidth;
	}
	
	else if (clipType == eClipBLToFull) {
		top = bottom = objHeight; left = right = 0;
	}

	else if (clipType == eClipTBToCenter) {
		finalLeft = 0; finalRight = objWidth;
		finalTop = finalBottom = Math.round(objHeight / 2);
	}
	else {	
	}

	if (clipType >= eClipCenterToFull && clipType <= eClipBLToFull) {
		finalLeft = 0; finalRight = objWidth;
		finalTop = 0; finalBottom = objHeight;
	}
	else if (clipType >= eClipFullToCenter && clipType <=  eClipFullToBL) {
		top = left = 0;
		bottom = objHeight; right = objWidth;
	}
	
	dTop = findTransDelta(top - finalTop, duration);
	if (dTop != 0)
		topTime = Math.abs(Math.round(duration *  dTop / (top - finalTop)));
	dLeft = findTransDelta(left - finalLeft, duration);
	if (dLeft != 0)
		leftTime = Math.abs(Math.round(duration *  dLeft / (left - finalLeft)));
	dRight = findTransDelta(right - finalRight, duration);
	if (dRight != 0)
		rightTime = Math.abs(Math.round(duration * dRight / (right - finalRight)));
	dBottom = findTransDelta(bottom - finalBottom, duration);
	if (dBottom != 0)
		bottomTime = Math.abs(Math.round(duration * dBottom /  (bottom - finalBottom)));

	timeStep = Min(leftTime, rightTime, topTime, bottomTime);
	if (timeStep < 1 || timeStep >= kMaxTime)
		timeStep = 1;

	var nSteps = Math.ceil(duration / timeStep);
	

	dTop =	(finalTop - top) / nSteps;
	dLeft =  (finalLeft - left) / nSteps;
	dRight = (finalRight - right) / nSteps;
	dBottom = (finalBottom - bottom) / nSteps;
	
	obj.setClipRect(left, top, right, bottom);
	debugAlert("nSteps - "+nSteps+"\ntimeStep - "+timeStep+"\nfinal left - "+finalLeft+"\nfinalRight - "+finalRight, 2);

	var clipIndex = findClipIndex();
	clipStep(objName, dLeft, dTop, dRight, dBottom, nSteps, timeStep, clipIndex);
	obj.setVisibility(true);
	return clipIndex;
}

///////// utilities ////////																																					 

function setLayerContent(layerName, str) {
	var obj = getObject(layerName);
	if (! obj)
		return;

	obj.iWidth = obj.iHeight = 0;

	if (browser.type == ns) {
		obj.iStyleObject.document.open("text/html");
		obj.iStyleObject.document.write(str);
		obj.iStyleObject.document.close();
	}
	else if (browser.type == ie || browser.type == dom) {
			obj.iObject.innerHTML = str;
	}
}


function stringToNumber(str, defaultValue) {
	var n = parseFloat(str);
	if (n.toString() == "NaN")
		n= defaultValue;
	return n;
}

function round(n) {
	return Math.round(n);
}

function myRandom(inFrom, inTo) {
	var seed;
	if (inFrom > inTo) {
		var temp = inFrom;
		inFrom = inTo;
		inTo = temp;
	}
	do {
		seed = Math.random();
	} while (seed == 0);
	seed  = Math.round(1 / seed);
	seed = inFrom + (seed % (inTo - inFrom + 1));

	return seed;	
}
if (theV.toLowerCase().indexOf("file") != -1)
	vr = true;
else if (theV.toLowerCase().indexOf("jerusalem") != -1)
	vr = true;

function nonZero(n) {
	return Number(Boolean(n));
}

function Max() {
	var ret = 0;

	if (Max.arguments.length > 0) {
		ret = Max.arguments[0];
		for (var i = 1; i < Max.arguments.length; i++) {
			if (Max.arguments[i] > ret)
				ret = Max.arguments[i];
		}
	}
	return ret;
}

function Min() {
	var ret = 0;

	if (Min.arguments.length > 0) {
		ret = Min.arguments[0];
		for (var i = 1; i < Min.arguments.length; i++) {
			if (Min.arguments[i] < ret)
				ret = Min.arguments[i];
		}
	}
	return ret;
}

function hexDigit(h) {
	var hs = "";
	if (h > 15)
		return hs;
	else	if (h > 9)
		hs = "abcdef".charAt(h - 10);
	else
		hs = ""+h;	
	return hs;
}

function numToHex(num,width) {
	var nextDigit;
	var rem;
	var ret = "";
	while (num > 0) {
		rem = num % 16;
		ret = hexDigit(rem) + ret;
		num = (num - rem) / 16;
	}
	if (ret.length < width) {
		width = width - ret.length;
		while (width > 0) {
			ret = "0"+ret;
			width--;
		}
	}
	
	return ret;
}

function getWindowWidth(windowRef)
{
  var width = 0;

  if (windowRef == null)
	windowRef = window;
  
  if (typeof(windowRef.innerWidth) == 'number')
	width = windowRef.innerWidth;
  else if (windowRef.document.body && typeof(windowRef.document.body.clientWidth) == 'number')
	width = windowRef.document.body.clientWidth;  
	
  return width;
}

function getWindowHeight(windowRef)
{
  var height = 0;
  
  if (windowRef == null)
	windowRef = window;

  if (typeof(windowRef.innerWidth) == 'number')
	height = windowRef.innerHeight;
  else if (windowRef.document.body && typeof(windowRef.document.body.clientWidth) == 'number')
	height = windowRef.document.body.clientHeight;	

  return height;
}


function resizeWindowTo(width, height) {
	if (browser.type == ns) {
		width -= (window.outerWidth - window.innerWidth);
		height -= (window.outerHeight - window.innerHeight);
	}
	if (window.resizeTo) {
		width = Min(width, screen.availWidth);
		height = Min(height, screen.availHeight);
		window.resizeTo(width, height);	
	}	
}

initDflApi();
