_union_fontsize = Class.create(
{
    stylesheets: [ "default_big",
                   "contenttab_big",
                   "ufo_relaunch_big",
                   "ufo_relaunch",
                   "pk_compat_big",
                   "pk_compat",
                   "ie_big",
                   "ie6_big",
                   "ie7_big",
                   "defaultCSS_big" ],

	/*
	 * Write a cookie
	 * name: Name of cookie
	 * value: Value of cookie
	 * hours: Expire time in hours. No expire if not set.
	 */
	createCookie: function(name,value,hours)
	{
	  var expires;
	
	  if (hours)
	  {
	    var date = new Date();
	    date.setTime(date.getTime()+((60*60*1000)*hours));
	    expires = "; expires="+date.toGMTString();
	  }
	  else
	  {
	    expires = "";
	  }
	
	  document.cookie = name+"="+value+expires+"; path=/";
	
	},
	
	/*
	 * Read a cookie
	 * name: name of wanted cookie
	 */
	readCookie: function(name)
	{
	  var nameEQ = name + "=";
	  var ca = document.cookie.split(';');
	
	  for(var i = 0; i < ca.length; 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;
	},

    switchClass: function(elem, fromClass, toClass)
    {
      if (elem && elem.hasClassName(fromClass))
      {
        elem.removeClassName(fromClass);
        elem.addClassName(toClass);
      }
    },

    /*
     * fontsize
     */

    setFontSize: function(big)
    {
      var i;
      var names = this.stylesheets;

      for (i = 0; i < names.length; i++)
      {
        var elem = $(names[i]);
        if (! elem)
          continue;

        if (names[i].indexOf("_big") > -1)
        {
          elem.disabled = ! big;
        }
        else
        {
          elem.disabled = big;
        }
      }

      if (big)
      {
        this.switchClass($('font-small-icon'), "font-small-active", "font-small");
        this.switchClass($('font-large-icon'), "font-large", "font-large-active");
      }
      else
      {
        this.switchClass($('font-small-icon'), "font-small", "font-small-active");
        this.switchClass($('font-large-icon'), "font-large-active", "font-large");
      }

      this.createCookie("bigfont", (big == true) ? "1" : "0");
      if (typeof(scriptMe) != "undefined" &&
          typeof(scriptMe.utils) != "undefined")
      {
        scriptMe.fireCallback("fontresize");
      }
     },
	
	fontPlus: function()
	{
	  this.setFontSize(true);
	},
	
	fontMinus: function()
	{
	  this.setFontSize(false);
	},


    initialize: function()
    {
        var bigfont = this.readCookie("bigfont");
        if (bigfont == "1")
            this.fontPlus();
        else
            this.fontMinus();
    }

});

union_fontsize = new _union_fontsize();

