// ---------------------------------------------------------------------
// global stuff - called on EVERY page - so keep tight!
//

// add "trim" to all strings
String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}

$(document).ready(function(){
	// global hover functions 
	// this one is used on the biglist lookup field types
	$('img#access').hover(
		function() { $(this).attr("src","/moddb/img/access.png"); },
		function() { $(this).attr("src","/moddb/img/access-std.png"); }
	);
	// this one is a "go" button in various places
	$('img.go').hover(
		function() { $(this).attr("src","/img/ui/go-right-ro.png");$(this).addClass('hover'); },
		function() { $(this).attr("src","/img/ui/go-right.png");$(this).removeClass('hover'); }
	);
	fadeclass('fade', 4500);	// all classes marked as "fade" get faded out after loading
	
	// setup clickable li sidebar menu that follows an interior link
/*	$(".blrow").click(function(){
    	window.location=$(this).find("a.mpplay").attr("href");return false;
	});
*/
	$(".blcontent").hover(function(){
		$(this).stop()
			.animate({backgroundColor:"#e0e0e0"},200)
			;
	},
	function() {
		$(this).stop().animate({ backgroundColor:"#f8f8f8"},3000);
	});
	

	_runajs();

});
$.fn.pause = function(duration) {
	$(this).animate({ dummy: 1 }, duration);
	return this;
};

// set focus of an ID
function setfocus(id) {
	$('#'+id).focus();
}
// default callback function sets input focus to the LAST element that has the class "focus". Used lots
function _runajs() {				/* run on every ajax page load */
$('input.focus:last').focus();
	$('input.focus:last').focus(); /* oddly - needs to be done twice (sometimes) on IE, so do it always just in case */
}

// common ajax loader
function ajaxload(target,gid,content,wait,callbackfunc) {

	// setup _runajs as a default callback function if not provided
	cbf = typeof(callbackfunc) != 'undefined' ? callbackfunc : '_runajs';
	
	$('#'+content).hide();
	$('#'+wait).show();
	$.ajax({
	   url: target,
	   cache: false,
	   error: function (XMLHttpRequest, textStatus, errorThrown) {
			alert('ajax error : '+textStatus);
		},
	   dataType: "html",
	   data: gid,
	   success: function(data){
			$('#'+wait).hide();
			$('#'+content).html(data);
			$('#'+content).show();
			eval(callbackfunc+'()');
	   },
	   failure: function(request, status) {
			$('#'+wait).hide();
			$('#'+content).html(status);
			$('#'+content).show();
	   }
	}); 
}

// ajaxSubmit is part of the jquery forms plugin
function axf(formname, filltarget) {
	$("form#"+formname).ajaxSubmit({target: '#'+filltarget});
	return false;
}
function axp(formname) {
	return axf(formname, 'ajaxfill');
}
// useful ID fadeout function
function fadeout(id, dly) {
	var left = parseInt($('#'+id).css('marginLeft'));
	$('#'+id)
		.animate({ marginLeft: left ? left : 0 }, dly)
		.fadeOut('slow');
}
// useful class fadeout function
function fadeclass(classid, dly) {
	var left = parseInt($('.'+classid).css('marginLeft'));
	$('.'+classid)
		.animate({ marginLeft: left ? left : 0 }, dly)
		.fadeOut('slow');
}

