// JavaScript Document
var PopupTip = new Class({
    Extends: Popup,
    canstop: true,
    position: 'top',
    
    initialize: function(adoptElement, _title, _height, _position){
        this.parent({'title': _title, 'width': 243, 'height': _height, 'adoptElement': adoptElement, 'add_close_button': false});
        if ($defined(_position)) {
        	this.position = _position;
        }
    },
    
    show: function (sender) {
      var x = sender.getPosition().x;
      if (this.position == 'top') {
    	  var y = sender.getPosition().y - this.options.height + $('full_width_container').getScroll().y;
      } else if(this.position == 'bottom') {
    	  var y = sender.getPosition().y + 20;
      } else if(this.position == 'top left') {
    	  var x = sender.getPosition().x - this.options.width;
    	  var y = sender.getPosition().y - this.options.height + $('full_width_container').getScroll().y;
    	  
      }
      this.setPosition(x, y);
      this.popupElement.set('tween', {duration: 'short'});

      this.popupElement.fade('in');
      
      var self=this;
	  
      sender.addEvent('mouseout', function() {
    	  self.canstop = true;
    	  setTimeout(function(){ self.tryclose(); },100);
      });
      
      this.popupElement.addEvent('mouseout', function() {
    	  self.canstop = true;
    	  setTimeout(function(){ self.tryclose(); },100);
      });

      this.popupElement.addEvent('mouseover', function() {
    	  self.canstop = false;
      });


    },
    
    tryclose: function() {
    	if (this.canstop) {
    		this.close();
    	}
    },
    
    close: function() {
      this.popupElement.fade('out');
    }    
    
    
});