/*
文章页相关JS
*/

var CArticle = {};

//转发
CArticle.repost = function( target ){
	target = $.trim( target );
	if( target == "" ){
		return false;
	}
	var _t = CArticle;
	var articleURL, articleTitle, source, targetURL;
	articleURL = encodeURIComponent( document.URL );
	articleTitle = encodeURIComponent( $.trim( document.title ) );
	source = encodeURIComponent( "爱活网" );
	var d = new Date();
	var unixtime = d.getTime();
	switch( target ){
		
		//转发到新浪微博
		case "sina":
			params = "url=" + articleURL + "&title=" + articleTitle + "&source=" + source +  "&content=utf-8&content=utf-8&pic=";
			targetURL = "http://v.t.sina.com.cn/share/share.php?" + params;
		break;

		//转发到网易微博
		case "163":
			targetURL = "http://t.163.com/article/user/checkLogin.do?link=http://www.evolife.cn&source=" + source + "&info=" + articleTitle + "%20" + articleURL + "&" + unixtime;
		break;

		case "sohu":
			params = "url=" + articleURL + "&title=" + articleTitle + "&content=utf-8&pic=" ;
			targetURL = "http://t.sohu.com/third/post.jsp?" + params;
		break;

		case "qq_bookmark":
			params = "from=3&jumpback=2&noui=1&uri=" + articleURL + "&title=" + articleTitle;
			targetURL = "http://shuqian.qq.com/post?" + params;
		break;

		case "renren":
			params="title=" + articleTitle + "&link=" + articleURL;
			targetURL = "http://share.renren.com/share/buttonshare.do?" + params;
		break;

		case "kaixin001":
			params = "rurl=" + articleURL + "&rtitle=" + articleTitle + "&rcontent=" + encodeURIComponent( _t.getDesc() );
			targetURL = "http://www.kaixin001.com/~repaste/repaste.php?" + params;
		break;

		case "baidu":
			params = "it=" + articleTitle + "&iu=" + articleURL + "&fr=ien#nw=1";
			targetURL = "http://cang.baidu.com/do/add?" + params;
		break;

		case "douban":
			params = "url=" + articleURL + "&title=" + articleTitle + "&sel=" + encodeURIComponent( _t.getDesc() ) + "&v=1";
			targetURL = "http://www.douban.com/recommend/?" + params;
		break;

		case "qq_t":
			var appKey = "3c5b065cc128434b8ca464c099c3d494";
			var articlePicObjects = $( "#art_text" ).find( "img" );
			var articlePics = new Array();
			for( var i = 0; i < articlePicObjects.length && i < 4; i++ ){
				articlePics.push( articlePicObjects[i].src );
			}
			articlePics.reverse();
			
			params = "title=" + articleTitle + "&url=" + articleURL + "&appkey=" + appKey + "&site=" + source + "&pic=" + articlePics.join( "|" );
			targetURL = "http://v.t.qq.com/share/share.php?" + params;
		break;
		
		default:
			return false;

	}
	window.open( targetURL );
};

//获取页面“meta-description”内容
CArticle.getDesc = function(){
	var metas = document.getElementsByTagName( "meta" );
	for( var i = 0; i < metas.length; i++ ){
		try{
			if( metas[i].name.toLowerCase() == "description" ){
				return metas[i].getAttribute( "content" );
			}
		}catch( e ){
		}
	}
	return null;
};
