// JavaScript Document

//FOR THE J DOG
if (typeof(cgmirrordir) == 'undefined') {
var cgmirrordir = "";
}

function fileInputUpdate(x) {
	var target = x.parentNode.getElementsByTagName("input")[1];
	target.value = x.value;
}

//BROWSER DETECTION GLOBALS
var isLTIE8 = false;
var isIE8 = false;
var isFF = false;
var isWK = false;
var isIPHONE = false;
var isSafari = false;
if(navigator.userAgent.match(/MSIE 8.0/gi) != null) {
	isIE8 = true;
}
else if(navigator.userAgent.match(/MSIE/gi) != null) {
	isLTIE8 = true;
}
else if(navigator.userAgent.match(/Firefox/gi) != null) {
	isFF = true;
}
else if(navigator.userAgent.match(/iPhone/gi) != null) {
	isIPHONE = true;
}
else if(navigator.userAgent.match(/Webkit/gi) != null) {
	if(navigator.userAgent.match(/Apple/gi) != null) {
		isSafari = true;
	}
	isWK = true;
}

//FORUM TEXT AREA 

var oldCaret;

function scalingTextarea(ph, specialFunction) {
	var gthis = this;
	if(typeof ph == "string") {
		this.phantom = document.getElementById(ph);
	}
	else {
		this.phantom = ph;
	}
	var interval = 250;
	this.locked = false;
	this.onchange = updateInterval;
	this.onkeydown = updateInterval;
	this.onkeypress = updateInterval;
	
	this.oldValue;
	
	function updateInterval() {
		var temp = this;
		if(this.locked == false) {
			this.locked = true;
			var t = setTimeout(function() {temp.update()},interval);
		}
	}
	
	this.update = function() {
		this.locked = false;
		this.phantom.innerHTML = this.value.replace(/&/gi, "&amp;").replace(/</gi, "&lt;").replace(/>/gi, "&gt;").replace(/"/gi, "&quot;") + "&nbsp;";
		
		//IF LTE IE8
		if(isIE8 == true) {
			this.phantom.innerHTML = this.value.replace(/\r\n/g, '<br/>') + "&nbsp;";
		}
		else if(isLTIE8 == true) {
			this.phantom.innerHTML = "<pre>" + this.value.replace(/\n/g, '<br/>') + "&nbsp;" + "</pre>";
		}
		
		var pHeight = this.phantom.offsetHeight;
		this.style.height = pHeight + "px";
		
		if(isIE8) {
			this.scrollTop = this.scrollHeight;
		}
		
		if(specialFunction) {
			specialFunction.call(this);
		}
	}
	
	this.update();
}

function GetCaretPosition(control) {
	var CaretPos = 0;
	//IF IS LOWER THAN IE 8
	if(isLTIE8 == true) {
		control.focus();
		var Sel = document.selection.createRange ();
		var Sel2 = Sel.duplicate();
		Sel2.moveToElementText(control);
		var CaretPos = -1;
		while(Sel2.inRange(Sel))
		{
		Sel2.moveStart('character');
		CaretPos++;
		}
	}
	
	if (control.selectionStart || control.selectionStart == '0') {
	CaretPos = control.selectionStart;
	}
	oldCaret = CaretPos;
	return (CaretPos);
}

function setCaretPosition(ctrl, pos){
	if(ctrl.setSelectionRange)
	{
		ctrl.focus();
		ctrl.setSelectionRange(pos,pos);
	}
	else if (ctrl.createTextRange) {
		var range = ctrl.createTextRange();
		range.collapse(true);
		range.moveEnd('character', pos);
		range.moveStart('character', pos);
		range.select();
	}
}

function forumTAInsert(ta, ph, what, what2, middle_text) {
	var textArea = document.getElementById(ta);
	var phantom = document.getElementById(ph);
	var text = textArea.value;
	var caret = GetCaretPosition(textArea);
	var text1 = text.slice(0,caret);
	var text2 = text.slice(caret);
if(what2 == null || !isNaN(what2)) // catch+fix old way.
	{
what2 = "";
	}
if(middle_text == null || !isNaN(middle_text)) // catch+fix
	{
middle_text = "";
	}
//middle_text is only used when user hasn't got text highlighted, so that [list]*Item 1\n*Item 2[/list] can wrap around without the middle part "*Item 1\n*Item 2" being entered
var currenttext = textArea.value;

if(document.selection)
	{
//IE:
var selection = document.selection.createRange().text;
if(selection && selection != "")
		{
if(selection.substr(0, 3) == 'www' && what == '[URL=www.google.com]' || selection.substr(0, 4) == 'http' && what == '[URL=www.google.com]') // HANDLE URL SPECIAL CASE.
{
selection = '[URL='+selection+']Click Me[/URL]';
}
else
{
selection = what+selection+what2;
}
document.selection.createRange().text = selection;
textArea.focus();
forumTAUpdate(textArea, phantom);
return;
		}
	}
	else if (textArea.selectionEnd && (textArea.selectionEnd - textArea.selectionStart > 0))
	{

var start = textArea.selectionStart;
var end = textArea.selectionEnd;
var length = end - start;
var currenttext = textArea.value;
var before = currenttext.substr(0, start);
var selection = currenttext.substr(start, length);
var after = currenttext.substr(end);
if(selection.substr(0, 3) == 'www' && what == '[URL=www.google.com]' || selection.substr(0, 4) == 'http' && what == '[URL=www.google.com]') // HANDLE URL SPECIAL CASE.
{
selection = '[URL='+selection+']Click Me[/URL]';
}
else
{
selection = what+selection+what2;
}
textArea.value = before+selection+after;
textArea.focus();
forumTAUpdate(textArea, phantom);
		return;
	}
//simply enter into textarea if nothing is highlighted above (or if it didnt detect that something was highlighted)
var newText = text1 + what + middle_text + what2 + text2;
textArea.value = newText;
setCaretPosition(textArea, oldCaret + what.length);
forumTAUpdate(textArea, phantom);
}
//END FORUM TEXT AREA


//MODERATION LISTS

//LIGHTWEIGHT ANIMATOR

function grow(trigger, target, direction) {
	
	//GET TARGETS
	var trig;
	var tar;
	
	if(typeof(trigger) == "string") {
		trig = document.getElementById(trigger);
	}
	else {
		trig = trigger;
	}
	
	if(typeof(target) == "string") {
		tar = document.getElementById(target);
	}
	else {
		tar = target;
	}
	
	clearTimeout(trig.timer);
	
	//RUN BEFORE?
	if(!tar.maxH) {
		tar.maxH = tar.offsetHeight;
		tar.curr = 0;
		tar.style.display = "block";
		tar.style.height = "0px";
		tar.style.visibility = "visible";
		tar.style.overflow = "hidden";
		alert("RUN");
	}
	else {
		trig.timer = setInterval(growAnim,50);
	}
	
	function growAnim() {
		var diff = Math.round(((tar.maxH * direction) - tar.curr) * .2);
		tar.curr += diff;
		if(diff == 0) {
			clearTimeout(trig.timer);
		}
		else {
			tar.style.height = tar.curr + "px";
		}
	}
}

//ROBUST ANIMATOR

function slider(trigger, target, triggerType, direction, delay, trigger2) {
	var tar;
	var tarHeight;
	var tarWidth;
	var io = false;
	var lockout = false;
	var overTimer;
	var outTimer;
	var gTimer;
	var rem = 0;
	
	//ACCEPT ELEMENTS AND ID STRINGS
	if(typeof(trigger) == "string") {
		trig = document.getElementById(trigger);
		trig2 = document.getElementById(trigger2);
	}
	else {
		trig = trigger;
		trig2 = trigger2;
	}
	
	this.trig = trig;
	this.trig2 = trig2;
	
	if(typeof(target) == "string") {
		tar = document.getElementById(target);
	}
	else {
		tar = target;
	}
	
	//SET VALUES
	
	tarHeight = tar.offsetHeight;
	tarWidth = tar.offsetWidth;
	
	if(direction == true) {
		tar.style.height = "0px";
	}
	else {
		tar.style.width = "0px";
	}
	
	tar.style.overflow = "hidden";
	tar.style.visibility = "hidden";

	
	//DISPATCHERS
	if(triggerType == true) {
		trig.onmouseover = function() {
			clearTimeout(gTimer); 
			if(io == false) {
				gTimer = setTimeout(function() {io = true; clearTimeout(outTimer);over(rem)},delay)
			}
		}
		trig.onmouseout = function() {
			clearTimeout(gTimer);
			if(io == true) {
				gTimer = setTimeout(function() {io = false; clearTimeout(overTimer);out(rem)},delay)
			}
		}
	}
	else {
		trigClick = function() {
			if(io == false) {
				clearTimeout(outTimer);
				over(rem);
				io = true;
			}
			else {
				clearTimeout(overTimer);
				out(rem);
				io = false;
			}
		}
		trig.onclick = trigClick;
		if(trig2 != null) {trig2.onclick = trigClick};
	}
		
	function over(rem) {
		//Prepare First Run
		if(rem == 0) {
			tar.style.visibility = "visible";
			if(direction == true) {
				var rem = tarHeight;
			}
			else {
				var rem = tarWidth;
			}
		}
		
		//Get new value
		var takeThis = rem*.5;
		if(takeThis < 1) {
			takeThis = 1;
		}
		rem -= takeThis;
		if(rem >= 0) {
			if(direction == true) {
				overTimer = setTimeout(function() {tar.style.height = (tarHeight - rem) + "px"; over(rem)},50);
			}
			else {
				overTimer = setTimeout(function() {tar.style.width = (tarWidth - rem) + "px"; over(rem)},50);
			}
		}
		else {
			if(direction == true) {
				tar.style.height = tarHeight + "px";
			}
			else {
				tar.style.width = tarWidth + "px";
			}
			tar.style.overflow = "visible";
			rem = 0;
		}
	}
	
	function out(rem) {
		//Prepare First Run
		if(rem == 0) {
			tar.style.overflow = "hidden";
			if(direction == true) {
				var rem = tarHeight;
			}
			else {
				var rem = tarWidth;
			}
		}
		
		//Get new value
		var takeThis = rem*.5;
		if(takeThis < 1) {
			takeThis = 1;
		}
		rem -= takeThis;
		if(rem >= 0) {
			if(direction == true) {
				outTimer = setTimeout(function() {tar.style.height = rem + "px"; out(rem)},50);
			}
			else {
				outTimer = setTimeout(function() {tar.style.width = rem + "px"; out(rem)},50);
			}
		}
		else {
			tar.style.visibility = "hidden";
			if(direction == true) {
				tar.style.height = "0px";
			}
			else {
				tar.style.width = "0px";
			}
			rem = 0;
		}
	}	
}

function textSlider() {
	var tables = document.getElementsByTagName("table");
	for(var i = 0; i < tables.length; i++) {
		var d = tables[i].getElementsByTagName("div");
		for(var y = 0; y < d.length; y++) {
			if(d[y].className == "title_wrapper") {
				if(d[y].checked != true) {
					var slider = d[y].getElementsByTagName("div")[0];
					var maxWidth = d[y].offsetWidth;
					var sliderWidth = slider.offsetWidth;
					
					if(sliderWidth > maxWidth) {
						d[y].mWidth = maxWidth;
						d[y].sWidth = sliderWidth;
						d[y].slider = slider;
						d[y].parentNode.style.backgroundImage = "url('" + cgmirrordir + "images/arrow_overflow.gif')";
						
						var animTimer;
						var lockoutTimer;
						d[y].onmouseover = function() {
							var savedthis = this;
							var totalWidth =savedthis.mWidth;
							var slider = savedthis.slider;
							var sliderWidth =  savedthis.sWidth;
							
							var diff = sliderWidth - totalWidth + 14;
							var offset = 0;
							var dir = true;
							animTimer = setInterval(function() {
								if(offset < diff && dir == true) {
									 offset += 5; 
									 slider.style.left = -offset + "px";
								}
								else if(offset >= diff && dir == true) {
									dir = false; 
								}
								else if(offset > -2 && dir == false){
									offset -= 5; 
									slider.style.left = -offset + "px";
								}
								else {
									dir = true; 
								}
							},100);
						}
						d[y].onmouseout = function() {
							clearTimeout(animTimer);
							clearTimeout(lockoutTimer);
							this.slider.style.left = 0 + "px";
						}
						
					}
				}
				d[y].checked = true;
			}
		}
	}
}

function alternator() {
	var tables = document.getElementsByTagName("table");
	var tables_no = tables.length;
	var lists = document.getElementsByTagName("ul");
	var lists_no = lists.length;
	var dlists = document.getElementsByTagName("dl");
	var dlists_no = dlists.length;
	
	for(var i = 0; i < tables_no; i++) {
		trAlternate(tables[i]);
	}
	
	for(var i = 0; i < lists_no; i++) {
		listAlternate(lists[i]);
	}
	
	for(var i = 0; i < dlists_no; i++) {
		listAlternate(dlists[i]);
	}
}

function listAlternate(list) {
	if(list.className.search("compact_list") != "-1") {
		if(list.nodeName.toLowerCase() == "ul") {
			var li_list = list.getElementsByTagName("li");
		}
		else if(list.nodeName.toLowerCase() == "dl") {
			var li_list = list.getElementsByTagName("dd");
		}
		var li_list_length = li_list.length;
		for(var i = 1; i < li_list_length; i++) {
			li_list[i].className = "odd";
			i++;
		}
	}
}

function trAlternate(table) {
	if(table.className.search("compact_table") != "-1" || table.className.search("fp_table") != "-1") {
		var trs = table.rows;
		for(var i = 1; i < trs.length; i++) {
			trs[i].className = "odd";
			i++;
		}
	}
}
//CUSTOM SELECT BOX

function customSelect(trigger, textarea, set) {
	var trig = document.getElementById(trigger);
	var text = document.getElementById(textarea);
	var target = trig.nextSibling;
	while(target.nodeType != 1)  {
		target = target.nextSibling;
	}
	if(set == false) {
		var title = target.firstChild;
		while(title.nodeType != 1) {
			title = title.nextSibling;
		}
		title = title.innerHTML;
		text.innerHTML = title;
	}
	else {
		var title = text.innerHTML;
	}
	var links = target.getElementsByTagName("a");
	for(var i = 0; i < links.length; i++) {
		links[i].onclick = function() {
			text.innerHTML = this.innerHTML;
			this.onmouseout = "";
		}
		links[i].onmouseover = function() {
			text.innerHTML = this.innerHTML;
		}
		links[i].onmouseout = function() {
			text.innerHTML = title;
		}
	}
	var width = target.offsetWidth;
	text.style.width = width + "px";
	target.style.width = width + 7 + "px";
	slider(trigger, target, false, true, "0", textarea);
}


//GET STYLE http://www.quirksmode.org

function getStyle(el,styleProp)
{
	var x = 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;
}


function list_select(x) {
	var el = x;
	var checkbox_ar = document.getElementsByName("chk");
	for(var i = 0; i < checkbox_ar.length; i++) {
		checkbox_ar[i].checked = x.checked;
		checkbox_ar[i].onchange();
	}
}

function list_select_listen() {
	var checkbox_ar = document.getElementsByName("chk");
	for(var i = 0; i < checkbox_ar.length; i++) {
		checkbox_ar[i].original = checkbox_ar[i].parentNode.parentNode.className; 
		checkbox_ar[i].onchange = function() {
			if(this.checked == true) {
				this.parentNode.parentNode.className = this.original + " mail_selected";
			}
			else {
				this.parentNode.parentNode.className = this.original;
			}
		}
		checkbox_ar[i].onchange();
	}
}

var popup_open;
var popup_button_wrapper;
var popup_temp_content = ""; //JEREMY TEMP FIX.
var popup_temp_contentid = ""; //JEREMY TEMP FIX.

//remove once sorted:
function popup(x, pWidth, posX, posY, content)
{
popupcg(x, pWidth, posX, posY, content);
}

function popupcg(x, pWidth, posX, posY, content) {
	
	var button_w = x.offsetWidth;
	var button_h = x.offsetHeight;
	var cloned = x.cloneNode(true);
	cloned.onclick = popup_close;
	
	//CLOSE OTHERS
	popup_close();
	
	//CREATE
	var xWrap = document.createElement("div");
	xWrap.className = "popup_bwrapper";
	var button = document.createElement("div");
	button.className = "button";
	button.appendChild(cloned);
	xWrap.appendChild(button);
	popup_button_wrapper = xWrap;
	var p_wrapper = document.createElement("div");
	p_wrapper.className = "popup_wrapper";
	var p = document.createElement("div");
	p.className = "popup";
	//p.innerHTML = content;

//BEGIN JEREMY. - to reverse, comment out all this, and uncomment line above
if(document.getElementById(content).innerHTML)
	{
p.innerHTML = document.getElementById(content).innerHTML; // changed content above to be the actual ID.
	}
	else
	{
p.innerHTML="ERROR";
	}
popup_temp_content = document.getElementById(content).innerHTML;
popup_temp_contentid = content;
document.getElementById(content).innerHTML = ""; // destroy current HTML so no duplicated IDs etc, should replace once popup is closed.
//END JEREMY



	p.style.width = pWidth + "px";
	
	p_wrapper.appendChild(p);
	popup_open = p_wrapper;
	document.body.appendChild(p_wrapper);
	document.body.appendChild(xWrap);
	
	//POSITION
	var pos = getAbsolutePos(x);
	var xy = pos.y;
	var xx = pos.x;
	if(posY == "up") {
		xy -= p_wrapper.offsetHeight;
		xy += button_h;
		xy += 7;
		p_wrapper.className += " up";
		xWrap.className += " up";
		xWrap.style.top = (pos.y - 5)  + "px";
	}
	else {
		xy -= 5;
		p_wrapper.className += " down";
		xWrap.className += " down";
		xWrap.style.top = (pos.y - 10) + "px";
	}
	if(posX == "left") {
		xx -= p_wrapper.offsetWidth;
		xx -= 4;
		xWrap.className += " left";
		xWrap.style.left = pos.x + "px";
		p_wrapper.className += " left";
	}
	else {
		xx += button_w;
		xx += 5;
		xWrap.className += " right";
		xWrap.style.left = (pos.x - 10) + "px";
		p_wrapper.className += " right";
	}
	
	p_wrapper.style.left = xx + "px";
	p_wrapper.style.top = xy + "px";
	button.style.height = button_h + "px";
	
}

function popup_close() {
	if(popup_open != null) {
		document.body.removeChild(popup_open);
		document.body.removeChild(popup_button_wrapper);
		popup_open = null;
		popup_button_wrapper = null;
		if(document.getElementById(popup_temp_contentid))
		{
		document.getElementById(popup_temp_contentid).innerHTML=popup_temp_content;
		}
	}
}

//TEXTAREA CLEARER 

function textfieldClear() {
	var inputs = document.getElementsByName("input_clear");
	for(var i = 0; i < inputs.length; i++) {
		if(inputs[i].getAttribute("type") == 'text' || inputs[i].getAttribute("type") == 'password') {
			inputs[i].orig = inputs[i].value;
			inputs[i].onfocus = function() {
				if(this.value == this.orig) {
					this.value = "";
				}
			}
			inputs[i].onblur = function() {
				if(this.value == "") {
					this.value = this.orig;
				}
			}
		}
	}
}

function removeAllChildNodes(node) {
	if (node && node.hasChildNodes && node.removeChild) {
		while (node.hasChildNodes()) {
			node.removeChild(node.firstChild);
		}
	}
}

/* CG WINDOW */
function cgwindow(id,t) {
	var html = document.getElementById(id).innerHTML;
	document.getElementById(id).innerHTML=""; // clear HTML
	var black = document.createElement("div");
	black.setAttribute("id","black_w");
	var shadow = document.createElement("div");
	shadow.className = "cg_window_s";
	var win = document.createElement("div");
	win.className = "popup cg_window";
	var title = document.createElement("div");
	title.className = "title";
	var titlespan = document.createElement("span");
	titlespan.innerHTML = t;
	var closeb = document.createElement("a");
	closeb.className = "sb_button close fr";
	var content = document.createElement("div");
	content.className = "content";
	content.setAttribute("id","cgwindow_content"); // JEREMY.
	content.innerHTML = html;
	closeb.onclick = function() {
		document.body.removeChild(black);
		document.getElementById(id).innerHTML=html; // reset HTML.
	}
	title.appendChild(closeb);
	title.appendChild(titlespan);
	win.appendChild(title);
	win.appendChild(content);
	shadow.appendChild(win);
	black.appendChild(shadow);
	document.body.appendChild(black);
	
	var availHeight;
	if(window.innerHeight) {
		availHeight = window.innerHeight;
	}
	else {
		availHeight = document.documentElement.clientHeight;
	}
	var height = shadow.offsetHeight;
	
	if(height < availHeight - 100) {
		var diff = availHeight - height;
		var margin = diff/2;
		shadow.style.marginTop = margin + "px";
	}
	else {
		content.style.height = availHeight - 154 + "px";
		shadow.style.marginTop = "50px";
	}
	
}

function cE(theType, theClass, theHTML) {
	var temp = document.createElement(theType);
	if(theClass != null) {temp.className = theClass}
	if(theHTML != null) {temp.innerHTML = theHTML}
	return temp;
}

var ajaxPopups_ar = new Array();
var ajaxPopups_queue = new Array();
var divert = false;
function ajaxPopup(titletext,contents) {
	var gthis = this;
	this.timerActive = null;
	this.shiftOffset = 0;
	
	this.wrapper = cE("div");
	this.wrapper.className="ajaxwrapper";
	this.wrapper.order = 0;
	this.wrapper.Y = 40;
	
	this.title = cE("div");
	this.title.className = "title";
	this.title.innerHTML = titletext;
	var closebtn = cE("div");
	closebtn.className="fr";
	closebtn.innerHTML ="X";
	closebtn.onclick = function() {
		makeSmaller();
		clearTimeout(gthis.timerActive);
	}
	var lining = cE("div");
	lining.className = "lining";
	this.text = cE("div");
	this.text.innerHTML = contents;
		
	this.title.appendChild(closebtn);
	lining.appendChild(this.title);
	lining.appendChild(this.text);
	this.wrapper.appendChild(lining);
	
	this.blockInit = function() {
		gthis.wrapper.style.visibility = "hidden";
		document.body.appendChild(gthis.wrapper);
		gthis.wrapper.maxWidth = gthis.wrapper.offsetWidth;
		ajaxPopups_ar.unshift(gthis.wrapper);
		gthis.wrapper.style.width = "0px";
		gthis.wrapper.currWidth = 0;
		gthis.wrapper.style.visibility="visible";
	}
	
	this.isfirst = function() {
		if(divert == false) {
			gthis.blockInit();
			if(ajaxPopups_ar.length > 1) {
				divert = true;
				shiftDown();
			}
			else {
				makeBigger();
			}
		}
		else {
			ajaxPopups_queue.push(gthis);
		}
	}
	this.isfirst();
			
	function makeBigger() {
		var newVal = gthis.wrapper.currWidth + ((gthis.wrapper.maxWidth - gthis.wrapper.currWidth)*.3);
		if(newVal < gthis.wrapper.maxWidth - 1 && newVal < gthis.wrapper.maxWidth) {
			gthis.wrapper.currWidth = newVal;
			gthis.wrapper.style.width = gthis.wrapper.currWidth + "px";
			setTimeout(function() {makeBigger()},50);
		}
		else {
			gthis.wrapper.currWidth = gthis.wrapper.maxWidth;
			gthis.wrapper.style.width = gthis.wrapper.maxWidth + "px";
		}
	}
	
	function makeSmaller() {
		var newVal = gthis.wrapper.currWidth + ((0 - gthis.wrapper.currWidth)*.3);
		if(newVal > 1) {
			gthis.wrapper.currWidth = newVal;
			gthis.wrapper.style.width = gthis.wrapper.currWidth + "px";
			setTimeout(function() {makeSmaller()},50);
		}
		else {
			gthis.wrapper.currWidth = 0;
			gthis.wrapper.style.width = "0px";
			document.body.removeChild(gthis.wrapper);
			ajaxPopups_ar.splice([gthis.wrapper.order],1);
			collapse(gthis.wrapper.order);
		}
	}
	
	function shiftDown() {
		if(gthis.shiftOffset < 8) {
			for(var i = 1; i < ajaxPopups_ar.length; i++) {
				ajaxPopups_ar[i].order = i;
				ajaxPopups_ar[i].Y += 6;
				ajaxPopups_ar[i].style.top = ajaxPopups_ar[i].Y + "px";
			}
			gthis.shiftOffset++;
			setTimeout(function() {shiftDown()},50);
		}
		else {
			makeBigger();
			gthis.shiftOffset = 0;
			divert = false;
			if(ajaxPopups_queue.length > 0) {
				var target = ajaxPopups_queue.shift();
				target.isfirst();
			}
		}
	}
	
	function collapse(start) {
		if(gthis.shiftOffset < 8) {
			for(var i = start; i < ajaxPopups_ar.length; i++) {
				ajaxPopups_ar[i].order = i;
				ajaxPopups_ar[i].Y -= 6;
				ajaxPopups_ar[i].style.top = ajaxPopups_ar[i].Y + "px";
			}
			gthis.shiftOffset++;
			setTimeout(function() {collapse(start)},50);
		}
		else {
			gthis.shiftOffset = 0;
		}
	}
		
	this.completed = function(delay) {
		if(gthis.timerActive == null) {
			gthis.wrapper.className += " completed";
			if(delay != null) {
				gthis.timerActive = setTimeout(function() {makeSmaller()}, delay);
			}
		}
	}
	
	this.failed = function(error, delay) {
		if(gthis.timerActive == null) {
			gthis.wrapper.className += " failed";
			gthis.text.innerHTML = error;
			gthis.wrapper.style.width = "auto";
			var newWidth = gthis.wrapper.offsetWidth;
			gthis.wrapper.maxWidth = newWidth;;
			gthis.wrapper.currWidth = newWidth;
			if(delay != null) {
				gthis.timerActive = setTimeout(function() {makeSmaller()}, delay);
			}
		}
	}
}

function showhide(x,target, hidden) {
	var tar = document.getElementById(target);
	if(x.clicked != true) {
		x.clicked = true;
		clearTimeout(x.timerClose);
		x.timerOpen = setTimeout(function() {
		if(hidden == true) {
			tar.style.display = "block";
		}
		else {
			tar.style.display = "block";
		}
										  },100);
	}
	else {
		x.clicked = false;
		clearTimeout(x.timerOpen);
		x.timerClose = setTimeout(function() {
		if(hidden == true) {
			tar.style.display = "none";
		}
		else {
			tar.style.display = "block";
		}
										   },100);
	}
}

function removeElement(id) {
	var el = document.getElementById(id);
	el.parentNode.removeChild(el);
}

function popup_gobottom(x) {
	var target;
	while(x.previousSibling.nodeType != 1) {
		x = x.previousSibling;
	}
	target = x.previousSibling;
	target.scrollTop = target.scrollHeight;
}

function tree(x) {
	if(!x.status && x.parentNode.className != "open tree" || x.status == "closed") {
		x.status = "closed";
	}
	else {
		x.status = "open";
	}
	showHide(x);
	function showHide(el) {
		var curr = el;
		var apply;
		var link = el.getElementsByTagName("a")[0];
		
		if(el.status == 'closed') {
			el.status = 'open';
			apply = "block";
			link.style.backgroundImage = "url(" + cgmirrordir + "images/buttons/collapse.png)";
		}
		else {
			el.status = 'closed';
			apply = "none";
			link.style.backgroundImage = "url(" + cgmirrordir + "images/buttons/expand.png)";
		}
		while(curr.nextSibling != null) {
			if(curr.nextSibling.style) {
				curr.nextSibling.style.display = apply;
			}
			curr = curr.nextSibling;
		}
	}
}

var star_ar = new Array();

function voteSlider(x,event) {
	var value;
	if(x.xcoord == null) {
		var pos = getAbsolutePos(x);
		value = event.clientX - pos.x;
		x.xcoord = pos.x;
	}
	else {
		value = event.clientX - x.xcoord;
	}
	var userStars;
	if(x.userStars == null) {
		userStars = x.getElementsByTagName("div")[1];
		x.userStars = userStars;
	}
	else {
		userStars = x.userStars;
	}
	var starCount = Math.ceil(value/7.5);
	var outOffive = starCount/2;
	var newValue = starCount * 7.5;
	userStars.style.width=newValue + "px";
	
	if(x.text == null) {
		var text = x.nextSibling;
		while(text.nodeType != 1) {
			text = text.nextSibling;
		}
		text.firstChild.innerHTML = outOffive;
		x.text = text.firstChild;
	}
	else {
		x.text.innerHTML = outOffive;
	}
		
	return outOffive;
}

function theatreStack(x,event) {
	var outOffive = voteSlider(x,event);
	
	if(x.alreadyDone == null) {
		star_ar.push(x);
	}
	x.alreadyDone = outOffive;
	voteTotal();
}

function voteTotal() {
	var totalEl = document.getElementById("theatre_yourvote").firstChild;
	var result = 0;
	
	for(var i = 0; i < 4; i++) {
		if(star_ar[i]) {
			result+=star_ar[i].alreadyDone*.25;
		}
	}
	
	totalEl.innerHTML = Math.round(result*10)/10;
}

function getChromeFrame() {
	cgwindow('chromePopup','Please upgrade your browser to view CyberGamer correctly...');
}


function tooltip(x, html, maxWidth, myEvent, location) {
	
	if(typeof(tt) == "undefined") {tt = document.createElement("div")}
	tt.className = "tooltip";
	tt.innerHTML = html;
	tt.style.maxWidth = maxWidth + "px";
	var arrow = new Image();
	if(location == "bottom") {
		arrow.src = cgmirrordir + "images/tooltip_arrowbtm.gif";
		arrow.setAttribute("id", "tt_arrowbtm");
	}
	else {
		arrow.src = cgmirrordir + "images/tooltip_arrow.gif";
		arrow.setAttribute("id", "tt_arrow");
	}
	tt.appendChild(arrow);
	
	tt.style.visibility = "hidden";
	document.body.appendChild(tt);
	
	var ttHeight = tt.offsetHeight + 4;
	var ttWidth = Math.round(tt.offsetWidth/2);
	var daHeight = x.offsetHeight;
	var pos = getAbsolutePos(x);
	
	tt.style.left = myEvent.clientX - ttWidth + "px";
	if(location == "bottom") {
		tt.style.top = Math.round((pos.y + x.offsetHeight + 4)) + "px";
	}
	else {
		tt.style.top = Math.round((pos.y - ttHeight)) + "px";
	}
	
	arrow.style.left = ttWidth - 4 + "px";
	tt.style.visibility = "visible";
	
	x.onmousemove = function(event) {
		if(isLTIE8 == true) {
			tt.style.left =	window.event.clientX - ttWidth + "px";
		}
		else {
			tt.style.left = event.clientX - ttWidth + "px";
		}
	}
	
	x.onmouseout = function() {
		tt.style.visibility = "hidden";
		x.onmousemove = null;
	}
}

var __isIE =  navigator.appVersion.match(/MSIE/);
var __userAgent = navigator.userAgent;
var __isFireFox = __userAgent.match(/firefox/i);
var __isFireFoxOld = __isFireFox && (__userAgent.match(/firefox\/2\./i) || __userAgent.match(/firefox\/1\./i));
var __isFireFoxNew = __isFireFox && !__isFireFoxOld;

function __parseBorderWidth(width) {
    var res = 0;
    if (typeof(width) == "string" && width != null && width != "" ) {
        var p = width.indexOf("px");
        if (p >= 0) {
            res = parseInt(width.substring(0, p));
        }
        else {
     		//do not know how to calculate other values (such as 0.5em or 0.1cm) correctly now
    		//so just set the width to 1 pixel
            res = 1; 
        }
    }
    return res;
}


//returns border width for some element
function __getBorderWidth(element) {
	var res = new Object();
	res.left = 0; res.top = 0; res.right = 0; res.bottom = 0;
	if (window.getComputedStyle) {
		//for Firefox
		var elStyle = window.getComputedStyle(element, null);
		res.left = parseInt(elStyle.borderLeftWidth.slice(0, -2));  
		res.top = parseInt(elStyle.borderTopWidth.slice(0, -2));  
		res.right = parseInt(elStyle.borderRightWidth.slice(0, -2));  
		res.bottom = parseInt(elStyle.borderBottomWidth.slice(0, -2));  
	}
	else {
		//for other browsers
		res.left = __parseBorderWidth(element.style.borderLeftWidth);
		res.top = __parseBorderWidth(element.style.borderTopWidth);
		res.right = __parseBorderWidth(element.style.borderRightWidth);
		res.bottom = __parseBorderWidth(element.style.borderBottomWidth);
	}
	return res;
}

//returns absolute position of some element within document
function getAbsolutePos(element) {
	var res = new Object();
	res.x = 0; res.y = 0;
	if (element !== null) {
		res.x = element.offsetLeft;
		res.y = element.offsetTop;
    	
		var offsetParent = element.offsetParent;
		var parentNode = element.parentNode;
		var borderWidth = null;

		while (offsetParent != null) {
			res.x += offsetParent.offsetLeft;
			res.y += offsetParent.offsetTop;
			
			var parentTagName = offsetParent.tagName.toLowerCase();	

			if ((__isIE && parentTagName != "table") || (__isFireFoxNew && parentTagName == "td")) {		    
				borderWidth = __getBorderWidth(offsetParent);
				res.x += borderWidth.left;
				res.y += borderWidth.top;
			}
		    
			if (offsetParent != document.body && offsetParent != document.documentElement) {
				res.x -= offsetParent.scrollLeft;
				res.y -= offsetParent.scrollTop;
			}

			//next lines are necessary to support FireFox problem with offsetParent
   			if (!__isIE) {
    			while (offsetParent != parentNode && parentNode !== null) {
					res.x -= parentNode.scrollLeft;
					res.y -= parentNode.scrollTop;
					
					if (__isFireFoxOld) {
						borderWidth = kGetBorderWidth(parentNode);
						res.x += borderWidth.left;
						res.y += borderWidth.top;
					}
    				parentNode = parentNode.parentNode;
    			}    
			}

   			parentNode = offsetParent.parentNode;
    		offsetParent = offsetParent.offsetParent;
		}
	}
    return res;
}


function preInlineLoad(sb_update_url) {
	//SET BROWSER DIMENSIONS
	detectBrowserDimensions();
	
	//SET WINDOW EVENTS
	window.onresize = detectBrowserDimensions;
	if(tournamentActive == true) {
		var existingOnscroll = (window.onscroll) ? window.onscroll : function() {};
		var existingOnresize = (window.onresize) ? window.onresize : function() {};
		window.onscroll = function() {existingOnscroll(); sendDetailstoFlash()};
		window.onresize = function() {existingOnresize(); sendDetailstoFlash()};
	}
	
	//CONFIGURE SKIN FOR IE
	if(isIE8 == true || isLTIE8 == true) {
		if(typeof skinEnabledLTEie8 == "boolean") {
			if(skinEnabledLTEie8 == true) {
				configureSkinIE();
			}
		}
	}
	//INITIALISE THE SMARTBAR
	if(typeof smartbar != "undefined") {
		if(isIPHONE != true) {
			smartbar.init(sb_update_url);
		}
	}
}

function inlineLoad() {
	moveAds();
}

var glbl_ad_inlineSlots = [];
var glbl_ad_phantomSlots = [];
function moveAds() {
	if(glbl_ad_inlineSlots.length == glbl_ad_phantomSlots.length) {
		for(var i = 0; i < glbl_ad_inlineSlots.length; i++) {
			var to = document.getElementById(glbl_ad_inlineSlots[i]),
				from = document.getElementById(glbl_ad_phantomSlots[i]);
			if(to && from) {
				to.appendChild(from);
			}
		}
	}
}

window.onload = function() {
	//RHSScroll
	RHSScroller.create();
	
	var oldScroll = (window.onscroll) ? window.onscroll : function() {};
	window.onscroll = function() {
		oldScroll();
		RHSScroller.uponScroll();
	}
}

function configureSkinIE() {
	if(g_browser_width >= 1500) {
		var headID = document.getElementsByTagName("head")[0];         
		var cssNode = document.createElement('link');
		cssNode.type = 'text/css';
		cssNode.rel = 'stylesheet';
		cssNode.href = 'http://www.cgmirror.com/css/skin.css';
		cssNode.media = 'all';
		headID.appendChild(cssNode);		
	}
	if(g_browser_width >= 1800) {
		var headID = document.getElementsByTagName("head")[0];         
		var cssNode = document.createElement('link');
		cssNode.type = 'text/css';
		cssNode.rel = 'stylesheet';
		cssNode.href = 'http://www.cgmirror.com/css/skin_fullhd.css';
		cssNode.media = 'all';
		headID.appendChild(cssNode);		
	}
}

var g_browser_width;
var g_browser_height;
function detectBrowserDimensions() {
	if(window.innerWidth) {
		g_browser_width = window.innerWidth;
		g_browser_height = window.innerHeight;
	}
	else {
		g_browser_width = document.documentElement.clientWidth;
		g_browser_height = document.documentElement.clientHeight;
	}
}

function sponsors() {
	//LOAD XML
	var sponsorXML = new XMLHttpRequest();
	sponsorXML.open("GET",rootdir+"xml/sponsors.php?site="+globalsite,false);
	sponsorXML.send("");
	var sponsorDoc = sponsorXML.responseXML;
	
	var majorSponsor_ar = sponsorDoc.getElementsByTagName("sponsor");
	var minorSponsor_ar = sponsorDoc.getElementsByTagName("minorsponsor");
		
	//VALUES
	var majorNo = majorSponsor_ar.length;
	var minorNo = minorSponsor_ar.length;
	var majorStart = Math.floor(Math.random()*majorNo);
	var minorStart = Math.floor(Math.random()*minorNo);
	
	//SETUP SLOTS
	if(majorNo > 0) {
		document.write('<div class="header">Major Sponsors</div><div id="ms_1"></div><div id="ms_2"></div>');
		var majorSlot_ar = new Array();
		majorSlot_ar.push(document.getElementById("ms_1"));
		majorSlot_ar.push(document.getElementById("ms_2"));
	}
	if(minorNo > 0) {
		document.write('<div class="header">Event Sponsors</div><div id="es_1"></div>');
		var minorSlot_ar = new Array();
		minorSlot_ar.push(document.getElementById("es_1"));
	}
	
	//PULSE
	function sponsorPulse() {
		//INSERT MAJORS
		if(majorNo > 0) {
			for(var i = 0; i < majorSlot_ar.length; i++) {
				majorSlot_ar[i].className = "sponsor " + majorSponsor_ar[majorStart].getElementsByTagName("class")[0].childNodes[0].nodeValue;
				majorSlot_ar[i].setAttribute("title",majorSponsor_ar[majorStart].getElementsByTagName("title")[0].childNodes[0].nodeValue);
				majorSlot_ar[i].savedNumber = majorStart;
				majorSlot_ar[i].onclick = function() {
					window.open(majorSponsor_ar[this.savedNumber].getElementsByTagName("url")[0].childNodes[0].nodeValue)
				}
				if(majorStart+1 >= majorNo) {
					majorStart = 0;
				}
				else {
					majorStart++;
				}
			}
		}
		//INSERT MINORS
		if(minorNo > 0) {
			for(var i = 0; i < minorSlot_ar.length; i++) {
				minorSlot_ar[i].className = "sponsor " + minorSponsor_ar[minorStart].getElementsByTagName("class")[0].childNodes[0].nodeValue;
				minorSlot_ar[i].setAttribute("title",minorSponsor_ar[minorStart].getElementsByTagName("title")[0].childNodes[0].nodeValue);
				minorSlot_ar[i].savedNumber = minorStart;
				minorSlot_ar[i].onclick = function() {
					window.open(minorSponsor_ar[this.savedNumber].getElementsByTagName("url")[0].childNodes[0].nodeValue)
				}
				if(minorStart+1 >= minorNo) {
					minorStart = 0;
				}
				else {
					minorStart++;
				}
			}
		}
	}
	sponsorPulse();
	setInterval(function() {sponsorPulse()}, 6000);
}

//TOURNAMENT

var tournamentActive = false;

function getScrollY() {
  var scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
  }
  return scrOfY;
}

