LowPro = {};
LowPro.Version = '0.5';
LowPro.CompatibleWithPrototype = '1.6';

if (Prototype.Version.indexOf(LowPro.CompatibleWithPrototype) != 0 && window.console && window.console.warn)
  console.warn("This version of Low Pro is tested with Prototype " + LowPro.CompatibleWithPrototype +
                  " it may not work as expected with this version (" + Prototype.Version + ")");

if (!Element.addMethods)
  Element.addMethods = function(o) { Object.extend(Element.Methods, o) };

// Simple utility methods for working with the DOM
DOM = {};

// DOMBuilder for prototype
DOM.Builder = {
	tagFunc : function(tag) {
    return function() {
     var attrs, children;
     if (arguments.length>0) {
       if (arguments[0].constructor == Object) {
         attrs = arguments[0];
         children = Array.prototype.slice.call(arguments, 1);
       } else {
         children = arguments;
       };
       children = $A(children).flatten()
     }
     return DOM.Builder.create(tag, attrs, children);
    };
  },
	create : function(tag, attrs, children) {
		attrs = attrs || {}; children = children || []; tag = tag.toLowerCase();
		var el = new Element(tag, attrs);

		for (var i=0; i<children.length; i++) {
			if (typeof children[i] == 'string')
			  children[i] = document.createTextNode(children[i]);
			el.appendChild(children[i]);
		}
		return $(el);
	}
};

// Automatically create node builders as $tagName.
(function() {
	var els = ("p|div|span|strong|em|img|table|tr|td|th|thead|tbody|tfoot|pre|code|" +
				     "h1|h2|h3|h4|h5|h6|ul|ol|li|form|input|textarea|legend|fieldset|" +
				     "select|option|blockquote|cite|br|hr|dd|dl|dt|address|a|button|abbr|acronym|" +
				     "script|link|style|bdo|ins|del|object|param|col|colgroup|optgroup|caption|" +
				     "label|dfn|kbd|samp|var").split("|");
  var el, i=0;
	while (el = els[i++])
	  window['$' + el] = DOM.Builder.tagFunc(el);
})();

DOM.Builder.fromHTML = function(html) {
  var root;
  if (!(root = arguments.callee._root))
    root = arguments.callee._root = document.createElement('div');
  root.innerHTML = html;
  return root.childNodes[0];
};



// Wraps the 1.6 contentloaded event for backwards compatibility
//
// Usage:
//
// Event.onReady(callbackFunction);
Object.extend(Event, {
  onReady : function(f) {
    if (document.body) f();
    else document.observe('dom:loaded', f);
  }
});

// Based on event:Selectors by Justin Palmer
// http://encytemedia.com/event-selectors/
//
// Usage:
//
// Event.addBehavior({
//      "selector:event" : function(event) { /* event handler.  this refers to the element. */ },
//      "selector" : function() { /* runs function on dom ready.  this refers to the element. */ }
//      ...
// });
//
// Multiple calls will add to exisiting rules.  Event.addBehavior.reassignAfterAjax and
// Event.addBehavior.autoTrigger can be adjusted to needs.
Event.addBehavior = function(rules) {
  var ab = this.addBehavior;
  Object.extend(ab.rules, rules);

  if (!ab.responderApplied) {
    Ajax.Responders.register({
      onComplete : function() {
        if (Event.addBehavior.reassignAfterAjax)
          setTimeout(function() { ab.reload() }, 10);
      }
    });
    ab.responderApplied = true;
  }

  if (ab.autoTrigger) {
    this.onReady(ab.load.bind(ab, rules));
  }

};

Event.delegate = function(rules) {
  return function(e) {
      var element = $(e.element());
      for (var selector in rules)
        if (element.match(selector)) return rules[selector].apply(this, $A(arguments));
    }
}

