// Begin jscript.js

function g(id) { return document.getElementById(id); }

function getFileFromPath(input) {
	cFileArr = input.split("/");
	cFile = cFileArr[cFileArr.length-1];
	return cFile;
}
function changeImage(imgid, sprClass) {
	g(imgid).className = "spr " + sprClass;
}
function writerssearch(type) 
{
	if (type=='login') 
	{
		if( g('graphic-login').className == "spr header_writers-login-off" ) 
		{
			g('graphic-login').className = 'spr header_writers-login-on';
			g('graphic-search').className  = 'spr header_story-search-off';
			g('loginbox').style.display = 'block';
			g('searchbox').style.display = 'none';
		}
	} 
	else if (type=='search') 
	{
		if( g('graphic-search').className == "spr header_story-search-off" ) 
		{			
			g('graphic-login').className = 'spr header_writers-login-off';
			g('graphic-search').className  = 'spr header_story-search-on';
			g('searchbox').style.display = 'block';
			g('loginbox').style.display = 'none';
		}
	}
}
function changeBox(boxNo) 
{
	for( var i = 1; i <= 3; i++ )
	{
		var tabBox = g('bobbox' + i);
		var content = g('bobcontent' + i);
		
		if( i == boxNo )
		{
			tabBox.className = "bobTab";
			content.className = "bobContent";
		}
		else
		{
			tabBox.className = "bobTab off";
			content.className = "bobContent off";
		}
	}
}
function playSound( soundEmbed ) 
{
	var thisSound = g( soundEmbed );
	thisSound.Play();
}

function ajaxManager( fileLoad ) 
{
	var args = ajaxManager.arguments;
	
	if( document.getElementById ) 
	{
		if( window.ActiveXObject )
			var x = new ActiveXObject("Microsoft.XMLHTTP") 
		else
			var x = new XMLHttpRequest();
	}
			
	if (x)
	{
		x.onreadystatechange = function()
		{
			if (x.readyState == 4 && x.status == 200)
			{
				var getheadTag = document.getElementsByTagName('head')[0];
				setjs = document.createElement('script'); 
				setjs.setAttribute('type', 'text/javascript');
				getheadTag.appendChild(setjs); 
				setjs.text = x.responseText;
				getheadTag.removeChild( setjs );
			}
		}
		
		x.open("GET", fileLoad, true);
		x.send(null);

		return 0;
	}
	
	return -1;
}

Highlighter = new function()
{
	var words = new Array();
	var count = 0;
	
	insert = function( node )
	{
		if( node.hasChildNodes() )
			for( var i = 0; i < node.childNodes.length; i++ )
				insert( node.childNodes[ i ] );
		
		if( node.nodeType == 3 ) 
		{ 
			tempNodeVal = node.nodeValue.toLowerCase(); 
			
			for( var i =0; i < words.length; i++ )
			{
				var word = words[ i ];
				tempWordVal = word.toLowerCase(); 
				
				if( tempNodeVal.indexOf( tempWordVal ) != -1 ) 
				{ 
					pn = node.parentNode; 
					
					if( pn != null && pn.className.indexOf( "KW " ) < 0 ) 
					{ 
						nv = node.nodeValue; 
						ni = tempNodeVal.indexOf( tempWordVal ); 
						before = document.createTextNode( nv.substr( 0, ni ) ); 
						docWordVal = nv.substr( ni, word.length ); 
						after = document.createTextNode( nv.substr( ni + word.length ) ); 
						
						hiwordtext = document.createTextNode( docWordVal ); 
						hiword = document.createElement( "span" ); 
						hiword.className = "KW w w" + (i + 1); 
						hiword.appendChild( hiwordtext ); 
						
						pn.insertBefore( before, node ); 
						pn.insertBefore( hiword, node ); 
						pn.insertBefore( after, node ); 
						pn.removeChild( node ); 
					} 
				}
			}
		}
	}
	
	this.go = function()
	{
		insert( document.body );
	}

	this.add = function( word )
	{
		words[ count++ ] = word;
	}
	
	this.toggle = function()
	{
		var spans = document.getElementsByTagName( "span" );
		var remove = false;
		
		for( var i = 0; i < spans.length; i++ )
		{
			var el = spans[ i ];
			
			if( el.className.indexOf( "KW" ) >= 0 && el.className.indexOf( " w w" ) < 0 )
			{
				el.className = el.className.replace( "KW ", "KW w w" );
				remove = false;
			}
			else if( el.className.indexOf( "KW" ) >= 0 )
			{
				el.className = el.className.replace( " w w", " " );
				remove = true;
			}
		}
		
		if( remove )
			g( "KWH" ).innerHTML = "restore highlighting";
		else
			g( "KWH" ).innerHTML = "remove highlighting";
	}
}

function mnuOvr( id )
{
	var left, top;
	var el = g( "mnu" + id );
	var ele = el;
	left = 0;
	top = el.offsetHeight;
	
	if( ele.offsetParent )
	{
		do 
		{
			var ol = ele.offsetLeft;
			if( ol < 0 )
				ol += 877;
			left += ol;
			top += ele.offsetTop;
		}
		while ( ele = ele.offsetParent );
	}
	
	var ovrMnu = g( "submnu" + id );
	var append = false;
	try
	{
		el.parentNode.removeChild( ovrMnu );
		append = true;
	}
	catch( err )
	{ //ignore
	}
		
	if( document.all )
		top -= document.body.scrollTop;
	else
		top -= window.pageYOffset;
	
	ovrMnu.style.position = "absolute";
	ovrMnu.style.top = top + "px";
	ovrMnu.style.left = left + "px";
	ovrMnu.style.display = "block";
	
	if( append )				
		g( "page" ).appendChild( ovrMnu );
}

function mnuOut( id )
{
	g( "submnu" + id ).style.display = "none";
}

// END jscript.js

// ratings.js
function resetStars( contentid ) 
{	
	for ( p = 1; p <= 5; p++ ) 
	{
		oldVal = eval( "stars" + contentid + "[ p ]" );
		changeImage( 'star' + contentid + p, oldVal );
	}
}

function selectStars( starid, contentid ) 
{
	try {xc = clearTimeout(xx)} catch(err) {}
	
	for ( p = 1; p <= 5; p++ ) 
	{
		if (p <= starid) 
			className = 'staronsel'; 
		else 
			className ='staroffsel';
			
		changeImage( 'star' + contentid + p, className);
	}
}

function resetTimeout( contentid ) 
{
	resetStars( contentid )
}