function getFlashMovie(movieName) {
  var isIE = navigator.appName.indexOf("Microsoft") != -1;
  return (isIE) ? window[movieName] : document[movieName];
}

function setTourneyHeight(height) {
	tournamentActive = true;
	try{document.getElementById("tournament_container").style.height = height + "px"}catch(err) {}
	sendDetailstoFlash();
	//SEND ONSCROLL EVENT
}

function flashAlert(message) {
	alert(message);
}

function useThisXMLFlash(xmlSrc) {
	getFlashMovie("CGtournament").useThisXMLFlash(xmlSrc);
}

function sendDetailstoFlash() {
	var scroll = getScrollY();
	var position = getAbsolutePos(document.getElementById("tournament_container"));
	var yoffset = position.y;
	var height;
	var outerHeight;
	if(window.innerHeight) {
		height = window.innerHeight;
		outerHeight = window.outerHeight;
	}
	else {
		height = document.documentElement.clientHeight;
		outerHeight = document.documentElement.offsetHeight;
	}
	height -= 27;
	//var sc = scrollOffset - scrollHeight;
	getFlashMovie("CGtournament").sendDetailstoFlash(scroll, height, yoffset, outerHeight);
	
	/*
	if(isWK == true) {
		var t = setTimeout(function() {window.scrollBy(0,1)},50);
	}
	*/
}

