var elesz = [];

function g(id) {
	var r = elesz[id] || document.getElementById(id) || false;
	elesz[id] = r;
	return r;
}

function basename(src){
	return src.substring(src.lastIndexOf('/')+1);
}

function Folder(obj,image){
	var div = g(obj);
	var image = g(image);
	var rpath = 'http://www.hiveworkshop.com/forums/';
	if (basename(image.src) == 'joinminus.gif' || basename(image.src) == 'joinplus.gif') {
		if ( div.style.display != 'none' ) {
			div.style.display = 'none';
			image.src = rpath+'images_all/trigger/joinplus.gif';
        } else {
			div.style.display = '';
			image.src = rpath+'images_all/trigger/joinminus.gif';
        }
    }

	if (basename(image.src) == 'joinbottomminus.gif' || basename(image.src) == 'joinbottomplus.gif') {
		if ( div.style.display != 'none' ) {
			div.style.display = 'none';
			image.src = rpath+'images_all/trigger/joinbottomplus.gif';
        } else {
			div.style.display = '';
			image.src = rpath+'images_all/trigger/joinbottomminus.gif';
        }
    }
}

function resRateHover(evt,typ) { // thanks to http://bytes.com/archives/javascript/149922-capture-mouse-position-image
	var obj_x;
	var obj_y;
	if (document.all) { // MSIE
		obj_x = evt.offsetX;
		obj_y = evt.offsetY;
	} else { // Netscape, etc.
		obj_x = evt.clientX;
		obj_y = evt.clientY;
		for (var offMark = evt.target; offMark; offMark = offMark.offsetParent) {
			obj_x -= offMark.offsetLeft;
		}
		for (var offMark = evt.target; offMark; offMark = offMark.offsetParent) {
			obj_y -= offMark.offsetTop;
		}
	}
	
	obj_x = Math.floor(obj_x / 60)*60+60;
	if(obj_x > 300) obj_x = 300;
	
	g('resourceRating').style.width = obj_x+'px';
	g('resourceRatingText').innerHTML = 'Give the '+typ+' a rating of '+(obj_x/60)+'/5';
}

function resRateBlur() {
	g('resourceRating').style.width = resRate+'px';
	g('resourceRatingText').innerHTML = '(Hover and click)';
}

function resRateExec(urla,urlb) {
	var r = parseInt( g('resourceRating').style.width );
	r = parseInt(r/60);
	new Ajax.Request(urla+r+urlb,{
		onSuccess:function(t)
		{
			t = t.responseText;
			if(t.substring(0,5) == 'error')
			{
				alert(t.substring(6));
			}
			else if(t.substring(0,7) == 'success')
			{
				g('resourceRatingText').innerHTML = t.substring(8);
			}
		},
		onFailure:function(t)
		{
			alert('The request was not processed, try again');
		}
	});
}

var voted = false;
var tempvoted = false;
function modbyuser_h()
{
	g('modbyusertext').style.display = '';
}
function modbyuser_o()
{
	if(voted == false && tempvoted == false)
	{
		g('modbyusertext').style.display = 'none';
	}
}
function modbyuser_hover(i)
{
	var e = g('mbu_'+i);
	e.style.color = '#60A600';
}
function modbyuser_out(i)
{
	var e = g('mbu_'+i);
	e.style.color = '';
}
function modbyuser_vote(obj)
{
	var url = obj.href+'&ajax=1';
	tempvoted = true;
	if(confirm('Are you sure that you want to cast this vote?'))
	{
		new Ajax.Request(url,{
			onSuccess: function(t)
			{
				voted = true;
				var r = t.responseText;
				var m = r.substring(1);
				var v = r.substring(0,1);
				g('modbyusertext').innerHTML = m;
				g('modbyusertext').style.color = (v == 0 ? 'red' : '');
			}
		});
	}
	else
	{
		tempvoted = false;
	}
	return false;
}