








var Bookmarking = {
	services: [
		"delicious", "stumbleupon", "google", "yahoo",
		"furl", "thisnext", "wists", "magnolia",
		"facebook", "stylehive", "kaboodle"
	],

	serviceTitles: {
		delicious:"del.icio.us",
		stumbleupon:"StumbleUpon",
		google:"Google Bookmarks",
		yahoo: "Yahoo! My Web",
		furl: "Furl",
		thisnext: "ThisNext",
		wists: "Wists",
		magnolia: "Ma.gnolia",
		facebook: "Facebook",
		stylehive: "StyleHive",
		kaboodle: "Kaboodle"
	},

	submitURLs: {
		delicious: "http://del.icio.us/post?url=[$url]&title=[$title]",
		stumbleupon: "http://www.stumbleupon.com/submit?url=[$url]&title=[$title]",
		google: "http://www.google.com/bookmarks/mark?op=edit&bkmk=[$url]&title=[$title]",
		yahoo: "http://myweb2.search.yahoo.com/myresults/bookmarklet?u=[$url]&t=[$title]",
		furl: "http://furl.net/storeIt.jsp?u=[$url]&t=[$title]",
		thisnext: "http://www.thisnext.com/pick/new/submit/bookmarklet/?url=[$url]&name=[$title]&_charset_=UTF-8",
		wists: "http://wists.com/r.php?c=null&r=[$url]&title=[$title]",
		magnolia: "http://ma.gnolia.com/bookmarklet/add?url=[$url]&title=[$title]",
		facebook: "http://www.facebook.com/share.php?u=[$url]",
		stylehive: "http://my.stylehive.com/authenticated/bookmark/bookmarkletpopup.htm?bookmark.url=[$url]&bookmark.title=[$title]",
		kaboodle: "http://www.kaboodle.com/za/additem?get=1&title=[$title]&url=[$url]"
	},

	getSubmissionURL: function(siteKey) {
		var submitUrl = this.submitURLs[siteKey];
		var rxUrl = "[$url]";
		submitUrl = submitUrl.replace(rxUrl, escape(document.location));
		//console.debug(submitUrl);

		var title = document.title;
		var rxTitle = "[$title]";
		submitUrl = submitUrl.replace(rxTitle, escape(title));
		//console.debug(submitUrl);

		return submitUrl;
	},

	buildToolbar: function() {
		if (document.getElementById) {
			var toolbar = document.getElementById('bookmark-toolbar');

			var tmpP = document.createElement('P');
			tmpP.appendChild(document.createTextNode('Bookmark & Share:'));
			toolbar.appendChild(tmpP);
				
			for (var i = 0; i < Bookmarking.services.length; i++) {
				var service = Bookmarking.services[i];
				var tempLi = document.createElement('LI');

				var tempA = document.createElement('A');
				//tempA.href = "/bookmark.aspx?serviceUrl="+escape(Bookmarking.getSubmissionURL(service))+"&url="+escape(document.location)+"&title="+escape(document.title)+"&serviceTitle="+service;
				tempA.href = Bookmarking.getSubmissionURL(service);
				tempA.target = "_blank";

				var tempImg = document.createElement('IMG');
				tempImg.src = "/i/bookmarking/" + service + ".png";
				tempImg.alt = Bookmarking.serviceTitles[service];
				tempImg.title = Bookmarking.serviceTitles[service];

				tempA.appendChild(tempImg);
				tempLi.appendChild(tempA);
				toolbar.appendChild(tempLi);
			 }
		 }
	},
	
	slideOpen: function(target) {
		target.style.width = 'auto';
		/*
		fullySupported = self.innerHeight || (document.documentElement && document.documentElement.clientHeight);
		if (fullySupported) {
			window.showEffect = new fx.AutoWidth(target, {duration: 300});
			window.showEffect.toggle();
		} else {
			target.style.width = 'auto';
		}
		*/
	},
	
	slideClosed: function (e, target) {
		if (isMouseLeaveOrEnter(e, target)) {
			target.style.width = '20px';
		}
	}
}

// 	Utility function courtesy of dynamic-tools.net:
//	http://www.dynamic-tools.net/toolbox/isMouseLeaveOrEnter/
function isMouseLeaveOrEnter(e, handler) {		
	var reltg = e.relatedTarget ? e.relatedTarget : e.type == 'mouseout' ? e.toElement : e.fromElement;
	while (reltg && reltg != handler) reltg = reltg.parentNode;
	return (reltg != handler);
}