

function setActiveStyleSheet(title) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
}

function getActiveStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
  }
  return null;
}

function getPreferredStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1
       && a.getAttribute("rel").indexOf("alt") == -1
       && a.getAttribute("title")
       ) return a.getAttribute("title");
  }
  return null;
}

function createCookie(name,value,days,path,domain,secure) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime() + (days*24*60*60*1000) );
   		expires = date.toGMTString();
  	}
   document.cookie = name + "=" + escape(value) +
    ((expires) ? "; expires=" + expires : "") +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    ((secure) ? "; secure" : "");
}

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}

window.onload = function(e) {
  	var cookie = readCookie("style");
  	var title = cookie ? cookie : getPreferredStyleSheet();
	setActiveStyleSheet(title);
}

window.onunload = function(e) {
  var title = getActiveStyleSheet();
  createCookie("style", title, 180, "/");
}

var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);

csize = 0;
szs = ['80%','90%','100%','110%','120%','130%','140%'];

function textSize(dir) {
	var cs = parseFloat(readCookie("txtsize"));
	if (!cs) { cs = csize; }
	if (dir=="up") {
			if (cs < szs.length-1) { 
				cs += 1;
				setSize(cs); 
			}
	} else {
			if (cs >= 1) { 
				cs -= 1;
				setSize(cs); 
			}
		}
}
function setSize(size) {
		createCookie("txtsize", size, 180, "/");
		csize = size;
		document.body.style.fontSize = szs[size];
}
function getAccessButtons(){
		html = "";	return html;
}
/*
function adjustClass(node, debug) {

  		if (node.nodeName=="LI") {
  			node.onmouseover=function() {
  				this.className="hover";
  				
    		}
  			node.onmouseout=function() {
  				this.className=this.className.replace("hover", "");
   			}
		}
}
startList = function() {
	
		if (document.all && document.getElementById) {	
			n = document.getElementById("topnav").childNodes[0];
			
			if (n) {
			l = n.childNodes.length;
			
			for (i=0; i<l; i++) {
 				node = n.childNodes[i];
 				adjustClass(node);
 				nl = node.childNodes.length;
 				
 				for (j=0;j<nl;j++) {
 					cn = node.childNodes[j];
 					
 					if (cn.nodeName=="UL") {
 						cl = cn.childNodes.length;
 						
 						for (k=0; k<cl; k++) {
 							cnode = cn.childNodes[k];	
 							adjustClass(cnode);
 						}
 					}
 				}	
			}
			}
		}
}
window.onload=startList;
*/

//UTILITIES
var isDOM = document.getElementById;


d = {
	$: function(id) {
		return document.getElementById(id);
	},
	getByTag: function(tagname) {
		return document.getElementsByTagName(tagname);
	}
}


function getById(id) {
		return document.getElementById(id);
	}


function getParentNodeByType(obj, type) {
		pn = obj.parentNode;
		if (pn.nodeName == type || pn.nodeName == type.toUpperCase()) {
				return pn;
			}
				
		return getParentNodeByType(pn, type);
	}


function removeWhiteSpaceNodes(parobj) {
			var notWhiteSpaceNode = /\S/;
				
			for (i=0;i<parobj.childNodes.length;i++){
				if ((parobj.childNodes[i].nodeType == 3) && (!notWhiteSpaceNode.test(parobj.childNodes[i].nodeValue))) {
					parobj.removeChild(parobj.childNodes[i]);
						i--;
				}
			}
		}

//



//prototype's fabulous bind and $A
var $A = Array.from = function(iterable) {
  if (!iterable) return [];
  if (iterable.toArray) {
    return iterable.toArray();
  } else {
    var results = [];
    for (var i = 0, length = iterable.length; i < length; i++)
      results.push(iterable[i]);
    return results;
  }
}
Function.prototype.bind = function() {
  var __method = this, args = $A(arguments), object = args.shift();
  return function() {
    return __method.apply(object, args.concat($A(arguments)));
  }
}
//


var E = {
	add: function(obj, evt, func) {
		if (document.addEventListener) obj.addEventListener(evt, func, false);
		else if(document.attachEvent) obj.attachEvent('on'+evt,func);
		},
	remove: function(obj, evt, func) {
			obj.removeEventListener(evt, func, false);
		},
	get: function(e, p) {
			var e = e || window.event;
			if (p) E.pd(e);
			return t = e.target || e.srcElement;
		},
	pd: function(e) {
			if (e.stopPropagation) e.stopPropagation();	 
			else if(e.cancelBubble) e.cancelBubble = true;			
			if (e.preventDefault) e.preventDefault();
			else e.returnValue = false; 
	},
	pos: function(e) {
		var left = 0;
		var top  = 0;
		while (e.offsetParent){
			left += e.offsetLeft;
			top  += e.offsetTop;
			e     = e.offsetParent;
		}
		left += e.offsetLeft;
		top  += e.offsetTop;

		return {x:left, y:top};
	}
}