function doRating( typeID, contentID, sectionID, rating, count, nonse, confirmed ) 
{
	if( rating > 2 || confirmed )
	{
		fileload = '/custom/ratingvote.cfm?contentType=' + typeID + '&contentID=' + contentID + '&sectionID=' + sectionID + '&rating=' + rating + '&count=' + count + '&nonse=' + nonse + '&id=' + new Date().getTime();

		ajaxManager( fileload );
		cancelRating( contentID, count );
	}
	else
	{
		setTimeout( 'showConfirm(' + typeID + ',' + contentID + ',' + sectionID + ',' + rating + ',' + count + ',' + nonse + ',' + confirmed + ')', 2500 );
	}
}

function showConfirm( typeID, contentID, sectionID, rating, count, nonse, confirmed )
{
	var el = g( "ratingConfirm" + contentID + "" + count );
	
	var rc = g( "rConfirm" );
	
	if( rc != null )
		rc.parentNode.removeChild( rc );
	
	el.innerHTML = '<div style="position:absolute;z-index:10;background-color:#fff;border:2px solid #fd0;padding:10px;width:150px;text-align:center;" id="rConfirm"><strong>Rate this item just ' + rating + ' star, are you sure?<br /><br /><input type="button" value="Yes" onclick="doRating(' + typeID + ',' + contentID + ',' + sectionID + ',' + rating + ',' + count + ',' + nonse + ',true);"> <input type="button" value="No" onclick="cancelRating(' + contentID + ',' + count + ');"></strong></div>';
	el.style.display = "block";
}

function cancelRating( contentID, count )
{
	g( "ratingConfirm" + contentID + "" + count ).style.display = "none";
}
// END ratings.js

// article.js
function hideStory() 
{
	g( 'article' ).style.display = "none";
	g( 'warningMessage' ).style.display = "block";
}

function displayStory() 
{
	g( 'article' ).style.display = "block";
	g( 'warningMessage' ).style.display = "none";
}

// Diary entry scripts

function revealWriter()
{
	g( 'whoWroteIt' ).style.display = "none";
	g( 'realWriter' ).style.display = "block";
}

// END article.js

// headlines.js
var headlines;
var currentHeadline;

var paused;
var fading;

function initHeadlines()
{
	headlines = g( "headlinesBox" ).getElementsByTagName( "div" );
	currentHeadline = 0;
	
	for( i = 0; i < headlines.length; i++ )
	{
		fixLength( headlines[ i ] );
	}
		
	setTimeout( "changeHeadline()", 2000);
}

function fixLength( headline )
{
	return;
	
	var aElement = headline.getElementsByTagName( "a" )[ 0 ];
	
	if( aElement != null )
	{
		var text = aElement.innerHTML;
		
		if( text.length > 68 )
			aElement.innerHTML = text.substring( 0, 68 ) + "&hellip;";
	}				
}

function changeHeadline()
{	
	if( paused )
	{
		setTimeout( "changeHeadline()", 2000);
		return;
	}
		
	var nextHeadline = ( currentHeadline + 1 ) % headlines.length;

	var toHide = headlines[ currentHeadline ];				
	var toShow = headlines[ nextHeadline ];
	
	setOpacity( toHide, 1 );
	setOpacity( toShow, 0 );
	
	toHide.style.display = "block";
	toShow.style.display = "block";
	
	currentHeadline = nextHeadline;
	
	fadeInOut( toHide, toShow, 0 );
}

function setOpacity( element, percent )
{
	element.style.opacity = percent;
	element.style.filter = "alpha(opacity=" + ( percent * 100 )  + ")";
}
			
function fadeInOut( toHide, toShow, pct )
{
	if( pct > 1.0 )
	{
		toHide.style.display = "none";
		toShow.style.filter = "";
		setTimeout( "changeHeadline()", 3000);
		fading = false;
		return;
	}
	
	fading = true;
	
	setOpacity( toHide, 1.0 - pct  );
	setOpacity( toShow, pct );
	
	pct += 0.2;
	
	setTimeout( function(){ fadeInOut( toHide, toShow, pct ) }, 100);
}

function headlinesHold()
{
	paused = true;
}

function headlinesResume()
{
	if( paused )
	{
		paused = false;
	}
}
// END headlines.js

// tags.js

var initElem = 'tagBlock';
var arrAnchors = new Array();
var maxFontSize = 200;

function getScreenDimensions() {
	var frameWidth,frameHeight;
	if (self.innerHeight) {
		frameWidth = self.innerWidth;
		frameHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) {
		frameWidth = document.documentElement.clientWidth;
		frameHeight = document.documentElement.clientHeight;
	} else if (document.body) {
		frameWidth = document.body.clientWidth;
		frameHeight = document.body.clientHeight;
	}
	dims = new Array();
	dims[0] = frameWidth;
	dims[1] = frameHeight;
	return dims;
}

function getMousePos(e) {
	var posx = 0;
	var posy = 0;
	if (!e) var e = window.event;
	if (e.pageX || e.pageY) {
		posx = e.pageX;
		posy = e.pageY;
	} else if (e.clientX || e.clientY) {
		if (document.documentElement.scrollTop) {
			posx = e.clientX + document.documentElement.scrollLeft;
			posy = e.clientY + document.documentElement.scrollTop;
		} else {
			posx = e.clientX + document.body.scrollLeft;
			posy = e.clientY + document.body.scrollTop;
		}
	}
	//g('posx').value = posx;
	//g('posy').value = posy;
	
	elementLeft = g(initElem).offsetLeft;
	elementTop = g(initElem).offsetTop;
	
	trackGravity(posx - elementLeft,posy - elementTop);//-8 here because that's the relative position of the main element on the page. Not sure why.
}		

function initMouse() {
	try
	{
		g(initElem).onmousemove=getMousePos;
	}
	catch( err )
	{
		//ignore
	}
}

