﻿/*
Anteater Bookmark 1.0.2
Design by Jason,milkmidi,Ash,MarkVnn
2010/12/07, 修改 Facebook share時, 增加一個 ?RAN 屬性, 強制更新抓新的屬性。
*/
var AnteaterBookmark = AnteaterBookmark || { };
(function(){
	AnteaterBookmark.WEB_SITE_HREF    = "http://www.sugus.com.tw/activity.aspx";
	//這兒更改專案的網址, 不用程式自已抓的原因是因為有可能後面會帶一堆有的沒有的參數
	//所以自已打比較快, 如果是空字串, 程式才會自已抓。
	AnteaterBookmark.WEB_SITE_TITLE   = "sugus 12‧12姊妹日午茶趴"
	//更改專案的標題, 和上方的網址一樣。
	//====================================================================
	AnteaterBookmark.FAVORITES		 = "Favorites";
	AnteaterBookmark.FACEBOOK  		 = "FaceBook";
	AnteaterBookmark.GOOGLE	  		 = "Google";
	AnteaterBookmark.PLURK 			 = "Plurk";
	AnteaterBookmark.TWITTER 		 = "Twitter";
	//====================================================================
	/*
	*/
	AnteaterBookmark.anteaterAddBookmark = function(pType){					
		var _title = AnteaterBookmark._getTitle();;
		_title = encodeURIComponent(_title);
		
		var _locationHref  = AnteaterBookmark._getLocation();
		_locationHref = encodeURIComponent(_locationHref);
		
		var _href;	
		switch (pType) {
			case AnteaterBookmark.FAVORITES:					
				AnteaterBookmark.anteaterAddFavorites();									
				return;
				break;
			case AnteaterBookmark.FACEBOOK:
				if(_locationHref.indexOf("?") == -1)
					_locationHref += "?ran="+new Date().getTime();
				else			
					_locationHref += "&ran="+new Date().getTime();		
				_href = "http://www.facebook.com/sharer.php?u="+ _locationHref + "&t=" + _title;
				break;
			case AnteaterBookmark.GOOGLE:
				_href = "http://www.google.com/bookmarks/mark?op=add&bkmk="+ _locationHref + "&title=" + _title;
				break;
			case AnteaterBookmark.PLURK:
				_href = "http://www.plurk.com/?qualifier=shares&status=".concat(_locationHref).concat(' ').concat('(').concat(_title).concat(')');
				break;
			case AnteaterBookmark.TWITTER:
				_href = "http://twitter.com/home/?status=" + _title + " " + _locationHref;
				break;
		}	
		window.open( _href , "_blank" );
		return false;
	}
	AnteaterBookmark.anteaterAddFavorites = function() {							
		var _title = AnteaterBookmark._getTitle();;
		_title = encodeURIComponent(_title);
		
		var _locationHref  = AnteaterBookmark._getLocation();
		_locationHref = encodeURIComponent(_locationHref);
		
		if( window.sidebar && window.sidebar.addPanel ) {
			// Gecko (Netscape 6)
			window.sidebar.addPanel( _title, _locationHref, '' );
		} else if( window.external ) {
			// IE
			window.external.AddFavorite( _locationHref, _title );
		} else if( document.layers ) {
			// NS4
			window.alert( 'Please click OK then press Ctrl+D to create a bookmark' );
		} else {
			// Other browsers
			window.alert( 'Please use your browsers\' bookmarking facility to create a bookmark' );
		}
	}
	AnteaterBookmark.gotoURL = function(pURL) {
	   location = pURL;
	}
	
	/*private
	* 抓指定的 meta name 裡的 content
	* @param pName 要找的 meta name
	*/
	AnteaterBookmark._getDescriptionMetaContent = function(pName)/*String*/ {
		var metas = document.getElementsByTagName('meta');    
		for (var i = 0; i < metas.length; i++){
			if (metas[i].getAttribute( pName ) == "description")
			return metas[i].getAttribute('content');
		}
		return "";
	}
	/*private*/
	AnteaterBookmark._getTitle = function()/*String*/{
		return AnteaterBookmark.WEB_SITE_TITLE || document.title;
	}
	/*private*/
	AnteaterBookmark._getLocation = function()/*String*/{
		return AnteaterBookmark.WEB_SITE_HREF || window.location.href;
	}
	
})();


