/*
JavaScript - http://www.mediafax.ro/vlad.roman/scroller/
http://www.mediafax.ro/vlad.roman/scroller/
http://www.mediafax.ro/vlad.roman/scroller/js/prototype.lite.js
*/
/*  Prototype JavaScript framework
 *  (c) 2005 Sam Stephenson <sam@conio.net>
 *  Prototype is freely distributable under the terms of an MIT-style license.
 *  For details, see the Prototype web site: http://prototype.conio.net/
/*--------------------------------------------------------------------------*/

//note: modified & stripped down version of prototype, to be used with moo.fx by mad4milk (http://moofx.mad4milk.net).

var Class = {
	create: function() {
		return function() {
			this.initialize.apply(this, arguments);
		}
	}
}

Object.extend = function(destination, source) {
	for (property in source) destination[property] = source[property];
	return destination;
}

Function.prototype.bind = function(object) {
	var __method = this;
	return function() {
		return __method.apply(object, arguments);
	}
}

Function.prototype.bindAsEventListener = function(object) {
var __method = this;
	return function(event) {
		__method.call(object, event || window.event);
	}
}

function $() {
	if (arguments.length == 1) return get$(arguments[0]);
	var elements = [];
	$c(arguments).each(function(el){
		elements.push(get$(el));
	});
	return elements;

	function get$(el){
		if (typeof el == 'string') el = document.getElementById(el);
		return el;
	}
}

if (!window.Element) var Element = new Object();

Object.extend(Element, {
	remove: function(element) {
		element = $(element);
		element.parentNode.removeChild(element);
	},

	hasClassName: function(element, className) {
		element = $(element);
		if (!element) return;
		var hasClass = false;
		element.className.split(' ').each(function(cn){
			if (cn == className) hasClass = true;
		});
		return hasClass;
	},

	addClassName: function(element, className) {
		element = $(element);
		Element.removeClassName(element, className);
		element.className += ' ' + className;
	},
  
	removeClassName: function(element, className) {
		element = $(element);
		if (!element) return;
		var newClassName = '';
		element.className.split(' ').each(function(cn, i){
			if (cn != className){
				if (i > 0) newClassName += ' ';
				newClassName += cn;
			}
		});
		element.className = newClassName;
	},

	cleanWhitespace: function(element) {
		element = $(element);
		$c(element.childNodes).each(function(node){
			if (node.nodeType == 3 && !/\S/.test(node.nodeValue)) Element.remove(node);
		});
	},

	find: function(element, what) {
		element = $(element)[what];
		while (element.nodeType != 1) element = element[what];
		return element;
	}
});

var Position = {
	cumulativeOffset: function(element) {
		var valueT = 0, valueL = 0;
		do {
			valueT += element.offsetTop  || 0;
			valueL += element.offsetLeft || 0;
			element = element.offsetParent;
		} while (element);
		return [valueL, valueT];
	}
};

document.getElementsByClassName = function(className) {
	var children = document.getElementsByTagName('*') || document.all;
	var elements = [];
	$c(children).each(function(child){
		if (Element.hasClassName(child, className)) elements.push(child);
	});  
	return elements;
}

//useful array functions
Array.prototype.iterate = function(func){
	for(var i=0;i<this.length;i++) func(this[i], i);
}
if (!Array.prototype.each) Array.prototype.each = Array.prototype.iterate;

function $c(array){
	var nArray = [];
	for (var i=0;i<array.length;i++) nArray.push(array[i]);
	return nArray;
}

http://www.mediafax.ro/vlad.roman/scroller/js/scroller.js

/*
author: Vlad Roman (vlad@afian.com)
*/
var MyJSSscrollerHASDragging = false;