function flashScrollTo(yCoord) {
	window.scroll(0,yCoord);
	
	//CHROME FIX
	//var t = setTimeout(function() {window.scrollBy(0,1)},50);
}

// OLD AJAX REQUEST HANDLER
function ajaxRequest(url, target, callthis, overwrite) {
	if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}
	else {// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4 && xmlhttp.status==200) {
			if(target != null) {
				if(overwrite != false) {
					target.innerHTML = xmlhttp.responseText;
				}
				else {
					target.innerHTML += xmlhttp.responseText;
				}
			}
			else {
				eval(xmlhttp.responseText);
			}
			if(typeof callthis == "function") {
				callthis.call();
			}
		}
	}
	xmlhttp.open("GET",url,true);
	xmlhttp.send();
}

function ajaxObject(url, callbackFunction) {
  var that=this;
  this.url = url;
  this.updating = false;
  this.abort = function() {
    if (that.updating) {
      that.updating=false;
      that.AJAX.abort();
      that.AJAX=null;
    }
  }
  this.update = function(passData,postMethod) {
    if (that.updating) { return false; }
    that.AJAX = null;                          
    if (window.XMLHttpRequest) {              
      that.AJAX=new XMLHttpRequest();              
    } else {                                  
      that.AJAX=new ActiveXObject("Microsoft.XMLHTTP");
    }                                             
    if (that.AJAX==null) {                             
      return false;                               
    } else {
      that.AJAX.onreadystatechange = function() {  
        if (that.AJAX.readyState==4) {             
          that.updating=false;                
          that.callback(that.AJAX.responseText,that.AJAX.status,that.AJAX.responseXML);        
          that.AJAX=null;                                         
        }                                                      
      }                                                        
      that.updating = new Date();                              
      if (/post/i.test(postMethod)) {
		if (typeof(globalsite) == 'undefined') {
			var uri=that.url+'?'+that.updating.getTime();
		}
		else
		{
			var uri=that.url+'&chk='+Math.random()+that.updating.getTime(); // Live Site.
		}
        that.AJAX.open("POST", uri, true);
        that.AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        that.AJAX.setRequestHeader("Content-Length", passData.length);
        that.AJAX.send(passData);
      } else {
		if (typeof(passData) == 'undefined') {
			var passData = "";
		}
		if (typeof(globalsite) == 'undefined') {
			var uri=that.url+'?'+passData+'&timestamp='+(that.updating.getTime());
		}
		else
		{
			var uri=that.url+'&chk='+Math.random()+passData+'&timestamp='+(that.updating.getTime()); // Live Site.
		}
        that.AJAX.open("GET", uri, true);                             
        that.AJAX.send(null);                                         

      }                  
      return true;                                             
    }                                                                           
  }
  this.callback = callbackFunction || function () { };
}
/*
function ajaxObject(url, callbackFunction) {
  var that=this;
  this.url = url;  
  this.updating = false;
  this.abort = function() {
    if (that.updating) {
      that.updating=false;
      that.AJAX.abort();
      that.AJAX=null;
    }
  }
  this.update = function(passData,postMethod) { 
    if (that.updating) { return false; }
    that.AJAX = null;                          
    if (window.XMLHttpRequest) {              
      that.AJAX=new XMLHttpRequest();              
    } else {                                  
      that.AJAX=new ActiveXObject("Microsoft.XMLHTTP");
    }                                             
    if (that.AJAX==null) {                             
      return false;                               
    } else {
      that.AJAX.onreadystatechange = function() {  
        if (that.AJAX.readyState==4) {             
          that.updating=false;                
          that.callback(that.AJAX.responseText,that.AJAX.status,that.AJAX.responseXML);        
          that.AJAX=null;                                         
        }                                                      
      }                                                        
      that.updating = new Date();                              
      if (/post/i.test(postMethod)) {
        var uri=urlCall+'?'+that.updating.getTime();
        that.AJAX.open("POST", uri, true);
        that.AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        that.AJAX.setRequestHeader("Content-Length", passData.length);
        that.AJAX.send(passData);
      } else {
        var uri=urlCall+'?'+passData+'&timestamp='+(that.updating.getTime()); 
        that.AJAX.open("GET", uri, true);                             
        that.AJAX.send(null);                                         
      }              
      return true;                                             
    }                                                                           
  }
  var urlCall = url;        
  this.callback = callbackFunction || function () { };
}
*/

