/* ///////////////////////////

	PRINT CONTROLS

*/ ///////////////////////////

function printpage() {
	
	window.print();

}



/* ////////////////////////////

	BROWSER DETECTION

*/ ////////////////////////////

var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.userAgent,
			subString: "Chrome",
			identity: "Chrome"
		},
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari",
			versionSearch: "Version"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Internet Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();




/* ///////////////////////////

	TEXT SIZE CONTROLS

	Increments/Decrements font and line-height values by counting the numer of times the scale-up/scale-down button has been clicked.
	A directional variable (1 or -1) is passed to the scaleFont function from the HTML via onmouseup. This value is used to determine
	which direction to scale the text. Explicit values are provided for a default font size (baseFontSize), maximum font size (fontSizeMax),
	and minimum font size (fontSizeMin). A specific element is targeted to receive the style adjustments via the contentArea variable.

*/ ///////////////////////////


// Text Scaling Variables
var baseFontSize = 12; // Must set an explicit value since JS will not extract a fontSize value from CSS
var currentFontSize = new Number(); // Create a new Number object to track the current font size during scaling. Value is set to 0 by default
var fontSizeMin = 8; // Set minimum font size. This also drives lineHeight.
var fontSizeMax = 16; // Set maximum font size. This also drives lineHeight.
var scaleUpMultiplier = 1.1;
var scaleDownMultiplier = 0.9;
var scaleStep = new Number(); // Create a new Number object to count the number of clicks from 0. Numbers will increase and decrease. Value is set to 0 by default

// Targeted Text Variables
var divList = document.getElementsByTagName('div'); // Builds array of all DIV elements on the page.
var contentID; // Identifies the content column. Allows for variable ID values.
var contentIDPath; // contstructs the path to call the correct content column based on contentID


// Define the main content block through browser detect
/*Since NS and IE have different methods of using the DOM to identify attributes in elements, determine the browser.
This uses the Browser Detection script. Query using BrowserDetect.browser, BrowserDetect.version, BrowserDetect.OS */
function setTargetBlock()
{
	contentID = "main-content";
}




// Main Function
function scaleFont(x) 
{
	
	
	//alert(appName[0] + " :: " + divList[8].attributes['id'].value);
	var scaleDirection = parseInt(x); // Convert incoming string from HTML to an interger
	
	setTargetBlock();
	
	
	
	contentIDPath = document.getElementById(contentID);
	
	//Create a function that sets the CSS values for font-size and line-height. Function is used throughout in conditional statements.
	function setLayout(contentID)
	{
		document.getElementById(contentID).style.fontSize = Math.round(currentFontSize) + "px"; // Creates string and sets the font-size in CSS
		document.getElementById(contentID).style.lineHeight = eval(Math.round(currentFontSize)*1.13) + "px"; // Creates a string and sets the line-height in CSS.
	}
	
	
	// First determine which direction the text is scaling. 
	switch (scaleDirection)
	{
		
		case 1: // If scaling up ...
			
			if (currentFontSize <= fontSizeMax) // Compare the font size against the maximum font size 
			{
			
				if (scaleStep == 0) // If scaleStep is 0 or its default value ...
				{
					currentFontSize = baseFontSize; // On the first click, set currentFontSize equal to baseFontSize so it has an explicit value other than 0.
					currentFontSize = baseFontSize*scaleUpMultiplier; // ... currentFontSize is scaled by an preset value
					setLayout(contentID); // ... CSS values are set
				}
				else // If scaleStep value is anything other than 0 the same operations as above are performed (negating the currentFontSize since it is already set).
				{
					currentFontSize = currentFontSize*scaleUpMultiplier;
					setLayout(contentID);
				}
			}
			else
			{
				//
			}
			scaleStep++; // Increase the value of scaleStep by 1 each time.
			
			createCookie('safsb_text', currentFontSize,1);
			break;
			
			
		case -1: // If scaling down ...
			if (currentFontSize >= fontSizeMin || currentFontSize == 0 ) // Compare the currentFontSize against the minimum font size OR determine if the currentFont Size is 0
			{
				
				if (scaleStep == 0)
				{
					currentFontSize = baseFontSize; // On the first click, set currentFontSize equal to baseFontSize so it has an explicit value other than 0.
					currentFontSize = currentFontSize*scaleDownMultiplier; // Multiplying by a value less than 1 will reduce the value (just a reminder).
					setLayout(contentID);
				}
				else // If scaleStep is a positive value (from scaling up) ...
				{
					currentFontSize = currentFontSize*scaleDownMultiplier;
					setLayout(contentID);
				}
			}
			else
			{
				//
			}
			
			scaleStep--; // Decrease the value of scaleStep by 1 each time
			
			createCookie('safsb_text',currentFontSize,1);
			break;
		
		default:
			//
	}
	
}



/* ///////////////////////////////

	SET FONT SIZE WITH COOKIE

*/ ///////////////////////////////


function setFontSize() 
{
	setTargetBlock();
	
	var isScaleFont = readCookie('safsb_text');
	
	//alert(isScaleFont);
	
	if (isScaleFont !== null)
	{
		//alert(Math.round(currentFontSize) + " :: " + baseFontSize);
		document.getElementById(contentID).style.fontSize = Math.round(isScaleFont) + "px"; // Creates string and sets the font-size in CSS
		document.getElementById(contentID).lineHeight = eval(Math.round(isScaleFont)*1.13) + "px"; // Creates a string and sets the line-height in CSS.;
	}
	
}
