// Profile tabs 
var tab_masks = {
'apps':          512
}

// Group tabs
var group_tab_masks = {
'apps':        65536
}
//...

/////------/////



function collapseBox(id, container, dopen, dclose, group){
  var box = ge(id);
  if (!box) return;
  
  var masks = (group) ? group_tab_masks : tab_masks;
  var cookie_key = (group) ? 'group_closed_tabs' : 'closed_tabs';
      
  var c = geByClass("slMenu", box)[0];
  if (!c) return;
  var newClass = isVisible(c) ? "RP_hide" : "RP";
  if (slideToggle(c, 300, function() {}))
  {
    container.className=newClass;
  }

  if(id=='apps1')
  {
    if(isVisible(c))
        {
            document.cookie="block1=0";
        }
    else
        {
            document.cookie="block1=1";
        }
  }

  if(id=='apps2')
  {
    if(isVisible(c))
        {
            document.cookie="block2=0";
        }
    else
        {
            document.cookie="block2=1";
        }
  }

  return false;
}

function ge() {
  var ea;
  for (var i = 0; i < arguments.length; i++) {
    var e = arguments[i];
    if (typeof e == 'string')
      e = document.getElementById(e);
    if (arguments.length == 1)
      return e;
    if (!ea)
      ea = new Array();
    ea.push(e);
  }
  return ea;
}


function geByClass(searchClass, node, tag) {
  var classElements = new Array();
  if ( node == null )
          node = document;
  if ( tag == null )
          tag = '*';
  if (node.getElementsByClassName) {
    classElements = node.getElementsByClassName(searchClass);
    if (tag != '*') {
      for (i = 0; i < classElements.length; i++) {
        if (classElements.nodeName == tag)
          classElements.splice(i, 1);
      }
    }
    return classElements;
  }
  var els = node.getElementsByTagName(tag);
  var elsLen = els.length;
  var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
  for (i = 0, j = 0; i < elsLen; i++) {
    if ( pattern.test(els[i].className) ) {
      classElements[j] = els[i];
      j++;
    }
  }
  return classElements;
}

function isVisible(elem) {
 elem = ge(elem);
 return getStyle(elem, 'display') != 'none' && getStyle(elem, 'visibility') != 'hidden';
}


// Get computed style
function getStyle(elem, name, force) {
  if (force === undefined) force = true;
  if (!force) {
    return elem.style[name];
  }
  if (name == "width" || name == "height") {
    return getSize(elem, true)[({'width':0, 'height':1})[name]] + 'px';
  }
  var ret, defaultView = document.defaultView || window;
  if (defaultView.getComputedStyle) {
    name = name.replace( /([A-Z])/g, "-$1" ).toLowerCase();
    var computedStyle = defaultView.getComputedStyle( elem, null );
      if (computedStyle)
        ret = computedStyle.getPropertyValue(name);
  } else if (elem.currentStyle) {
    if (name == 'opacity' && browser.msie) {
      var filter = elem.currentStyle['filter'];
      return filter && filter.indexOf("opacity=") >= 0 ?
        (parseFloat(filter.match(/opacity=([^)]*)/)[1] ) / 100) + '' : '1';
    }
    var camelCase = name.replace(/\-(\w)/g, function(all, letter){
      return letter.toUpperCase();
    });
    ret = elem.currentStyle[name] || elem.currentStyle[camelCase];
    // If we're not dealing with a regular pixel number
    // but a number that has a weird ending, we need to convert it to pixels
    if ( !/^\d+(px)?$/i.test( ret ) && /^\d/.test( ret ) ) {
      // Remember the original values
      var left = style.left, rsLeft = elem.runtimeStyle.left;

      // Put in the new values to get a computed value out
      elem.runtimeStyle.left = elem.currentStyle.left;
      style.left = ret || 0;
      ret = style.pixelLeft + "px";

      // Revert the changed values
      style.left = left;
      elem.runtimeStyle.left = rsLeft;
    }
  }
  return ret;
}