//DROPDOWN EVENTS
var global_dd_zIndex = 5;
function applyDDevents(x) {
	//APPLY FOR ALL
	var ul_list = x.getElementsByTagName("ul");
	var list_len = ul_list.length;
	for(var i = 0; i < list_len; i++) {
		ul_list[i].parentNode.hasUL = ul_list[i];
		ul_list[i].parentNode.superParent = x;
		ul_list[i].parentNode.onmouseover = function() {
			var that = this;
			var temp = this.hasUL;
			var superIE = this.superParent;
			clearTimeout(this.timer);
			this.timer = setTimeout(function() {temp.style.zIndex = global_dd_zIndex; temp.style.display = "block"; global_dd_zIndex++; if(that == superIE) {superIE.className+=" typical_dropdown_activeDD"}},100);
		}
		ul_list[i].parentNode.onmouseout = function() {
			var that = this;
			var temp = this.hasUL;
			var superIE = this.superParent;
			clearTimeout(this.timer);
			this.timer = setTimeout(function() {temp.style.display = "none"; if(that == superIE) {x.className = superIE.className.replace(/\s?typical_dropdown_activeDD/gi, "")}},300);
		}
	}
	x.onmouseover();
}


function suggestionInsert(x) {
	var insertWhat = x.innerHTML;
	var insertWhere = x.parentNode.parentNode.previousSibling;
	while(insertWhere.nodeName != "INPUT") {
		insertWhere = insertWhere.previousSibling;
	}
	
	insertWhere.value = insertWhat;
	
	//NOW CLOSE
	
	x.parentNode.parentNode.style.display = "none";
	
	return false; //PREVENT LINK
}

