function jCookie (key, value, options) {
    
    // key and at least value given, set cookie...
    if (arguments.length > 1 && String(value) !== "[object Object]") {
        options = jQuery.extend({}, options);

        if (value === null || value === undefined) {
            options.expires = -1;
        }

        if (typeof options.expires === 'number') {
            var days = options.expires, t = options.expires = new Date();
            t.setDate(t.getDate() + days);
        }
        
        value = String(value);
        
        return (document.cookie = [
            encodeURIComponent(key), '=',
            options.raw ? value : encodeURIComponent(value),
            options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
            options.path ? '; path=' + options.path : '',
            options.domain ? '; domain=' + options.domain : '',
            options.secure ? '; secure' : ''
        ].join(''));
    }

    // key and possibly options given, get cookie...
    options = value || {};
    var result, decode = options.raw ? function (s) { return s; } : decodeURIComponent;
    return (result = new RegExp('(?:^|; )' + encodeURIComponent(key) + '=([^;]*)').exec(document.cookie)) ? decode(result[1]) : null;
};
$(document).ready(function() {
  // Lazy load;
  $(".bodyleftarea img").lazyload({effect      : "fadeIn"});
  $('#hide-this a').click(function() {
    $("#hide-this").slideUp();
    jCookie("no_redirect", 1, {expires: 999});
  });

  // Detect schema type
  if(location.href.indexOf("http://") == 0) {
    var schema = "http://";
  }
  else if(location.href.indexOf("https://") == 0) {
    var schema = "https://";
  }
  else {
    // Unexpected error. Shouldn't be there in 99.99% cases
    return;
  }
  var home = schema + jCookie("HOME_URL");
  // check if the current page is homepage
  var is_home = location.href == home || location.href == home + "/" || location.href.substring(0, home.length+1) == home+"#" || location.href.substring(0, 
home.length+2) == home+"/#"|| location.href.substring(0, home.length+1) == home+"?" || location.href.substring(0, home.length+2) == home+"/?";

  // Please change this if the links' order are changed. Or please provide an unique id/class for the two links
  var options = {0: "LEADERSHIP_PATH", 1: "QUICKBASE_PATH"};
  $("#hide-this .toparealist a").each(function(i, link) {
    // We don't redirect 'Both' option
    if(i < 2) {
      $(link).click(function(){
        jCookie("home_redirect", options[i], {expires: 999});
      });
    }
    else {
      $(link).click(function(){
        jCookie("home_redirect", null);
        jCookie("no_redirect", 1, {expires: 999});
      });
    }
  });

});

