// cookie functions
jQuery.cookie = function(name, value, options) {
	if (typeof value != 'undefined') { // name and value given, set cookie
		options = options || {};
		if (value === null) {
			value = '';
			options = jQuery.extend({}, options); // clone object since it's unexpected behavior if the expired property were changed
			options.expires = -1;
		}
		var expires = '';
		if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
			var date;
			if (typeof options.expires == 'number') {
				date = new Date();
				date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
			} else {
				date = options.expires;
 			}
 			expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
 		}
 		// NOTE Needed to parenthesize options.path and options.domain
 		// in the following expressions, otherwise they evaluate to undefined
 		// in the packed version for some reason...
 		var path = options.path ? '; path=' + (options.path) : '';
 		var domain = options.domain ? '; domain=' + (options.domain) : '';
 		var secure = options.secure ? '; secure' : '';
 		document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
 	} else { // only name given, get cookie
 		var cookieValue = null;
 		if (document.cookie && document.cookie != '') {
 			var cookies = document.cookie.split(';');
 			for (var i = 0; i < cookies.length; i++) {
 				var cookie = jQuery.trim(cookies[i]);
 				// Does this cookie string begin with the name we want?
 				if (cookie.substring(0, name.length + 1) == (name + '=')) {
 					cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
 					break;
 				}
 			}
 		}
 		return cookieValue;
 	}
};
// /cookie functions 

// fixes for IE-7 cleartype bug on fade in/out
jQuery.fn.fadeIn = function(speed, callback) {
	return this.animate({opacity: 'show'}, speed, function() {
 	if (jQuery.browser.msie) this.style.removeAttribute('filter');
 	if (jQuery.isFunction(callback)) callback();
 });
};

jQuery.fn.fadeOut = function(speed, callback) {
 	return this.animate({opacity: 'hide'}, speed, function() {
 	if (jQuery.browser.msie) this.style.removeAttribute('filter');
 	if (jQuery.isFunction(callback)) callback();
 });
};

jQuery.fn.fadeTo = function(speed,to,callback) {
 	return this.animate({opacity: to}, speed, function() {
 	if (to == 1 && jQuery.browser.msie) this.style.removeAttribute('filter');
 	if (jQuery.isFunction(callback)) callback();
 });
};
 

jQuery(document).ready(function(){
 	// body .safari class
 	if (jQuery.browser.safari) jQuery('body').addClass('safari');

 	// layout controls
 	jQuery("#layoutcontrol a").click(function() {
 		switch (jQuery(this).attr("class")) {
 			case 'setFont' : setFontSize(); break;
 			case 'setLiquid' : setPageWidth(); break;
 		}
 		return false;
 	});
 	// set the font size from cookie
 	var font_size = jQuery.cookie('fontSize');
 	if (font_size == '.70em') { jQuery('body').css("font-size",".70em"); }
 	if (font_size == '.95em') { jQuery('body').css("font-size",".95em"); }
 	if (font_size == '.75em') { jQuery('body').css("font-size",".75em"); }

 	// set the page width from cookie
 	var page_width = jQuery.cookie('pageWidth');
 	if (page_width) jQuery('#wrapper').css('width', page_width); 
});


// liquid <> fixed
function setPageWidth(){
 var currentWidth = jQuery('#wrapper').css('width');
 if (currentWidth=="77%") 
 	newWidth = "80%"; 
 else if (currentWidth=="80%") 
 	newWidth = "85%"; 
 else if (currentWidth=="85%") 
 	newWidth = "90%"; 
 else if (currentWidth=="90%") 
 	newWidth = "95%"; 
 else if (currentWidth=="95%") 
 	newWidth = "100%";  	
 else if (currentWidth=="100%") 
 	newWidth = "77%";  	
 else 
 	newWidth = "80%";
 jQuery("#wrapper").animate({width: newWidth}, 333).fadeIn("slow");
 jQuery.cookie('pageWidth', newWidth);
}

// body font size
function setFontSize() {
 var size = jQuery.cookie('fontSize');
 if (size=='.75em') newSize = '.95em';
 else if (size=='.95em') newSize = '.70em';
 else if (size=='.70em') newSize = '.75em';
 else newSize = '.95em';
 jQuery("body").animate({fontSize: newSize}, 333).fadeIn("slow");
 jQuery.cookie('fontSize',newSize)
}

