// 홈페이지 SNS링크 공유(twitter, facebook, kakao)

Kakao.init('fe3969d637468a294038764db3b5a1b0');

function Linksns(title, type, navi) {
	
	
	var page = "";
    var url = document.location.href;

    page = url;
    page = page.split("&").join("%26");
    page = page.replace("?", "%3F");
    
    boardPage = document.location + "%26sp=";
    boardPage = boardPage.replace("?", "%3F");
    boardPage = boardPage.replace("\&", "%26");

    if (type == 'twitter') {
    	
        // var sendUrl = "http://twitter.com/share?url=" + boardPage
        // + encodeURI(page) + "&amp;text="
        // + encodeURIComponent(title);
        var sendUrl = "http://twitter.com/intent/tweet?text=" + encodeURIComponent(title) + "&url=" + encodeURIComponent(document.location);
        window.open(sendUrl);

    } else if (type == 'facebook') {

        var facebookurl = url;
        facebookurl = facebookurl.split("&").join("^");

        var strShareUrl = "https://www.facebook.com/sharer/sharer.php";
        var strParam = "";
        var strImageUrl = "https://www.ifans.go.kr/knda/statics/ifans/kor/image/main/fb_share.jpg";
        strUrl = encodeURIComponent(document.location);
        strTitle = encodeURIComponent(navi);
        strsummary = encodeURIComponent(title);

        
    	// strParam += "?s=100";
        // strParam += "&p[title]=" + strTitle;
        // strParam += "&p[url]=" + strUrl;
        // strParam += "&p[summary]=" + strsummary;

		strParam += "?u=" + strUrl;
		window.open(strShareUrl + strParam, "_blank");
		// newwin = window.open('about:blank');
		// newwin.location.href = strShareUrl + strParam;
    } 
    
    else if (type == 'kakao') {
    	
    	    var url = document.location.href;
    	    var strsummary = $('meta[property="og\\:title"]').attr("content");
    	    var description = $('meta[property="og\\:description"]').attr("content");
    	    var thumbnails = $('meta[property="og\\:image"]').attr("content");

    	    Kakao.Link.sendDefault({
    	      objectType: 'feed',
    	      content: {
    	        title: strsummary,
    	        description: description,
    	        imageUrl: thumbnails,
    	        link: {
    	          mobileWebUrl: url,
    	          webUrl: url,
    	        },
    	      },
    	      buttons: [
    	        {
    	          title: '자세히 보기',
    	          link: {
    	            mobileWebUrl: url,
    	            webUrl: url,
    	          },
    	        },
    	      ],
    	    })
    }
    
}
