var MindTip = new Class({
	
	properties: {
		title: null,
		message: null,
		icon: null,
		target: null,
		duration: 150,
		align: 'tl',
		offset: 10,
		mouse: false
	},
	
	mousePoint: null,
	
	ie6: null,
		
	tip: null,
	tipcontent: null,
	tiptitle: null,
	tipmessage: null,
	tipbottom: null,
	
	initialize: function(b) {
		for(var a in b)this.properties[a] = b[a];
		this.create();
	},
	
	create: function() {
		this.tip = new Element('div').setProperty('class','tip-container').setStyles({opacity:0});
		this.disableSelection(this.tip);
		this.tip.fx = {up:new Fx.Morph(this.tip,{duration:this.properties.duration}),down:new Fx.Morph(this.tip,{duration:this.properties.duration})};
		this.tipcontent = new Element('div').setProperty('class','tip-top').injectInside(this.tip);
		if(this.properties.title)this.tiptitle = new Element('div').setProperty('class','tip-title').injectInside(this.tipcontent);
		if(this.properties.message)this.tipmessage = new Element('div').setProperty('class','tip-message').injectInside(this.tipcontent);
		this.tipbottom = new Element('div').injectInside(this.tip);
		if(Browser.Engine.trident) {
			this.tipcontent.setProperty('class','tip-top-gif');
			this.tipbottom.setProperty('class','tip-bottom-gif');
		} else {
			this.tipcontent.setProperty('class','tip-top-png');
			this.tipbottom.setProperty('class','tip-bottom-png');
		}
		this.container().addEvent('mouseenter',function(e){
			this.mousePoint = e.client;
		}.bind(this));
		if(this.properties.title)this.createTitle();
		if(this.properties.message)this.createMessage();
		if(this.properties.target)
			this.move();
		this.tip.injectInside(document.body);
		window.addEvent('resize',this.move.bind(this));
	},
	
	move: function() {
		var z = this.tip.getSize();
		var e = {x:0,y:0};
		if(this.properties.mouse&&this.mousePoint) {
			e.x = this.mousePoint.x-35;
			e.y = this.mousePoint.y-z.y-10;	
		} else {
			var e = this.properties.target.getPosition();
			var s = this.properties.target.getSize();
			switch(this.properties.align) {
				case 'tl':e.x=e.x-15;e.y=(e.y-z.y+this.properties.offset);break;
				case 'tr':e.x=e.x+s.x-35;e.y=(e.y-z.y+this.properties.offset);break;
				case 'tc':e.x=(e.x+s.x*0.5)-28;e.y=(e.y-z.y+this.properties.offset);break;
			}
		}
		this.tip.setStyles({left:e.x,top:e.y});
	},
	
	createTitle: function() {
		this.tiptitle.setProperty('html',this.properties.title);
	},
	
	createMessage: function() {
		this.tipmessage.setProperty('html',this.properties.message);
	},
	
	show: function() {
		this.move();
		if(this.tip.fx.down)this.tip.fx.down.cancel();
		this.tip.fx.up.start({opacity:1});
	},
	
	hide: function() {
		if(this.tip.fx.up)this.tip.fx.up.cancel();
		this.tip.fx.down.start({opacity:0});
	},
	
	container: function() {
		return this.tip;
	},
	
	disableSelection: function(item) {
		item.onselectstart = function() {
			return false;
		};
		item.unselectable = "on";
		item.style.MozUserSelect = "none";
		item.style.cursor = "default";
	}
	
});