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

function getByTag(par,el) {
	var par = (par == '') ? document.body : par;
	return par.getElementsByTagName(el);
}

function addClass(obj,newClass) {
	if(!obj.className.match(new RegExp(newClass)))
		obj.className+=(obj.className.length>0? " ": "") + newClass;
}
	
function removeClass(obj,oldClass) {
	obj.className=obj.className.replace(new RegExp("( ?|^)"+oldClass+"\\b"), "");
}

function getByClass(cla,par,el) {
	var getEls;
	if (/.*native code.*/.test(document.getElementsByClassName)) { 
		getEls = function(cla,par,el) { 
			return par.getElementsByClassName(cla);
		}
	}
	else { 
		getEls = function(cla,par,el) { 
			var tagColl = par.getElementsByTagName(el);
			trimedColl = new Array;
			for (var i = 0; tagColl[i]; i++) {
				if(tagColl[i].className.match(new RegExp(cla)))
					trimedColl[trimedColl.length]=tagColl[i];
			}
			return trimedColl;
		} 
	} 
	getByClass = function(cla,par,el) { 
		var par = (par == '') ? document.body : par;
		var el = (el == '') ? '*' : el;
		return getEls(cla,par,el); 
	}
	return getByClass(cla,par,el);
}

function createEl(tag,classN,content) {
	var el = document.createElement(tag);
	if(classN&&(classN!='')) el.className = classN;
	if(content&&(content!='')) el.innerHTML = content;
	return el;
}

var addEvent = function() {
  if (window.addEventListener) {
    return function(el, type, fn) {
      el.addEventListener(type, fn, false);
    };
  } else if (window.attachEvent) {
    return function(el, type, fn) {
      var f = function() {
        fn.call(el, window.event);
      };
      el.attachEvent('on' + type, f);
    };
  }
}();

