/* ------------------------------------------------------------ *
 * Copyright 2004 TRUTH PUBLISHING. All Rights Reserved.        *
 * ------------------------------------------------------------ *
 * Version:     7.0                                             *
 * Author:      Andy Abbott [aabbott at etruth dot com]         *
 *              Truth Publishing [www.etruth.com]               *
 * Date:        02.24.2005                                      *
 * Title:       StoryTools.js                                   *
 * Description: Story tools used to manipulate story text.      *
 *              Idea and concepts from SacBee's StoryToolbar    *
 *              which is originally from the UI Sharp Shooter.  *
 *              SacBee's StoryToolbar                           *
 *                - Seth Van Booveen <svanbooven@sacbee.com>    *
 *              UI Sharp Shooter                                *
 *                - John Weir [info@smokinggun.com]             * 
 * ------------------------------------------------------------ */

var fontSize = 10;
var fontFamily = 'arial,verdana,helvetica,sans-serif';

function stSetObj() {
	bodyObj = (document.getElementById) ? document.getElementById('storyBody') : document.all('storyBody');
}

function stSizeIncrease() {
	stSetObj();
	fontSize += 1;

	if (fontSize > 16) 
		fontSize = 16;

	stSetObj();
	bodyObj.style.fontSize = fontSize + 'pt';
	stSavePrefs()
}
	
function stSizeDecrease() {
	stSetObj();
	fontSize -= 1;

	if (fontSize < 8)
		fontSize = 8;

	stSetObj();
	bodyObj.style.fontSize = fontSize + 'pt';
	stSavePrefs()
}

function stFontToggle() {
	stSetObj();
	if (fontFamily == 'arial,verdana,helvetica,sans-serif') {
		fontFamily = 'georgia,times,times new roman,serif';
	}
	else {
		fontFamily = 'arial,verdana,helvetica,sans-serif';
	}
	bodyObj.style.fontFamily = fontFamily;
	stSavePrefs()
}

function stPopUp(pURL,name,features) {
		new_window = window.open(pURL,name,features);
		new_window.focus();
}

function stSavePrefs() {
	tmpCookie = 'storyPrefs=';
	tmpCookie = tmpCookie + '^fontSize=' + fontSize + '^fontFamily=' + fontFamily;
	var expire = new Date ();
   	expire.setTime (expire.getTime() + (30 * 24 * 3600000));
   	expire = expire.toGMTString();
	myCookie = tmpCookie + '; path=/; expires=' + expire; 
  	document.cookie = myCookie;
}

function stLoadPrefs() {
	stPrefString = null;
	tmpArray = document.cookie.split(';');
	for (tA = 0; tA < tmpArray.length; tA++) {
		if (tmpArray[tA].indexOf('storyPrefs=') > -1) {
			tPos = tmpArray[tA].indexOf('=') + 2;
			stPrefString = tmpArray[tA].substring(tPos, tmpArray[tA].length);
		}
	}
	if (stPrefString != null) {
		tmpArray = stPrefString.split('^');
		for (tA = 0; tA < tmpArray.length; tA++) {
			if (tmpArray[tA].indexOf('fontSize') > -1) {
				tmpFontSize = tmpArray[tA].split('=');
				fontSize  = parseInt(tmpFontSize[1]);
			}
			if (tmpArray[tA].indexOf('fontFamily') > -1) {
				tmpFontFamily = tmpArray[tA].split('=');
				fontFamily  = (tmpFontFamily[1]);
			}
		}
	}
}

function stSetElm() {
	stSetObj();
	bodyObj.style.fontSize = fontSize + 'pt';
	bodyObj.style.fontFamily = fontFamily;
	stSavePrefs();
}

function stInit() {
	stLoadPrefs();
	stSetElm();
}
