
var currentTitle = "";
var currentURL = "";

var shareLink = Class.create();
shareLink.prototype = {

	element:null,
	title:null,
	url:null,
	eventMouseClick:null,
	eventMouseMove:null,
	elementWidth: 0,
	elementHeight: 0,

	initialize: function (element) {
		Element.extend(element);
		if(!element.hasClassName("notip")) {
			this.element = element;
			this.title = element.readAttribute("rel");
			this.url = element.readAttribute("href");
			//this.element.writeAttribute("href","#");
			this.eventMouseClick = this.click.bindAsEventListener(this);
			this.eventMouseMove   = this.move.bindAsEventListener(this);
			Event.observe(this.element, "mousedown", this.eventMouseClick);
			Event.observe(this.element, "mouseup", function(e){Event.stop(e);});
			Event.observe(this.element, "click", function(e){Event.stop(e);});
		}
	},

	click: function(event) {
		Event.stop(event);
		if(!$('shareTip').visible()) {
			$('shareTip').show();
			currentTitle =  this.title;
			currentURL =  this.url;
			var left = Element.cumulativeOffset(this.element).left-Element.cumulativeOffset($('page')).left;
			var top = Element.cumulativeOffset(this.element).top-Element.cumulativeOffset($('page')).top;
			var width = Element.getDimensions($('shareTip')).width;
			var height = Element.getDimensions($('shareTip')).height;

			/*if (navigator.appName=="Microsoft Internet Explorer" && navigator.appVersion.search("MSIE 6.0") !==-1){
				tempY = event.clientY + document.body.scrollTop;
				top = tempY-500;
				left = left+20;
			}*/

			Element.setStyle($('shareTip'),{left:(left+(Element.getDimensions(this.element).width-width)/2)+'px', top:(top-90)+'px'});
		}
		Event.observe(document, 'mousemove', this.eventMouseMove,false);
	},

	move: function(e) {
		if($('shareTip').visible()) {
			var left = Element.cumulativeOffset($('shareTip')).left;
			var top = Element.cumulativeOffset($('shareTip')).top;
			var width = Element.getDimensions($('shareTip')).width;
			var height = Element.getDimensions($('shareTip')).height;
			var mouseX = Event.pointerX(e);
			var mouseY = Event.pointerY(e);
			if(mouseX<left-20 || mouseX>left+width+20 || mouseY<top-20 || mouseY>top+height+20) {
				$('shareTip').hide();
				Event.stopObserving(document, 'mousemove', this.eventMouseMove,false);
			}
		}
	}

}

this.doShare = function(support) {
	//pageTracker._trackPageview('/share/'+support);
	$('shareTip').hide();
	url = sprintf(support, encodeURIComponent(currentURL), encodeURIComponent(currentTitle));
	window.open(url);
};