function trackGravity(posx,posy) 
{
	for( x=0; x<arrAnchors.length; x++ ) 
	{		
		cTag = arrAnchors[x].id;
		minFontSize = arrAnchors[x].originalFontSize;
		currentTop = g(cTag).style.top;
		currentTop = 1*currentTop.replace(/[px]/g, "");
		currentLeft = g(cTag).style.left;
		currentLeft = 1*currentLeft.replace(/[px]/g, "");
		currentWidth = 1*g(cTag).offsetWidth;
		currentHeight = 1*g(cTag).offsetHeight;

		centreOfGravX = currentLeft + (currentWidth/2);
		centreOfGravY = currentTop + (currentHeight/2);	
		
		boxBoundsX = currentWidth;
		boxBoundsY = currentHeight;
		
		if ( 
			 posx > (currentLeft - boxBoundsX) 
		  && posx < (currentLeft + currentWidth + boxBoundsX) 
		  && posy > (currentTop - boxBoundsY) 
		  && posy < (currentTop + currentHeight + boxBoundsY)
		  ) //inside gravitational pull
		{
			gravityStrengthX = (centreOfGravX - posx);
			
			if (gravityStrengthX < 0) 
				gravityStrengthX = gravityStrengthX * -1;
				
			gravityStrengthY = (centreOfGravY - posy);
			
			if (gravityStrengthY < 0) 
				gravityStrengthY = gravityStrengthY * -1;
				
			gravityStrengthX = gravityStrengthX;
			
			gravityStrengthY = gravityStrengthY;
			
			maxYBound = boxBoundsY + (currentHeight/2);
			
			gravityStrengthY = maxFontSize - ((maxFontSize / (maxYBound * 2)) * gravityStrengthY);
			
			maxXBound = boxBoundsX + (currentWidth/2);
			
			gravityStrengthX = maxFontSize - ((maxFontSize / (maxXBound * 2)) * gravityStrengthX);
			
			gravityStrength = Math.round(gravityStrengthX) + Math.round(gravityStrengthY) - 200;
			
			if (gravityStrength < minFontSize) 
				gravityStrength = minFontSize;
		} 
		else 
		{
			gravityStrength = minFontSize;
		}
		
		g(cTag).style.fontSize = gravityStrength + '%';
		g(cTag).style.opacity = ( gravityStrength - 100 ) / 100;
		g(cTag).style.left = centreOfGravX - g(cTag).offsetWidth / 2 + "px";
		g(cTag).style.top = centreOfGravY - g(cTag).offsetHeight / 2 + "px";		
	}
}
arrColours = new Array("000000","FF6600","CC0000","0000CC","00CC00");

Array.prototype.near = function near( pxPos, distance )
{
	for( var i = 0; i < this.length; i++ )			
		if( Math.abs( this[ i ] - pxPos ) < distance )
			return true;
	
	return false;
}


function initTags() {
	var maxWidth = 250;
	var maxHeight = 200;
	
	maxWidth = parseInt( g( 'tagBlock' ).style.width.replace(/[px]/g, "") );
	maxHeight = parseInt( g( 'tagBlock' ).style.height.replace(/[px]/g, "") );
	
	try
	{
		arrAnchors = g(initElem).getElementsByTagName("a");
		lineHeight = g(initElem).style.lineHeight;
		
		tops = new Array();
		
		widthX = maxWidth / 8;

		for (i=0;i<arrAnchors.length;i++) 
		{
			var c = 0;
			
			thisWidth = arrAnchors[i].offsetWidth;
			thisHeight = arrAnchors[i].offsetHeight;

			pos = Math.round( Math.random() * ( maxWidth - thisWidth ) );
			arrAnchors[i].style.left = pos + 'px';		
			
			do
			{
				pos = Math.round( Math.random() * ( maxHeight - thisHeight ) );
				arrAnchors[ i ].style.top = pos + 'px';
			}
			while( tops.near( pos, 11 )  && c++ < 400 );
				
			tops[ i ] = pos;

			arrAnchors[i].originalFontSize = arrAnchors[i].style.fontSize.replace(/%/,"");	
			arrAnchors[i].style.opacity = (arrAnchors[i].originalFontSize - 100) / 100;	
			arrAnchors[i].style.color = '#' + arrColours[ Math.floor( Math.random() * 5 ) ];
		}
	}
	catch( err )
	{
		//ignore
	}
}
// END tags.js

// ticker.js
var tickerQualifier1 = "-";
var tickerQualifier2 = "_";
var tickerSpeed = 30;

