			function debug(variable) {
//				if (e = document.getElementById('_js__debugelement')) {
				if (e = document.getElementById('mainsearch_edit')) {
					e.value = variable;
//					e.innerHTML = variable;
				}
			}

			var moveGalleryBusy = 0;
			var galleryPosition = 0; 
			var galleryPositionMin = 0; 
			var galleryPositionMax = 0;
			var turnSpeedDelay = 10;
			var turnSpeed;
			var turnTo;
			var galleryTimer = null;
			
			var idPrefixContainer = 'gallery_object';
			var idPrefixItemContainer = 'gallery_items_slider';
			var idPrefixItems = 'gallery_items';
			function startGalleryTurn(evt, idn) {
				id = idPrefixContainer + idn;
				if (element = document.getElementById(id)) {
					if (gal = document.getElementById(idPrefixItems + idn));
					if (gal2 = document.getElementById(idPrefixItemContainer + idn));
					galleryPositionMin = -1 * (gal.offsetWidth-gal2.offsetWidth);
					galleryPositionMax = 0; //element.offsetLeft;
					resetGalleryTurn(evt, id);
				}
			}
			
			function stopGalleryTurn(evt, idn) {
				id = idPrefixContainer + idn;
				clearTimeout(galleryTimer);
				moveGalleryBusy = 0;
			}

			function resetGalleryTurn(evt, idn) {
					if (galleryPositionMin > galleryPositionMax)
					  return;
				id = idPrefixContainer + idn;
				if (moveGalleryBusy != 0)
					return 0;

				if (element = document.getElementById(id)) {
					var posx = 0;
					if (!evt) var evt = window.event;
					if (evt.pageX) 
						posx = evt.pageX;
					else if (evt.clientX)
						posx = evt.clientX;
	
					halfWidth = element.offsetWidth; 
					
					elementpos = findPos(element);
					by = (halfWidth / 2)- posx + elementpos[0]; //element.offsetLeft;
					//by =  posx - elementpos[0];

					perc = by / halfWidth * 200;
					if (perc > 30)
						turnTo = 1;
					else
						if (perc < 30)
							turnTo = -1;
						else
						 	turnTo = 0;

					perc = Math.abs(perc);
					if (perc > 30)
						perc = perc - 30;
					else
						perc = 0;

					//kierunek
					
					if (perc != 0) {
//						turnSpeed = Math.round((100 - perc) / 1, 0);
//						turnSpeed = Math.round(Math.cos( (( 90-(perc*0.9)) / 1) * Math.PI / 180)*100, 0);
						perc = perc*1.3; //celem zakresu 0-90st (zakladajac wczesniejsze ograniczenie 0-60)
						if (perc>90) perc = 90; //zapezpieczenie
						turnSpeed = Math.round(Math.sin( ((perc) * Math.PI) / 180)*100, 0);
					}
					else
						turnSpeed = 0;
					if (turnSpeed > 0) {
						moveGalleryBusy = 1;
						if (galleryTimer)
							clearTimeout(galleryTimer);
						galleryTimer = setTimeout("redrawGalleryPosition(" + idn +");", turnSpeedDelay);
					}
				}
			}
			
			function redrawGalleryPosition(idn) {
				//jezeli nie ma czego przesuwac - nie przesuwamy
				if (galleryPositionMin > galleryPositionMax)
				  return;
//				debug(turnTo + ' ' + galleryPosition + ' ' + turnSpeed);
				moveGalleryBusy = 0;
//				galleryPosition = galleryPosition + 1 * turnTo;
				galleryPosition = galleryPosition + Math.round(((turnSpeed/10)), 0) * turnTo;
				if (gal = document.getElementById(idPrefixItems + idn)) {
					if (galleryPosition < galleryPositionMin) {
						galleryPosition = galleryPositionMin;
						gal.style.left = galleryPosition+'px';
						return;
					}
					if (galleryPosition > galleryPositionMax) {
						galleryPosition = galleryPositionMax;
						gal.style.left = galleryPosition+'px';
						return;
					}
					gal.style.left = galleryPosition+'px';
				}
				
				if (turnSpeed > 0) {
					if (galleryTimer)
						clearTimeout(galleryTimer);
					galleryTimer = setTimeout("redrawGalleryPosition(" + idn +");", turnSpeedDelay);
				}
			}
			
			
			function containsDOM (container, containee) {
				var isParent = false;
				do {
					if ((isParent = container == containee))
						break;
					containee = containee.parentNode;
				}
				while (containee != null);
				return isParent;
			}

			function checkMouseEnter (element, evt) {
				if (element.contains && evt.fromElement) {
					return !element.contains(evt.fromElement);
				}
				else if (evt.relatedTarget) {
					return !containsDOM(element, evt.relatedTarget);
				}
			}

			function checkMouseLeave (element, evt) {
				if (element.contains && evt.toElement) {
					return !element.contains(evt.toElement);
				}
				else if (evt.relatedTarget) {
					return !containsDOM(element, evt.relatedTarget);
				}
			}

			function findPos(obj) {
				var curleft = curtop = 0;
				if (obj.offsetParent) {
					do {
						curleft += obj.offsetLeft;
						curtop += obj.offsetTop;
					} while (obj = obj.offsetParent);
					return [curleft,curtop];
				}
			}

