/* Social Network Buttons
 * Facebook, Hyves, Twitter and e-mail
 * By: Martijn van der Veen
 * Created: 09/03/2011
 * Edited:  09/03/2011
 */


        function smClick(smName) {
            document.getElementById(smName).href = smLink(smName);
        }

        
        function smLink(smName) {
            var result = "";
            var url = location.href;
            var title = document.title;
            var message = trim(getMetaTag('description'));
            if (smName == 'twitter') {
                result = "http://twitter.com/home?status=" + encodeURIComponent(title + ": " + url);
            }
            if (smName == 'hyves') {
                result = "http://www.hyves-share.nl/button/tip/?rating=5&title=" + encodeURIComponent(title) + "&body=" + encodeURIComponent(message + " " + url);
            }
            if (smName == 'facebook') {
                result = "http://www.facebook.com/sharer.php?u=" + encodeURIComponent(url) + "&t=" + encodeURIComponent(title + " " + message);
            }
            if (smName == 'email') {
                result = "mailto://?SUBJECT=" + encodeURIComponent(title) + encodeURI("&BODY=") + encodeURIComponent(message + " " + url);
            }
            return result;
        }

        function getMetaTag(name) {
            g_metadata = document.getElementsByTagName("meta");
            g_keywords = []
            var len = g_metadata.length;
            for (var i = 0; i < len; i++) {
              if (g_metadata[i].name == name) {
                g_keywords = g_metadata[i].content
              }
            }
            return g_keywords;
        }

        function trim(str) {
            str = str.replace(/^\s+/, '');
            str = str.replace(/\s+$/, '');
            return str;
        }

