 $(document).ready(function() {
						
   $('.helptext').addClass('hide');
   
   $('.help').click(function() {
		$(this).parent().siblings('.helptext').toggle('slow');
		return false; 
   });
   
   $('.hideme').click(function() {
	   	$(this).parent().hide('slow');
		return false;
   });
   
 
   $('.popup').click(function() {
		window.open(this.href, '', 'top=0,left=0,width=600,height=500,scrollbars=yes, resizable=yes');
		return false;
   });
   
   

	
	/*
		-------------
		  - forms -
		-------------
	*/
	// onclick, clear value of: search box, location box (comments) 
   $('#searchwords, input#location').focus(function() {
		this.value = '';							
	});


	//var fontsize = $.cookie('fontsize');
	
	//error checking: if div.row has a child element of .errormsg then add a class of required-error to row
	 $('.row span.errormsg').parent().addClass("required-error");

	/*
		- accessibility and customisation
	*/
 	

	
		/*
			user wants to change fontsize:
		*/
		$('.fontsize').click(function() {
			setFontsize(this.value)
			$.cookie('fontsize', this.value, {expires: 7, path: '/'});
		});
		var fs_c = $.cookie('fontsize');
		if (fs_c) setFontsize(fs_c)
		
		/*
			user wants to set forum to open in new window
		*/		
		$('#mb_prefs input').click(function() {
			var name = $(this).attr("name");
			//alert(name);
			if ( $.cookie(name) ) {
				// if it already exists, delete it
				$.cookie(name, this.value, {expires: -1, path: '/'});
			}
			else {
				$.cookie(name, this.value, {expires: 7, path: '/'});
			}
		});	
		var nw_c = $.cookie('newwindow')//new window cookie
		var skip_c = $.cookie('skip');//skip prefs page cookie
		if (nw_c) {
			rememberPrefStates('newwindow')
			
		}
		if (skip_c) rememberPrefStates('skip')
	

		
		$('a[@href*=/message-board]').each(function(i) {
			if ($(this).attr("rel") != "exception") {
				if ($.cookie('skip') ) {
					$(this).attr("href", "http://www.renalreg.com/cgi-bin/ikonboard.cgi");
				}
			}
		});
		$('a[@href*=/forum]').click(function() {
			if ($.cookie('newwindow') ) {
				window.open(this.href, '');
				return false;
			}
		});	
		$('#enter_forum').click(function() {
			if ($.cookie('newwindow') ) {
				var href = $('#mb_prefs').attr("action");
				window.open(href, '');
				return false;
			}		
		});	
		

		
	$("#latest tr:even, #forumlist tr:even").addClass("alt");
	$("#reports-home ul li:odd").addClass("alt");
		 
});//close $document.ready
 

/*------------------------------------------------------------------------------------------------------------------------------------*/

/*
	---------------------------------------------------------------------------------
	some functions outside the document.ready function, called from the above
	---------------------------------------------------------------------------------
*/

function setFontsize(fontSize) {
	$('body').css("font-size", fontSize + "%");	
	
/*	$('input[@rel*=fontsize]').each(function(i) { 
		if (this.getAttribute("value" == fontSize)) this.setAttribute("checked", "checked");
	});*/
}
function setDeviceStylesheet(device) {
	$('link[@rel*=style]').each(function(i) {
		if (this.getAttribute('title') == device) {
			this.disabled = false;
		}
		else {
			if (this.getAttribute('title') == "handheld") this.disabled=true;
			
		}
	});	
	

}
function rememberPrefStates(cookie) {
	$('input[@type=checkbox]').each(function(i) {
		if (this.getAttribute('name') == cookie) {
			$(this).attr("checked", "checked");
		}

	});	

}