var MyJSScrollerHandler = {
	scrollers : [],
	intvals : [],
	
	initByClassName : function(className) {
		i = this.scrollers.length;
		document.getElementsByClassName(className).each(function(node) {
			var orient, dir, speed;
			MyJSScrollerHandler.scrollers[i] = new MyJSScroller(node, i, orient, dir, speed);
			i++;
		});
	},
	
	attachMouseWheel : function(el, index) {
		if (window.addEventListener)
		        /** DOMMouseScroll is for mozilla. */
		       el.addEventListener('DOMMouseScroll', function(event){MyJSScrollerHandler.wheel(event, index);}, false);
		/** IE/Opera. */
			el.onmousewheel = function(event){MyJSScrollerHandler.wheel(event, index);};
	},
		
	handleWheelMovement : function(delta, index) {
		MyJSScrollerHandler.scrollers[index].move(-(delta*10));
	},
	
	wheel : function(event, index){
	        var delta = 0;
	        if (!event) /* For IE. */
	                event = window.event;
	        if (event.wheelDelta) { /* IE/Opera. */
	                delta = event.wheelDelta/120;
	                if (window.opera)
	                        delta = -delta;
	        } else if (event.detail) { /** Mozilla case. */
	                delta = -event.detail/3;
	        }
	        if (delta)
	                MyJSScrollerHandler.handleWheelMovement(delta, index);
	        if (event.preventDefault)
	                event.preventDefault();
		event.returnValue = false;
	}
};


function MyJSScroller(node, index,  orient, dir, speed) {
	
	if (MyJSScrollerHandler.scrollers[index]) {
		return false;
	}
	

	if (node.getAttribute('myjsscroller') == 'true') {
		return false;
	}
	
	node.setAttribute('myjsscroller', 'true');
	
	this.pausePoints = [];
	this.pauseTimer = 0;
	this.node = node;
	this.index = index;
	this.orient = orient || node.getAttribute('orientation');
	this.dir = dir || node.getAttribute('direction');
	spd = speed || node.getAttribute('scrollspeed');
	if (!spd) {
		spd = 20;
	}
	
	this.speed = 1000/spd;
	wraper = document.createElement('DIV');
	//wraper.style.border = '1px solid red';
	wraper.style.height = '100%';
	node.style.overflow = 'hidden';
	wraper.style.overflow = 'hidden';
	
	wraper.style.position = 'relative';
	wraper.style.top = '0px';
	wraper.style.left = '0px';
	this.wraper = wraper;
	movingWraper = document.createElement('DIV');
	if (this.orient == 'horizontal') {
		movingWraper.style.whiteSpace = 'nowrap';
	}
	
	//movingWraper.style.border = '1px solid blue';
	movingWraper.style.position='absolute';
	this.movingWraper = movingWraper;
	wraper.appendChild(movingWraper);
	movingWraper.innerHTML = node.innerHTML;
	node.innerHTML = '';
	node.appendChild(wraper);
	this.w = movingWraper.offsetWidth;
	this.h = movingWraper.offsetHeight;
	
	if (this.orient != 'horizontal' && this.dir == 'down') {
		this.movingWraper.style.top = -this.h+'px';
	}
	
	
	if (MyJSSscrollerHASDragging) {
		if (this.orient == 'horizontal') {
	 		drg = Drag.init(movingWraper, null, -this.w, this.w, 0, 0);
		} else {
	 		drg = Drag.init(movingWraper, null, 0, 0, -this.h, this.h);
		}
	}
	
	
	
	
	for (var i = 0 ; i < movingWraper.childNodes.length ; i++) {
		ch = movingWraper.childNodes[i];
		if (ch.className == 'scrollpauser') {
			
			
			if (ch.getAttribute('scrollhide') == "1") {
				ch.style.visibility = 'hidden';
				ch.style.display ='inline';
				ch.style.margin = '0px';
				ch.style.border = '0px';
			}
			if (ch.getAttribute('scrolldelay') > 0) {
				delay = ch.getAttribute('scrolldelay');
			} else {
				delay = 2000;			
			}
			this.pausePoints.push([ch.offsetTop, ch.offsetLeft, delay]);
		}
	}
	
	
	
	
	movingWraper.onDragStart = function(x,y) {
		MyJSScrollerHandler.scrollers[index].dragged = true;
		MyJSScrollerHandler.scrollers[index].pause();
	}
	movingWraper.onDragEnd = function() {
		MyJSScrollerHandler.scrollers[index].dragged = false;
		MyJSScrollerHandler.scrollers[index].resume();
	}
	
	
	node.onmouseover = function() {
		MyJSScrollerHandler.scrollers[index].pause();
	}
	node.onmouseout = function() {
		if (!MyJSScrollerHandler.scrollers[index].dragged) {
			MyJSScrollerHandler.scrollers[index].resume();
		}
	}
	MyJSScrollerHandler.attachMouseWheel(node, index);
	
	this.start();
	
}