Object.extend(Event.addBehavior, {
  rules : {}, cache : [],
  reassignAfterAjax : false,
  autoTrigger : true,

  load : function(rules) {
    for (var selector in rules) {
      var observer = rules[selector];
      var sels = selector.split(',');
      sels.each(function(sel) {
        var parts = sel.split(/:(?=[a-z]+$)/), css = parts[0], event = parts[1];
        $$(css).each(function(element) {
          if (event) {
            var wrappedObserver = Event.addBehavior._wrapObserver(observer);
            $(element).observe(event, wrappedObserver);
            Event.addBehavior.cache.push([element, event, wrappedObserver]);
          } else {
            if (!element.$$assigned || !element.$$assigned.include(observer)) {
              if (observer.attach) observer.attach(element);

              else observer.call($(element));
              element.$$assigned = element.$$assigned || [];
              element.$$assigned.push(observer);
            }
          }
        });
      });
    }
  },

  unload : function() {
    this.cache.each(function(c) {
      Event.stopObserving.apply(Event, c);
    });
    this.cache = [];
  },

  reload: function() {
    var ab = Event.addBehavior;
    ab.unload();
    ab.load(ab.rules);
  },

  _wrapObserver: function(observer) {
    return function(event) {
      if (observer.call(this, event) === false) event.stop();
    }
  }

});

Event.observe(window, 'unload', Event.addBehavior.unload.bind(Event.addBehavior));

// A silly Prototype style shortcut for the reckless
$$$ = Event.addBehavior.bind(Event);

// Behaviors can be bound to elements to provide an object orientated way of controlling elements
// and their behavior.  Use Behavior.create() to make a new behavior class then use attach() to
// glue it to an element.  Each element then gets it's own instance of the behavior and any
// methods called onxxx are bound to the relevent event.
//
// Usage:
//
// var MyBehavior = Behavior.create({
//   onmouseover : function() { this.element.addClassName('bong') }
// });
//
// Event.addBehavior({ 'a.rollover' : MyBehavior });
//
// If you need to pass additional values to initialize use:
//
// Event.addBehavior({ 'a.rollover' : MyBehavior(10, { thing : 15 }) })
//
// You can also use the attach() method.  If you specify extra arguments to attach they get passed to initialize.
//
// MyBehavior.attach(el, values, to, init);
//
// Finally, the rawest method is using the new constructor normally:
// var draggable = new Draggable(element, init, vals);
//
// Each behaviour has a collection of all its instances in Behavior.instances
//
var Behavior = {
  create: function() {
    var parent = null, properties = $A(arguments);
    if (Object.isFunction(properties[0]))
      parent = properties.shift();

      var behavior = function() {
        if (!this.initialize) {
          var args = $A(arguments);

          return function() {
            var initArgs = [this].concat(args);
            behavior.attach.apply(behavior, initArgs);
          };
        } else {
          var args = (arguments.length == 2 && arguments[1] instanceof Array) ?
                      arguments[1] : Array.prototype.slice.call(arguments, 1);

          this.element = $(arguments[0]);
          this.initialize.apply(this, args);
          behavior._bindEvents(this);
          behavior.instances.push(this);
        }
      };

    Object.extend(behavior, Class.Methods);
    Object.extend(behavior, Behavior.Methods);
    behavior.superclass = parent;
    behavior.subclasses = [];
    behavior.instances = [];

    if (parent) {
      var subclass = function() { };
      subclass.prototype = parent.prototype;
      behavior.prototype = new subclass;
      parent.subclasses.push(behavior);
    }

    for (var i = 0; i < properties.length; i++)
      behavior.addMethods(properties[i]);

    if (!behavior.prototype.initialize)
      behavior.prototype.initialize = Prototype.emptyFunction;

    behavior.prototype.constructor = behavior;

    return behavior;
  },
  Methods : {
    attach : function(element) {
      return new this(element, Array.prototype.slice.call(arguments, 1));
    },
    _bindEvents : function(bound) {
      for (var member in bound) {
        var matches = member.match(/^on(.+)/);
        if (matches && typeof bound[member] == 'function')
          bound.element.observe(matches[1], Event.addBehavior._wrapObserver(bound[member].bindAsEventListener(bound)));
      }
    }
  }
};



Remote = Behavior.create({
  initialize: function(options) {
    if (this.element.nodeName == 'FORM') new Remote.Form(this.element, options);
    else new Remote.Link(this.element, options);
  }
});

Remote.Base = {
  initialize : function(options) {
    this.options = Object.extend({
      evaluateScripts : true
    }, options || {});

    this._bindCallbacks();
  },
  _makeRequest : function(options) {
    if (options.update) new Ajax.Updater(options.update, options.url, options);
    else new Ajax.Request(options.url, options);
    return false;
  },
  _bindCallbacks: function() {
    $w('onCreate onComplete onException onFailure onInteractive onLoading onLoaded onSuccess').each(function(cb) {
      if (Object.isFunction(this.options[cb]))
        this.options[cb] = this.options[cb].bind(this);
    }.bind(this));
  }
}

