_dialog = {
  minSize : .8,
  maxSize : 1.5,
  currentSize : 1,
  init : false,
  cookieName : 'rex_js_scripts',
	cookieValDevider : '-/VALUE/-',
  cookieItemDevider : '-/ITEM/-',

  _init : function(){
    if(this.init) return false;
    
    if($('header'))
    {
      box = new Element('div#resize-font').inject($('header'));;
      
      new Element('a.resize-minus')
      .set('html','-')
      .set('href','javascript:void(0)')
      .addEvent('click',function(){
        this._setSize(-1);
      }.bind(this))
      .inject(box);

      new Element('a.resize-plus')
      .set('html','+')
      .set('href','javascript:void(0)')
      .addEvent('click',function(){
        this._setSize(1);
      }.bind(this))
      .inject(box);

    }
    size = this._readCookie('fontsize');
    if(size)
    {
      this.currentSize = parseFloat(size);
      this._setSize(0);
    }
    this.init = true;
  },
  
  _setSize : function(dir)
  {
    this.currentSize += dir/10;
    if(this.currentSize < this.minSize) this.currentSize = this.minSize;
    else if(this.currentSize > this.maxSize) this.currentSize = this.maxSize;
    
    $$('body')[0].setStyle('font-size',.625*this.currentSize+'em');
    this._writeCookie('fontsize',this.currentSize);
  },
  
  _readAllCookieVars : function()
  {
    variables = {};
    
    if(cookie = Cookie.read(this.cookieName))
    {
      values = cookie.split(this.cookieValDevider);
      cookie = new Object();
      
      for(j=0; j<values.length; j++)
      {
        value = values[j];
        name = value.substring(0,value.indexOf('='));
        value = value.substring(value.indexOf('=')+1);
        variables[name] = value;
      }
    }
    
    return variables; 
  },
  
  _readCookie : function(cookiename)
  {
    if(typeOf('cookiename')!='string') return null;
    
    variables = this._readAllCookieVars();
    
    if(variables[cookiename]!=null) return variables[cookiename];
    else return null;
  },
  
  _writeCookie :  function(cookiename,cookievalue)
  {
    if(typeOf('cookiename')!='string') return null;
    
    variables = this._readAllCookieVars();
    
    variables[cookiename] = cookievalue;
    
    cookie = new Array();
    
    for(var prop in variables)
      if(variables[prop]!=null) cookie.push(prop+'='+variables[prop]);
      
    if(cookie.length>0)
    {
      cookie = cookie.join(this.cookieValDevider);
      Cookie.write(this.cookieName, cookie);
    }
    else
    {
      Cookie.dispose(this.cookieName);
    }    
  }  
}

window.addEvent('domready',function(){
  _dialog._init();
});
