var XETagStore = Class.create();
XETagStore.createLinks= function(text) {
	var linkTemplate = new Template("<ul>" +
			"<li class='flickr'><a href='http://flickr.com/photos/tags/#{name}/'>View photos tagged '#{name}' on Flickr</a></li>" +
			"<li class='youtube'><a href='http://youtube.com/results?search_query=#{name}&search=tag'>View videos tagged '#{name}' on YouTube</a></li>" +
			"<li class='wikipedia'><a href='http://en.wikipedia.org/wiki/Special:Search?search=#{name}&fulltext=Search'>Search Wikipedia for '#{name}'</a></li>" +
			"<li class='delicious'><a href='http://del.icio.us/tag/#{name}'>View bookmarks tagged '#{name}' on del.icio.us</a></li>" +
			"<li><a href='"+document.baseURI+"tags/#{name}'>Search for pages tagged '#{name} on this site</a></li>" +
			"</ul>");
  return linkTemplate.evaluate({name: text});
}

XETagStore.applyTo("div.XETagStore");

XETagStore.prototype = {
	tagstore: null,
	initialize: function() {
		Element.extend(this);
		this.tagstore = this.down('.tagstore');
		this.initLinks();
	},
	initLinks: function() {
		var links = Element.getElementsBySelector(this, 'a[rel="tag"]');
		links.each(function(i) {
      new Tip(i, XETagStore.createLinks(i.textContent), {rollOver: true, effect: "appear", hook: {target: "bottomRight", tip: "topLeft"}});
    });
	},
	
  ExecuteForm: function(form) {
  	var me = this;
    Form.request(form, {
    	onSuccess: function(req) {
    		me.tagstore.update(req.responseText);
    		new Effect.Highlight(me.tagstore);
    		me.initLinks();
    		form.Tags.clear();
    	}
    });
    return false;
  }
};