Remote.Link = Behavior.create(Remote.Base, {
  onclick : function() {
    var options = Object.extend({ url : this.element.href, method : 'get' }, this.options);
    return this._makeRequest(options);
  }
});


Remote.Form = Behavior.create(Remote.Base, {
  onclick : function(e) {
    var sourceElement = e.element();

    if (['input', 'button'].include(sourceElement.nodeName.toLowerCase()) &&
        sourceElement.type == 'submit')
      this._submitButton = sourceElement;
  },
  onsubmit : function() {
    var options = Object.extend({
      url : this.element.action,
      method : this.element.method || 'get',
      parameters : this.element.serialize({ submit: this._submitButton.name })
    }, this.options);
    this._submitButton = null;
    return this._makeRequest(options);
  }
});

Observed = Behavior.create({
  initialize : function(callback, options) {
    this.callback = callback.bind(this);
    this.options = options || {};
    this.observer = (this.element.nodeName == 'FORM') ? this._observeForm() : this._observeField();
  },
  stop: function() {
    this.observer.stop();
  },
  _observeForm: function() {
    return (this.options.frequency) ? new Form.Observer(this.element, this.options.frequency, this.callback) :
                                      new Form.EventObserver(this.element, this.callback);
  },
  _observeField: function() {
    return (this.options.frequency) ? new Form.Element.Observer(this.element, this.options.frequency, this.callback) :
                                      new Form.Element.EventObserver(this.element, this.callback);
  }
});



WebForm = Behavior.create({
  spinner_element : $div({id : "processing_spinner"},
                      $img({src : "/images/business/loaders/loading-01.gif"})),
  onsubmit : function(e) {
    this._showSpinner();
  },
  _showSpinner : function(el) {
    $(el).hide().insert({before : this.spinner_element});
  }
});

Rotater = Class.create({

  initialize: function(container_id, element_ids) {

    this.container = $(container_id);
    this.elements  = $A(element_ids).collect(function(id) { return $(id) });

    new PeriodicalExecuter(this.swap.bind(this), 12);

    this.index = 0;

    this.element_height = this.current().getHeight();

    this.current().setStyle({ top : "0px" });

  },

  current: function() {

    return this.elements[this.index];

  },

  swap: function() {

    var last = this.current();

    this.index++;
    if (this.index >= this.elements.length) this.index = 0;

    var next = this.current();

    next.setStyle({ top : this.element_height + "px"});

    new Effect.Move(last, { y : -1 * this.element_height });
    new Effect.Move(next, { y : -1 * this.element_height });


  }


});

QuoteBox = Class.create({

  initialize: function(id) {
    this.container = $(id);

    this.quotes = this.container.select(".quote");

    this.current = this.quotes.first();
    this.current.show();

    new PeriodicalExecuter(this.swap.bind(this), 12);

  },

  swap: function() {
    
    var old = this.current;

    var i = (this.quotes.indexOf(this.current) + 1) % this.quotes.length;
    this.current = this.quotes[i];

    this.current.setStyle({ top : "230px", position : "absolute" });
    this.current.show();

    new Effect.Parallel([
    
      new Effect.Move(old,          { y : -230, duration: 1 }),
      new Effect.Move(this.current, { y : -230, duration: 1 })
    
    ]);

  },

  image: function(el) {
    if (!el) el = this.current;
    return el.down(".quote_person img");
  },

  quote: function(el) {
    if (!el) el = this.current;
    return el.down("blockquote");
  },

  name: function(el) {
    if (!el) el = this.current;
    return el.down(".name");
  }


});

