function Shareit() {}

Shareit.hideBubble = function(){
	if(Shareit.activeBubble)
		Shareit.activeBubble.hide();
}

Shareit.showBubble = function(controlElm){
	Shareit.hideBubble();
	var bbl = controlElm.up().select('.smlink-bbl').first();	
	if(bbl){
		bbl.show();
		Shareit.activeBubble = bbl;
	}
}

Shareit.email = function(postId){
	var inputs = Shareit.activeBubble.select('input');
	if(inputs.length){
		var validators = [/^[a-z0-9\-\+\.\_]+@([a-z0-9\-]+\.)+[a-z]{2,5}$/i, /.+/]
		var isvalid = true;
		inputs.each(function(input, index){
			if(input.value.trim().match(validators[index])){
				input.removeClassName('smlink-txtfield-warn');
			}else{
				input.addClassName('smlink-txtfield-warn');
				isvalid = false;
			}
		});
		if(isvalid){
			if(postId){
				new Ajax.Request('/wp-content/plugins/shareit/bootstrap.php', {
					parameters: {
						shareit_action: 'email',
						email: inputs[0].value,
						sender: inputs[1].value,
						post: postId
					}
				})
			}
			Shareit.hideBubble();
		}
	}
	//wp-content/plugins/shareit/shareit.php
}

Shareit.activeBubble = null;

document.observe("dom:loaded", function(){
	$(document.body).observe('click', function(e){
		var elm = Event.element(e);
		if(!elm || !elm.up('.smlinks'))
			Shareit.hideBubble();
	})
});