MyJSScroller.prototype.start = function() {
	
	if (!MyJSScrollerHandler.intvals[this.index]) {
		MyJSScrollerHandler.intvals[this.index] = window.setInterval('MyJSScrollerHandler.scrollers[\''+this.index+'\'].move()', this.speed);
	}
}

MyJSScroller.prototype.move = function(delta) {
	
	mw = this.movingWraper;
	slf = this;
	
	if (!delta) {
			delta = 1
		}
		
	if (this.orient == 'horizontal') {
		if (this.dir != "right") {
			if (mw.offsetLeft < -this.w) {
				mw.style.left = this.wraper.offsetWidth+'px';
			} else {
			 	mw.style.left = (mw.offsetLeft-delta)+'px';
			}
		} else {
			if (mw.offsetLeft > this.wraper.offsetWidth) {
				mw.style.left = -mw.offsetWidth+'px';
			} else {
			 	mw.style.left = (mw.offsetLeft+delta)+'px';
			}
		}
	} else {
		if (this.dir != "down") {
			if (mw.offsetTop > -this.h) {
			
				//pausers
				this.pausePoints.each(function(point){
					if (-point[0] == mw.offsetTop) {
						slf.pause();
						window.setTimeout('MyJSScrollerHandler.scrollers[\''+slf.index+'\'].start()', point[2]);
					}
				});
				
				mw.style.top = (mw.offsetTop-delta)+'px';
				
			} else {
			 	mw.style.top = this.wraper.offsetHeight+'px';
			}
		} else {
			if (-mw.offsetTop+this.wraper.offsetHeight > 0) {
				mw.style.top = (mw.offsetTop+delta)+'px';
			} else {
			 	mw.style.top = -mw.offsetHeight+'px';
			}
		}
	}
}

MyJSScroller.prototype.pause = function() {
	window.clearInterval(MyJSScrollerHandler.intvals[this.index]);
	MyJSScrollerHandler.intvals[this.index] = false;
}

MyJSScroller.prototype.resume = function() {
	this.start();
}

//window.onload = function() {MyJSScrollerHandler.initByClassName('scrollable');}

http://www.mediafax.ro/vlad.roman/scroller/js/dom-drag.js

/**************************************************
 * dom-drag.js
 * 09.25.2001
 * www.youngpup.net
 **************************************************/
var MyJSSscrollerHASDragging = true;

function BrowserCheck() {
var b = navigator.appName;
if (b == "Netscape") this.b = "NS";
else if (b == "Microsoft Internet Explorer") this.b = "IE";
else this.b = b;
this.v = parseInt(navigator.appVersion);
this.NS = (this.b == "NS" && this.v>=4);
this.NS4 = (this.b == "NS" && this.v == 4);
this.NS5 = (this.b == "NS" && this.v == 5);
this.IE = (this.b == "IE" && this.v>=4);
this.IE4 = (navigator.userAgent.indexOf('MSIE 4')>0);
this.IE5 = (navigator.userAgent.indexOf('MSIE 5')>0);
this.Opera = (navigator.appName=='Opera');
if (this.IE5 || this.NS5) this.VER5 = true;
if (this.IE4 || this.NS4) this.VER4 = true;
this.OLD = (! this.VER5 && ! this.VER4) ? true : false;
this.min = (this.NS||this.IE);
}
is = new BrowserCheck();

if (is.NS) {
	document.captureEvents(Event.MOUSEMOVE);
}