Lightbox = Class.create({
  
  initialize: function(id, animate) {

    this.lightbox = $(id);
    
    this.overlay  = $("modal_overlay");
    if (!this.overlay) this.overlay = this.insert_overlay();
    
    $$("." + this.lightbox.id + "-trigger").each(function(trigger) {
      trigger.observe("click", this.toggle.bindAsEventListener(this));
    }.bind(this));
    
    this.lightbox.select(".trigger").each(function(trigger) {
      trigger.observe("click", this.toggle.bindAsEventListener(this));
    }.bind(this));
    
    this.lightbox.select("a.submit-tag").each(function(trigger) {
      trigger.observe("click", function(event) {
        this.lightbox.select("form").first().submit();
      }.bind(this));
    }.bind(this));

    this.animate = animate;

		this.current_content = false;
  },

  add_trigger: function(element) {
    element.observe("click", this.toggle.bindAsEventListener(this));
  },

  toggle: function(event) {

    if(!this.lightbox.visible()) {
      this.show(event);
    } else {
      this.hide(event);
    }

    Event.stop(event);
  },

  show: function(event) {
    
		// Get the CSS class of the content to show in the modal lightbox
		var trigger = this.find_trigger(event);
		if (trigger) {
			var content_class = trigger.id.split('_modal-trigger')[0];
		} else {
			// We need to know the content to show in the modal
			return false;
		}

    this.lightbox.setStyle({
			position : "fixed",
			left     : (($(document.body).getWidth() - this.lightbox.getWidth()) / 2) + "px"
		});

		if (this.current_content) {
	    this.lightbox.select("." + this.current_content).invoke("hide");
		}
		
	  contents = (content_class.blank()) ? [] : this.lightbox.select('.' + content_class);
    contents.invoke("show");
	  this.current_content = content_class;

    if (!this.animate) {

      this.overlay.show();
      this.lightbox.show();

    } else {

      this.overlay.setOpacity(0);
      this.overlay.show();
      this.overlay.morph("opacity:0.8", { duration : 0.5 });

      new Effect.BlindDown(this.lightbox, { duration : 0.7, scaleFrom : 10 });

    }

  },

  hide: function(event) {
    this.lightbox.hide();
    this.overlay.hide();
  },

  insert_overlay: function() {

    $(document.body).insert({ top : new Element("div", { id : "modal_overlay" }).hide() });

    return $("modal_overlay");

  },

	// Returns the CSS classname used to identify trigger elements for this lightbox
	trigger_class: function(){
		return $(this.lightbox).id + '-trigger'
	},

	// Returns the trigger element for the click event.
	find_trigger: function(event) {

		target = event.element();

		if (target.hasClassName(this.trigger_class())) {
			trigger = target;
		} else {
			trigger = $(event.target).up('.' + this.trigger_class());
		}

		return trigger;

	}
});


TabbedLightbox = Class.create(Lightbox, {

  initialize: function($super, id, animate) {

     $super(id, animate);
     
     this.lightbox.select("ul.tabs li a").invoke("observe", "click", this.change_tab.bindAsEventListener(this));

  },
  
  toggle: function($super, event) {
    
    $super(event);
    
    // select the first tab
    this.change_tab();
    
    return false;
  },

  change_tab: function(event) {
        
    // get the current container
    var container = this.lightbox.down("." + this.current_content);

    if (event) {
      var link = event.element();
    } else {
      var link = container.select("ul.tabs li a").first(); // select the first tab
    }
    
    var image_container        = container.down(".example_images");
    var channel_name_container = container.down(".channel_name");
    
    // out with the old
    container.select("ul.tabs li").invoke("removeClassName", "active");
    image_container.select("img").invoke("hide");
    channel_name_container.select("span").invoke("hide");

    // in with the new
    link.up("li").addClassName("active");

    var link_type = $w(link.className).first();
    image_container.down("img." + link_type).show();
    channel_name_container.down("span." + link_type).show();

    if (event) event.stop();
    return false;

  }

});

MarketingSiteForm = Behavior.create(WebForm, {
  _showSpinner : function($super) {
    $super(this.element.down('.button-login'));
  }
});

Event.addBehavior({
  '#flashes' : function() {
    Effect.SlideDown(this);
  },
  '#flashes:click' : function(e) {
    Effect.SlideUp(this);
    e.stop();
  },
  '#submit-account' : function() {
    if (!$('user_terms_of_service').checked) {
      this.disable();
      $('please-accept').show();
      this.up('div').setOpacity(0.6)
    }
  },
  '#terms_link:click' : function(e) {
    // $('terms_container').toggle();
    Effect.toggle('terms_container', 'slide');
    e.stop();
  },
  '#user_terms_of_service:click' : function(e) {
    Effect.toggle('please-accept', 'slide');
    if (this.checked) {
      $('submit-account').enable();
      $('submit-account').up('div').setOpacity(1)
    } else {
      $('submit-account').disable();
      $('submit-account').up('div').setOpacity(0.6)
    }
  },
  '#invite_form' : MarketingSiteForm,
  '.social_network_nav a:click' : function(e) {
    window.open(this.href)
    return false
  }
});


/**

  Simple Carousel Control

**/

