/* ============================================================
	Javascript (c) 2009 Why Whimsy
	for the Bill Sebastian Forum
	11-03-09
============================================================== */

/* ---------------------------------------------------------
	global variables	
------------------------------------------------------------ */

	var to_set = 0;													// time-out set state
	var to_len = 3000;												// time-out length
	var flipped = 0;												// up/down icon state
	var fs_iconel = "";												// the icon object
	var fs_max = 79;												// maximum font size
	var fs_min = 57;												// minimum font size
	var fs_incr = 3;												// single-step increment
	var fs_def = 70;												// default font size
	var CK_name = 'fsize';											// cookie name
	var CK_persist = 30;											// cookie persist 30 days
	var CK_path = '/';												// path is whatever
	var CK_domain = '';												// domain is whatever
	var FS_id = "fsize_icon";										// id of icon parent
	var FS_imgfile = "icon_fsize_";									// base for image file name
	
/* --------------------------------------------------------
	document font set
		if user click, pass the size
---------------------------------------------------------- */

	function fsize_docset()
	{
		var fsize = "";
		
		if(arguments.length == 0)									// if no arg was passed, it's a page-load set
		{
			fsize = fsize_get();									// get cookie or default
		}
		else
		{
			fsize = arguments[0];									// otherwise grab the arg
		}
		
		document.body.style.fontSize = fsize + "%";					// set the body font size property
			
	}	
		
/* --------------------------------------------------------
	document font change -- called by onclick
---------------------------------------------------------- */

	function fs_updown()
	{									
		var fsize = fsize_get();											// get current font size
	
		var fsint = parseInt(fsize,10);										// fsize is a string
												
		fsint = fsint + fs_incr * flipped;									// increment/decrement by one step
											
		if(fsint > fs_max) { fsint = fs_max; }								// check/set min/max size
		if(fsint < fs_min) { fsint = fs_min; }
		
		fsize = fsint + "";													// make it a string
								
		fsize_save(fsize);													// save the new font size to the cookie
		
		fsize_docset(fsize)													// set it in the document body style

	}
		
/* --------------------------------------------------------
	mouseover icon control
---------------------------------------------------------- */
		
	function fsicon_flip()
	{
		var fscur = fsize_get();											// get the current font size;
		var ifscur = parseInt(ifscur,10);									// convert to a number
		
		fs_iconel = document.getElementById("fsize_icon");					// get a handle to the icon object

		if(to_set != 0) { clearTimeout(to_set); }							// if prev set timeout hasn't expired, clear it
												
		if(flipped == 0)													// if the prev state is defocus then set focus up arrow
		{
			if(ifscur >= fs_max)	{ return; }								// if the size is already at max, nothing to do, just exit
			flipped = 1;													// set the arrow state variable
			fsicon_set('up');												// alter the icon display to show up arrow
			to_set = setTimeout('fsicon_defocus()',to_len);					// and set the timeout to defocus
		}
		else if(flipped == 1)												// if arrow state is up, change it to down
		{
			if(ifscur <= fs_min)	{ return; }
			fsicon_set('down');												// change icon to down arrow
			flipped = -1;
			to_set = setTimeout('fsicon_defocus()',to_len);
		}
		else if(flipped == -1)												// otherwise reset back to defocus 
		{
			flipped = 0;
			fsicon_set('updown');											// set updown or neutral
			to_set = setTimeout('fsicon_defocus()', to_len);
		}
									
	}
											
/* -------------------------------------------------------
	'defocus' icon - return to up/down neutral
-------------------------------------------------------- */
											
	function fsicon_defocus()
	{		
		fsicon_set('updown');
		return;
	}

/* ------------------------------------------------------
	set the icon state
-------------------------------------------------------- */

	function fsicon_set(iconstate)
	{
		var fnpath = fs_imgpath + FS_imgfile + iconstate + '.gif';					// construct a path/filename
		
		document.getElementById(FS_id).src = fnpath;								// change the src property
	}

/* ------------------------------------------------------
	get the current font size from the cookie
------------------------------------------------------- */

	function fsize_get()
	{
		var ckstr = cookie_get(CK_name);											// get cookie data for font size

		if(ckstr == '')																// if null string returned
		{
			return fs_def;															// no cookie, return the default
		}
		
		return ckstr;																// otherwise return what the cookie said
	}
	
/* --------------------------------------------------------
	save the font size clicked by the user
	arg = font size in percent
----------------------------------------------------------- */
	
	function fsize_save(fsize)
	{
		cookie_put(CK_name, fsize, CK_persist, CK_path, CK_domain);
	}								
	
/* --------------------------------------------------------
	cookie functions
---------------------------------------------------------- */

/*	--- cookie read ---
		arg: cookie name */

	function cookie_get(ckname)
	{
		var ck_str = '' + document.cookie;												// document cookie string

		if(ck_str === '') { return ''; }												// no cookie string

		var cksrch = ckname + '=';														// search string
		
		var here = ck_str.indexOf('; ' + cksrch);										// look for in cookie string
		
		if(here == -1)																	// if no semicolon then look at beginning
		{
			here = ck_str.indexOf(cksrch);					
			
			if(here !== 0)																// if it's not here
			{
				return '';
			}
		}
		else																			// but if in middle, then use two digits after
		{
			here += 2;
		}
		
		var end = ck_str.indexOf(';', here);											// next semicolon is end of data
		
		if(end == -1) { end = ck_str.length; }											// no more semicolon, that's all the data
																						// send back what we got, unescaped
		return unescape(ck_str.substring(here + cksrch.length, end));
	}

/* --- cookie write ---
		args: cookie name, data value, expiration, path, domain */

	function cookie_put(ckname, ckvalue, ckdays, ckpath, ckdomain)
	{

		var exp_date = new Date();
		var exp_str = '';

		if((typeof ckdays === 'undefined') || (typeof ckdays === 'object'))				// if these args not passed then assign default
		{
			ckdays = CK_persist;
		}
		
		if((typeof ckpath === 'undefined') || (typeof ckpath === 'object'))
		{
			ckpath = CK_path;
		}
		
		if((typeof ckdomain === 'undefined') || (typeof ckdomain === 'object'))
		{
			ckdomain = CK_domain;
		}
															
		exp_date.setTime(exp_date.getTime() + (ckdays*24*60*60*1000));					// expires on GMT date string
		exp_str = exp_date.toGMTString();

		var ckstr = ckname + '=' + escape(ckvalue);										// value

		ckstr = ckstr + '; expires=' + exp_str;											// expiration

		ckstr = ckstr + '; path=' + ckpath;												// path
		
		ckstr = ckstr + '; domain=' + ckdomain;											// domain

		document.cookie = ckstr;														// set the cookie
		
	}

/* -----------------------------------------------------------------------
	for hide/show of the posting rules
------------------------------------------------------------------------*/

	function rulesHideShow() {
	
		if(document.getElementById("link-showrules").className == "ruleslink-visible")
		{
			document.getElementById("link-showrules").className = "ruleslink-notvisible";
			document.getElementById("link-hiderules").className = "ruleslink-visible";
			document.getElementById("forumrules-box").className = "rulesbox-show";
			return;
		}
		
		if(document.getElementById("link-hiderules").className == "ruleslink-visible") 
		
		{
			document.getElementById("link-showrules").className = "ruleslink-visible";
			document.getElementById("link-hiderules").className = "ruleslink-notvisible";
			document.getElementById("forumrules-box").className = "rulesbox-noshow";
		}
	}
	
	