function show(elem) {
  if (arguments.length > 1) {
    for (var i = 0; i < arguments.length; i++) {
      show(arguments[i]);
    }
    return;
  }
  elem = ge(elem);
  if (!elem) return;
  var old = data(elem, "olddisplay");
  elem.style.display = old || "";

  if (getStyle(elem, 'display') == "none" ) {
    if (elem.tagName.toLowerCase() == 'tr' && !browser.msie) {
      elem.style.display = 'table-row';
    } else if (elem.tagName.toLowerCase() == 'table' && !browser.msie) {
      elem.style.display = 'table';
    } else {
      elem.style.display = data(elem, "olddisplay", "block");
    }
  }
}

function hide(elem){
  if (arguments.length > 1) {
    for (var i = 0; i < arguments.length; i++) {
      hide(arguments[i]);
    }
    return;
  }
  elem = ge(elem);
  if (!elem) return;
  if (getStyle(elem, 'display') != "none")
    data(elem, "olddisplay", elem.style.display);
  elem.style.display = "none";
}

function toggle(elem) {
  if (isVisible(elem)) {
    hide(elem);
  } else {
    show(elem);
  }
}


function getSize(elem, woBounds) {
  var s = [0, 0];
  if (elem == document) {
    s =  [Math.max(
        document.documentElement["clientWidth"],
        document.body["scrollWidth"], document.documentElement["scrollWidth"],
        document.body["offsetWidth"], document.documentElement["offsetWidth"]
      ), Math.max(
        document.documentElement["clientHeight"],
        document.body["scrollHeight"], document.documentElement["scrollHeight"],
        document.body["offsetHeight"], document.documentElement["offsetHeight"]
      )];
  } else if (elem){
    function getWH() {
      s = [elem.offsetWidth, elem.offsetHeight];
      if (!woBounds) return;
      var padding = 0, border = 0;
      each(s, function(i, v) {
        var which = i ? ['Top', 'Bottom'] : ['Left', 'Right'];
        each(which, function(){
          s[i] -= parseFloat(getStyle(elem, "padding" + this)) || 0;
          s[i] -= parseFloat(getStyle(elem, "border" + this + "Width")) || 0;
        });
      });
      s = [Math.round(s[0]), Math.round(s[1])];
    }
    if (!isVisible(elem)) {
      var props = {position: "absolute", visibility: "hidden", display:"block"};
      var old = {};
      each(props, function(i, val){
        old[i] = elem.style[i];
        elem.style[i] = val;
      });
      getWH();
      each(props, function(i, val){
        elem.style[i] = old[i];
      });
    } else getWH();

  }
  return s;
}


Function.prototype.bind = function(object) {
  var __method = this;
  return function() {
    return __method.apply(object, arguments);
  }
};
function isFunction(obj) {return Object.prototype.toString.call(obj) === "[object Function]"; }
function isArray(obj) { return Object.prototype.toString.call(obj) === "[object Array]"; }
function now() { return +new Date; }
function trim(text) { return (text || "").replace(/^\s+|\s+$/g, ""); }
function stripHTML(text) { return text.replace(/<(?:.|\s)*?>/g, ""); }
function escapeRE(s) { return s.replace(/[.*+?^${}()|[\]\/\\]/g, '\\$0'); }

/**
 *  Arrays, objects
 **/

function each(object, callback) {
  var name, i = 0, length = object.length;

  if ( length === undefined ) {
    for ( name in object )
      if ( callback.call( object[ name ], name, object[ name ] ) === false )
        break;
  } else
    for ( var value = object[0];
      i < length && callback.call( value, i, value ) !== false; value = object[++i] ){}

  return object;
};
function indexOf(arr, value, from) {
  from = (from == null) ? 0 : from;
  var m = arr.length;
  for(var i = from; i < m; i++)
    if (arr[i] == value)
       return i;
   return -1;
}

