﻿	if (navigator.appName.indexOf("Microsoft") == -1)
	{
		HTMLElement.prototype.attachEvent = function (sType, fHandler) {
		   var shortTypeName = sType.replace(/on/, "");
		   fHandler._ieEmuEventHandler = function (e) {
			  window.event = e;
			  return fHandler();
		   };
		   this.addEventListener(shortTypeName, fHandler._ieEmuEventHandler, false);
		};

		HTMLElement.prototype.detachEvent = function (sType, fHandler) {
		   var shortTypeName = sType.replace(/on/, "");
		   if (typeof fHandler._ieEmuEventHandler == "function")
			  this.removeEventListener(shortTypeName, fHandler._ieEmuEventHandler, false);
		   else   // we can always try :-)
			  this.removeEventListener(shortTypeName, fHandler, true);
		};
	}
	

	var ScrollersGlobal = {
		canWheel:true,
		fCanWheel:function(e) {
			if (!ScrollersGlobal.canWheel) {
				ScrollersGlobal.canWheel = true;
				if (window.addEventListener)
					e.returnValue = false;
				return false;
			}

			return true;	
		},
		documentScrollTop:0
	}

	if (window.addEventListener) {


		//window.onscroll = function() {
			//alert(document.documentElement.scrollTop);
				// alert(document.scrollTop);
				//alert(document.documentElement.scrollTop);
			//window.scrollTo(0,document.documentElement.scrollTop);
			//alert(document.documentElement.scrollTop);
			
			//window.scrollTo(0,document.documentElement.scrollTop*1);
			
			

			//event.preventDefault();

		//}
/*
		window.addEventListener('DOMMouseScroll',function() {
		
			
			
		},false);

		/*
		document.onscroll = function() {
			document.documentElement.scrollTop = ScrollersGlobal.documentScrollTop;
		} */

	} else
		window.onmousewheel = document.onmousewheel = function() { return ScrollersGlobal.fCanWheel() };

	function Scroller(oParams) {

		var This = this;
		this.FixPixel = false;
		this.obj = null;
		this.objHeight = 0;
		this.objWidth = 0; // horizontal scroller
		this.objFullHeight = 0;
		this.objFullWidth = 0; // horizontal scroller
		this.scrollTop = 0;
		this.scrollLeft = 0; // horizontal scroller
		this.DragY = 0;
		this.DragX = 0; // horizontal scroller
		this.intrvl = null;
		this.iScroller = null;
		this.oArrowTop = null;
		this.oArrowLeft = null; // horizontal scroller
		this.oArrowBottom = null;
		this.oArrowRight = null; // horizontal scroller
		this.DraggedLineContainer = null;
		this.Spacer = null;
		this.iIntrvlCount = 0;
		this.oScroller = null;
		this.DraggedLine = null;
		this.imgArrowTop = "/images/controllers/scroller/arrow-top.gif";
		this.imgArrowBottom = "/images/controllers/scroller/arrow-bottom.gif";
		this.imgArrowLeft = "/images/controllers/scroller/arrow-left.gif"; // horizontal scroller
		this.imgArrowRight = "/images/controllers/scroller/arrow-right.gif"; // horizontal scroller
		this.imgBgScroller = "/images/controllers/scroller/bg-scroller.gif";
		this.imgBgScrollerHorizontal = "/images/controllers/scroller/bg-scroller-horizontal.gif"; // horizontal scroller
		this.Direction = "Vertical"; // Indicated the Direction of Scroller (Vertical/Horizontal)
		this.scrollerBorder = "#cdcdcd";
		this.scrollerBgColor = "#e9e9e9";
		this.scrollerInnerBgColor = "#cdcdcd";
		this.scrollerInnerBorderColor = "white";
		this.iArrowWidth = 7;
		this.iArrowHeight = 6;
		this.iArrowWidthHorizontal = 6;
		this.iArrowHeightHorizontal = 7;

		this.isIE = navigator.appName.indexOf("Microsoft") > -1;

		this.FullHeight = 0;
		this.FullWidth = 0;
		this.iInnerScrollHeight = 0;
		this.iInnerScrollWidth = 0;
		this.iDistancePerPixel = 0;
		this.iSpaceFromTop = 0;
		this.iSpaceFromLeft = 0;

		this.SetContinuing = function(fFunc,bCancelCondidtion) {
			fFunc();
			This.iIntrvlCount = 0;
			This.intrvl = setInterval(function() {
				fFunc();
				This.iIntrvlCount++;
				if (This.iIntrvlCount > 3 && !This.isIE && !bCancelCondidtion)
					clearInterval(This.intrvl);
			},15);
		}

		this.ScrollUp = function() {
			if (This.obj.scrollTop > 0)
				if (This.obj.scrollTop > 3)
					This.obj.scrollTop -= 3;
				else
					This.obj.scrollTop = 0;
			This.Update();
		}

		this.ScrollLeft = function() {
			if (This.obj.scrollLeft > 0)
				if (This.obj.scrollLeft > 3)
					This.obj.scrollLeft -= 3;
				else
					This.obj.scrollLeft = 0;
			This.Update();
		}

		this.ScrollDown = function() {
			if (This.obj.scrollTop < This.obj.scrollHeight)
				if (This.obj.scrollTop < (This.obj.scrollHeight - 3))
					This.obj.scrollTop += 3;
				else
					This.obj.scrollTop = This.obj.scrollHeight;

			This.Update();
		}

		this.ScrollRight = function() {
			if (This.obj.scrollLeft < This.obj.scrollWidth)
				if (This.obj.scrollLeft < (This.obj.scrollWidth - 3))
					This.obj.scrollLeft += 3;
				else
					This.obj.scrollLeft = This.obj.scrollWidth;

			This.Update();
		}

		this.Apply = function(sId,sIdToAppendScroller) {

			This.obj = document.getElementById(sId);
			if (This.obj.tagName == "TEXTAREA" && !This.isIE)
			{
				var oDiv = document.createElement("DIV");
					oDiv.style.cssText = "float:left;margin-right:2px";
					oDiv.style.width = This.obj.offsetWidth + "px";
					oDiv.style.height = (This.obj.offsetHeight) + "px";

					oDiv.style.whiteSpace = "nowrap";
					oDiv.style.overflow = "hidden";

					var oTextarea = This.obj.cloneNode(true);
					oTextarea.style.overflow = "visible";

					oTextarea.style.whiteSpace = "pre";
					oTextarea.style.height = (This.obj.offsetHeight) + "px";
					oTextarea.style.width = (This.obj.offsetWidth + 17) + "px";
					oDiv.appendChild(oTextarea);

				This.obj.parentNode.insertBefore(oDiv,This.obj);
				This.obj.parentNode.removeChild(This.obj);
				This.obj = document.getElementById(sId);
			}

			if (This.Direction == "Vertical")
			{
				
				This.iScroller = This.obj.scrollHeight < This.obj.offsetHeight ? This.obj.offsetHeight : This.obj.scrollHeight; 
				This.oScroller = document.getElementById(sIdToAppendScroller);
					This.oScroller.innerHTML = "";
					
					if (This.obj.offsetHeight>2) This.oScroller.style.height = (This.obj.offsetHeight - (This.FixPixel ? 3 : 2)) + "px";

					This.oScroller.style.width = "7px";
					This.oScroller.style.border = "1px solid "+ This.scrollerBorder;
					This.oScroller.style.backgroundColor = This.scrollerBgColor;

				if (!This.isIE && This.obj.tagName == "TEXTAREA")
					This.oScroller.style.marginTop = "1px";
				
				This.oArrowTop = document.createElement("DIV");

					if (oParams && oParams.SpriteMini)
					{
						This.oArrowTop.style.background = "url(/images/sprites/sprite-index-mini.gif) -1342px -350px no-repeat";
					} else {
						This.oArrowTop.style.background = "url(/images/sprites/sprite-boxes.gif) 0px -350px no-repeat"; // arrow top
					}

					This.oArrowTop.style.display = "block";
					This.oArrowTop.style.overflow = "hidden";
					This.oArrowTop.innerHTML = "&nbsp;";
					This.oArrowTop.style.width = This.iArrowWidth +"px";
					This.oArrowTop.style.height = This.iArrowHeight+"px";
					This.oArrowTop.attachEvent("onmousedown",function() { This.SetContinuing(This.ScrollUp) });
					This.oArrowTop.onmouseout = function() {clearInterval(This.intrvl)}
					This.oArrowTop.onmouseup = function() {clearInterval(This.intrvl)}

				This.oArrowBottom = document.createElement("DIV");


					if (oParams && oParams.SpriteMini)
					{
						This.oArrowBottom.style.background = "url(/images/sprites/sprite-index-mini.gif) -1342px -297px no-repeat";
					} else {
						This.oArrowBottom.style.background = "url(/images/sprites/sprite-boxes.gif) 0px -297px no-repeat"; // arrow top
					}
					


					This.oArrowBottom.style.overflow = "hidden";
					This.oArrowBottom.innerHTML = "&nbsp;";
					// This.oArrowBottom.src = This.imgArrowBottom;
					This.oArrowBottom.style.width = This.iArrowWidth +"px";
					This.oArrowBottom.style.height = This.iArrowHeight+"px";
					This.oArrowBottom.attachEvent("onmousedown",function() { This.SetContinuing(This.ScrollDown) });
					This.oArrowBottom.onmouseout = function() {
						if (This.DraggedLineContainer.style.marginBottom == "0px")
							clearInterval(This.intrvl);
					}
					This.oArrowBottom.onmouseup = function() {clearInterval(This.intrvl)}

				This.DraggedLineContainer = document.createElement("DIV");
				This.DraggedLineContainer.style.width = "7px";
				This.DraggedLineContainer.style.background = "url("+This.imgBgScroller+")";
				if (This.obj.offsetHeight>2) This.DraggedLineContainer.style.height = (This.obj.offsetHeight - (This.iArrowHeight * 2) - 2) + "px"; // 2 is the border of the arrows

				This.Spacer = document.createElement("DIV");
				This.DraggedLine = document.createElement("DIV");
				
				This.oScroller.appendChild(This.oArrowTop);
				This.oScroller.appendChild(This.DraggedLineContainer);

				This.DraggedLineContainer.appendChild(This.Spacer);
				This.DraggedLineContainer.appendChild(This.DraggedLine);
				This.oScroller.appendChild(This.oArrowBottom);
				if (This.obj.tagName == "TEXTAREA")
				{
					This.obj.onkeypress = This.Update;
					This.obj.attachEvent("onkeyup",This.Update);
				}



			} else { // Horizontal
				
				This.obj.scrollLeft = 0;
				This.iScroller = This.obj.scrollWidth < This.obj.offsetWidth ? This.obj.offsetWidth : This.obj.scrollWidth;

				This.oScroller = document.getElementById(sIdToAppendScroller);
					This.oScroller.innerHTML = "";
					This.oScroller.style.height = "7px";
					if (This.obj.offsetWidth>2) This.oScroller.style.width = (This.obj.offsetWidth - 2) + "px";
					This.oScroller.style.border = "1px solid "+ This.scrollerBorder;
					This.oScroller.style.backgroundColor = This.scrollerBgColor;
				
				This.oArrowLeft = document.createElement("DIV");

					if (oParams && oParams.SpriteMini)
					{
						This.oArrowLeft.style.cssText = "overflow:hidden;background:url(/images/sprites/sprite-index-mini.gif) -1342px -403px no-repeat;float:left;display:inline;margin:0px;padding:0px;";
					} else {
						This.oArrowLeft.style.cssText = "overflow:hidden;background:url(/images/sprites/sprite-boxes.gif) 0px -403px no-repeat;float:left;display:inline;margin:0px;padding:0px;";
					}

					This.oArrowLeft.innerHTML="&nbsp;";
					This.oArrowLeft.style.width = This.iArrowWidthHorizontal + "px";
					This.oArrowLeft.style.height = This.iArrowHeightHorizontal + "px";
					This.oArrowLeft.attachEvent("onmousedown",function() { This.SetContinuing(This.ScrollLeft) });
					This.oArrowLeft.onmouseout = function() {clearInterval(This.intrvl)}
					This.oArrowLeft.onmouseup = function() {clearInterval(This.intrvl)}

				This.oArrowRight = document.createElement("DIV");

					if (oParams && oParams.SpriteMini)
					{
						This.oArrowRight.style.background = "url(/images/sprites/sprite-index-mini.gif) -1342px -323px no-repeat";
					} else {
						This.oArrowRight.style.background = "url(/images/sprites/sprite-boxes.gif) 0px -323px no-repeat";
					}
					

					This.oArrowRight.style.overflow = "hidden";
					This.oArrowRight.innerHTML="&nbsp;";
					This.oArrowRight.style.width = This.iArrowWidthHorizontal + "px";
					This.oArrowRight.style.height = This.iArrowHeightHorizontal + "px";
					This.oArrowRight.attachEvent("onmousedown",function() { This.SetContinuing(This.ScrollRight) });
					This.oArrowRight.onmouseup = function() {clearInterval(This.intrvl)}

				This.DraggedLineContainer = document.createElement("DIV");
				This.DraggedLineContainer.style.cssText = "float:left;height:7px;font-size:0px;";
				This.DraggedLineContainer.style.background = "url("+This.imgBgScrollerHorizontal+")";

				if (navigator.appVersion.indexOf("MSIE 6") > -1)
					This.DraggedLineContainer.style.marginRight = "-3px";	
				
				if (This.obj.offsetHeight>2) This.DraggedLineContainer.style.width = (This.obj.offsetWidth - (This.iArrowWidthHorizontal * 2) - 2) + "px";

				This.Spacer = document.createElement("DIV");
				This.Spacer.style.cssText = "float:left;width:0px;height:7px;";

				This.DraggedLine = document.createElement("DIV");
				This.DraggedLine.style.cssText = "float:left;width:0px;height:7px;";
				
				This.oScroller.appendChild(This.oArrowLeft);
				This.oScroller.appendChild(This.DraggedLineContainer);
				
				This.DraggedLineContainer.appendChild(This.Spacer);
				This.DraggedLineContainer.appendChild(This.DraggedLine);
				
				This.oScroller.appendChild(This.oArrowRight);
			}

			if (!This.isIE)
			{
				This.obj.addEventListener('DOMMouseScroll',This.Wheel,false);
			} else {
				This.obj.onmousewheel = This.Wheel;
			}

			

		}

		this.Wheel = function(event) {

			

			
			ScrollersGlobal.canWheel = false;

			var delta = 0;
			if (!event)
				event = window.event;
			if (event.wheelDelta) {
				delta = event.wheelDelta/120;
				if (window.opera)
						delta = -delta;
			} else if (event.detail) { /** Mozilla case. */
				delta = -event.detail/3;
			}


			if (event.preventDefault) {
			  event.preventDefault();
			  event.stopPropagation();
			} else {
			  event.returnValue = false;
			  event.cancelBubble = true;
			}

			
			if (delta > 0)
			{
				if (This.Direction == "Vertical")
				{
					This.ScrollUp();
				} else {
					This.ScrollLeft();
				}

			} else {
				if (This.Direction == "Vertical")
				{
					This.ScrollDown();
				} else {
					This.ScrollRight();
				}
			}
			

		}

		this.Update = function() {

			
			if (This.Direction=="Vertical")
			{
				
				This.iScroller = This.obj.scrollHeight < This.obj.offsetHeight ? This.obj.offsetHeight : This.obj.scrollHeight;
				This.DraggedLineContainer.style.marginBottom = "0px";
				This.FullHeight = This.DraggedLineContainer.offsetHeight - 2;
				// This.DraggedLineContainer.style.height = This.FullHeight.toString() + "px";

				// alert("obj.offsetHeight:"+This.obj.offsetHeight + "\nThis.iScroller:" + This.iScroller + "\nThis.FullHeight:" + This.FullHeight + "\nThis.obj.scrollTop:"+ This.obj.scrollTop);


				if (This.iScroller > This.obj.offsetHeight)
				{

					This.Spacer.style.visibility = This.DraggedLine.style.visibility = "visible";
					This.DraggedLine.style.width = "5px";
					This.DraggedLine.style.marginLeft = "1px";
					This.DraggedLine.style.borderTop = "1px solid " + This.scrollerInnerBorderColor;
					This.DraggedLine.style.borderBottom = "1px solid " + This.scrollerInnerBorderColor;
					This.DraggedLine.style.backgroundColor = This.scrollerInnerBgColor;
					This.DraggedLine.onmousedown = This.ScrollMove;

					This.iMinHeight = 5;	

					This.iInnerScrollHeight = (This.obj.offsetHeight / This.iScroller) * This.FullHeight;
					This.DraggedLine.style.height = Math.max(This.iInnerScrollHeight,This.iMinHeight) + "px"; //  הגודל של בר הגרירה
					This.iDistancePerPixel = (This.obj.offsetHeight/This.iInnerScrollHeight) ; // מס' הפיקסלים עבור פיקסל אחד של סקרולר
					This.iSpaceFromTop = (This.obj.scrollTop / This.iDistancePerPixel);
					This.Spacer.style.height = This.iSpaceFromTop + "px";
					This.scrollTop = This.iSpaceFromTop;

					try
					{
						if (This.iInnerScrollHeight < This.iMinHeight)
							This.Spacer.style.height = (This.iSpaceFromTop-2) + "px";
					}
					catch (e)
					{
					}


					

				} else {
					This.Spacer.style.visibility = This.DraggedLine.style.visibility = "hidden";
				}

			} else {
				
				This.iScroller = This.obj.scrollWidth < This.obj.offsetWidth ? This.obj.offsetWidth : This.obj.scrollWidth;
				This.DraggedLineContainer.style.marginBottom = "0px";
				This.FullWidth = This.DraggedLineContainer.offsetWidth - 2;

				if (This.iScroller > This.obj.offsetWidth)
				{
					This.Spacer.style.visibility = This.DraggedLine.style.visibility = "visible";
					This.DraggedLine.style.height = "5px";
					This.DraggedLine.style.marginTop = "1px";
					This.DraggedLine.style.borderLeft = "1px solid " + This.scrollerInnerBorderColor;
					This.DraggedLine.style.borderRight = "1px solid " + This.scrollerInnerBorderColor;
					This.DraggedLine.style.backgroundColor = This.scrollerInnerBgColor;
					This.DraggedLine.onmousedown = This.ScrollMove;

					This.iInnerScrollWidth = (This.obj.offsetWidth / This.iScroller) * This.FullWidth;
					This.DraggedLine.style.width = This.iInnerScrollWidth.toString() + "px";
					This.iDistancePerPixel = This.obj.offsetWidth/This.iInnerScrollWidth;

					This.iSpaceFromLeft = (This.obj.scrollLeft / This.iDistancePerPixel);
					This.Spacer.style.width = This.iSpaceFromLeft + "px";
					This.scrollLeft = This.iSpaceFromLeft;

				} else {
					This.Spacer.style.visibility = This.DraggedLine.style.visibility = "hidden";
				}
			}
		}

		this.ScrollMove = function() {
			var e = arguments[0] || event;

			if (!This.isIE)
				e.preventDefault();
		
			if (This.Direction == "Vertical")
				This.DragY = e.clientY;
			else
				This.DragX = e.clientX;

			document.body.attachEvent("onselectstart",This.SelectStartFalse);
			if (This.isIE)
			{
				document.body.attachEvent("onmousemove",This.Move);
				document.body.attachEvent("onmouseup",This.ScrollStop);
			} else {
				window.onmousemove = This.Move;
				window.onmouseup = This.ScrollStop;
			}
		}

		this.SelectStartFalse = function() {
			return false;
		}

		this.ScrollStop = function() {

			document.body.detachEvent("onselectstart",This.SelectStartFalse);
			if (This.isIE)
			{
				document.body.detachEvent("onmousemove",This.Move);
				document.body.detachEvent("onmouseup",This.ScrollStop);
			} else {
				window.onmousemove = null;
				window.onmouseup = null;
			}
		}

		this.Move = function() {
			var e = arguments[0] || event;

			if (This.Direction == "Vertical")
			{
				if (This.obj.scrollHeight > (This.iDistancePerPixel * (This.scrollTop + (e.clientY - This.DragY))) && (This.scrollTop + (e.clientY - This.DragY)) > 0 && e.clientY != This.DragY)
				{
					This.obj.scrollTop = ((This.scrollTop + (e.clientY - This.DragY)) < 2) ? 0 : This.iDistancePerPixel * (This.scrollTop + (e.clientY - This.DragY));
					This.Update();
				}
				This.DragY = e.clientY;
			} else {
				
				if (This.obj.scrollWidth > (This.iDistancePerPixel * (This.scrollLeft + (e.clientX - This.DragX))) && (This.scrollLeft + (e.clientX - This.DragX)) > 0 && e.clientX != This.DragX)
				{
					This.obj.scrollLeft = ((This.scrollLeft + (e.clientX - This.DragX)) < 2) ? 0 :  This.iDistancePerPixel * (This.scrollLeft + (e.clientX - This.DragX));
					This.Update();
				}
				This.DragX = e.clientX;

			}
		}
	}