//alert(Math.prototype);
if (typeof Math.sgn == "undefined"){
	Math.sgn = function(nr) {
		return nr >= 0 ? 1 : -1;
	}
}
if (typeof Function.prototype.bind == "undefined"){
	Function.prototype.bind = function() {
		var __method = this, args, object = arguments[0];
		return function() { return __method.apply(object, arguments); }
	}
}
if (typeof Object.prototype.contains == "undefined"){
	Object.prototype.contains = function(elem) {
		if (this == elem) return false;
		try{
			while (elem && (elem != this)){
				elem = elem.parentNode;
			}
		}catch(e){}
		return this == elem;
	}
}

var jsScroller = {
	//public variables
	scrollerType : 'horizontal',				//((string)(horizontal|vertical)) scroll direction
	scrollerMinHeight : 6.9,				//((float) em) min height
	scrollerArrowBackgroundHeight : 6.9,			//((float) em) arrow background image height !ONLY FOR HORIZONTAL SCROLL
	scrollerArrowBackgroundWidth : 6.9,			//((float) em) arrow background image height !ONLY FOR VERTICAL SCROLL
	scrollerSpeed : 0.9,					//((float) em) em / frame
	scrollFPS : 35,						//((int) FPS)
	scrollParentClass : 'js_scroller',
	scrollAditionalParentClass : '',
	//37.1
	//scrollerIntervalLength : 50,//500

	scrollerViewPortHeight : 18,				//((int) em) view port height
	scrollerViewPortHeightAuto : false,			//(true|false) auto resize viewport ( NOT RECOMENDED if you use inline scripts and IMAGES ) ( RECOMENDED only after PAGE LOAD )

        //vertical only
	scrollerViewPortWidth : 18,				//((int) em) view port height
	scrollerViewPortWidthAuto : false,			//(true|false) auto resize viewport ( NOT RECOMENDED if you use inline scripts and IMAGES ) ( RECOMENDED only after PAGE LOAD )

	scrollerAuto : true,					//(true|false) auto scroll
	scrollerAutoDirection : -1,				//(1|-1) starting auto scroll direction ( horizontal : 1 = right, -1 = left ) ( vertical : 1 = down, -1 up );
	scrollerAutoSpeed : 0.1,				//((float) em) em / frame
	scrollerAutoBounce : true,				//(true|false) bounce against walls
	scrollElementHoverPause : true,				//(true|false) pause auto scrolling on hover element

	scrollerCircular : true,

	scrollerNoEvents : false,
        scrollAproachLimit : 200,				//((int) em)
	onAproachViewPort : function(){},
	onEnterViewPort : function(){},
	onLeaveViewPort : function(){},

	//private variables
	scrollerMoveWidth : 0,
	scrollerOnLoadCheckArray : new Array,
        scrollerAutoCan : false,
        scrollerCircularCan : false,
        scrollerCircularFirstElemInd : 0,
        scrollerCircularLastElemInd : 0,
        scrollerCircularMinShowDiff : 2,			//scroller is circular if showen elements  +  scrollerCircularMinShowDiff <= to
        scrollerDefaultFontSize : 10,
        scrollerDistProperty : '',
        scrollerSizeProperty : '',
        scrollerDoubleCheckCircular : BrowserDetect.browser.toLowerCase() == "explorer",
        scrollerVerticalCan : 1 || BrowserDetect.browser.toLowerCase() != "opera",

	//constants
	SCROLLER_PARAM_NAMES : ["scrollerType", "scrollerMinHeight", "scrollerArrowBackgroundHeight", "scrollerArrowBackgroundWidth",
		"scrollerViewPortHeight", "scrollerViewPortHeightAuto", "scrollerSpeed", "scrollAproachLimit", "onAproachViewPort", "onEnterViewPort",
		"onLeaveViewPort", "scrollerIntervalLength", "scrollerMoveWidth", "scrollerAuto", "scrollerAutoDirection", "scrollerAutoSpeed",
		"scrollFPS", "scrollElementHoverPause", "scrollerAutoCan", "scrollerCircular", "scrollerCircularFirstElemInd",
		"scrollerCircularLastElemInd", "scrollerDefaultFontSize", "scrollParentClass", "scrollAditionalParentClass", "scrollerDistProperty",
		"scrollerSizeProperty", "scrollerCircularCan", "scrollerCircularMinShowDiff", "scrollerAutoBounce"],
	SECOND : 1000,
	ONLOAD_CHECK : (BrowserDetect.browser.toLowerCase() == "safari") || (BrowserDetect.browser.toLowerCase() == "opera"),

	//function declarations
	onloadCreate : function(){
		for (var i=0; i<jsScroller.scrollerOnLoadCheckArray.length; i++){
			jsScroller.create(jsScroller.scrollerOnLoadCheckArray[i], true);
		}
	},
	create : function(params, afterLoad){
		if (!afterLoad && (jsScroller.ONLOAD_CHECK || params.scrollerType == 'vertical' || (typeof params.scrollerType == 'undefined' && jsScroller.scrollerType == 'vertical'))){
			jsScroller.scrollerOnLoadCheckArray.push(params);
			return;
		}
                var el;
                if ((typeof params.targetElement == "object") && (params.targetElement != null)){
			el = params.targetElement;
		}else if (typeof params.targetId == "string"){
			var a;
			if (a = document.getElementById(params.targetId)){
				el = a;
			}
		}
		if (typeof el == "object" && el != null){
			var scrollerContainer = document.createElement("div");
			scrollerContainer.getElementLeft = jsScroller.getElementLeft.bind(scrollerContainer);
                        scrollerContainer.getElementWidth = jsScroller.getElementWidth.bind(scrollerContainer);

			for (var i=0; i<jsScroller.SCROLLER_PARAM_NAMES.length; i++){
				if (typeof params[jsScroller.SCROLLER_PARAM_NAMES[i]] == "undefined"){
					scrollerContainer[jsScroller.SCROLLER_PARAM_NAMES[i]] = jsScroller[jsScroller.SCROLLER_PARAM_NAMES[i]];
				}else{
					scrollerContainer[jsScroller.SCROLLER_PARAM_NAMES[i]] = params[jsScroller.SCROLLER_PARAM_NAMES[i]];
                                }
			}
			if (scrollerContainer.scrollerType == 'vertical' && !jsScroller.scrollerVerticalCan){
				return;
			}

			scrollerContainer.scrollerDistProperty = scrollerContainer.scrollerType == 'horizontal' ? 'left' : 'top';
			scrollerContainer.scrollerSizeProperty = scrollerContainer.scrollerType == 'horizontal' ? 'width' : 'height';

			/* if (scrollerContainer.scrollerType == 'vertical'){
				scrollerContainer.scrollerViewPortHeightAuto = true;
			} */
			scrollerContainer.scrollAproachLimit = parseInt(scrollerContainer.scrollAproachLimit);
			if (isNaN(scrollerContainer.scrollAproachLimit)){
				scrollerContainer.scrollAproachLimit = 0;
			}
			if (scrollerContainer.scrollAproachLimit < 0){
				scrollerContainer.scrollAproachLimit = Math.abs(scrollerContainer.scrollAproachLimit);
			}

			//calculate scroller font size
			var fontGetter = document.createElement("div");
			fontGetter.style.fontSize = "1em";
			fontGetter.style.width = "1em";
			//fontGetter.style.fontSize = "1.2em";
			el.parentNode.appendChild(fontGetter);
			scrollerContainer.scrollerFontSize = scrollerContainer.getElementWidth(fontGetter);
			if (scrollerContainer.scrollerFontSize <= 0){
				scrollerContainer.scrollerFontSize = scrollerContainer.scrollerDefaultFontSize;
			}
			fontGetter.parentNode.removeChild(fontGetter);

			scrollerContainer.scrollerIntervalLength = jsScroller.SECOND / scrollerContainer.scrollFPS;
			scrollerContainer.scrollerMoveWidth = scrollerContainer.scrollerSpeed;

			var objectWidth = jsScroller.getElementWidth(el, true) - (BrowserDetect.browser.toLowerCase() == "explorer" ? 2 : 0);// ie
			var objectHeight = jsScroller.getElementHeight(el) - (BrowserDetect.browser.toLowerCase() == "explorer" ? 2 : 0);// ie
			
			var minHeight = objectHeight / scrollerContainer.scrollerFontSize;
			
                        objectWidth = objectWidth / scrollerContainer.scrollerFontSize;
			objectHeight = minHeight > scrollerContainer.scrollerMinHeight ? minHeight : scrollerContainer.scrollerMinHeight;

                        scrollerContainer.scrollToLeft = jsScroller.scrollToLeft.bind(scrollerContainer);
                        scrollerContainer.scrollToRight = jsScroller.scrollToRight.bind(scrollerContainer);
                        scrollerContainer.init = jsScroller.init.bind(scrollerContainer);
                        scrollerContainer.autoScroll = jsScroller.autoScroll.bind(scrollerContainer);
                        scrollerContainer.setScroll = jsScroller.setScroll.bind(scrollerContainer);
                        scrollerContainer.stopScroll = jsScroller.stopScroll.bind(scrollerContainer);
                        scrollerContainer.stopAutoScroll = jsScroller.stopAutoScroll.bind(scrollerContainer);
                        scrollerContainer.calcShowemElements = jsScroller.calcShowemElements.bind(scrollerContainer);

                        /* getElementLeft
                        getElementWidth
                        getElementTop
                        getElementHeight */

                        scrollerContainer.scrollMax = 0;
                        scrollerContainer.scrollInterval = 0;
                        //scrollerContainer.objectWidth = objectWidth;

                        scrollerContainer.scrollElements = new Array();
                        
                        scrollerContainer.className = scrollerContainer.scrollParentClass + (scrollerContainer.scrollAditionalParentClass != '' ? ' '+scrollerContainer.scrollAditionalParentClass : '');
			scrollerContainer.style.width = objectWidth+"em";
			//scrollerContainer.style.border = "1px solid red;";

			scrollerContainer.leftArrow = document.createElement("a");
			scrollerContainer.leftArrow.href = "javascript:void(0);";
			scrollerContainer.leftArrow.className = scrollerContainer.scrollerType == 'horizontal' ? "js_scroller_left_arrow" : "js_scroller_up_arrow";
			//scrollerContainer.leftArrow.onmouseover = scrollerContainer.stopScroll;
			scrollerContainer.leftArrow.onmousedown = scrollerContainer.scrollToLeft;
			scrollerContainer.leftArrow.onmouseup = scrollerContainer.stopAutoScroll;
			scrollerContainer.leftArrow.onmouseout = scrollerContainer.stopAutoScroll;
			scrollerContainer.appendChild(scrollerContainer.leftArrow);

			scrollerContainer.scrollContent = document.createElement("div");
			scrollerContainer.scrollContent.className = "js_scroller_content";
			scrollerContainer.appendChild(scrollerContainer.scrollContent);

                        scrollerContainer.rightArrow = document.createElement("a");
			scrollerContainer.rightArrow.href = "javascript:void(0);";
			scrollerContainer.rightArrow.className = scrollerContainer.scrollerType == 'horizontal' ? "js_scroller_right_arrow" : "js_scroller_down_arrow";
			//scrollerContainer.rightArrow.onmouseover = scrollerContainer.stopScroll;
			scrollerContainer.rightArrow.onmousedown = scrollerContainer.scrollToRight;
			scrollerContainer.rightArrow.onmouseup = scrollerContainer.stopAutoScroll;
			scrollerContainer.rightArrow.onmouseout = scrollerContainer.stopAutoScroll;
			scrollerContainer.appendChild(scrollerContainer.rightArrow);

			el.parentNode.insertBefore(scrollerContainer,el);
   			scrollerContainer.scrollContent.appendChild(el);

			el.style.position = "absolute";
			el.style.left = "0";
			el.style.top = "0";
			el.style[scrollerContainer.scrollerSizeProperty] = "10000em";

			if (scrollerContainer.scrollerType == 'horizontal'){
				var objectHeight = scrollerContainer.scrollerViewPortHeightAuto ? getElementHeight(el) / scrollerContainer.scrollerFontSize : scrollerContainer.scrollerViewPortHeight;
				scrollerContainer.style.height = objectHeight+"em";
                        	scrollerContainer.scrollContent.style.height = objectHeight+"em";
                        	scrollerContainer.scrollContent.style.width = ((scrollerContainer.getElementLeft(scrollerContainer.rightArrow) - scrollerContainer.getElementLeft(scrollerContainer.leftArrow) - scrollerContainer.getElementWidth(scrollerContainer.leftArrow))/scrollerContainer.scrollerFontSize) + "em";


				//check horizontal for margins
				var containerTop = getElementTop(scrollerContainer) / scrollerContainer.scrollerFontSize;
				var arrowTop = getElementTop(scrollerContainer.rightArrow) / scrollerContainer.scrollerFontSize;
				var contentWidth = parseFloat(scrollerContainer.scrollContent.style.width);
				var k=0;
				while ((arrowTop - containerTop) >= (objectHeight-1)){
					contentWidth -= 0.1;
					scrollerContainer.scrollContent.style.width = contentWidth+"em";
					arrowTop = getElementTop(scrollerContainer.rightArrow) / scrollerContainer.scrollerFontSize;
					if (k == 100){//too much
						break;
					}
					k++;
				}
				var arrowBackgroundTop = ((objectHeight - scrollerContainer.scrollerArrowBackgroundHeight) / 2);
				scrollerContainer.leftArrow.style.backgroundPosition = "0 "+arrowBackgroundTop+"em";
                        	scrollerContainer.rightArrow.style.backgroundPosition = "0 "+arrowBackgroundTop+"em";
			}else{
				objectHeight = scrollerContainer.scrollerViewPortHeight;
				el.style[scrollerContainer.scrollerSizeProperty] = objectHeight+"em";
				//var objectHeight = scrollerContainer.scrollerViewPortHeightAuto ? getElementHeight(el) / scrollerContainer.scrollerFontSize : scrollerContainer.scrollerViewPortHeight;
				scrollerContainer.style.height = objectHeight+"em";
                        	scrollerContainer.scrollContent.style.width = objectWidth+"em";
                        	scrollerContainer.scrollContent.style.height = (objectHeight - 2 * (jsScroller.getElementHeight(scrollerContainer.rightArrow) / scrollerContainer.scrollerFontSize))+ "em";

                        	//check vertical for margins
				var arrowBottom = (getElementTop(scrollerContainer.rightArrow) + getElementHeight(scrollerContainer.rightArrow) - getElementTop(scrollerContainer.leftArrow))/ scrollerContainer.scrollerFontSize;
				var contentHeight = parseFloat(scrollerContainer.scrollContent.style.height);
				var k=0;
				while (arrowBottom >= objectHeight){
					contentHeight -= 0.1;
					scrollerContainer.scrollContent.style.height = contentHeight+"em";
					arrowBottom = (getElementTop(scrollerContainer.rightArrow) + getElementHeight(scrollerContainer.rightArrow) - getElementTop(scrollerContainer.leftArrow))/ scrollerContainer.scrollerFontSize;
					if (k == 100){//too much
						break;
					}
					k++;
				}

				if (contentHeight > objectHeight) { alert('da'); scrollerContainer.style.height = contentHeight+"em"; }

                        	var arrowBackgroundLeft = ((objectWidth - scrollerContainer.scrollerArrowBackgroundWidth) / 2);
				scrollerContainer.leftArrow.style.backgroundPosition = arrowBackgroundLeft+"em 0";
                        	scrollerContainer.rightArrow.style.backgroundPosition = arrowBackgroundLeft+"em 0";
			}
			scrollerContainer.init();
			scrollerContainer.autoScroll();
		}
	},
	scrollToLeft : function(){
		if (this.scrollerAuto && this.scrollerAutoCan) this.stopScroll();
		if (this.scrollInterval <= 0){
			this.scrollInterval = setInterval(this.scrollToLeft,this.scrollerIntervalLength);
		}
		this.scrollerAutoDirection = -1;
		this.setScroll(-this.scrollerMoveWidth);
	},
	scrollToRight : function(){
		if (this.scrollerAuto && this.scrollerAutoCan) this.stopScroll();
		if (this.scrollInterval <= 0){
			this.scrollInterval = setInterval(this.scrollToRight,this.scrollerIntervalLength);
		}
		this.scrollerAutoDirection = 1;
		this.setScroll(this.scrollerMoveWidth);
	},
	autoScroll : function(){
		if (!this.scrollerAuto || !this.scrollerAutoCan) return;
		if (this.scrollInterval <= 0){
			this.scrollInterval = setInterval(this.autoScroll,this.scrollerIntervalLength);
		}
		this.setScroll(this.scrollerAutoSpeed * this.scrollerAutoDirection);
		if (!this.scrollerCircularCan){
			var crLeft = parseFloat(this.scrollContent.firstChild.style[this.scrollerDistProperty]);
			if (isNaN(crLeft)) crLeft = 0;
			if (crLeft >= 0){
				if (this.scrollerAutoBounce) this.scrollerAutoDirection = -1;
				else this.stopScroll();
			}
			if (Math.round(crLeft * 10) / 100 <= Math.round(-this.scrollMax * 10) / 100){
				if (this.scrollerAutoBounce) this.scrollerAutoDirection = 1;
				else this.stopScroll();
			}
		}
	},
	setScroll : function(val){
		var targetEl = this.scrollContent.firstChild;
		var lft = 0;
		lft = parseFloat(targetEl.style[this.scrollerDistProperty]);
		if (isNaN(lft)) lft = 0;
		lft += parseFloat(val);
		/* if (lft > 0) lft = 0;
		if (lft <= -this.scrollMax) lft = -this.scrollMax; */
		var CircularMove = false;
		var lastFirst = 0;
		var bLeft = 0;

		if (lft > 0){
			if (this.scrollerCircularCan && (val>0)){
				if (this.scrollerCircularLastElemInd < 0) this.scrollerCircularLastElemInd = this.scrollElements.length-1;
				if (this.scrollerCircularLastElemInd >= this.scrollElements.length) this.scrollerCircularLastElemInd = 0;

				bLeft = this.getElementLeft(this.scrollElements[this.scrollerCircularFirstElemInd].el);

				targetEl.insertBefore(this.scrollElements[this.scrollerCircularLastElemInd].el,this.scrollElements[this.scrollerCircularFirstElemInd].el);
				var aLeft = this.getElementLeft(this.scrollElements[this.scrollerCircularFirstElemInd].el);
				var diff = (bLeft - aLeft)/this.scrollerFontSize;
				lft += diff;

				lastFirst = this.scrollerCircularFirstElemInd;
                                this.scrollerCircularFirstElemInd = this.scrollerCircularLastElemInd;
                                this.scrollerCircularLastElemInd--;

				CircularMove = true;
			}else lft = 0;
		}
		if (lft <= -this.scrollMax){
			if (this.scrollerCircularCan && (val<0)){
				if (this.scrollerCircularFirstElemInd < 0) this.scrollerCircularFirstElemInd = this.scrollElements.length-1;
				if (this.scrollerCircularFirstElemInd >= this.scrollElements.length) this.scrollerCircularFirstElemInd = 0;

				bLeft = this.getElementLeft(this.scrollElements[this.scrollerCircularLastElemInd].el);

				if (this.scrollElements[this.scrollerCircularLastElemInd].el.nextSibling){
					targetEl.insertBefore(this.scrollElements[this.scrollerCircularFirstElemInd].el, this.scrollElements[this.scrollerCircularLastElemInd].el.nextSibling);
				}else{
					targetEl.appendChild(this.scrollElements[this.scrollerCircularFirstElemInd].el);
				}
				var aLeft = this.getElementLeft(this.scrollElements[this.scrollerCircularLastElemInd].el);
				var diff = (bLeft - aLeft)/this.scrollerFontSize;
				lft += diff;

                                lastFirst = this.scrollerCircularLastElemInd;
                                this.scrollerCircularLastElemInd = this.scrollerCircularFirstElemInd;
                                this.scrollerCircularFirstElemInd++;
                                
                                CircularMove = true;
			}else lft = -this.scrollMax;
		}
		lft = Math.round(lft * 100) / 100;
                targetEl.style[this.scrollerDistProperty] = lft+"em";
		this.calcShowemElements(val);

		if (CircularMove && jsScroller.scrollerDoubleCheckCircular){
			var aaLeft = this.getElementLeft(this.scrollElements[lastFirst].el);
			if (bLeft - aaLeft != 0){
				//(Math.abs(val) * 2)/
				//error_log(this.scrollerFontSize);//(Math.abs(val) * 0.2)
				lft = lft-val-0.2*Math.sgn(val)+((bLeft - aaLeft)/this.scrollerFontSize);
				lft = (Math.ceil(lft * 100) / 100);
				targetEl.style[this.scrollerDistProperty] = lft+"em";
				//this.stopScroll();
			}
		}
	},
	stopScroll : function(){
		clearInterval(this.scrollInterval);
		this.scrollInterval = 0;
	},
	stopAutoScroll : function(){
		this.stopScroll();
		this.autoScroll();
	},
	init : function(){
		var maxRight = 0;
		var nodeRight = 0;
		var elems = new Array();
		var crLeft = this.getElementLeft(this.scrollContent);
		var nodes = this.scrollContent.firstChild.childNodes;
		for (var i=0; i<nodes.length; i++){
			if (nodes[i].nodeType == 1){
				nodeRight = parseInt(this.getElementLeft(nodes[i]) + this.getElementWidth(nodes[i]));
				if (isNaN(nodeRight)){
					nodeRight = 0;
				}
				if ((nodeRight > maxRight) && (getElementHeight(nodes[i]) > 0)){
					maxRight = nodeRight;
				}
				if (nodes[i].getAttribute("rel") == "scrollElement"){
					var elLeft = this.getElementLeft(nodes[i]);
					elems.push({
						el:nodes[i],
						left:(elLeft - crLeft)/this.scrollerFontSize,
						right: (elLeft + this.getElementWidth(nodes[i])) / this.scrollerFontSize,
						showem : false,
						aproaching : false
					});
				}
			}
		}
		var crlft = this.getElementLeft(this.scrollContent);
		var contentWidth = parseFloat(this.scrollContent.style[this.scrollerSizeProperty]);
		maxRight = maxRight - crlft;// - this.getElementWidth(this.leftArrow);
		this.scrollMax = (maxRight / this.scrollerFontSize) - contentWidth;
		if (this.scrollMax < 0) this.scrollMax = 0;

		if (!this.scrollerNoEvents){
	                this.scrollElements = new Array();
			for (var j=0; j<elems.length; j++){
				var minElem = 0;
				var minLeft = 0;
				var fst = true;
	
				for (var i=0; i<elems.length; i++){
					if ((elems[i] != null) && ((elems[i].left < minLeft) || (fst == true))){
						fst = false;
						minElem = i;
					}
				}
				if (elems[minElem] != null){
					this.scrollElements.push(elems[minElem]);
					var n = this.scrollElements.length-1;
	
					this.scrollElements[n].onEnterViewPort = this.onEnterViewPort.bind(this.scrollElements[n].el);
					this.scrollElements[n].onLeaveViewPort = this.onLeaveViewPort.bind(this.scrollElements[n].el);
					this.scrollElements[n].onAproachViewPort = this.onAproachViewPort.bind(this.scrollElements[n].el);
					this.scrollElements[n].el.parentScroller = this;
					 if (this.scrollElementHoverPause == true){
						addEvent(this.scrollElements[n].el,'mouseover', function(e){
							var targetEl = e.relatedTarget || e.fromElement;
							if (!this.contains(targetEl) || (targetEl == this)){
								this.parentScroller.stopScroll();
							}
						});
						addEvent(this.scrollElements[n].el,'mouseout', function(e){
							var targetEl = e.relatedTarget || e.toElement;
							if (!this.contains(targetEl) && (targetEl != this)){
								this.parentScroller.autoScroll();
							}
						});
					}
					delete(elems[minElem]);
				}
			}
			this.scrollerCircularFirstElemInd = 0;
			this.scrollerCircularLastElemInd = elems.length-1;
	
	                //this.scrollerCircularCan = true;
			var showElements = this.calcShowemElements();
			if (showElements == this.scrollElements.length){
	   			this.scrollerAutoCan = false;
	   			this.scrollerCircularCan = false;
			}else{
				if (this.scrollerAuto) this.scrollerAutoCan = true;
				if ((showElements + this.scrollerCircularMinShowDiff) >= this.scrollElements.length){
					this.scrollerCircularCan = false;
				}else if (this.scrollerCircular) this.scrollerCircularCan = true;
			}
			//this.calcShowemElements();
		}
	},
	calcShowemElements : function(leftDiff){
		if (this.scrollerNoEvents) return 0;
		var leftDiff = parseFloat(leftDiff);
		if (isNaN(leftDiff)) leftDiff = 0;
		var showElements = 0;
		var contentWidth = parseFloat(this.scrollContent.style[this.scrollerSizeProperty]);
		var crLeft = this.getElementLeft(this.scrollContent);
		for (var i=0; i<this.scrollElements.length; i++){
			this.scrollElements[i].left = (this.getElementLeft(this.scrollElements[i].el) - crLeft)/this.scrollerFontSize;
			this.scrollElements[i].right = (this.getElementLeft(this.scrollElements[i].el) + this.getElementWidth(this.scrollElements[i].el)) / this.scrollerFontSize;

			this.scrollElements[i].left += leftDiff;
			this.scrollElements[i].right -= leftDiff;
			if (((this.scrollElements[i].left < contentWidth) && (this.scrollElements[i].left >= 0)) ||
				((this.scrollElements[i].right < contentWidth) && (this.scrollElements[i].right >= 0))){
				if (this.scrollElements[i].showem == false){
					this.scrollElements[i].showem = true;
					this.scrollElements[i].aproaching = false;
					this.scrollElements[i].onEnterViewPort();
					showElements++;
				}
			}else{
				if (this.scrollElements[i].showem == true){
					this.scrollElements[i].showem = false;
					this.scrollElements[i].onLeaveViewPort();
				}else if (this.scrollAproachLimit>0){
					if (this.scrollElements[i].aproaching == true){
						var circularAproach = false;
						if (this.scrollerCircularCan){
							if ((this.scrollMax - this.scrollElements[i].right > this.scrollAproachLimit) || 
								((-this.scrollElements[i].left > this.scrollAproachLimit) && (this.scrollElements[i].left<0))){
									circularAproach = true;
							}
						}
						if (circularAproach || (this.scrollElements[i].left > contentWidth + this.scrollAproachLimit) || (this.scrollElements[i].right < -this.scrollAproachLimit)){
							this.scrollElements[i].aproaching = false;
							//get away from view port :D
							//this.scrollElements[i].onAproachViewPort();
						}
					}else{
						var circularAproach = false;
						if (this.scrollerCircularCan){
							if ((this.scrollMax - this.scrollElements[i].right <= this.scrollAproachLimit) ||
								((-this.scrollElements[i].left <= this.scrollAproachLimit) && (this.scrollElements[i].left<0))){
									circularAproach = true;
							}
						}
						if (circularAproach || ((this.scrollElements[i].left - contentWidth <= this.scrollAproachLimit) && (this.scrollElements[i].left>0)) ||
							((this.scrollElements[i].right + contentWidth >= -this.scrollAproachLimit) && (this.scrollElements[i].right<0))){
								this.scrollElements[i].aproaching = true;
								this.scrollElements[i].onAproachViewPort();
						}
					}
				}
			}
		}
		return showElements;
	},
        getElementLeft : function(pElt){
		if (this.scrollerType == 'vertical') return jsScroller.getElementTop(pElt);
		var intX = pElt.offsetLeft;
		while ((pElt = pElt.offsetParent) != null){
			intX += pElt.offsetLeft;
		}
		return intX;
	},
        getElementWidth : function(pElt, force){
		if (!force && this.scrollerType == 'vertical') return jsScroller.getElementHeight(pElt);
		return pElt.offsetWidth;
	},
	getElementTop : function(pElt){
		var intY = pElt.offsetTop;
		while((pElt = pElt.offsetParent) != null){
			intY += pElt.offsetTop;
		}
		return intY;
	},
	getElementHeight : function(pElt){
		return pElt.offsetHeight;
	}

}
//if (jsScroller.ONLOAD_CHECK){
	addEvent(window,'load',jsScroller.onloadCreate);
