if(typeof MakinHey == "undefined" || !MakinHey) { var MakinHey = {}; }

MakinHey.PauseScroller = function() {
	function calculateHeight(vp) {
		var parent = vp.parentNode;
		var children = parent.childNodes;
		var totalHeight = 0;
		for(var index = 0; index < children.length; index++) {
			var child = children[index];
			if(child != vp && 1 == child.nodeType) {
				totalHeight += child.offsetHeight;
			}
		}
		vp.style.height = (parent.offsetHeight - totalHeight) + "px";
	}

	function initViews(vp) {
		var views = [];
		var children = vp.childNodes;
		for(var index = 0; index < children.length; index++) {
			var child = children[index];
			if(1 == child.nodeType) {
				views.push(child);
			}
		}
		return views;
	}
	
	function create(viewport) {
		var vp = document.getElementById(viewport);
		if(vp) {
			calculateHeight(vp);
			var vpHt = vp.offsetHeight;
			var views = initViews(vp);
			if(views.length > 0) {
				var pause = false;
				vp.onmouseout = function() {
					pause = false;
				};
				vp.onmouseover = function() {
					pause = true;
				};

				var index = 0;
				var view = views[index];
				var prevView = null;
				var vTop = 0;
				view.style.position = "absolute";
				function scrollView() {
					var speed = 10;
					if(!pause) {
						if(vTop == 0) {
							speed = 3000;
							vTop = vpHt;
							if(prevView) {
								prevView.style.top = vpHt + "px";
							}
							if(views.length > 1) {
								prevView = view;
							}
							index = (index + 1) % views.length;
							view = views[index];
						}
						else {
							vTop -= 1;
							view.style.top = vTop + "px";
							if(prevView) {
								prevView.style.top = (vTop - vpHt) + "px";
							}
						}
					}
					setTimeout(scrollView, speed);
				}
				scrollView();
			}
		}
	}
	
	return {create:create};
}();

