/**
 * AdjustFont (BETA)
 * @author		Jerome Coloma
 * @email 		jeromecoloma@gmail.com
 * @version 	0.9
 * @update 		2007-01-25
 *
**/

if( typeof com == "undefined" ) { var com = {}; }
if( typeof com.frozynart == "undefined" ) { com.frozynart = {}; }
com.frozynart.toString = function( ) { return 'Package: com.frozynart'; };
com.frozynart.AdjustFont = function( ) {
	this.currentFontSize = null;
};
com.frozynart.AdjustFont.prototype.toString = function( ) {
	return 'Frozynart { AdjustFont ver. 0.9 }';
};
com.frozynart.AdjustFont.prototype.getPreferredFontSize = function( ) {
	return '100%';
};
// -- http://www.alistapart.com
com.frozynart.AdjustFont.prototype.createCookie = function( name, value, days ) {
	if( days ) {
		var date = new Date( );
		date.setTime( date.getTime()+(days*24*60*60*1000) );
		var expires = "; expires="+date.toGMTString( );
	} else {
		expires = "";
	}
	document.cookie = name+"="+value+expires+"; path=/";
};
com.frozynart.AdjustFont.prototype.readCookie = function( name ) {
	var nameEQ = name + "=";
	var ca     = document.cookie.split(';');
	var caLen  = ca.length;
	for( var i=0;i<caLen; i++ ) {
		var c  = ca[i];
		while (c.charAt(0)==' ') {
			c = c.substring( 1, c.length );
		}
		if( c.indexOf(nameEQ) == 0 ) {
			return c.substring( nameEQ.length, c.length );
		}
	}
	return null;
};

// -- only applies to body tag
com.frozynart.AdjustFont.prototype.setFontSize = function( $adjustedFontSize ) {
	var currentStyleSheet = document.styleSheets[0];
	var rules             = currentStyleSheet.cssRules ? currentStyleSheet.cssRules : currentStyleSheet.rules;
	var rulesLen          = rules.length;
	for( var i=0; i<rulesLen; i++ ) {
		if( rules[i].selectorText.toLowerCase().indexOf('body')!= -1 ) {
			//rules[i].style.fontSize == "100%" || 
			if( rules[i].style.fontSize != '' ) {
				//alert( rules[i].style.fontSize );
				this.currentFontSize    = $adjustedFontSize;
				rules[i].style.fontSize = $adjustedFontSize;
			}
			/*
			if( rules[i].style.fontSize == this.readCookie('currentFontSize') ) {
				this.currentFontSize    = $adjustedFontSize;
				rules[i].style.fontSize = $adjustedFontSize;
				alert( rules[i].style.fontSize );
			}
			*/
		}
	}
};