function clean(input) {
	output = input.replace(/'/g, "\\'");
	output = output.replace(/\\\\/g, "\\");
	output = output.replace("&amp;", "&");
	output = output.replace("&quot;", "\"");
	return output;
}
function loadMe(loadElems) {
	elements = loadElems.split(",");
	headers = document.getElementsByTagName("h1");
	for (n=0;n<elements.length;n++) {
		thisid = "h1"+n;
		headers[n].setAttribute("id", thisid);
		fullText = clean(headers[n].innerHTML);
		headers[n].style.color = '#F20909';
		animateText(thisid, tickerQualifier1, fullText);
	}
}
function animateText(elementRef, currentText, fullText) {
	thisObj = g(elementRef);
	thisObj.innerHTML = currentText;
	if (currentText.length % 2 == 0) thisQualifier = tickerQualifier1; else thisQualifier = tickerQualifier2;
	newText = fullText.substr(0, currentText.length) + thisQualifier;
	if (newText.length < fullText.length + 1) {
		ticker = setTimeout("animateText('"+elementRef+"', '"+clean(newText)+"', '"+clean(fullText)+"')", tickerSpeed);
	} else {
		thisObj.innerHTML = fullText;
	}
}
// END ticker.js

// tooltips.js
var ss, so, startOpacity = 0, finalOpacity = 95, opacitySpeed = 10, boxOnSpeed = 0, boxOffSpeed = 500, turnedOff = 0;
var currentOpacity = startOpacity;
var boxwidth = 250;
var cancelTimeout = 0;

function getScreenDimensions() 
{
	var frameWidth,frameHeight;

	if (self.innerHeight) 
	{
		frameWidth = self.innerWidth;
		frameHeight = self.innerHeight;
	} 
	else if (document.documentElement && document.documentElement.clientHeight) 
	{
		frameWidth = document.documentElement.clientWidth;
		frameHeight = document.documentElement.clientHeight;
	} 
	else if (document.body) 
	{
		frameWidth = document.body.clientWidth;
		frameHeight = document.body.clientHeight;
	}
	
	dims = new Array();
	
	dims[0] = frameWidth;
	dims[1] = frameHeight;
	
	return dims;
}

function stoptimeout() 
{
	if (ss) 
	{
		sy = clearTimeout(ss);
		ss = null;
	}
}

function showBox( e ) 
{
	boxToFloat = 'floatBox';

	if (this.id.length == 4) 
	{
		elementStart = this.id.charAt( this.id.length - 1 );
	} 
	else if (this.id.length == 5) 
	{
		elementStart = this.id.charAt( this.id.length - 2 ) + this.id.charAt( this.id.length - 1 );
	} 
	else 
	{
		elementStart = this.id.charAt( this.id.length - 3 ) + this.id.charAt( this.id.length - 2 ) + this.id.charAt( this.id.length - 1 );
	}
	
	
	if (elementStart != 'Box') 
	{
		cancelTimeout = 1;
	
		try 
		{
			ss = clearTimeout( ss );		
		}
		catch(err) 
		{
		}
		
		if (tips[elementStart].length > 0) 
		{
			g( 'tooltip' ).innerHTML = tips[elementStart][0];	

			boxDisplay( boxToFloat, 1, tips[elementStart][1], tips[elementStart][2], tips[elementStart][3] );	
		} 
		else 
		{
			boxDisplay(boxToFloat, 0, 0, 0);
		}
	}
	
	if (!e) 
		var e = window.event;
		
	var posx = 0;
	var posy = 0;
	
	if (!e) 
		var e = window.event;
		
	if (e.pageX || e.pageY) 
	{
		posx = e.pageX;
		posy = e.pageY;
	} 
	else if (e.clientX || e.clientY) 
	{
		if( document.documentElement.scrollTop )
		{
			posx = e.clientX + document.documentElement.scrollLeft;
			posy = e.clientY + document.documentElement.scrollTop;
		}
		else
		{
			posx = e.clientX + document.body.scrollLeft;
			posy = e.clientY + document.body.scrollTop;
		}
	}	
	
	screenDims = getScreenDimensions();			
	posx = posx;
	posy = posy + 15; 
	
	if (posx + boxwidth + 20 > screenDims[0]) 
		posx = posx - ( ( posx + boxwidth ) - screenDims[0] ) - 25;	
		
	//alert( posx + ", " + posy + " " + document.documentElement.scrollTop );
		
	//g('myiframe').style.top = posy+'px';
	//g('myiframe').style.left = posx+'px';
	//g('myiframe').style.height = g(boxToFloat).offsetHeight;
	g(boxToFloat).style.left = posx+'px';
	g(boxToFloat).style.top = posy+'px';
}		

function boxDisplay(boxToFloat, status, maxx, maxy, animate) 
{
	if( g(boxToFloat).style.display == "block" )
		maxy = g( 'tooltip' ).offsetHeight;
		
	if( currentOpacity != startOpacity ) 
	   currentOpacity = finalOpacity;

	if (status==1) 
	{
		turnedOff = 0;

		if (animate==1) 
		{
			so = setTimeout( "xpand( 0, 0, "+maxx+", "+maxy+" )", boxOnSpeed);	
		} 
		else 
		{
			g( boxToFloat ).style.width = maxx+'px';
			g( boxToFloat ).style.height = maxy+'px';
		}
		
		g( boxToFloat ).style.width = maxx+'px';
		g( boxToFloat ).style.height = maxy+'px';
		
		so = setTimeout("changeOpacity()", boxOnSpeed);
	} 
	else if (cancelTimeout==0) 
	{
		g(boxToFloat).style.opacity = 0;
		g(boxToFloat).style.display = 'none';
		//g('myiframe').style.display = 'none';	
		
		if (maxx > 0 && maxy > 0) 
		{
			g(boxToFloat).style.width = 0;
			g(boxToFloat).style.height = 0;
		}
		
		currentOpacity = startOpacity;
	}
	
	if (cancelTimeout==1) 
		cancelTimeout = 0;
}

function xpand(x,y,maxx,maxy) 
{	
	if (turnedOff == 0) 
	{
		speed = 10;
		xtoy = maxx/maxy;
		g(boxToFloat).style.width = x+'px';
		g(boxToFloat).style.height = y+'px';
		
		if (x < maxx) 
		{
			x = x + Math.round(speed * xtoy);
		}
		
		if (y < maxy) 
		{
			y = y + speed;
		}
		
		setTimeout("xpand("+x+","+y+","+maxx+","+maxy+")",1);
	}
}

function changeOpacity() 
{
	if (turnedOff == 0) 
	{
		//g('myiframe').style.display = 'block';
		g(boxToFloat).style.display = 'block';

		//g( boxToFloat ).style.height = g( 'tooltip' ).offsetHeight + "px";

		if (g) 
		{
			if (finalOpacity != startOpacity) 
			{
				currentOpacity = currentOpacity + opacitySpeed;	
			
				if (document.all) //IE
				{
					g(boxToFloat).style.filter = "alpha(opacity=" + currentOpacity + ")"; 
				} 
				else //mozilla
				{
					g(boxToFloat).style.opacity = currentOpacity / 100;
				}
				
				if (currentOpacity < finalOpacity) 
				{
					so = setTimeout("changeOpacity()", 100);
				} 
				else 
				{
					if (document.all) //IE
					{
						g(boxToFloat).style.filter = "alpha(opacity=" + finalOpacity + ")"; 
					} 
					else //mozilla
					{
						g(boxToFloat).style.opacity = finalOpacity / 100;
					}
					
					so = clearTimeout(so);
					
					currentOpacity = finalOpacity;
				}
			} 
			else 
			{
				if (document.all) //IE
				{
					g(boxToFloat).style.filter = "alpha(opacity=" + finalOpacity + ")"; 
				} 
				else //mozilla
				{
					g(boxToFloat).style.opacity = finalOpacity / 100;
				}				
				
				currentOpacity = finalOpacity;				
			}
		}
	}
}

function initTips() 
{	
	for ( i=0; i < tips.length; i++ ) 
	{
		try
		{
			g( 'box' + i ).onmousemove = showBox;
			g( 'box' + i ).onmouseout = starttimeout;
		}
		catch( err )
		{
			// There is a gap in the number of displayed tooltips.
			// Ignore and continue.
		}
	}
	
	/*if (navigator.appName == 'Microsoft Internet Explorer') //IE frame thingy
	{
		//g('myiframe').style.width = boxwidth+'px';
	}*/
	
	g( 'floatBox' ).onmousemove = showBox;
	g( 'floatBox' ).onmouseout = starttimeout;	
}

function starttimeout() 
{
	turnedOff = 1;
	
	if( currentOpacity != finalOpacity ) 
		currentOpacity = startOpacity;

	ss = setTimeout("boxDisplay('floatBox',0)",boxOffSpeed);
}

function checkMessage() 
{
	cStatus = g('addMessage').checked;
	
	if (cStatus == false) 
	{
		g('message').disabled = true;
		g('message').style.backgroundColor = '#F0F0F0';
		g('message').style.border = '1px solid #999999';
	} 
	else 
	{
		g('message').disabled = false;
		g('message').style.backgroundColor = '#FFFFFF';
	}
}
// END tooltips.js

// wchart.js
function Utils(){}

Utils.addCommas = function( n )
{
	n += "";
	
	x = n.split( "." );
	x1 = x[0];
	x2 = x.length > 1 ? "." + x[1] : "";
	
	var rgx = /(\d+)(\d{3})/;
	
	while( rgx.test( x1 ) )
		x1 = x1.replace( rgx, '$1' + ',' + '$2' );

	return x1 + x2;
}

P = function( mType, sType, ptot )
{
	this.mainType = mType;
	this.subType = sType;
	this.points = ptot;
}

W = function( id, username, pointsArr, thisW )
{
	this.getID = function() { return id; };
	this.getUsername = function() { return username; };
	
	var top = 0;
	var pos = 0;
	var pointTotal = 0;
	
	this.getID = function()
	{
		return id;
	}
	
	this.isPlaced = function()
	{
		return this.getDiff() == 0;
	}
	
	this.getDiff = function()
	{
		var curTop = this.container.style.top.substring( 0, this.container.style.top.length - 2 ) * 1;
		return top - curTop;
	}
	
	this.move = function()
	{
		var el = this.container;
		var diff = this.getDiff();
		
		if( diff != 0 )
		{
			if( el.style.display == "none" && pointTotal > 0 )
				el.style.display = "block";
				
			var amount = Math.floor( diff * 0.4 );
			
			if( amount != 0 )
			{
				el.style.opacity = "0.9";
				el.style.filter = "alpha(opacity=90)";
				var curTop = el.style.top.substring( 0, el.style.top.length - 2 ) * 1;
				el.style.top = ( curTop + amount ) + "px";
				return true;
			}
			
			el.style.top = top + "px";
		}
		
		el.style.opacity = "1";
		
		if( pointTotal == 0 )
			el.style.display = "none";
		else
			el.style.display = "block";
			
		return false;
	}
	
	this.seat = function()
	{
		var el = this.container;
		var diff = this.getDiff();
		el.style.top = top + "px";
		
		if( pointTotal == 0 )
			el.style.display = "none";
		else
			el.style.display = "block";
	}
	
	this.calculateTotalPoints = function()
	{
		pointTotal = 0;
		
		for( var i = 0; i < pointsArr.length; i++ )
		{
			var point = pointsArr[ i ];
			
			if( g( "mType" + point.mainType ).checked )
			{
				if( ( point.mainType == 1 && g( "sType" + point.subType ).checked ) || point.mainType > 1 )
					pointTotal += point.points;
			}
		}
		
		this.ptot.innerHTML = Utils.addCommas( pointTotal );
		
		return pointTotal;
	}
	
	this.getTotalPoints = function()
	{
		return pointTotal;
	}
	
	this.setPos = function( p )
	{
		pos = p - 1;
		top = pos * 32;
		top += Math.floor( pos / 10 ) * 10;
		this.rank.innerHTML = p;
	}
	
	this.setMine = function()
	{
		this.container.style.zIndex = "10";
		this.rank.className += " WCmine";
		this.name.className += " WCmine";
		this.ptot.className += " WCmine";
	}
	
	var oldEl = g( "WR" + id );
	if( oldEl != null )
	{
		g( "rows" ).removeChild( oldEl );
	}
	
	this.container = document.createElement( "div" );
	this.container.id = "WR" + id;
	this.container.style.clear = "left";
	this.container.style.position = "absolute";
	
	this.rank = document.createElement( "div" );
	this.rank.className = "WCvalue WCcol1";
	
	this.name = document.createElement( "div" );
	this.name.className = "WCvalue WCcol2";
	this.name.innerHTML = "<a href=\"/profile.cfm?uID=" + id + "\">" + username + "</a>";
	
	this.ptot = document.createElement( "div" );
	this.ptot.className = "WCvalue WCcol3";
	
	this.container.appendChild( this.rank );
	this.container.appendChild( this.name );
	this.container.appendChild( this.ptot );
	
	g( "rows" ).appendChild( this.container );
}

var Warr = new Array();

function sort( noAnim )
{
	var cnt = 0;
	
	for( var i = 0; i < Warr.length; i++ )
	{
		cnt += Warr[ i ].calculateTotalPoints()>0?1:0;
	}

	var hTot = cnt * 32 + Math.floor( cnt / 10 ) * 10;
	
	hTot = Math.max( 140, hTot );
	
	g( "rows" ).style.height = hTot + "px";
	
	if( cnt == 0 )
		g( "WCnoneFound" ).style.display = "block";
	else
		g( "WCnoneFound" ).style.display = "none";

	Warr.sort
	(
		function( a, b )
		{
			return b.getTotalPoints() - a.getTotalPoints();
		}
	);

	for( var i = 0; i < Warr.length; i++ )
	{
		Warr[ i ].setPos( i + 1 );
	}
	
	if( noAnim == null )
		anim();
	else
		display();
}

function display()
{
	for( var i = 0; i < Warr.length; i++ )
		Warr[ i ].seat();
}

function checker(lu)
{
	ajaxManager( "/custom/loadChart.cfm?lu=" + lu + "&ts=" + new Date().getTime() );
	setTimeout( "checker("+lu+")", 60000 );
}

function anim()
{
	var keepGoing = false;
	
	for( var i = 0; i < Warr.length; i++ )
	{
		if( Warr[ i ].move() )
			keepGoing = true;
	}
	
	if( keepGoing )
		setTimeout( "anim()", 100 );
}

function updN()
{
	var isNSel = g( "mType1" ).checked;
	var sTChd = g( "sTypeN" ).getElementsByTagName( "input" );

	for( var i = 0; i < sTChd.length; i++ )
		sTChd[ i ].checked = isNSel;
}

function chkN()
{
	var sTChd = g( "sTypeN" ).getElementsByTagName( "input" );
	var isSel = false;
	
	for( var i = 0; i < sTChd.length; i++ )
	{
		if( sTChd[ i ].checked )
		{
			isSel = true;
			break;
		}
	}
	
	g( "mType1" ).checked = isSel;
}
// END wchart.js

// snippets.js
width = 240;	//box width, in px
speed = 30;		//arbitrary figure. For instant refresh, change to 1000.

refactor = 0;
limit = 10;
noBoxes = 0;
cBox = 0;

pause = 5000;	//millisecond delay between movements

currentBox = null;
firstBox = null;
lastBox = null;

paused = 0;
allowMove = 1;

direction = 1;
RTL = 1;
LTR = 0;

thread = 0;
animating = 2;
animator = 0;
sem = 0;

help = 0;

maxSnips = 0;
posScroller = null;
posRefactor = 0;

function SnippetBox( snippetID )
{
	this.snippetID = snippetID;
	this.next = null;
	this.prev = null;
	
	this.writerName;
	this.writerID;
	this.rating;
	this.datetime;
	this.rowNumber;
	this.n;
	
	this.toString = function toString()
	{
		return "snippetBox" + snippetID;
	}
}

function initSnippets( totalSnippets, snippetIDs ) 
{
	width = g("animbox").offsetWidth;
	maxSnips = totalSnippets;
	posScroller = g( "posScroller" );
	posRefactor = ( width + 12 ) / maxSnips;

	if( posRefactor <= 0 || maxSnips == 0 )
		posRefactor = 0.2;
	
	posScroller.style.width = Math.ceil( posRefactor ) + "px";
	
	for( i = 0; i < snippetIDs.length; i++ )
		addSnippet( snippetIDs[ i ] );
		
	posScroller.style.left = ( ( firstBox.rowNumber * posRefactor ) - ( posRefactor ) ) + "px";
	
	playForwards();
}

function addSnippet( snippetID )
{
	thisBox = new SnippetBox( snippetID );
	thisBox.prev = lastBox;
	
	initSnipData( thisBox );
	
	if( lastBox != null )
		lastBox.next = thisBox;
	
	lastBox = thisBox;
	
	if( firstBox == null )
	{
		firstBox = thisBox;
		noMoreBox = new SnippetBox( 0 );
		noMoreBox.next = firstBox;
		noMoreBox.prev = noMoreBox;
		firstBox.prev = noMoreBox;
		currentBox = firstBox;
	}
	
	lastBox.next = firstBox;
	
	noBoxes++;
}

function removeSnippetFront()
{
	g( 'animbox' ).removeChild( g( firstBox ) );
	temp = firstBox.prev;
	firstBox = firstBox.next;
	firstBox.prev = temp;
	lastBox.next = firstBox;
	
	noBoxes--;
}

function removeSnippetBack()
{
	g( 'animbox' ).removeChild( g( lastBox ) );
	lastBox = lastBox.prev;
	lastBox.next = firstBox;

	noBoxes--;
}

function initSnipData( snippetBox )
{
	snippetInfo = g( 'snippetInfo' + thisBox.snippetID ).innerHTML;
	
	snippetBox.rating = snippetInfo.substring( 0, snippetInfo.indexOf( '#' ) );
	snippetInfo = snippetInfo.substring( snippetInfo.indexOf( '#' ) + 1 );
	snippetBox.writerID = snippetInfo.substring( 0, snippetInfo.indexOf( '#' ) );
	snippetInfo = snippetInfo.substring( snippetInfo.indexOf( '#' ) + 1 );
	snippetBox.writerName = snippetInfo.substring( 0, snippetInfo.indexOf( '#' ) );
	snippetInfo = snippetInfo.substring( snippetInfo.indexOf( '#' ) + 1 );
	snippetBox.datetime = snippetInfo.substring( 0, snippetInfo.indexOf( '#' ) );
	snippetInfo = snippetInfo.substring( snippetInfo.indexOf( '#' ) + 1 );
	snippetBox.rowNumber = snippetInfo.substring( 0, snippetInfo.indexOf( '#' ) );
	snippetBox.n = snippetInfo.substring( snippetInfo.indexOf( '#' ) + 1 );
}

function toggleHelp()
{
	if( waitForAnimation( "toggleHelp()" ) )
		return;
	
	if( help = !help )
	{
		g( "animbox" ).style.overflowY = "auto";
		g( currentBox ).style.display = 'none';
		g( "helpBox" ).style.display = '';
	}
	else 
	{
		g( "helpBox" ).style.display = 'none';
		g( currentBox ).style.display = '';
		g( 'animbox' ).scrollTop = 0

		playForwards();
	}
}

function setBoxes(boxCount) 
{
	noBoxes = boxCount;
}

function increaseSpeed()
{
	if( pause > 1000 )
	{
		pause -= 2000;
		
		updateSpeed();
	}
}

function decreaseSpeed()
{
	if( pause < 9000 )
	{
		pause += 2000;
		
		updateSpeed();
	}
}

function updateSpeed()
{
	switch( pause )
	{
		case 9000:
			changeImage( 'speedIndicator', 'RHS_icons_five'  ); 
			break;
		case 7000:
			changeImage( 'speedIndicator', 'RHS_icons_four' ); 
			break;
		case 5000:
			changeImage( 'speedIndicator', 'RHS_icons_three'  ); 
			break;
		case 3000:
			changeImage( 'speedIndicator', 'RHS_icons_two'  ); 
			break;
		case 1000:
			changeImage( 'speedIndicator', 'RHS_icons_one'  ); 
			break;
	}
}

function playForwards()
{
	if( help )
		return;
		
	if( waitForAnimation( "playForwards()" ) )
		return;
		
	changeImage( 'forwardButton', 'RHS_icons_forward_on'  ); 
	changeImage( 'pauseButton', 'RHS_icons_pause'  ); 

	direction = RTL;
	
	paused = 0;

	prepareNext();
}

function playPause()
{
	if( help )
		return;
		
	if( paused == 0 )
	{
		if( waitForAnimation( "playPause()" ) )
			return;
		
		paused = 1;
	
		changeImage( 'pauseButton', 'RHS_icons_pause_on'  ); 
		changeImage( 'forwardButton', 'RHS_icons_forward'  ); 
		
		hold();	
	}
}

function skipBack()
{
	if( help )
		return;
		
	paused = 1;
	allowMove = 1;
	
	if( waitForAnimation( "skipBack()" ) )
		return;
	
	changeImage( 'pauseButton', 'RHS_icons_pause_on'  ); 
	changeImage( 'forwardButton', 'RHS_icons_forward'  ); 
	
	direction = LTR;
	
	prepareNext();
}

function skipForward()
{
	if( help )
		return;
		
	paused = 1;
	allowMove = 1;
	
	if( waitForAnimation( "skipForward()" ) )
		return;
	
	changeImage( 'pauseButton', 'RHS_icons_pause_on'  ); 
	changeImage( 'forwardButton', 'RHS_icons_forward'  ); 

	direction = RTL;
	
	prepareNext();
}

function clearAndCallBack( callBack )
{
	sem = 0;
	eval( callBack );
}

function waitForAnimation( callBack )
{	
	if( sem != 0 )
	{
		return 2;
	}
		
	if( animating == 1 ) 
	{
		sem = 1;
		thread = clearTimeout( thread );		
		thread = setTimeout( "clearAndCallBack( " + callBack + ")", 100 );

		return 1;
	}
	
	animator = clearTimeout( animator );
	
	return 0;
}

function getNextBox()
{
	saveCurrentBox();
	
	if( direction == RTL )
	{
		return currentBox.next;
	}
	
	cBox--;
	if( currentBox.prev == lastBox )
		cBox = noBoxes;
	return currentBox.prev;
}

function prepareNext()
{	
	if( paused )
		timeout = 0;
	else
		timeout = pause;
	
	if( direction == RTL )
	{
		cBox++;
		if( currentBox.next == firstBox )
			cBox = 0;
	}
	else
	{
		cBox--;
		if( currentBox.prev == lastBox )
			cBox = noBoxes;
	}
	
	if( direction == RTL && cBox % limit == 1 )		
		loadMoreSnippets();
	
	animating = 2;
	
	if( paused )
	{
		if( direction == RTL )
			changeImage( 'skipForwardButton', 'RHS_icons_skipforward_on'  ); 
		else
			changeImage( 'skipBackButton', 'RHS_icons_skipback_on'  ); 
	}

	animator = clearTimeout( animator );
	animator = setTimeout( "animate( " + width + ")", timeout );	
}

function saveCurrentBox()
{
	var date = new Date();
	date.setTime(date.getTime()+86400000);
	document.cookie = "LASTSNIPPET = " + currentBox.datetime + ";expires=" + date.toGMTString() + "; path=/";
}

function animate( remainingWidth ) 
{
	if( !allowMove )
		return;

	first = 0;

	origBox = currentBox;
	newBox = getNextBox();
	
	animating = 1;

	if( direction == RTL )
		g( newBox ).style.left = width + 'px';
	else
		g( newBox ).style.left = -width + 'px';
	
	if( g( newBox ).style.display != '' ) 
		g( newBox ).style.display = '';
	
	if( g( "animbox" ).style.overflowY != "hidden" )
	{
		g( "animbox" ).style.overflowY = "hidden";
		g( 'animbox' ).scrollTop = 0
	}
	
	posScroller.style.left = ( ( newBox.rowNumber * posRefactor ) - ( posRefactor ) ) + "px";
	
	cSpeed = 1 + remainingWidth / width * speed;
		
	start = remainingWidth - parseInt( cSpeed );
	
	if( cSpeed == 1 )
		start = 0;
	
	if( direction == RTL )
	{
		boxA = start - width;
		boxB = start;
	}
	else
	{
		boxA = width - start;
		boxB = 0 - start;
	}
	
	g( origBox ).style.left = boxA + 'px';
	g( newBox ).style.left = boxB + 'px';
	
	if( start > 0 )
		animator = setTimeout( "animate( " + start + ")", 5 );
	else 
	{	
		if( currentBox.prev != currentBox )
			g( origBox ).style.display = 'none';
		
		currentBox = getNextBox();
		
		if( !paused )
			prepareNext();
		else
		{
			if( direction == RTL )
				changeImage( 'skipForwardButton', 'RHS_icons_skipforward'  ); 
			else
				changeImage( 'skipBackButton', 'RHS_icons_skipback'  ); 
		}
		
		fixHeight( newBox );
		
		animating = 0;
	}
}

function fixHeight( cid )
{
	if( g( cid ).offsetHeight > 138 )
	{
		g( "animbox" ).style.overflowY = "auto";
	}
	else if( g( cid ).offsetHeight < 138 )
		g( cid ).style.height = 138 + "px";
}

function hold()
{	
	if( waitForAnimation( "hold()" ) )
		return;

	changeImage( 'pauseButton', 'RHS_icons_pause_on'  ); 
		
	allowMove = 0;	
}

function vote()
{	
	if( waitForAnimation( "vote()" ) )
		return;
	
	full = Math.floor( currentBox.rating / 2 );
	half = currentBox.rating % 2;
	
	voteBlock = g( 'voteBlock' + currentBox.snippetID );
	
	if( voteBlock.innerHTML == '' )
	{
		voteBlock.innerHTML = 'written by <a href="/profile.cfm?uID=' + currentBox.writerID + '">' + currentBox.writerName + '</a><br /><br />';
		voteBlock.innerHTML += '<img src="/images/t.gif" class="spr rate_this" alt="Rating: " align="absbottom" /><br />'
		
		orig = '';
		
		eval( "stars" + currentBox.snippetID + "0 = new Array( 5 )" );
		
		for( i = 1; i <= 5; i++ )
		{
			if( i <= full )
				imgSrc = 'staronsel';
			else if ( half != 0 && i == full + 1 )
				imgSrc = 'starhalf';
			else
				imgSrc = 'staroffsel';
			
			eval( "stars" + currentBox.snippetID + "0[ i ] = '" + imgSrc + "'" );
			
			voteBlock.innerHTML += '<span><img src="/images/t.gif" class="spr ' + imgSrc + '" width="20" height="20" onmouseover="selectStars( ' + i + ', ' + currentBox.snippetID + '0 );" onmouseout="resetTimeout( ' + currentBox.snippetID + '0 );" onClick="doRating( 3, ' + currentBox.snippetID + ',0, ' + i + ',0,' + currentBox.n + ');" id="star' + currentBox.snippetID + '0' + i + '" alt="" align="absbottom" /></span>';
			
			orig += "'" + imgSrc + "', ";
		}
		
		loadResult( currentBox );
	}
	
	g( 'vote' + currentBox.snippetID ).style.display = "";
	g( 'animbox' ).scrollTop = 0;
}

function resume()
{
	if( help )
		return;
	
	if( waitForAnimation( "resume()" ) )
		return;
	
	animator = clearTimeout( animator );
	
	if( paused == 0 )
	{
		allowMove = 1;
		animator = setTimeout( "animate( " + width + ")", pause );
		
		changeImage( 'pauseButton', 'RHS_icons_pause'  ); 
	}
	
	if( g( 'vote' + currentBox.snippetID ) != null )
		g( 'vote' + currentBox.snippetID ).style.display = "none";
}

function loadResult( currentBox )
{
	g( 'result' + currentBox.snippetID ).innerHTML = '<div id="ratingNew' + currentBox.snippetID + '0" style="display:none;padding:18px 0 0 0;"><span style="color:#f20909;display:block;">Thank you for your rating,</span>Your vote has been counted and is reflected above.</div><div id="ratingOld' + currentBox.snippetID + '0" style="display:none;padding:18px 0 0 0;"><span style="color:#f20909;display:block;">You have already rated this,</span>Thank you for your support.</div>';
}

function loadMoreSnippets()
{
	fileload = '/custom/snippetLoader.cfm?lastdt=' + lastBox.datetime + '&direction=' + direction + '&id=' + new Date().getTime();

	ajaxManager( fileload );
}
// END snippets.js

// snippetvote.js
function doVote( voteType, snippetID ) 
{
	fileload = '/custom/snippetvote.cfm?voteType=' + voteType + '&snippetID=' + snippetID;

	ajaxManager( fileload );
}
// END snippetvote.js

// morewriter.js
var mwStories = new Array();
var mwMaxCount = 0;
var mwStoryIndex = 0;
var mwBoxWidth = 280;
var mwThread = 0;
var mwRunning = false;
var mwLeft = true;
var mwBuffer = 20;
var mwUser = 0;

function MWStory( url, title, summary, image, published )
{
	var url = url;
	var title = title;
	var summary = summary;
	var image = image;
	this.published = published;
	
	this.loadStory = function( index )
	{
		var storyBox = g( "mw-story-" + index );
				
		var h4 = storyBox.getElementsByTagName( "h4" )[ 0 ];
		h4.innerHTML = '<a href="' + url + '" title="View Story">' + title + '</a>';
		
		var children = storyBox.getElementsByTagName( "div" );
		
		for( var i = 0; i < children.length; i++ )
		{
			var el = children[ i ];
			
			if( el.className.indexOf( "image" ) > -1 )
				el.innerHTML = image;
			else if( el.className.indexOf( "summary" ) > -1 )
				el.innerHTML = summary;
		}
		
		children = storyBox.getElementsByTagName( "a" );
		
		for( var i = 0; i < children.length; i++ )
			children[ i ].href = url;
	};
	
	this.equals = function( u )
	{
		return url.equals( u );
	}
}

function mwMoveLeft()
{
	if( mwRunning )
		return;

	mwLeft = true;
	mwStoryIndex += 2;
	
	if( mwStoryIndex >= mwMaxCount )
		mwStoryIndex = mwStoryIndex - mwMaxCount;
	
	mwRunning = true;

	for( var i = 5, j = 3; i >= 0; i--, j-- )
	{
		var storyBox = g( "mw-story-" + i );
		
		storyBox.id = "t-mw-story-" + j;
					
		storyBox.style.left = ( j * (mwBoxWidth + 20) )+ "px";
					
		if( j == 0 )
			j = 6;
	}
	
	for( var i = 0; i < 6; i++ )
		g( "t-mw-story-" + i ).id = "mw-story-" + i;
	
	mwLoadStories();
	mwAnimate( 1 );
}
	
function mwMoveRight()
{
	if( mwRunning )
		return;

	mwLeft = false;
	
	mwStoryIndex -= 2;
	
	if( mwStoryIndex < 0 )
		mwStoryIndex = mwMaxCount + mwStoryIndex;

	mwRunning = true;

	for( var i = 0, j = 2; i < 6; i++, j++ )
	{
		var storyBox = g( "mw-story-" + i );
		
		storyBox.id = "t-mw-story-" + j;
					
		storyBox.style.left = ( ( j - 4 ) * (mwBoxWidth + 20) )+ "px";
		
		if( j == 5 )
			j = -1;
	}
	
	for( var i = 0; i < 6; i++ )
		g( "t-mw-story-" + i ).id = "mw-story-" + i;

	mwLoadStories();
	mwAnimate( -1 );
}

// right = -1, left = 1
function mwAnimate( dir )
{
	var keepGoing = true;
	var subt = mwBoxWidth / (dir<0?6:2.5);
	
	var stopBox = g( "mw-story-2" );
	
	if( dir * stopBox.offsetLeft < subt )
	{
		subt = dir * stopBox.offsetLeft + ( -dir * 30 );
		keepGoing = false;
	}
	
	for( var i = 0; i < 6; i++ )
	{
		var storyBox = g( "mw-story-" + i );
		
		storyBox.style.left = ( storyBox.offsetLeft + (-dir * subt) ) + "px";
	}

	if( keepGoing )
		setTimeout( "mwAnimate( " + dir + ")", 100 );
	else
		mwRunning = false;
}

function mwLoadStories()
{
	for( var i = 0, j = mwStoryIndex - 2; i < 6; i++, j++ )
	{
		var t = j;
		
		if( mwMaxCount <= 2 && j > 1 )
			break;
	
		if( j < 0 )
			t = j + mwMaxCount;
		else if( j >= mwMaxCount )
			t = 0;
					
		if( mwStories[ t ] != null )	
			mwStories[ t ].loadStory( i );
			
		if( mwLeft )
		{
			if( mwStories[ t + mwBuffer ] == null && t + mwBuffer < mwMaxCount )
			{
				var idx = t + mwBuffer;
				
				while( mwStories[ idx ] == null )
				{
					if( idx < 0 )
						break;
						
					idx--;
				}
				
				ajaxManager( "/custom/loadMoreWriter.cfm?u=" + mwUser + "&i="+ (idx + 1) +"&m=" + mwMaxCount + "&r=-" + mwBuffer + "&d=" + mwStories[ idx ].published );
				break;
			}
		}
		else
		{
			if( mwStories[ t - mwBuffer + 1 ] == null )
			{
				var idx = t - mwBuffer + 1;
				
				if( idx < 0 )
					continue;
				
				while( mwStories[ idx ] == null )
				{						
					if( idx > mwMaxCount )
						break;
					
					idx++;
				}

				ajaxManager( "/custom/loadMoreWriter.cfm?u=" + mwUser + "&i="+ ( idx + 1 ) +"&m=" + mwMaxCount + "&r=" + mwBuffer + "&d=" + mwStories[ idx ].published );
				break;
			}
		}
	}
	
	g( "MW" ).style.display = "block";
}

function mwInit( m, u, d )
{
	mwMaxCount = m;
	mwUser = u;
	
	ajaxManager( "/custom/loadMoreWriter.cfm?u=" + mwUser + "&i=0&m=" + mwMaxCount + "&r=-" + mwBuffer * 3 + "&d=" + d );
	ajaxManager( "/custom/loadMoreWriter.cfm?u=" + mwUser + "&i=1&m=" + mwMaxCount + "&r=" + mwBuffer * 3 + "&d=" + d );
}
// END morewriter.js

var sbBoxes = new Array();
var sbRunning = false;
var sbIdx = 0;
var sbPad = 34;

function sbInit(cnt)
{
	for( var i = 0; i < cnt; i++ )
	{
		sbBoxes[ i ] = g( "sb" + i );
	}
}

function sbMoveRight()
{
	if( sbRunning ) return;
	
	sbRunning = true;
	
	var nxt = sbNextIdx( 1 );
	sbBoxes[ nxt ].style.left = "605px";
	
	sbMove( 1 );
}

function sbMoveLeft()
{
	if( sbRunning ) return;
	
	sbRunning = true;
	
	var nxt = sbNextIdx( -1 );
	sbBoxes[ nxt ].style.left = "-605px";
	
	sbMove( -1 );
}

function sbMove( dir )
{
	var nxt = sbNextIdx( dir );
	var tBox = sbBoxes[ sbIdx ];
	var nBox = sbBoxes[ nxt ];
	
	var m = -dir * 50;
	var tnl = tBox.offsetLeft  + m;
	var nnl = nBox.offsetLeft + m;
	
	var d = 0;
	
	if( dir < 0 && nnl >= 0 || dir > 0 && nnl <= 0 )
		d = -nnl;
	
	tBox.style.left = ( tnl + d ) + "px";
	nBox.style.left = ( nnl + d ) + "px";

	if( d == 0 )
		setTimeout( "sbMove( " + dir + ")", 100 );
	else
	{
		sbIdx = sbNextIdx( dir );
		sbRunning = false;
	}
}

function sbNextIdx( dir )
{
	var nxt = sbIdx + dir;
	
	if( nxt < 0 )
		nxt = sbBoxes.length + dir;
	else if( nxt >= sbBoxes.length )
		nxt = -1 + dir;
	
	return nxt;
}