/*MAILBOX*/
function mailbox_selectAll(bool, x) {
	var table = document.getElementById(x);
	var checkboxes = table.getElementsByTagName("input");
	
	for(var i = 0; i < checkboxes.length; i++) {
		if(checkboxes[i].getAttribute("type") == "checkbox") {
			checkboxes[i].checked = bool;
		}
	}
}
function mailbox_removeRow(x) {
	var row = x.parentNode.parentNode;
	row.parentNode.removeChild(row);
}

/***********************************************
* Disable Text Selection script- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/
function disableSelection(target){
    if (typeof target.onselectstart!="undefined") //IE route
        target.onselectstart=function(){return false}

    else if (typeof target.style.MozUserSelect!="undefined") //Firefox route
        target.style.MozUserSelect="none"

    else //All other route (ie: Opera)
        target.onmousedown=function(){return false}

}

/*COOKIES*/
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

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;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

function isNode(o){
  return (
    typeof Node === "object" ? o instanceof Node : 
    typeof o === "object" && typeof o.nodeType === "number" && typeof o.nodeName==="string"
  );
}

//RIGHT HAND SIDE SCROLLER
function createRHSSroller(el) {
}

var RHSScroller = {
	div: null,
	h: null,
	y: null,
	col_h: null,
	col_y: null,
	body_h: null,
	target: null,
	timer: null,
	fadeTimer: null,
	opacity: 0,
	oldScroll: 0,
	
	create: function() {
		var el = document.getElementById("column_right_scroller_target");
		if(!el) {
			RHSScroller.uponScroll = function() {};
			return;
		}
				
		RHSScroller.target = el;
		RHSScroller.h = el.offsetHeight + 20 ;//padding
		RHSScroller.y = getAbsolutePos(el).y;
		var col = document.getElementById("body_column_right");
		RHSScroller.col_h = col.offsetHeight;
		RHSScroller.col_y = getAbsolutePos(col).y;
		RHSScroller.body_h = document.getElementById("body").offsetHeight;
		var scroller = cE("div");
		scroller.setAttribute("id","column_right_scroller");
		scroller.style.visibility = "hidden";
		var padding = cE("div", "pad10");
		scroller.appendChild(padding);
		padding.appendChild(el.cloneNode(true));
		
		col.appendChild(scroller);
		RHSScroller.div = scroller;
		
		if(getScrollY() !== 0) {
			RHSScroller.uponScroll();
		}
	},
	
	uponScroll: function() {
		if(!RHSScroller.div) {
			return;
		}
		
		clearTimeout(RHSScroller.timer);
		clearInterval(RHSScroller.fadeTimer);
		RHSScroller.div.style.visibility = "hidden";
		
		RHSScroller.timer = setTimeout(function() {
			var y = getScrollY();
			if(y > (RHSScroller.col_h + RHSScroller.col_y) && (y + RHSScroller.h - RHSScroller.col_y) < (RHSScroller.body_h)) {
				var direction = (RHSScroller.oldScroll < y) ? 1 : -1;
				RHSScroller.div.style.top = y - RHSScroller.col_y + (-direction*20) + "px";
				RHSScroller.fadeIn(direction);
				RHSScroller.oldScroll = y;
			}
		},3000);
	},
	
	fadeIn: function(dir) {
		RHSScroller.div.style.opacity = 0;
		RHSScroller.div.style.visibility = "visible";
		RHSScroller.opacity = 0;
	
		RHSScroller.fadeTimer = setInterval(function() {
			var currPos = parseInt(RHSScroller.div.style.top);
			RHSScroller.div.style.top = parseInt(RHSScroller.div.style.top) + dir + "px";
			var val = (RHSScroller.opacity + 5 < 100) ? RHSScroller.opacity+=5 : 100;
			if(val >= 100) {
				clearInterval(RHSScroller.fadeTimer);
			}
			RHSScroller.div.style.opacity = val/100;
		},40);
	}
}