SimpleCarousel = Class.create({

  default_options : $H({ window_size : 3, scroll_increment : 1, page_indicator : null }),

  initialize: function(container, options) {

    this.container = $(container);
    this.clip      = new Element("div", { "class" : "clip" });

    this.list  = this.container.down("ul");
    this.list.wrap(this.clip);

    this.items     = this.list.select("li");

    if (this.items.size() == 0) return;

    // remove nested lists
    nested_items = this.list.select("ul > li");
    this.items   = this.items.filter(function(e) {
      return (nested_items.indexOf(e) == -1);
    });

    this.prev_arrows = this.container.select(".arrow.prev");
    this.next_arrows = this.container.select(".arrow.next");

    this.arrows = this.prev_arrows.concat(this.next_arrows);

    this.options = this.default_options.merge(options);

    this.init_styles();
    this.init_page_indicators();

    this.current_index = 0;
    if (initial = this.options.get("initial_position")) this.scroll_to_position(initial, false);

    this.update_arrows();

    this.arrows.each(function(arrow) {

      arrow.observe("click", this.scroll.bindAsEventListener(this));

    }.bind(this));

    if (this.options.get("hide_arrows") && this.options.get("window_size") >= this.items.size()) {
      this.arrows.invoke("hide");
    }

  },

  init_styles: function() {

    this.clip.setStyle({ position : "relative", "overflow" : "hidden" });
    this.list.setStyle({ position : "relative", "overflow" : "hidden",
                         width    : "99999px",  left       : "0px" });


    var padding = parseInt(this.items.first().getStyle("padding-left")) +
                    parseInt(this.items.first().getStyle("padding-right"));
    var margins = parseInt(this.items.first().getStyle("margin-left") || 0) +
                      parseInt(this.items.first().getStyle("margin-right") || 0);
    var item_width = Math.ceil(this.container.getWidth() / this.options.get("window_size"));
    var inner_margins = Math.ceil(margins * (this.options.get("window_size") - 1)) / this.options.get("window_size");

    this.scroll_width = item_width + margins - inner_margins;
    this.item_width   = item_width - padding - inner_margins;

    var item_width = this.item_width + 'px';
    this.items.each(function(item, index) {
      item.setStyle({ width : item_width, cssFloat : "left" });
    })

    return;
  },

  init_page_indicators: function() {

    // create the page indicators
    if (id = this.options.get("page_indicator")) {
      this.page_indicator = $(id);
      this.number_pages   = this.items.size() / this.options.get("window_size");

      for (var i = 0; i < this.number_pages; i++) {
        var indicator_light = new Element("span");

        // For some reason IE8 does not add the className if it's passed to new Element as
        // {class:page_i} so we have to add it on its own.
        indicator_light.addClassName("page_" + i);

        indicator_light.observe("click", this.scroll_to_page_indicator.bindAsEventListener(this));
        this.page_indicator.insert({ bottom : indicator_light });
      }

    }

  },

  update_arrows: function() {
    var prev = (this.current_index == 0) ? "addClassName" : "removeClassName";
    var next = (this.current_index + this.options.get("window_size") >= this.items.size()) ? "addClassName" : "removeClassName";

    eval("this.prev_arrows.invoke('" + prev + "', 'disabled');");
    eval("this.next_arrows.invoke('" + next + "', 'disabled');");

    if (this.page_indicator) {
      this.page_indicator.select("span").invoke("removeClassName", "active");

      var current_page = Math.ceil(this.current_index / this.options.get("window_size"));
      var active = this.page_indicator.down(".page_" + current_page)
      if (active) {
        active.addClassName("active");
      }
    }

    return;
  },

  scroll: function(event) {

    // mutex so we don't do partial moves
    if (this.moving) return;
    this.moving = true;

    var direction = (event.element().hasClassName("prev")) ? -1 : 1;

    var new_position  = this.current_index + (direction * this.options.get("scroll_increment"));

    this.scroll_to_position(new_position, true);

    event.stop();
    return false;

  },

  scroll_to_page_indicator: function(event) {

    var indicator = event.element();

    var page_number = parseInt(event.element().className.gsub("page_", ""));

    this.scroll_to_position(page_number * this.options.get("window_size"), true);

  },

  scroll_to_position: function(new_position, animate) {

    var last_pos      = this.items.size() - this.options.get("window_size");

    if (new_position > last_pos) new_position = last_pos;
    if (new_position < 0) new_position = 0;

    // reached the end or the start
    if (new_position == this.current_index) {
      this.moving = false;
      return;
    }

    var offset = -1 * (this.scroll_width * (new_position - this.current_index));

    // compensate for webkit being weirdly lame
    if (Prototype.Browser.WebKit) { 
      offset = (offset < 0) ? offset + 2 : offset -2;
    }

    if (animate) {

      new Effect.Move(this.list, { x : offset, duration : 0.5,

                                  afterFinish : function() {

                                    this.undim();
                                    this.moving = false;

                                  }.bind(this) });

      this.dim();

    } else {

      var current_left = parseInt(this.list.getStyle("left"));

      this.list.setStyle({ left : (offset + current_left) + "px" });
      this.moving = false;

    }

    this.current_index = new_position;
    this.update_arrows();

    return;

  },

  dim: function() {
    this.items.invoke("setOpacity", 0.7);
  },

  undim: function() {
    this.items.invoke("setOpacity", 1);
  }


});