//}


function getElementLeft(pElt){
  var intX = pElt.offsetLeft;
  while ((pElt = pElt.offsetParent) != null){
    intX += pElt.offsetLeft;
  }
  return intX;
}
function getElementTop(pElt){
  var intY = pElt.offsetTop;
  while((pElt = pElt.offsetParent) != null){
    intY += pElt.offsetTop;
  }
  return intY;
}
function getElementHeight(pElt){
  return pElt.offsetHeight;
}
function getElementWidth(pElt){
  return pElt.offsetWidth;
}









function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	xScr = xScroll;
	yScr = yScroll;

	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	

	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else {
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight,xScr,yScr)
	return arrayPageSize;
}

function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return [ scrOfX, scrOfY ];
}










function error_log(str){
	try{
	  	var a;
		if (a = document.getElementById("error_log")){
			a.value += "\n"+str;
		}
	}catch(e){}
}

/* function getStyle(el,styleProp){
	var x = typeof el == "object" ? el : document.getElementById(el);
	if (x.currentStyle)
		var y = x.currentStyle[styleProp];
	else if (window.getComputedStyle)
		var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(styleProp);
	return y;
} */









//user custom function
function loadAcc(){
	if (!this.loaded){
		var id = this.id.replace('acc_container_','');
		var spn;
		var img;
		try{
			img = document.getElementById('prod_img_'+id);
			spn = document.getElementById('prod_span_'+id);
			img.src = spn.getAttribute("rel");
		}catch(e){}
		this.loaded = true;
	}
}

function loadRec(){
	if (!this.loaded){
		var id = this.id.replace('rec_container_','');
		var spn;
		var img;
		try{
			img = document.getElementById('prod_img_rec_'+id);
			spn = document.getElementById('prod_span_rec_'+id);
			img.src = spn.getAttribute("rel");
		}catch(e){}
		this.loaded = true;
	}
}




