/*================================================================================
 * increaseFontSize(size)
 * - changes font size of div container and stores selection in cookie "fontsize=size" 
 * - settings applied until user closes browser
/*================================================================================*/

function increaseFontSize(size)
{
	var p = document.getElementById('readResults');
	p.style.fontSize = size;
	set_cookie('fontsize', size);
}

/*================================================================================
 * changeFont(font)
 * - changes font family of div container and stores selection in cookie "fontname=font" 
 * - settings applied until user closes browser
/*================================================================================*/

function changeFont(font)
{
	var p = document.getElementById('readResults');
	//var whatToChange = getElementsByClassName("ch");
	//whatToChange.style.fontFamily = font;
	//getElementsByClassName("changeable").style.fontFamily = font;
	p.style.fontFamily = font;
	
	set_cookie('fontname', font);
}

/*================================================================================
 * background(image)
 * - changes background image of body and stores selection in cookie "backgroundImage=image" 
 * - settings applied until user closes browser
/*================================================================================*/

function background(image)
{
	var backgroundImage = document.body;
	
	var defaultPic = "url(images/backgrounds/bluelakejetty.jpg)";
	var picture = "url(images/backgrounds/" + image +".jpg)";
	
	if(picture != defaultPic) 
	{
		backgroundImage.style.backgroundImage = picture;
		backgroundImage.style.backgroundRepeat = "no-repeat";
		backgroundImage.style.backgroundPosition = "top";
		backgroundImage.style.backgroundAttachment = "fixed";
		backgroundImage.style.backgroundColor = "#fff";
		//document.getElementById('container').style.backgroundImage = "url(images/whiteT	ransparent.png)";
	}
	else
	{
		backgroundImage.style.backgroundImage = defaultPic;
		document.body.style.backgroundRepeat = "no-repeat";
		document.body.style.backgroundPosition = "top";
		document.body.style.backgroundAttachment = "fixed";
		document.body.style.backgroundColor = "#fff";
		//backgroundImage.style.backgroundRepeat = "repeat-y";
		//backgroundImage.style.backgroundPosition = "center";
		//backgroundImage.style.backgroundColor = "#babcbe";
		//document.getElementById('container').style.backgroundImage = "url(images/whiteTransparent.png)";
	}
	
	set_cookie('backgroundImage', picture);
}

/*================================================================================
 * set_cookie
 * - use this function to set a cookie
/*================================================================================*/

function set_cookie ( name, value, exp_y, exp_m, exp_d, path, domain, secure )
{
  var cookie_string = name + "=" + escape ( value );

  if ( exp_y )
  {
    var expires = new Date ( exp_y, exp_m, exp_d );
    cookie_string += "; expires=" + expires.toGMTString();
  }

  if ( path )
        cookie_string += "; path=" + escape ( path );

  if ( domain )
        cookie_string += "; domain=" + escape ( domain );
  
  if ( secure )
        cookie_string += "; secure";
  
  document.cookie = cookie_string;
}

/*================================================================================
 * get_cookie
 * - use this function to get a cookie
/*================================================================================*/

function get_cookie ( cookie_name )
{
  var results = document.cookie.match ( '(^|;) ?' + cookie_name + '=([^;]*)(;|$)' );

  if ( results )
    return ( unescape ( results[2] ) );
  else
    return null;
}

/*================================================================================
 * applySettings()
 * - This function applies all settings when the page is loaded. 
 * - Settings are applied by cookies
/*================================================================================*/

function applySettings()
{
	//apply font size
	var appliedFontSize = get_cookie("fontsize");
	document.getElementById('container').style.fontSize = appliedFontSize;
	
	//apply font
	var appliedFont = get_cookie("fontname");
	document.getElementById('container').style.fontFamily = appliedFont;
	
	//default pic is set to gray gradient image
	var defaultPic = "url(images/backgrounds/bluelakejetty.jpg)";
	
	//user selected background (determined from cookie)
	var appliedBackgroundImage = get_cookie('backgroundImage');
	
	if(!appliedBackgroundImage || appliedBackgroundImage == defaultPic)
	{
	//sets default background image settings
		document.body.style.backgroundImage = defaultPic;
		document.body.style.backgroundRepeat = "no-repeat";
		document.body.style.backgroundPosition = "top";
		document.body.style.backgroundAttachment = "fixed";
		document.body.style.backgroundColor = "#fff";
		//document.body.style.backgroundRepeat = "repeat-y";
		//document.body.style.backgroundPosition = "center";
		//document.body.style.backgroundColor = "#babcbe";
		//document.getElementById('container').style.backgroundImage = "url(images/whiteTransparent.png)";
		return;
	}
	
	//checks to see if seleced image is different than the default image
	//if different, set new background image
	if(appliedBackgroundImage != defaultPic)
	{
		document.body.style.backgroundImage = appliedBackgroundImage;
		document.body.style.backgroundRepeat = "no-repeat";
		document.body.style.backgroundPosition = "top";
		document.body.style.backgroundAttachment = "fixed";
		document.body.style.backgroundColor = "#fff";
		//document.getElementById('container').style.backgroundImage = "url(images/whiteTransparent.png)";
		return;
	}
}

/* ============================================================ */