ToolTip = Class.create({
  initialize : function(element, klass, content) {    
    this.element = element;
    this.klass = klass;
    this.content = content;
    
    this.enable();
    
  },
  
  disable : function() {
    
    this.element.stopObserving("mouseout");
    this.element.stopObserving("mouseover");
    
  },

  enable : function() {
    
    this.element.observe("mouseover", this.showtooltip.bindAsEventListener(this));
    this.element.observe("mouseout", this.hidetooltip.bindAsEventListener(this));
    
    
  },
  
  showtooltip : function() {
            
      this.hide = false;
            
      if (this.tooltip == null) {   
        
        this.tooltip = new Element("div").addClassName("bubble").addClassName(this.klass);
        
        //add listeners to tooltip
        this.tooltip.observe("mouseover", this.showtooltip.bindAsEventListener(this));
        this.tooltip.observe("mouseout", this.hidetooltip.bindAsEventListener(this));
        
        //add tooltip internals
        var content = new Element("blockquote").addClassName("bubble_tooltip_content");
        this.tooltip.insert(content);
        var cite = new Element("cite").addClassName("bubble_cite");
        this.tooltip.insert(cite);
      
        // insert tooltip at top of document
        // body tag selector used as document.body doesnt work in IE
        $$('body').first().insert({"top" : this.tooltip});
        
        // add content
        this.tooltip.select("blockquote").first().innerHTML = this.content;
        
        // position tooltip on page
        // adding the element width only works if the element is display: block
        var leftPos = this.element.cumulativeOffset().left - this.tooltip.getWidth() / 2 + this.element.getWidth() / 2;
        if (leftPos < 0) {
          leftPos = 0;
        }

        // Keep the tooltip inside the body and adjust the bottom pointer thingy to always point at
        // the triggering element.
        var bodyWidth = $(document.body).getWidth();
        if (leftPos + this.tooltip.getWidth() > bodyWidth) {
          var arrowOffset = leftPos + this.tooltip.getWidth() - bodyWidth;
          leftPos = bodyWidth - this.tooltip.getWidth();
        } else {
          var arrowOffset = 0;
        };

        // cross browser height detection
        var content = document.body;
        var height = Math.max(
            content.scrollHeight,
            content.offsetHeight,
            content.clientHeight
        );

        var bottomPos = height - this.element.cumulativeOffset().top;
                
        this.tooltip.style.left = leftPos + 'px';
        this.tooltip.style.bottom = (bottomPos < 0 ? 0 : bottomPos) + 'px';
        
        // set position of the bottom pointer thingy
        this.tooltip.select("cite").first().style.backgroundPosition = "" + ((this.tooltip.getWidth() / 2) + arrowOffset - 5) + "px 0px";
        
        // one tooltip at a time
        if (window.tooltip != null && window.tooltip != this) {
          window.tooltip.instantRemove();
        }
        if (window.tooltip == null) {
          window.tooltip = this;
        }
      
      }
  },
  
  hidetooltip : function() {
    this.hide = true;
    setTimeout(function() {
      if (this.tooltip != null && this.hide == true) {
        this.tooltip.remove();
        this.tooltip = null;
        if (window.tooltip == this) {
          window.tooltip = null;
        }
      }
    }.bind(this), 1000);
  },
  
  instantRemove : function() {
    this.hide = false;
    this.tooltip.remove();
    this.tooltip = null;
    if (window.tooltip == this) {
      window.tooltip = null;
    }
  }
});
