function MiniPreview(){}
MiniPreview.prototype = {
	init: function(pl){
		this.pl = pl;
		this.addEvents();
	},
	addEvents: function() {
		this.pl.onmouseover = as.bind(function() {
			this.preview ? this.showPreview() : this.createPreview();
		},this);
		this.pl.onmouseout = as.bind(function(){this.clear();},this);
	},
	clear: function() {
		this.noshow = true;	
	},
	createPreview: function() {
		this.preview = as.create("<div class='mini-preview-bg as-hidden'><div class='mini-preview'><a href='" + this.pl.href + "'>"+this.pl.innerHTML + "</a></div><div>");
		this.showPreview();
	},
	showPreview: function() {
		this.noshow = false;
		setTimeout(as.bind(function(){
			if (this.noshow) return;
			as.append(this.preview,document.body);		
			var cs = as.getElementPosition(this.pl);
			as.style(this.preview,{
				left: cs.left + (cs.width - this.preview.offsetWidth)/2 + "px",
				top: cs.top - this.preview.offsetHeight + 23 + "px"
			});
			this.preview.className = this.preview.className.replace(/\bas-hidden\b/,"");
			setTimeout(
				as.bind(function(){
					document.onmouseover = as.bind(function(e) {
						e = e || window.event;
						var target = e.target || e.srcElement;
						if (!as.parent(target,"div.mini-preview-bg")) {
							document.onmouseover = '';
							this.hidePreview();
						}
					},this);
				},this),0
			);
		},this),300);
	},
	hidePreview: function() {
		as.remove(this.preview);
	}
};
function miniPreviews() {
	as.foreach(as.$("a.preview-link"),function(pl){
		new MiniPreview().init(pl);
	});	
}
as.ready(miniPreviews);