var zindexcount=0; 
 
 
var Drag = {
	obj : null,

	init : function(o, oRoot, minX, maxX, minY, maxY, bSwapHorzRef, bSwapVertRef, fXMapper, fYMapper)
	{
		o.onmousedown	= Drag.start;

		o.hmode			= bSwapHorzRef ? false : true ;
		o.vmode			= bSwapVertRef ? false : true ;

		o.root = oRoot && oRoot != null ? oRoot : o ;

		if (o.hmode  && isNaN(parseInt(o.root.style.left  ))) o.root.style.left   = "0px";
		if (o.vmode  && isNaN(parseInt(o.root.style.top   ))) o.root.style.top    = "0px";
		if (!o.hmode && isNaN(parseInt(o.root.style.right ))) o.root.style.right  = "0px";
		if (!o.vmode && isNaN(parseInt(o.root.style.bottom))) o.root.style.bottom = "0px";

		o.minX	= typeof minX != 'undefined' ? minX : null;
		o.minY	= typeof minY != 'undefined' ? minY : null;
		o.maxX	= typeof maxX != 'undefined' ? maxX : null;
		o.maxY	= typeof maxY != 'undefined' ? maxY : null;

		o.xMapper = fXMapper ? fXMapper : null;
		o.yMapper = fYMapper ? fYMapper : null;

		o.root.onDragStart	= new Function();
		o.root.onDragEnd	= new Function();
		o.root.onDrag		= new Function();
		o.root.onmouseover = function() {
		zindexcount = zindexcount+100;
		this.style.zIndex = zindexcount;
		}
	},

	start : function(e)
	{
		if(is.IE) {
		eveniment = window.event;
		} else {
		eveniment = e;
		}
		
		if(is.IE){
		elementul = eveniment.srcElement;
		}else{
		elementul = eveniment.target;
		}

		if (elementul.tagName == 'A' || elementul.tagName == 'INPUT') {
			return false;
		}
		
		

		var o = Drag.obj = this;

		
		e = Drag.fixE(e);
		var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);
		var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
		o.root.onDragStart(x, y);

		o.lastMouseX	= e.clientX;
		o.lastMouseY	= e.clientY;

		if (o.hmode) {
			if (o.minX != null)	o.minMouseX	= e.clientX - x + o.minX;
			if (o.maxX != null)	o.maxMouseX	= o.minMouseX + o.maxX - o.minX;
		} else {
			if (o.minX != null) o.maxMouseX = -o.minX + e.clientX + x;
			if (o.maxX != null) o.minMouseX = -o.maxX + e.clientX + x;
		}

		if (o.vmode) {
			if (o.minY != null)	o.minMouseY	= e.clientY - y + o.minY;
			if (o.maxY != null)	o.maxMouseY	= o.minMouseY + o.maxY - o.minY;
		} else {
			if (o.minY != null) o.maxMouseY = -o.minY + e.clientY + y;
			if (o.maxY != null) o.minMouseY = -o.maxY + e.clientY + y;
		}

		document.onmousemove	= Drag.drag;
		document.onmouseup		= Drag.end;

		return false;
	},

	drag : function(e) {
		e = Drag.fixE(e);
		var o = Drag.obj;

		var ey	= e.clientY;
		var ex	= e.clientX;
		var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);
		var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
		var nx, ny;

		if (o.minX != null) ex = o.hmode ? Math.max(ex, o.minMouseX) : Math.min(ex, o.maxMouseX);
		if (o.maxX != null) ex = o.hmode ? Math.min(ex, o.maxMouseX) : Math.max(ex, o.minMouseX);
		if (o.minY != null) ey = o.vmode ? Math.max(ey, o.minMouseY) : Math.min(ey, o.maxMouseY);
		if (o.maxY != null) ey = o.vmode ? Math.min(ey, o.maxMouseY) : Math.max(ey, o.minMouseY);

		nx = x + ((ex - o.lastMouseX) * (o.hmode ? 1 : -1));
		ny = y + ((ey - o.lastMouseY) * (o.vmode ? 1 : -1));

		if (o.xMapper)		nx = o.xMapper(y)
		else if (o.yMapper)	ny = o.yMapper(x)

		Drag.obj.root.style[o.hmode ? "left" : "right"] = nx + "px";
		Drag.obj.root.style[o.vmode ? "top" : "bottom"] = ny + "px";
		Drag.obj.lastMouseX	= ex;
		Drag.obj.lastMouseY	= ey;

		
		Drag.obj.root.onDrag(nx, ny, Drag.obj);
		return false;
	},

	end : function()
	{
		document.onmousemove = null;
		document.onmouseup   = null;
		Drag.obj.root.onDragEnd(	parseInt(Drag.obj.root.style[Drag.obj.hmode ? "left" : "right"]), 
									parseInt(Drag.obj.root.style[Drag.obj.vmode ? "top" : "bottom"]), Drag.obj);
		Drag.obj = null;
	},

	fixE : function(e)
	{
		if (typeof e == 'undefined') e = window.event;
		if (typeof e.layerX == 'undefined') e.layerX = e.offsetX;
		if (typeof e.layerY == 'undefined') e.layerY = e.offsetY;
		return e;
	}
};