function clone(obj) {
  var newObj = {};
  for (var i in obj) {
    newObj[i] = obj[i];
  }
  return newObj;
}


// Extending object by another
function extend() {
  // copy reference to target object
  var target = arguments[0] || {}, i = 1, length = arguments.length, deep = false, options;

  // Handle a deep copy situation
  if (typeof target === "boolean") {
    deep = target;
    target = arguments[1] || {};
    // skip the boolean and the target
    i = 2;
  }

  // Handle case when target is a string or something (possible in deep copy)
  if (typeof target !== "object" && !isFunction(target))
    target = {};

  // return target object if only one argument is passed
  if (length == i) {
    return target;
  }

  for (; i < length; i++)
    // Only deal with non-null/undefined values
    if ((options = arguments[i]) != null)
      // Extend the base object
      for (var name in options) {
        var src = target[name], copy = options[name];

        // Prevent never-ending loop
        if (target === copy)
          continue;

        // Recurse if we're merging object values
        if (deep && copy && typeof copy === "object" && !copy.nodeType)
          target[name] = extend(deep,
            // Never move original objects, clone them
            src || (copy.length != null ? [] : { })
          , copy);

        // Don't bring in undefined values
        else if (copy !== undefined)
          target[name] = copy;
      }

  // Return the modified object
  return target;
}


/**
 * CSS classes
 **/


function setStyle(elem, name, value){
  elem = ge(elem);
  if (name == 'opacity'){
    if (browser.msie) {elem.style.filter = "alpha(opacity=" + value*100 + ")"; elem.style.zoom = 1; };
    elem.style.opacity = value;
  } else elem.style[name] = typeof(value) == 'number' && !(/z-?index|font-?weight|opacity|zoom|line-?height/i).test(name) ? value + 'px': value;
}

/**
 * Store data connected to element
 **/

var expand = "VK" + now(), vk_uuid = 0, vk_cache = {};

// Get or set element data
function data(elem, name, data) {
  var id = elem[ expand ], undefined;
  if ( !id )
    id = elem[ expand ] = ++vk_uuid;

  if (name && !vk_cache[id])
    vk_cache[id] = {};

  if (data !== undefined)
    vk_cache[id][name] = data;

  return name ?
    vk_cache[id][name] :
    id;
}

/**
 * Simple FX
 **/
function animate(el, params, speed, callback) {
  el = ge(el);
  var options = extend({}, typeof speed == 'object' ? speed : {duration: speed, onComplete: callback || function(){}});
  var tween = data(el, 'tween');
  if (tween) {
    tween.setOptions(options);
  } else {
    tween = data(el, 'tween', new Fx.Base(el, options));
  }
  return tween.custom(params);
}

function fadeTo(el, speed, to, callback) {return animate(el, {opacity: to}, speed, callback);}

var Fx = fx = {};

Fx.Transitions = {
  linear: function(t, b, c, d) { return c*t/d + b; },
  sineInOut: function(t, b, c, d) { return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b; }
};

Fx.Attrs = [
  [ "height", "marginTop", "marginBottom", "paddingTop", "paddingBottom" ],
  [ "width", "marginLeft", "marginRight", "paddingLeft", "paddingRight" ],
  [ "opacity" ]
];

function genFx(type, num){
  var obj = {};
  each( Fx.Attrs.concat.apply([], Fx.Attrs.slice(0,num)), function(){
    obj[this] = type;
  });
  return obj;
};

// Shortcuts for custom animations
each({slideDown: genFx('show', 1),
 slideUp: genFx('hide', 1),
 slideToggle: genFx('toggle', 1),
 fadeIn: {opacity: 'show'},
 fadeOut: {opacity: 'hide'},
 fadeToggle: {opacity: 'toggle'}}, function(f, val){
 window[f] = function(el, speed, callback){return animate(el, val, speed, callback);}
});


