	function biiPreloadImage(imagefile)
	{
		var imageobj = new Image();
		imageobj.src=imagefile;
	}

	function biiFindPos(obj){
		var curleft = curtop = 0;
		if (obj.offsetParent) {
			do {
				curleft += obj.offsetLeft;
				curtop += obj.offsetTop;
			} while (obj = obj.offsetParent);
	
			return [curleft,curtop];
		}
	}
	
	function biiGetImageSize(image, dimension)
	{
		ret_dim = 0;
		if(dimension=='height')
		{
			ret_dim=image.height;
			if(ret_dim=='') ret_dim = image.style.height
			if(ret_dim=='') ret_dim = 40
		}
		else if(dimension=='width')
		{
			ret_dim=image.width;
			if(ret_dim=='') ret_dim = image.style.width
			if(ret_dim=='') ret_dim = 40
		}
		return ret_dim;
	}

	function showBigImageInline(e,smallim,bigim,bigimagesrc)
	{
		//calculate coordiates
			//coordinates
			event_postitions = biiGetEventPosition(e)
			eventleft = event_postitions[0]
			eventtop = event_postitions[1]
				//smallpositions = biiFindPos(smallim)
				//smallleft=smallpositions[0];//smallim.style.left;
				//smalltop=smallpositions[1];//smallim.style.top;
			//small image width
			smallwidth=biiGetImageSize(smallim, 'width');
			//small image height
			smallheight=biiGetImageSize(smallim, 'height');
		//create big image element
			var newelement=document.createElement('img');
			newelement.src=bigimagesrc;
			newelement.id=bigim;
			//calculate starting postition
			bigwidth=biiGetImageSize(newelement, 'width');
			bigheight=biiGetImageSize(newelement, 'height');
			//calculate if has a space to be displayed to the left or to the rigth
				hasspace_right = document.body.clientWidth - (eventleft-document.body.scrollLeft)-bigwidth;//negative means overflow
				hasspace_left = (eventleft-document.body.scrollLeft) - bigwidth;//negative means overflow
				
				display_bii_hor = '';
				if(hasspace_right >= hasspace_left){//display image to the right
					display_bii_hor = 'right';
				}
				else{//display image to the left
					display_bii_hor = 'left';
				}
			//--

			newelement.style.left= display_bii_hor == 'right' ? eventleft+20 : eventleft-bigwidth-20;
			newelement.style.top= eventtop+20;
			newelement.style.position='absolute';
			newelement.style.zIndex='100';
			document.body.appendChild(newelement);
			

		//add Mouse event listeners
			if (document.addEventListener != null)
			{ // e.g. Firefox, Opera, Safari
				eval('document.addEventListener("mousemove", bigim_mousemove_function = function(e){moveBigImageInline(e,"'+smallim+'","'+bigim+'", "'+display_bii_hor+'");}, true)');
				eval('document.addEventListener("mouseup", bigim_mouseup_function = function(){hideBigImageInline("'+bigim+'")}, true)');
			}
			else
			{ // e.g. Internet Explorer (also would work on Opera)
				eval('bigim_mousemove_function = function(e){moveBigImageInline(e,"'+smallim+'","'+bigim+'", "'+display_bii_hor+'");}')
				eval('bigim_mouseup_function = function(){hideBigImageInline("'+bigim+'")}');

				document.attachEvent("onmousemove", bigim_mousemove_function);
				document.attachEvent("onmouseup", bigim_mouseup_function);
			}
		//--end showBigImageInline
	}

	//function finds x and y position of an event
	function biiGetEventPosition(e)
	{
			var IE = document.all?true:false;
			var tempX = 0;
			var tempY = 0;
			if (IE) { // grab the x-y pos.s if browser is IE
				tempX = event.clientX + document.body.scrollLeft;
				tempY = event.clientY + document.body.scrollTop;
			}
			else { // grab the x-y pos.s if browser is NS
				tempX = e.pageX;
				tempY = e.pageY;
			}
			if (tempX < 0){tempX = 0;}
			if (tempY < 0){tempY = 0;}
			
			return [tempX, tempY];
	}

	//define onmousemove event function	for bigimage
	function moveBigImageInline(e, smallim, bigim)//, display_bii_hor)
	{
		var bigimage = document.getElementById(bigim);
		event_postitions = biiGetEventPosition(e);

		posX = event_postitions[0]
		posY = event_postitions[1]

		if(display_bii_hor=='right'){
			bigimage.style.left = posX+20;
			newtop = posY+20;
		}
		else{
			bigimage.style.left = posX-bigwidth-20;
			newtop = posY;
		}	
		
		//bigim_left = document.getElementById(bigim).style.left;
		//bigim_top = parseInt(bigimage.style.top);

		//check if image stays in window vertically
		hasspace_top = newtop - document.body.clientHeihgt - document.body.scrollTop - bigheight;//positive is good
		hasspace_bottom = document.body.clientHeight - (newtop - document.body.scrollTop) - bigheight;//
//		hasspace_bottom = document.body.clientHeihgt - (smalltop-document.body.scrollTop)-smallheight-bigheight;//positive is good
//		hasspace_top = (smalltop-document.body.scrollTop) - bigheight;//
		
		if(hasspace_bottom<0){
			bigimage.style.top = newtop + hasspace_bottom - 10;
		}
		else{
			bigimage.style.top = newtop;
		}
		
		
		return true;
	}

	function hideBigImageInline(bigim)
	{
		var remove_elem = document.getElementById(bigim);
		remove_elem.parentNode.removeChild(remove_elem);
		if (document.removeEventListener != null)
		{ //e.g. Firefox, Opera, Safari
			document.removeEventListener("mousemove", bigim_mousemove_function, true);
			document.removeEventListener("mouseup", bigim_mouseup_function, true);
		}
		else
		{ //e.g. Internet Explorer (also would work on Opera)
			document.detachEvent("onmousemove", bigim_mousemove_function);
			document.detachEvent("onmouseup", bigim_mouseup_function);
		}
	}
