var com = com||{};
com.wo2online = com.wo2online||{};

com.wo2online.Cookie = function() {

  /**
    reads the cookie strong as hashmap
    @method cookieStringToObject
    @private
    @returns hashmap of cookie values
  */
  function cookieStringToObject(str) {
    var i,sets = str.split('; ');
    var obj = {};
    for (i=0; i<sets.length; i++) {
      var pair = sets[i].split('=');
      obj[unescape(pair[0])] = unescape(pair[1]||pair[0]);
    }
    return obj;
  };

  /**
    @class Cookie
    @static
  */
  var Cookie = {};
  
  /**
    @method write
    @param key
    @param value
    @param {Date} expires
    @static
  */
  Cookie.write = function(key,value,expires,path) {
    var inOneYear = new Date();
    var path = (path)?';path='+path:'';
    inOneYear.setFullYear(inOneYear.getFullYear()+1);
    document.cookie = escape(key)+'='+escape(value)+path+"; expires="+(expires||inOneYear).toGMTString();
  };
  
  /**
    reads the cookie value identified by key as string, 
    @method read
    @param key
    @static
    @returns cookie value if found or undefined
  */  
  Cookie.read = function(key) {
    var cookieObj = cookieStringToObject(document.cookie);
    return cookieObj[key]||undefined;
  };
  
  /**
    drops the cookie idetified by the key
    @method drop
    @param key
    @static
  */  
  Cookie.drop = function(key,path) {
    Cookie.write(key,'',new Date(0),path);
  };
  return Cookie;
}();
