/* *******************************************************
J  a  v  a  c  a  t  z
Filename:   socialbookmark.js
Purpose:    This file is created to hold the scripts
            to generate javacatzSocialBookmark layer.
            Please do not put other codes in this file.
			Need Prototype.js & Scriptaculous.js
Created by: KY 2009.11.05
Modified by: KY 2010.05.13
******************************************************* */

var javacatzSocialBookmark = {
	version: '1.2.2010.05.13',
	currentNode: null,
	skipList: new Hash(),
	init: function() {
		if(!Prototype || parseFloat(Prototype.Version) < 1.6) return;
		var url = encodeURIComponent(document.location);
		var title = encodeURIComponent(document.title);
		var layer = new Element('div', { 'id':'layer-javacatzSocialBookmark' }).hide();
		$$('body')[0].insert({'bottom':layer});
		var innerLayer = new Element('div', { 'class':'padding' });
		$(layer).update(innerLayer);
		$(innerLayer).insert(new Element('div', { 'class':'title' }).update('Share/Bookmark this page').insert(new Element('div', { 'class':'closeButton', title:'Close' }).update('&times;').observe('click', function() { javacatzSocialBookmark.toggle(); })));
		// build up social bookmarking list
		var sbList = new Element('ul');
		$(innerLayer).insert(sbList);
		if(!javacatzSocialBookmark.skipList.get('delicious')) $(sbList).insert(new Element('li').update(new Element('a', { 'class':'delicious', 'title':'Del.icio.us', 'target':'_blank' }).update('<span>Del.icio.us</span>').writeAttribute('href','http://del.icio.us/post?url=' + url + '&title=' + title)));
		if(!javacatzSocialBookmark.skipList.get('digg')) $(sbList).insert(new Element('li').update(new Element('a', { 'class':'digg', 'title':'Digg', 'target':'_blank' }).update('<span>Digg</span>').writeAttribute('href','http://digg.com/submit?phase=2&url=' + url + '&title=' + title)));
		if(!javacatzSocialBookmark.skipList.get('facebook')) $(sbList).insert(new Element('li').update(new Element('a', { 'class':'facebook', 'title':'Facebook', 'target':'_blank' }).update('<span>Facebook</span>').writeAttribute('href','http://www.facebook.com/share.php?u=' + url)));
		if(!javacatzSocialBookmark.skipList.get('google')) $(sbList).insert(new Element('li').update(new Element('a', { 'class':'google', 'title':'Google Bookmarks', 'target':'_blank' }).update('<span>Google Bookmarks</span>').writeAttribute('href','http://www.google.com/bookmarks/mark?op=edit&bkmk=' + url + '&title=' + title)));
		if(!javacatzSocialBookmark.skipList.get('linkedin')) $(sbList).insert(new Element('li').update(new Element('a', { 'class':'linkedin', 'title':'LinkedIn', 'target':'_blank' }).update('<span>LinkedIn</span>').writeAttribute('href','http://www.linkedin.com/shareArticle?mini=true&url=' + url + '&title=' + title)));
		if(!javacatzSocialBookmark.skipList.get('myspace')) $(sbList).insert(new Element('li').update(new Element('a', { 'class':'myspace', 'title':'MySpace', 'target':'_blank' }).update('<span>MySpace</span>').writeAttribute('href','http://www.myspace.com/Modules/PostTo/Pages/?u=' + url + '&t=' + title)));
		if(!javacatzSocialBookmark.skipList.get('newsvine')) $(sbList).insert(new Element('li').update(new Element('a', { 'class':'newsvine', 'title':'Newsvine', 'target':'_blank' }).update('<span>Newsvine</span>').writeAttribute('href','http://www.newsvine.com/_tools/seed&save?u=' + url + '&h=' + title)));
		if(!javacatzSocialBookmark.skipList.get('reddit')) $(sbList).insert(new Element('li').update(new Element('a', { 'class':'reddit', 'title':'Reddit', 'target':'_blank' }).update('<span>Reddit</span>').writeAttribute('href','http://reddit.com/submit?url=' + url + '&title=' + title)));
		if(!javacatzSocialBookmark.skipList.get('stumbleupon')) $(sbList).insert(new Element('li').update(new Element('a', { 'class':'stumbleupon', 'title':'StumbleUpon', 'target':'_blank' }).update('<span>StumbleUpon</span>').writeAttribute('href','http://www.stumbleupon.com/submit?url=' + url + '&title=' + title)));
		if(!javacatzSocialBookmark.skipList.get('twitter')) $(sbList).insert(new Element('li').update(new Element('a', { 'class':'twitter', 'title':'Twitter', 'target':'_blank' }).update('<span>Twitter</span>').writeAttribute('href','http://twitthis.com/twit?url=' + url + '&title=' + title)));
		if(!javacatzSocialBookmark.skipList.get('windowslive')) $(sbList).insert(new Element('li').update(new Element('a', { 'class':'windows-live', 'title':'Windows Live', 'target':'_blank' }).update('<span>Windows Live</span>').writeAttribute('href','https://favorites.live.com/quickadd.aspx?marklet=1&mkt=en-us&url=' + url + '&title=' + title + '&top=1')));
		if(!javacatzSocialBookmark.skipList.get('yahoo')) $(sbList).insert(new Element('li').update(new Element('a', { 'class':'yahoo', 'title':'Yahoo!', 'target':'_blank' }).update('<span>Yahoo!</span>').writeAttribute('href','http://myweb.yahoo.com/myresults/bookmarklet?t=' + title + '&u=' + url + '&ei=UTF')));
		
		// powered by Javacatz
		var poweredByJavacatz = new Element('div', { 'class':'poweredByJavacatz' }).update(new Element('a', { 'href':'http://www.javacatz.com/', 'target':'_blank', 'title':'Javacatz' }).update('Powered by Javacatz')).insert({'top': new Element('div', { 'class':'notice' }).update('All logos belong to their rightful owners')});
		$(innerLayer).insert(poweredByJavacatz);
		
		window.onresize = javacatzSocialBookmark.onResize;
	},
	toggle: function(node) {
		javacatzSocialBookmark.currentNode = node;
		if($(node) && !$('layer-javacatzSocialBookmark').visible()) $('layer-javacatzSocialBookmark').setStyle({
			'left':$(node).cumulativeOffset().left + 'px',
			'top':$(node).getOffsetParent().cumulativeOffset().top + $(node).getOffsetParent().getHeight() + 2 + 'px'
		});
		new Effect.toggle($('layer-javacatzSocialBookmark'), 'appear', { 'duration':0.3, afterSetup: function() {
			if($('layer-javacatzSocialBookmark').cumulativeOffset().left + $('layer-javacatzSocialBookmark').getWidth() > $('layer-javacatzSocialBookmark').getOffsetParent().getWidth()) {
				$('layer-javacatzSocialBookmark').setStyle({ 'left':'auto', 'right':'10px' });
			}
		} });
	},
	onResize: function() {
		var node = javacatzSocialBookmark.currentNode;
		if($(node) && $('layer-javacatzSocialBookmark')) $('layer-javacatzSocialBookmark').setStyle({
			'left':$(node).cumulativeOffset()[0] + 'px',
			'top':$(node).getOffsetParent().cumulativeOffset().top + $(node).getOffsetParent().getHeight() + 2 + 'px'
		});
		if($('layer-javacatzSocialBookmark').cumulativeOffset().left + $('layer-javacatzSocialBookmark').getWidth() > $('layer-javacatzSocialBookmark').getOffsetParent().getWidth()) {
			$('layer-javacatzSocialBookmark').setStyle({ 'left':'auto', 'right':'10px' });
		}
	}
};
