var GOOGLE		= "Google";
var FACEBOOK	= "Facebook";
var PLURK		= "Plurk";
var TWITTER 	= "Twitter";

// 開新視窗
function popupWin(w, h, url) {
	var wleft = (($("#content").width() - w) >> 1);
	var wtop = (($("#content").height() - h) >> 1);
	
	var win = window.open(url,
	"likepopup",
	'width=' + w + ', height=' + (h + 70) + ', ' +
	'left=' + wleft + ', top=' + wtop + ', ' +
	'location=no, menubar=no, ' +
	'status=no, toolbar=no, scrollbars=no, resizable=no');
	
	win.resizeTo(w, h + 70);
	win.moveTo(wleft, wtop);
	win.focus();
}

// 簡易開新視窗
function ezPop(url) {
	window.open(url, 'newWin');	
}

// 簡易 FB 分享
function ezFbPublish(url) {
	var _location = encodeURIComponent(url);
	
	var _href = "http://www.facebook.com/sharer.php?u=" + _location;
	
	var _open;
	_open = window.open(_href, 'publish');
}

// FB 分享視窗屬性
function winOpt() {
	var bounce = {
		w 			: 626, 
		h 			: 346,
		x 			: 0, 
		y 			: 0,
		toolbar : 0,
		status 	: 0
	};
	bounce.x = (screen.width - bounce.w) / 2;
	bounce.y = (screen.height - bounce.h) / 2;
	bounce.opt = 'toolbar='+ bounce.toolbar +',status='+ bounce.status +',width='+ bounce.w +',height='+ bounce.h +',top='+ bounce.y + ',left=' + bounce.x;	
	return bounce.opt;
}

// 分享
function ezPublish(type, url, title, imgSrc) {
	var _location = url;
	_location = encodeURIComponent(_location);
	var _title = !title ? "" : title;
	_title = encodeURIComponent(_title);
	var _imgSrc = !imgSrc ? "" : imgSrc;
	_imgSrc = encodeURIComponent(_imgSrc);
	var _href;
	switch (type) {
		case GOOGLE :
			_href = "http://www.google.com/bookmarks/mark?op=add&bkmk="+ _location + "&title=" + _title;
			break;
		case FACEBOOK :
			_href = "http://www.facebook.com/sharer.php?u="+ _location + "&t=" + _title;
			break;
		case PLURK :
			if (_imgSrc != "") {
				_href = "http://www.plurk.com/?qualifier=shares&status=".concat(_imgSrc).concat(' ').concat(_location).concat(' ').concat('(').concat(_title).concat(')');	
			} else {
				_href = "http://www.plurk.com/?qualifier=shares&status=".concat(_location).concat(' ').concat('(').concat(_title).concat(')');
			}
			break;
		case TWITTER :
			_href = "http://twitter.com/home/?status=" + _title + " " + _location;
			break;
		case FAVORITES :
			addFavorites();									
			return;
			break;
	}
	var _open;
	if (type == FACEBOOK) {
		_open = window.open(_href, 'publish', winOpt());
	} else {
		_open = window.open(_href, 'publish');
	}
	return false;	
}

// 客製化 FB 分享
function customFbPublish(url, title, desc, imgSrc,videoSrc) {
	var _location = encodeURIComponent(url);
	var _title = !title ? "" : title;
	_title = encodeURIComponent(_title);
	var _desc = !desc ? "" : desc;
	_desc = encodeURIComponent(_desc);
	var _imgSrc = encodeURIComponent(imgSrc);
	var _videoSrc=encodeURIComponent(videoSrc);
	
	var _href = "http://www.facebook.com/sharer/sharer.php?s=100&p[title]=" + _title + "&p[summary]=" + _desc + "&p[url]=" + _location + "&p[images][0]=" + _imgSrc + "&p[video][0]=" + _videoSrc;
	
	var _open;
	_open = window.open(_href, 'publish', winOpt());
	
	return false;
}