Fx.Base = function(el, options){
  this.element = ge(el);
  this.setOptions(options);
  this.now = {};
};
Fx.Base.prototype = {

  setOptions: function(options){
    if (this.isTweening()) return;
    this.options = extend({
      onComplete: function(){},
      transition: Fx.Transitions.sineInOut,
      duration: 500
    }, options || {});
  },

  step: function(){
    var time = new Date().getTime();
    if (time < this.time + this.options.duration){
      this.cTime = time - this.time;
      this.setNow();
    } else {
      setTimeout(this.options.onComplete.bind(this, this.element), 10);
      this.clearTimer();
      this.now = this.to;
      if (this.options.hide) hide(this.element);
      if (this.options.hide || this.options.show) {
        this.now = this.options.orig;
      }
      this.increase();
      return false;
    }
    this.increase();
    return true;
  },

  setNow: function(){
    for (p in this.from) {
      if (isArray(this.to[p])) // color fx
        this.now[p] = [Math.min(parseInt(this.compute(this.from[p][0], this.to[p][0])), 255), Math.min(parseInt(this.compute(this.from[p][1], this.to[p][1])), 255), Math.min(parseInt(this.compute(this.from[p][2], this.to[p][2])), 255)];
      else
        this.now[p] = this.compute(this.from[p], this.to[p]);
    }
  },

  compute: function(from, to){
    var change = to - from;
    return this.options.transition(this.cTime, from, change, this.options.duration);
  },

  clearTimer: function(){
    clearInterval(this.timer);
    this.timer = null;
    return this;
  },

  _start: function(from, to){
    if (this.timer) return;
    this.from = from;
    this.to = to;
    this.time = new Date().getTime();
    if (this.step()) this.timer = setInterval(this.step.bind(this), 13);
    return this;
  },

  increase: function(){
    for (var p in this.now) {
      if (isArray(this.now[p])) setStyle(this.element, p, 'rgb(' + this.now[p].join(',') + ')');
      else setStyle(this.element, p, this.now[p]);
    }
  },

  isTweening: function() {
    return this.timer ? true : false;
  },

  custom: function(prop){
    if (this.isTweening()) return false;

    var from = {}, to = {}, visible = isVisible(this.element), from_val, self = this;

    self.options.show = self.options.hide = false;
    self.options.orig = {};

    for (p in prop) {
      if (prop[p] == 'show' && visible || prop[p] == 'hide' && !visible)
        return this.options.onComplete.call(this, this.element);
    }
    each(prop, function(name, val){
     if (/backgroundColor|borderBottomColor|borderLeftColor|borderRightColor|borderTopColor|color|outlineColor/.test(name)) {
      from_val = getColor(self.element, name);
      val = getRGB(val);
     } else {
      from_val = parseFloat(getStyle(self.element, name)) || 0;
      val = val == 'toggle' ? visible ? 'hide' : 'show' : val;
      if (val == 'show') {
        self.options.show = true;
        val = from_val;
        from_val = (name == "width" || name == "height" ? 1 : 0);
        show(self.element);
      } else if (val == 'hide') {
        self.options.hide = true;
        val = 0;
      } else {
        var parts = val.toString().match(/^([\d+-.]+)(.*)$/);
        val = parts ? parseFloat(parts[1]) : val;
      }
      if (self.options.hide || self.options.show)
        self.options.orig[name] = getStyle(self.element, name, false);

      if ((name == "height" || name == "width") && self.element.style) {
        self.element.style.overflow = 'hidden';
        self.element.style.display = 'block';
      }
      if (name == "opacity" && val > 0 && !visible) {
        setStyle(self.element, 'opacity', 0);
        from_val = 0;
        show(self.element);
      }
     }
     if (from_val != val || (isArray(from_val) && from_val.join(',') == val.join(','))) {
      from[name] = from_val;
      to[name] = val;
     }
    });
    return this._start(from, to);
  }
};


///////////////////////////---------------------///////////////