var Req = {
	__GET: {},
	filename: '',
	query_string: location.search || '',
	type: '',
	uri: location.href,
	initialized: false,
	
	init: function() {
		ps = this.uri
				
		this.type = ps.match(/^https?|ftp|file/);		
		ps = ps.replace(/https?:\/\/|file:\/|ftp:\/\//g, '');
		
		ps = ps.split('/');
		psl = ps.length
		 
		ps[psl-1] = ps[psl-1].split('?');
		this.filename = (ps[psl-1].length > 1) ? ps[psl-1].shift() : ps.pop();
		
		params = location.search.slice(1).split('&');
		for (i=0;i<params.length;i++) {
			x = params[i].split('=');
			this.__GET[x[0]] = unescape(x[1]);
		}
		this.initialized = true;
	},
	get: function(key) {
		return (this.__GET[key] != undefined) ? this.__GET[key] : false;
	},
	set: function(params) {
		//params {'key':'value', 'key2':'value2'}
		try {
			for (key in params) {
				if (key != '')
					this.__GET[key] = params[key];
			}
		} catch(e) {}
	},
	serialize: function() {
		params = [];
		for (key in this.__GET)
			if (key != '')
				if (this.__GET[key] != undefined)
					params.push(key + '=' + escape(this.__GET[key]))
		
		return params.join('&');
		
	},
	Cookie: {
		set: function(name,value,days,path,domain,secure) {
			if (!days) days = 360;
		    
			var date = new Date();
		    date.setTime(date.getTime() + (days*24*60*60*1000) );
		   	expires = date.toGMTString();
		  	
		   document.cookie = name + "=" + escape(value) +
		    ((expires) ? "; expires=" + expires : "") +
		    ((path) ? "; path=" + path : "") +
		    ((domain) ? "; domain=" + domain : "") +
		    ((secure) ? "; secure" : "");
		},

		get: function(name) {
		  var nameEQ = name + "=";
		  var ca = document.cookie.split(';');
		  for(var i=0;i < ca.length;i++) {
		    var c = ca[i];
		    while (c.charAt(0)==' ') c = c.substring(1,c.length);
		    if (c.indexOf(nameEQ) == 0) return unescape(c.substring(nameEQ.length,c.length));
		  }
		  return null;
		}
	}
}
Req.init();

var Util = {
		
		clean: function(parobj) {
			var notWhiteSpaceNode = /\S/;
				
			for (i=0;i<parobj.childNodes.length;i++){
				if ((parobj.childNodes[i].nodeType == 3) 
				&& (!notWhiteSpaceNode.test(parobj.childNodes[i].nodeValue))) {
					parobj.removeChild(parobj.childNodes[i]);
						i--;
				}
			}
		}
	
	
	}









var _TextScroller = {
	
	// @private

	_text: '',
	intrvl: 0,
	
	// @public
	content : '',
	height : undefined,
	speed : 1,
	delay : 10,
	top : 0,
	dir : '+',
	allowForceDirectionChange : true,
	pauseOnMouseOver : true,
	showScrollBars : false,
	isPlaying : false,
	
	
	// @private Methods
	__init : function() {
				
		removeWhiteSpaceNodes(this.content);
		
		_text = this.content.childNodes[1];
		if (this.height != undefined)
			_text.style.height = this.height + 'px';
		
		if (this.showScrollBars)
			_text.style.overflow = 'auto';
		else
			_text.style.overflow = 'hidden';
		
		if (this.allowForceDirectionChange)
			E.add(_text, 'click', this.__changeDir.bind(this));
		
		if (this.pauseOnMouseOver) {	
			E.add(_text, 'mouseover', this.__stopScroll.bind(this));
			E.add(_text, 'mouseout', this.__startScroll.bind(this));
		}
		
		this.__startScroll();

	},
	
	
	
	__startScroll : function(e) {
		if (this.isPlaying) return;
		this.isPlaying = true;
		this.intrvl = setInterval(this._animate.bind(this),60);
		this._tsH = this.content.childNodes[1].scrollHeight;
		this._tsT = this.content.childNodes[1].scrollTop;
		this.dc = 0;
		this.y = this._tsT;
		this._bx = this.content.childNodes[1];
	},
	
	_animate : function() {	
			
			if (this.dir == '+') {
				if ((this._tsH - this.y) <= this.height) {
					if (this.dc == this.delay) {
						this.dir = '-'; this.dc = 0;
					} else {
						this.dc += 1;
					}
				} else {
					this.y+=this.speed;
				}
			
			} else {
				if (this.y <= -10) {
					if (this.dc == this.delay) { 
						this.dir = '+'; this.dc = 0;
					} else {
						this.dc += 1;
					}
				} else {
					this.y-=this.speed;
				}
			}
			
			this._bx.scrollTop = this.y;
		
	},
	
	__changeDir : function(e) {
		this.dir = (this.dir == '-') ? '+' : '-';
	},
	
	__stopScroll : function(e) {
		clearInterval(this.intrvl);
		this.isPlaying = false;
	},
	
	startScroll : function(pnl) {
		this.__init(); //will start after initialising.
		//to call without init, use private method __startScroll
	}
	
	
}



function TextScroller() {}
TextScroller.prototype = _TextScroller

function setTextScroller() {
	pnl = getById("scroller");	
	
	if (pnl) {
		scroller = new TextScroller();
		scroller.speed = 1;
		scroller.delay = 20; //delay at begin and end
		scroller.height = 100; // height of the box. this can also be set using css
		scroller.content = pnl; //
		scroller.allowForceDirectionChange = true; //changes direction on click
		scroller.pauseOnMouseOver = true;
		scroller.startScroll();
		
	} else {
		return;
	}

}

window.onload = function() {
		setTextScroller();
	};


