﻿// --------------------------------------------------------------------
// Author  : mashimonator
// Create  : 2009/01/19
// Update  : 2009/01/20
// Description : 各SBMサービスの登録ボタンを自動で配置する
// --------------------------------------------------------------------
var bookmark ="<a><img style=\"CURSOR: hand\" onclick=\"addfavorite()\" src=\"/css/images/bookmark/favorite_ico.gif\" width=\"16\" height=\"16\" alt=\"お気に入りに登録\" border=\"0\" /></a>"
var sbm = {

	//-----------------------------------------
	// 設定値
	//-----------------------------------------
	conf : {

		hatenaFlg : 1,             // はてなブックマーク
		livedoorFlg : 1,           // livedoorクリップ
		yahooFlg : 1,              // Yahooブックマーク
		googleFlg : 1,             // Googleブックマーク
		niftyFlg : 1,              // @niftyクリップ
		deliciousFlg : 1,          // del.icio.us
		technoratiFlg : 1,         // テクノラティ
		fc2Flg : 1,                // fc2ブックマーク
		pookmarkFlg : 1,           // POOKMARK Airline
		choixFlg : 1,              // choix

		targetTag : 'p',           // 挿し込み対象の要素名
		targetCls : 'bookmark'      // 挿し込み対象の要素のclass名

	},

	//-----------------------------------------
	// Main処理
	//-----------------------------------------
	main : function() {

		var url = encodeURIComponent(location.href);
		var title = encodeURIComponent(document.title);
		var elements = sbm.getTargetElements(sbm.conf.targetTag, sbm.conf.targetCls);

		for (var i = 0; i < elements.length; i++) {

			var element = elements[i];
			//element.innerHTML = '';
			element.innerHTML =bookmark;

			if (sbm.conf.hatenaFlg) {
				var a = document.createElement('a');
				//a.setAttribute('href', 'http://b.hatena.ne.jp/append?' + url);
				//a.setAttribute('target', '_blank');
				a.setAttribute('href', 'javascript:(function(){var%20d=(new%20Date);var%20s=document.createElement(\'script\');s.charset=\'UTF-8\';s.src=\'http://b.hatena.ne.jp/js/Hatena/Bookmark/let.js?\'+d.getFullYear()+d.getMonth()+d.getDate();(document.getElementsByTagName(\'head\')[0]||document.body).appendChild(s);})();');
				
				var img = document.createElement('img');
				img.setAttribute('src', '/css/images/bookmark/b_append.gif');
				img.setAttribute('alt', 'この記事をはてなブックマークに追加');
				img.setAttribute('border', '0');
				
				a.appendChild(img);
				element.appendChild(a);
			}

			if (sbm.conf.livedoorFlg) {
				var a = document.createElement('a');
				a.setAttribute('href', 'http://clip.livedoor.com/redirect?link=' + url + '&title=' + title + '&ie=euc');
				a.setAttribute('target', '_blank');
				
				var img = document.createElement('img');
				img.setAttribute('src', '/css/images/bookmark/clip_16_16_w.gif');
				img.setAttribute('width', '16');
				img.setAttribute('height', '16');
				img.setAttribute('alt', 'この記事をクリップ！');
				img.setAttribute('border', '0');
				
				a.appendChild(img);
				element.appendChild(a);
			}

			if (sbm.conf.yahooFlg) {
				var a = document.createElement('a');
				a.setAttribute('href', 'javascript:void window.open(\'http://bookmarks.yahoo.co.jp/bookmarklet/showpopup?t=\'+encodeURIComponent(document.title)+\'&amp;u=\'+encodeURIComponent(window.location.href)+\'&amp;opener=bm&amp;ei=UTF-8\',\'popup\',\'width=550px,height=480px,status=1,location=0,resizable=1,scrollbars=0,left=100,top=50\',0);');
				
				//javascript:void window.open('http://bookmarks.yahoo.co.jp/bookmarklet/showpopup?t='+encodeURIComponent(document.title)+'&amp;u='+encodeURIComponent(window.location.href)+'&amp;opener=bm&amp;ei=UTF-8','popup','width=550px,height=480px,status=1,location=0,resizable=1,scrollbars=0,left=100,top=50',0);
				
				var img = document.createElement('img');
				img.setAttribute('src', '/css/images/bookmark/yahoo_ico.gif');
				img.setAttribute('width', '16');
				img.setAttribute('height', '16');
				img.setAttribute('alt', 'Yahoo!ブックマークに登録');
				img.setAttribute('style', 'border:none;');
				img.setAttribute('border', '0');
				
				a.appendChild(img);
				element.appendChild(a);
			}

			if (sbm.conf.googleFlg) {
				var a = document.createElement('a');
				a.setAttribute('href', 'http://www.google.com/bookmarks/mark?op=edit&bkmk=' + url + '&title=' + title);
				a.setAttribute('target', '_blank');
				
				var img = document.createElement('img');
				img.setAttribute('src', '/css/images/bookmark/google_ico.gif');
				img.setAttribute('width', '16');
				img.setAttribute('height', '16');
				img.setAttribute('alt', 'この記事をGoogleブックマークに追加');
				img.setAttribute('border', '0');
				
				a.appendChild(img);
				element.appendChild(a);
			}

			if (sbm.conf.niftyFlg) {
				var a = document.createElement('a');
				a.setAttribute('href', 'http://clip.nifty.com/create?url=' + url + '&title=' + title);
				a.setAttribute('target', '_blank');
				
				var img = document.createElement('img');
				img.setAttribute('src', '/css/images/bookmark/addclip_icn.gif');
				img.setAttribute('width', '16');
				img.setAttribute('height', '16');
				img.setAttribute('alt', '@niftyクリップに追加');
				img.setAttribute('border', '0');
				
				a.appendChild(img);
				element.appendChild(a);
			}

			if (sbm.conf.deliciousFlg) {
				var a = document.createElement('a');
				a.setAttribute('href', 'http://del.icio.us/post?url=' + url + '&title=' + title);
				a.setAttribute('target', '_blank');
				
				var img = document.createElement('img');
				img.setAttribute('src', '/css/images/bookmark/delicious_ico.gif');
				img.setAttribute('width', '16');
				img.setAttribute('height', '16');
				img.setAttribute('alt', 'del.icio.usに追加');
				img.setAttribute('border', '0');
				
				a.appendChild(img);
				element.appendChild(a);
			}

			if (sbm.conf.technoratiFlg) {
				var a = document.createElement('a');
				a.setAttribute('href', 'http://technorati.com/faves?add=' + url);
				a.setAttribute('target', '_blank');
				
				var img = document.createElement('img');
				img.setAttribute('src', '/css/images/bookmark/technorati_ico.gif');
				img.setAttribute('width', '16');
				img.setAttribute('height', '16');
				img.setAttribute('alt', 'テクノラティのお気に入りに追加');
				img.setAttribute('border', '0');
				
				a.appendChild(img);
				element.appendChild(a);
			}

			if (sbm.conf.fc2Flg) {
				var a = document.createElement('a');
				a.setAttribute('href', 'http://bookmark.fc2.com/user/post?url=' + url + '&title=' + title);
				a.setAttribute('target', '_blank');
				
				var img = document.createElement('img');
				img.setAttribute('src', '/css/images/bookmark/fc2_ico.gif');
				img.setAttribute('width', '16');
				img.setAttribute('height', '16');
				img.setAttribute('alt', 'fc2ブックマークに追加');
				img.setAttribute('border', '0');
				
				a.appendChild(img);
				element.appendChild(a);
			}

			if (sbm.conf.pookmarkFlg) {
				var a = document.createElement('a');
				a.setAttribute('href', 'http://pookmark.jp/post?title=' + title + '&url=' + url);
				a.setAttribute('target', '_blank');
				
				var img = document.createElement('img');
				img.setAttribute('src', '/css/images/bookmark/pookmark_ico.gif');
				img.setAttribute('width', '16');
				img.setAttribute('height', '16');
				img.setAttribute('alt', 'POOKMARK Airlineに登録');
				img.setAttribute('border', '0');
				
				a.appendChild(img);
				element.appendChild(a);
			}

			if (sbm.conf.choixFlg) {
				var a = document.createElement('a');
				a.setAttribute('href', 'http://www.choix.jp/bloglink/' + title);
				a.setAttribute('target', '_blank');
				
				var img = document.createElement('img');
				img.setAttribute('src', '/css/images/bookmark/choix_ico.gif');
				img.setAttribute('width', '16');
				img.setAttribute('height', '16');
				img.setAttribute('alt', 'choixへ追加');
				img.setAttribute('border', '0');
				
				a.appendChild(img);
				element.appendChild(a);
							}

		}

	},

	//-----------------------------------------
	// ターゲットタグを取得する
	//-----------------------------------------
	getTargetElements : function(tag, cls) {

		var elements = new Array();
		var targetElements = document.getElementsByTagName(tag);

		for (var i = 0; i < targetElements.length; i++) {
			if (targetElements[i].className.match(cls)) {
				elements[elements.length] = targetElements[i];
			}
		}

		return elements;
		

	},

	//-----------------------------------------
	// Loadイベントに追加
	//-----------------------------------------
	addLoadEvent : function() {
		try {
			window.addEventListener('load', this.main, false);
			
		} catch (e) {			
			window.attachEvent('onload', this.main);
			
			
			 
		}
	}

}

sbm.addLoadEvent();

function addfavorite()
{
   if (document.all)
   {
      window.external.addFavorite(window.location,document.title);
   }
   else if (window.sidebar)
   {
      window.sidebar.addPanel(document.title, window.location, "");
   }
  
} 