function GET_XMLHTTPRequest() {
	var request;
	try{
		request = new ActiveXObject("Microsoft.XMLHTTP");
	}
	catch(ex1){
		try{
			request = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(ex2){
			try{
				request = new ActiveXObject("Msxml3.XMLHTTP");
			}
			catch(ex3){
				request = null;
			}
		}
	}
	if(!request && typeof XMLHttpRequest != "undefined"){
		request = new XMLHttpRequest();
	}
	return request;
}

function getStyle(obj,cssRule) {
	if (document.defaultView && document.defaultView.getComputedStyle) {
		getStyle = function(obj,cssRule) {
			return document.defaultView.getComputedStyle(obj, "").getPropertyValue(cssRule);
		};
	}
	else {
		getStyle = function(obj,cssRule) {
			if (obj.currentStyle) {
				cssRule = cssRule.replace(/\-(\w)/g, function (match, p1) {
					return p1.toUpperCase();
				});
				return obj.currentStyle[cssRule];
			}
		};
	}
	return getStyle(obj,cssRule);
}

function findPosition( oElement ) {
	if( typeof( oElement.offsetParent ) != 'undefined' ) {
		for( var posX = 0, posY = 0; oElement; oElement = oElement.offsetParent ) {
			posX += oElement.offsetLeft;
			posY += oElement.offsetTop;
		}
		return [ posX, posY ];
	} else {
		return [ oElement.x, oElement.y ];
	}
}

function getPageY() {
	var docHeight = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
	// Order maters here as for IE 6 documentElement.clientHeight != body.clientHeight
	var docScrollY = document.documentElement.scrollTop || document.body.scrollTop;
	return [docHeight,docScrollY];
}

// function setLinks(linkTags){
// 	var linkCollection = [];
// 	for (var j = 0; linkTags[j]; j++) {
// 		linkCollection[j] = getByTag('',linkTags[j]);
// 		for (var i = 0; linkCollection[j][i]; i++) {
// 			if(/bookmark|external|corporate|sponsor|download/.test(linkCollection[j][i].getAttribute('rel'))) {
// 				linkCollection[j][i].onclick = function(e) {
// 					if (!e) var e = window.event;
// 					if (e.shiftKey || e.altKey || e.ctrlKey || e.metaKey)
// 						return true;
// 					window.open(this.href);
// 					return false;
// 				}
// 			}
// 		}
// 	}
// }

function openVideo(url, parameters) {

	parameters=parameters.replace(/\s+/g,'');

	var aParameters=parameters.split(',');
	var data=new Array();
	data["width"]='600';
	data["height"]='400';
	for (var i=0;i<aParameters.length;i++) {
		var pr=aParameters[i];
		var key = pr.substr(0,pr.indexOf('='));
		var value=pr.substr(pr.indexOf('=')+1);
		data[key]=value;
	}
	
	var z = window.open(url,'video','toolbar=0,location=0,status=0,scrollbars=0,resizable=0,width='+data["width"]+',height='+data["height"]+'');
	if(z&&z.focus()) z.focus();
	
	return false;
} 

function setLinks(linkTags,prt){
	var linkCollection = [];
	for (var j = 0; linkTags[j]; j++) {
		linkCollection[j] = getByTag(prt,linkTags[j]);
		for (var i = 0; linkCollection[j][i]; i++) {
			if(/bookmark|external|corporate|sponsor|download/.test(linkCollection[j][i].getAttribute('rel'))) {
				linkCollection[j][i].onclick = function(e) {
					if (!e) var e = window.event;
					if (e.shiftKey || e.altKey || e.ctrlKey || e.metaKey)
						return true;
					window.open(this.href);
					return false;
				}
			}
			else if(/video/.test(linkCollection[j][i].getAttribute('rel'))) {
				linkCollection[j][i].onclick = function(e) {
					
					var x = '600';
					var y = '400';
					
					if(/dimX/.test(this.className)){
						var reg = new RegExp("dimX([0-9]*)", "gi");
						var x = this.className.match(reg)[0];
						x = x.split('dimX')[1];
						x = parseInt(x,10);
					}
					
					if(/dimY/.test(this.className)){
						var reg = new RegExp("dimY([0-9]*)", "gi");
						var y = this.className.match(reg)[0];
						y = y.split('dimY')[1];
						y = parseInt(y,10);
					}
					
					if (!e) var e = window.event;
					if (e.shiftKey || e.altKey || e.ctrlKey || e.metaKey)
						return true;
					var z = window.open(this.href,'video','toolbar=0,location=0,status=0,scrollbars=0,resizable=0,width='+x+',height='+y+'');
					if(z&&z.focus()) z.focus();
					return false;
				}
			}
		}
	}
}

/* Fancy field stuff
---------------------- */
function setFancyFields(){
	var labelColl = getByClass('fancyField',getById('page'),'label');
	for(var i = 0; i < labelColl.length; i++) {
		var spansA = getByTag(labelColl[i],'span');
		var spanI = spansA[spansA.length-1];
		var fieldI = getByTag(labelColl[i],'input')[0];
		var textAreaI = getByTag(labelColl[i],'textarea')[0];
		if( spanI && fieldI ){
			if(fieldI.type == 'password') {
				var fieldN = document.createElement('input');
				fieldN.type= "text";
				fieldN.value = fieldI.title = spanI.childNodes[0].nodeValue;
				fieldN.id = fieldI.id;
				fieldN.name = fieldI.name;
				fieldI.parentNode.replaceChild(fieldN,fieldI);
				addClass(fieldN,"password");
				addEvent(fieldN, 'focus', function(e) {
					if(this.value==getByTag(this.parentNode,'span')[0].childNodes[0].nodeValue)
						this.value='';
						addClass(this,'straight');
						if(/password/.test(this.className)) {
							var fieldP = document.createElement('input');
							fieldP.type= "password";
							fieldP.setAttribute("value","");
							fieldP.id = this.id;
							fieldP.name = this.name;
							fieldP.className='straight';
							this.parentNode.replaceChild(fieldP,this);
							setTimeout("document.getElementById('"+fieldP.id+"').focus()",1);
						}
				});
			}
			else {
				if (spanI.childNodes.length) {
					fieldI.title = spanI.childNodes[0].nodeValue;
					if (fieldI.value =="")
						fieldI.value = fieldI.title;
					addEvent(fieldI, 'focus', function(e) {
						if(this.value==getByTag(this.parentNode,'span')[0].childNodes[0].nodeValue)
							this.value='';
						addClass(this,'straight');
					});
					addEvent(fieldI, 'blur', function(e) {
						if(this.value=='')
							this.value=getByTag(this.parentNode,'span')[0].childNodes[0].nodeValue;
						removeClass(this,'straight');
					});
				}
			}
		}
		if( spanI && textAreaI ){
			if (spanI.childNodes.length) {
				textAreaI.title = spanI.childNodes[0].nodeValue;
				if (textAreaI.innerHTML =="" )
					textAreaI.innerHTML = textAreaI.title;
				addEvent(textAreaI, 'focus', function(e) {
					if(this.innerHTML==getByTag(this.parentNode,'span')[0].childNodes[0].nodeValue)
						this.innerHTML='';
					addClass(this,'straight');
				});
				addEvent(textAreaI, 'blur', function(e) {
					if(this.innerHTML=='')
						this.innerHTML=getByTag(this.parentNode,'span')[0].childNodes[0].nodeValue;
					removeClass(this,'straight');
				});
			}
		}
	}
}

function fixIE() {
	var ulColl = getByTag(getById('footer'),'ul');
	for(var i = 0; ulColl[i]; i++) {
		var liColl = getByTag(ulColl[i],'li');
		for(var j = 1; liColl[j]; j++) {
			liColl[j].innerHTML = '  /  ' + liColl[j].innerHTML;
		}
	}
	if(getById('header')) {
		var ulColl = getByTag(getById('header'),'ul');
		for(var i = 0; ulColl[i]; i++) {
			if(!/noCrank/.test(ulColl[i].className)){
				var ulSet = true;
				var liColl = getByTag(ulColl[i],'li');
				for(var j = 1; liColl[j]; j++) {
					liColl[j].innerHTML = '  -   ' + liColl[j].innerHTML;
				}
			}
		}
		if(getById('content')){
			if(ulSet&&ulSet==true)return;
			var ulColl = getById('tools');
			if(ulColl){
				if(!/noCrank/.test(ulColl.className)){
			        var liColl = getByTag(ulColl,'li');
			        for(var j = 1; liColl[j]; j++) {
			        	liColl[j].innerHTML = '  -   ' + liColl[j].innerHTML;
			        }
				}
			}
		}
	}
	else {
		if(getById('content')){
			var div = getByClass('intro',getById('content'),'div');
			var ulColl = getByTag(div[0],'ul');
			for(var i = 0; ulColl[i]; i++) {
				if(!/noCrank/.test(ulColl[i].className)){
			        var liColl = getByTag(ulColl[i],'li');
			        for(var j = 1; liColl[j]; j++) {
			        	liColl[j].innerHTML = '  -   ' + liColl[j].innerHTML;
			        }
				}
			}
		}
		if(getById('subcontent')){
			var div = getByClass('intro',getById('subcontent'),'div');
			var ulColl = getByTag(div[0],'ul');
			for(var i = 0; ulColl[i]; i++) {
				if(!/noCrank/.test(ulColl[i].className)){
					var liColl = getByTag(ulColl[i],'li');
					for(var j = 1; liColl[j]; j++) {
						liColl[j].innerHTML = '  -   ' + liColl[j].innerHTML;
					}
				}
			}
		}
	}
	if(getById('ieFix')) {
		var sp = getByTag(getById('gallery'),'div');
		var x = 999;
		for (var j = 0; sp[j]; ++j) {
			sp[j].style.zIndex = 1;
			var a = getByTag(sp[i],'a');
			for( var i = 0; a[i]; ++i) {
				a[i].style.zIndex = 1;
			}
			var s = getByTag(sp[i],'span');
			for( var i = 0; s[i]; ++i) {
				s[i].style.zIndex = 1;
			}
			var im = getByTag(sp[i],'img');
			for( var i = 0; im[i]; ++i) {
				im[i].style.zIndex = 1;
			}
			sp[j].onmouseover = function() {
				this.style.zIndex = 999;
				var a = getByTag(this,'a');
				for( var i = 0; a[i]; ++i) {
					a[i].style.zIndex = 999;
				}
				var s = getByTag(this,'span');
				for( var i = 0; s[i]; ++i) {
					s[i].style.zIndex = 999;
				}
				var im = getByTag(this,'img');
				for( var i = 0; im[i]; ++i) {
					im[i].style.zIndex = 999;
				}
			}
			sp[j].onmouseout = function() {
				this.style.zIndex = 1;
				var a = getByTag(this,'a');
				for( var i = 0; a[i]; ++i) {
					a[i].style.zIndex = 1;
				}
				var s = getByTag(this,'span');
				for( var i = 0; s[i]; ++i) {
					s[i].style.zIndex = 1;
				}
				var im = getByTag(this,'img');
				for( var i = 0; im[i]; ++i) {
					im[i].style.zIndex = 1;
				}
			}
		}
	}
}

function fixLowIE() {
	var ulColl = getByTag(getById('page'),'ul');
	for(var i = 0; ulColl[i]; i++) {
		var liColl = getByTag(ulColl[i],'li');
		if(liColl[0])
			addClass(liColl[0],'first-child');
	}
	
	var fp = getByTag(getById('footer'),'p');
	if(fp && fp[0]) {
		var fa = getByTag(fp[0],'a');
		if(fa && fa[0]) {
			fa[0].innerHTML = fa[0].innerHTML + '<span class="ie">&nbsp;</span>';
		}
	}
	if(fp && fp[1]) {
		var fa = getByTag(fp[1],'a');
		if(fa && fa[0]) {
			fa[0].innerHTML = fa[0].innerHTML + '<span class="ie">&nbsp;</span>';
		}
	}
}

/* Frise
---------------------- */
function setScroller() {
	var sb = getById('scrollerBox');
	var si = getById('scrollerItems');
	var db = getById('displayBox');
	var di = getById('displayerD');
	var inf = getById('info');
	
	var cId = 0;

	if(!sb || !si || !db || !inf || !di) return;
	var siColl = getByClass('item',si,'div');
	if(siColl.length==0) return;
	var sbW = sb.offsetWidth;
	var siW = 0;
	var callers = [];
	var mr = 0;
	for(var i = 0; siColl[i]; i++) {
		var a = getByTag(siColl[i],'a');
		if(a && a[0]) {
			a[0].cId = callers.length;
			callers[callers.length] = a[0];
		}
		if(i==0)
			mr = parseInt(getStyle(siColl[i],'margin-right'),10);
		siW = siW + siColl[i].offsetWidth + mr;
		siColl[i].style.marginRight = '9px';
		if(/current/.test(siColl[i].className))
			cId = i;
	}
	siColl[siColl.length-1].style.marginRight = 0;
	siW = siW - mr;
	si.style.width = siW+'px';
	removeClass(sb,'scrollable');
	if(siW > sbW) {
		addClass(sb,'scrollable');
	}

	var d = document.createElement('div');
	d.id = 'scrollBar';
	var s = document.createElement('div');
	s.id = 'scroller';
	d.appendChild(s);
	sb.appendChild(d);
	new ScrollItems(s,si,db,inf,di,callers,cId);
}

function ScrollItems(scrl,box,db,inf,di,callers,cId) {
	this.scrl = scrl;
	
	this.box = box;
	this.displayBox = db;
	this.displayer = di;
	this.infoBox = inf;
	this.iniInfo = inf.innerHTML;
	this.interstice = this.box.parentNode;
	this.callers = callers;

	this.w = this.scrl.offsetWidth;
	this.bW = this.box.offsetWidth;
	this.prt = this.scrl.parentNode;
	this.prtX = findPosition(this.prt)[0];
	this.prtW = this.prt.offsetWidth;
	this.prtZ = this.prtX + this.prtW;
	this.ratio =  (this.bW - this.prtW) / (this.prtW - this.w);
	this.state = null;
    this.prevX = null;
	this.curOffset = null;
	this.scrolled = null;
	this.cId = cId;
	for(var i = 0; this.callers[i]; i++) {
		if(/described/.test(this.box.className)) {
			this.callers[i].onmouseover = function (that) {
				return function () {
					that.swapDescription(this.cId);
					return false;
				}
			}(this);
			this.callers[i].onfocus = function (that) {
				return function () {
					that.swapDescription(this.cId);
					return false;
				}
			}(this);
			this.callers[i].onmouseout = function (that) {
				return function () {
					that.swapDescription(-1);
					return false;
				}
			}(this);
		}
		else {
			this.callers[i].onmouseover = function (that) {
				return function () {
					that.swapLegend(this.cId);
					return false;
				}
			}(this);
			this.callers[i].onmouseout = function (that) {
				return function () {
					that.swapLegend(this.cId);
					return false;
				}
			}(this);
		}
	}
	if(!/described/.test(this.box.className))
		this.swapLegend(this.cId);
	this.makeDraggable();
}

ScrollItems.prototype.swapLegend = function (cId) {
	var desc = getByTag(this.callers[cId].parentNode,'div')[0];
	if(desc && desc.innerHTML)
		this.infoBox.innerHTML = desc.innerHTML;
	else
		this.infoBox.innerHTML = '';
	if(this.cId != cId)
		addClass(this.infoBox,'lite');
	else
		removeClass(this.infoBox,'lite');
}

ScrollItems.prototype.swapDescription = function (cId) {
	if( cId == -1 ) {
		this.infoBox.innerHTML = this.iniInfo;
		return;
	}
	var desc = getByTag(this.callers[cId].parentNode,'div')[0];
	if(desc && desc.innerHTML)
		this.infoBox.innerHTML = desc.innerHTML;
	else
		this.infoBox.innerHTML = this.iniInfo;
}

ScrollItems.prototype.makeDraggable = function () {
	this.scrl.onmousedown = function (that) {
		return function (e) {
		that.mousedown(e);
		return false;
		}
	}(this);
		this.interstice.onscroll = function (that) {
		return function (e) {
			that.scrollH(e);
		}
	}(this);
	this.init(this.cId);
}

ScrollItems.prototype.scrollH = function (e) {
	e = e ? e : window.event;
	this.scrl.style.left = ((this.interstice.scrollLeft - this.box.offsetLeft) / this.ratio) + 'px';
	this.curOffset = this.w/2;
}

ScrollItems.prototype.init = function (cId) {
	x = this.callers[cId].parentNode.offsetLeft;
	this.interstice.scrollLeft = x;
	if(!this.curOffset) {
		this.curOffset = x - this.prtX;
	}
	else if(this.prevX) {
		this.curOffset = x - (this.prtX + this.prevX);
	}
}

ScrollItems.prototype.mousedown = function (e) {
	e = e ? e : window.event;
	var x = e.clientX ? e.clientX : e.pageX;
	if(!this.curOffset) {
		this.curOffset = x - this.prtX;
	}
	else if(this.prevX) {
		this.curOffset = x - (this.prtX + this.prevX);
	}
	this.state = "drag";
	addClass(this.scrl,'scrolling');
	document.onmousemove = function (that) {
        return function (e) {
            that.mousemove(e);
 			return false;
        }
    }(this);
    document.onmouseup = function (that) {
        return function (e) {
            that.mouseup(e);
        }
    }(this);
}

ScrollItems.prototype.mousemove = function (e) {
	e = e ? e : window.event;
	var x = e.clientX ? e.clientX : e.pageX;
	if(this.state === "drag") {
		if( (x > this.prtX) && (x < this.prtZ)) {
			var scrollerX = (x - this.curOffset) - this.prtX;
			var scrollItemsX = (this.prtX - (x - this.curOffset)) * this.ratio;
			if( (scrollerX > -1) && ( (x - this.curOffset) < (this.prtZ - this.w) )) {
				this.scrl.style.left = scrollerX + 'px';
				this.interstice.scrollLeft = - scrollItemsX;

			}
			else if(scrollerX < 0) {
				this.scrl.style.left = 0 + 'px';
				this.interstice.scrollLeft = 0;
			}
			else if (scrollerX > (this.prtW - this.w)) {
				this.scrl.style.left = (this.prtW - this.w) + 'px';
				this.interstice.scrollLeft = - (this.prtW - this.bW);
			}
		}
	}
}

ScrollItems.prototype.mouseup = function (e) {
	e = e ? e : window.event;
	this.state = '';
	this.prevX = this.scrl.offsetLeft;
	removeClass(this.scrl,'scrolling');
}


/* Scrollee
---------------------- */
function Scrollee(outerBox,middleBox,innerBox,html,callee,stylee) {
	var clls = getByClass('calleeOn','','');
	for (var i = 0; clls[i]; i++) {
		removeClass(clls[i],'calleeOn');
	}
	this.outerBox = document.createElement('div');
	this.outerBox.id = outerBox;
	this.interstice = document.createElement('div');
	this.interstice.id = middleBox;
	this.box = document.createElement('div');
	this.box.id = innerBox;
	this.box.innerHTML = html;
	this.interstice.appendChild(this.box);
	this.outerBox.appendChild(this.interstice);
	getById('content').appendChild(this.outerBox);
	setLinks(['a','area'],this.outerBox);
	if(/arti/.test(this.outerBox.className))
		removeClass(this.outerBox,'arti');
	addClass(this.outerBox,stylee);
	this.callee = callee;

	this.closer = document.createElement('a');
	this.closer.className = 'closer';
	this.closer.href= '#';
	this.closer.onclick = function (that) {
        return function (e) {
            that.close(e);
 			return false;
        }
    }(this);
	this.outerBox.appendChild(this.closer);
	this.outerBox.h = this.outerBox.offsetHeight;
	this.interstice.h = this.interstice.offsetHeight;
	
	this.prt = document.createElement('div');
	this.prt.className = 'scrollBar';
	this.scrl = document.createElement('div');
	this.scrl.className = 'scroller';
	this.prt.appendChild(this.scrl);
	this.outerBox.appendChild(this.prt);
	
	this.h = this.scrl.offsetHeight;
	this.bH = this.box.offsetHeight;
	this.prtH = this.prt.offsetHeight;
	this.prtY = findPosition(this.prt)[1];
	this.prtZ = this.prtY + this.prtH;

	this.state = null;
    this.prevY = null;
	this.curOffset = null;
	this.scrolled = null;
	this.cId = 0;
		
	this.set();
}

Scrollee.prototype.set = function() {
	addClass(this.callee,'calleeOn');
	this.bH = this.box.offsetHeight;
	 if(this.interstice.h < this.bH)
		addClass(this.outerBox,'scrollable');
	 else
		removeClass(this.outerBox,'scrollable');
	this.ratio =  (this.bH - this.prtH) / (this.prtH - this.h);
	this.makeDraggable();
	this.changePosition();

}

Scrollee.prototype.makeDraggable = function () {
	this.scrl.onmousedown = function (that) {
        return function (e) {
            that.mousedown(e);
 			return false;
        }
    }(this);
	
	this.interstice.onscroll = function (that) {
        return function (e) {
            that.scrollV(e);
        }
    }(this);
}

Scrollee.prototype.scrollV = function (e) {
	e = e ? e : window.event;
	this.scrl.style.top = ((this.interstice.scrollTop - this.box.offsetTop) / this.ratio) + 'px';
	this.curOffset = this.h/2;
}

Scrollee.prototype.mousedown = function (e) {
	e = e ? e : window.event;
	var y = e.clientY ? e.clientY : e.pageY;

	if(!this.curOffset) {
		this.curOffset = y - this.prtY;
	}
	else if(this.prevY) {
		this.curOffset = y - (this.prtY + this.prevY);
	}
	this.state = "drag";
	addClass(this.scrl,'scrolling');
	document.onmousemove = function (that) {
        return function (e) {
            that.mousemove(e);
 			return false;
        }
    }(this);
    document.onmouseup = function (that) {
        return function (e) {
            that.mouseup(e);
        }
    }(this);
}

Scrollee.prototype.mousemove = function (e) {
	e = e ? e : window.event;
	var y = e.clientY ? e.clientY : e.pageY;
	if(this.state === "drag") {
		this.prtY = findPosition(this.prt)[1] - getPageY()[1];
		this.prtZ = this.prtY + this.prtH;
		if( (y > this.prtY) && (y < this.prtZ)) {
			var scrollerY = (y - this.curOffset) - this.prtY;
			var scrollItemsY = (this.prtY - (y - this.curOffset)) * this.ratio;
			if( (scrollerY > -1) && ( (y - this.curOffset) < (this.prtZ - this.h) )) {
				this.scrl.style.top = scrollerY + 'px';
				this.interstice.scrollTop = - scrollItemsY;

			}
			else if(scrollerY < 0) {
				this.scrl.style.top = 0 + 'px';
				this.interstice.scrollTop = 0;
			}
			else if (scrollerY > (this.prtH - this.h)) {
				this.scrl.style.top = (this.prtH - this.h) + 'px';
				this.interstice.scrollTop = - (this.prtH - this.bH);
			}
		}
	}
}

Scrollee.prototype.mouseup = function (e) {
	e = e ? e : window.event;
	this.state = '';
	this.prevY = this.scrl.offsetTop;
	removeClass(this.scrl,'scrolling');
}

Scrollee.prototype.close = function() {
	addClass(getById(this.outerBox.id),'hidden');
	removeClass(this.callee,'calleeOn');
}

Scrollee.prototype.changePosition = function () {
	this.outerBox.style.top = ((getPageY()[0] - this.outerBox.offsetHeight) / 2) + getPageY()[1] + 'px';
}

function initScrollee(html,title,callee,classy) {
	if(getById('recipientContainer')) {
		getById('content').removeChild(getById('recipientContainer'));
	}
	if(title) html = '<h2>'+title+'</h2>'+html;
	var scrollee = new Scrollee('recipientContainer','recipient','recipientInner',html,callee,classy);

}

function setAddendas() {
	var addendas = getByClass('addended',getById('page'),'div');
	for(var i = 0; addendas[i]; ++i) {
		var caller = getByClass('addendaCaller',addendas[i],'');
		var titeul = getByClass('addendaTitle',addendas[i],'');
		var content = getByClass('addendaContent',addendas[i],'');

		if(caller && content && caller[0]) {
			var classy = (/addendedArti/.test(caller[0].className)) ? 'arti' : '';
			if(titeul.length>0) {titeul = titeul[0].innerHTML;}
			else {titeul = '';}
			caller[0].content = content[0].innerHTML;
			caller[0].titeul = titeul;
			caller[0].classy = classy;
			caller[0].onclick = function() {
		        initScrollee(this.content,this.titeul,this,this.classy);
				return false;
			}
		}
	}
}

/* 
----- */
function setRandoms() {
	var r = getByClass('random',getById('page'),'div');
	if(r&&r[0]) {
		var c = getByClass('call',r[0],'a');
		var l = getByTag(getByTag(r[0],'ul')[0],'a');
		if(c&&c[0]&&l&&l[1])
			new Randoms(r[0],c[0],l);
	}
}

function Randoms(r,c,l){
	this.container = r;
	this.call = c;
	this.rands = l;
	this.cId= -1;
	this.max=l.length;
	for(var i = 0; l[i]; ++i) {
		if(/current/.test(l[i].className))
			this.cId = i;
	}

	this.call.onclick = function(that) {
		return function() {
			var r = Math.ceil(Math.random()*that.max)-1;
			if (that.cId==r) {
				if((r-1)>0) r--;
				else if((r+1)<that.max) r++;
			}
			removeClass(that.rands[that.cId],'current');
			addClass(that.rands[r],'current');
			that.cId = r;
			return false;
		}
	}(this);
}

/* Comments
----- */
function setComments() {
	var c = getById('comments');
	if(!c) return;
	var h2Coll = getByTag(c,'h2');
	var f = getByTag(c,'form');
	var co = getByClass('comments',c,'div');
	var cod = (co) ? co[0]:null;

	if(h2Coll&&f&&f[0])
		new Comments(c,h2Coll,f[0],cod);
}

function Comments(prt,titles,f,c) {
	this.prt = prt;
	this.nav = prt.insertBefore(createEl('div','commentsNav',''),titles[0]);
	for(var i = 0; titles[i]; ++i) {
		addClass(titles[i],'wai');
		if(i!=0)
			this.nav.appendChild(createEl('span','navSeparator',''));
		var b = this.nav.appendChild(createEl('button','commentBtn',titles[i].innerHTML));
		b.cId = i;
	}

	this.cId = 0;
	this.btns = getByTag(this.nav,'button');
	addClass(this.btns[0],'current');
	addClass(f,'current');
	this.cForm = f;
	
	if (c) {
		this.comments = c;
		for(var i = 0; this.btns[i]; ++i) {
			this.btns[i].onclick = function(that) {
				return function() {
					that.swap(this.cId);
				}
			}(this);
		}
		
		var displayForm=/#form/.test(window.location.href);
		if (getById('frmFailed') && getById('frmFailed').value=="True" ) {
			displayForm=true;
			window.location.hash="#form";
		}
		if ( !displayForm )
			this.swap(this.btns[1].cId);
	}
}

Comments.prototype = {
	swap: function(cId) {
		if(this.cId==cId) return;
		removeClass(this.btns[this.cId],'current');
		addClass(this.btns[cId],'current');
		if(cId==0){
			addClass(this.cForm,'current');
			removeClass(this.comments,'current');
		}
		else {
			addClass(this.comments,'current');
			removeClass(this.cForm,'current');
		}
		this.cId=cId;
	}
}



/* Init
-------------------- */
var init = function() {
	if (arguments.callee.done) return;
	arguments.callee.done = true;
	if(!document.getElementsByTagName)
		return;
	addClass(getById('page'),'scripted');
	setFancyFields();
	setLinks(['a','area'],'');
	setTimeout("setScroller();",220);
	setAddendas();
	setRandoms();
	setComments();
	/*@cc_on @*/
	/*@if (@_win32)
	var ua = navigator.userAgent;
	var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
	if (re.exec(ua) != null) {
		rv = parseFloat( RegExp.$1 );
		if(rv < 7) fixLowIE();
		if(rv < 8) fixIE();
	}
	/*@end @*/
}

if (document.addEventListener) {
	document.addEventListener("DOMContentLoaded", function(){
		document.removeEventListener("DOMContentLoaded",arguments.callee,false);
		init();
	},false);
}
else if (document.attachEvent) {
	document.attachEvent("onreadystatechange", function(){
		if (document.readyState === "complete") {
			document.detachEvent("onreadystatechange",arguments.callee);
			init();
		}
	});
	if (document.documentElement.doScroll && window == window.top) (function(){
		if (arguments.callee.done) return;
		try {
			document.documentElement.doScroll("left");
		} catch(error) {
			setTimeout(arguments.callee, 0);
			return;
		}
		init();
	})();
}
window.onload = init;


/* IE anti FOUC
----- */
/*@cc_on @*/
/*@if (@_win32)
document.write("<script id=__ie6_onload defer src=javascript:void(0)><\/script>");
var script = document.getElementById("__ie6_onload");
script.onreadystatechange = function() {
	if (this.readyState == "complete") {
		var b = document.getElementsByTagName('body')[0];
		b.className = b.className + ' scripted';
	}
};
/*@end @*/