/*
Iconsets
--------
http://jwloh.deviantart.com/art/Social-me-90694011
http://infopirat.com/_ueber-20-deutsche-social-bookmark-icons-download

http://www.myspace.com/Modules/PostTo/Pages/?u=###URL###
http://www.meinvz.net/Link/Share/?url=###URL###&desc=###TITLE###
http://www.studivz.net/Link/Share/?url=###URL###&desc=###TITLE###
http://www.linkedin.com/shareArticle?mini=true&url=###URL###&title=###TITLE###&ro=false&summary=&source=


*/
   var ppSocialBookmark = new Array ();

   ppSocialBookmark['mister-wong'] = new Array ();
   ppSocialBookmark['mister-wong']['url'] = 'http://www.mister-wong.de/index.php?action=addurl&bm_url=###URL###&bm_description=###TITLE###&bm_notice=###DESCRIPTION###&bm_tags=###TAGS###';
   ppSocialBookmark['mister-wong']['img'] = 'mister-wong.png';
   ppSocialBookmark['mister-wong']['text'] = 'Mister Wong';

   ppSocialBookmark['google'] = new Array ();
   ppSocialBookmark['google']['url'] = 'http://www.google.com/bookmarks/mark?op=add&hl=de&bkmk=###URL###&title=###TITLE###&annotation=###DESCRIPTION###&labels=###TAGS###';
   ppSocialBookmark['google']['img'] = 'Google.png';
   ppSocialBookmark['google']['text'] = 'Google';

   ppSocialBookmark['facebook'] = new Array ();
   ppSocialBookmark['facebook']['url'] = 'http://www.facebook.com/sharer.php?u=###URL###';
   ppSocialBookmark['facebook']['img'] = 'facebook.png';
   ppSocialBookmark['facebook']['text'] = 'Facebook';

   ppSocialBookmark['twitter'] = new Array ();
   ppSocialBookmark['twitter']['url'] = 'http://twitter.com/share?url=###URL###&text=###TITLE###';
   ppSocialBookmark['twitter']['img'] = 'twitter.png';
   ppSocialBookmark['twitter']['text'] = 'Twitter';

   ppSocialBookmark['myspace'] = new Array ();
   ppSocialBookmark['myspace']['url'] = 'http://www.myspace.com/Modules/PostTo/Pages/?u=###URL###';
   ppSocialBookmark['myspace']['img'] = 'myspace.png';
   ppSocialBookmark['myspace']['text'] = 'Myspace';

   ppSocialBookmark['meinvz'] = new Array ();
   ppSocialBookmark['meinvz']['url'] = 'http://www.meinvz.net/Link/Share/?url=###URL###&desc=###TITLE###';
   ppSocialBookmark['meinvz']['img'] = 'meinvz.png';
   ppSocialBookmark['meinvz']['text'] = 'Meinvz';

   ppSocialBookmark['studivz'] = new Array ();
   ppSocialBookmark['studivz']['url'] = 'http://www.studivz.net/Link/Share/?url=###URL###&desc=###TITLE###';
   ppSocialBookmark['studivz']['img'] = 'studivz.png';
   ppSocialBookmark['studivz']['text'] = 'Studivz';

   ppSocialBookmark['linkedin'] = new Array ();
   ppSocialBookmark['linkedin']['url'] = 'http://www.linkedin.com/shareArticle?mini=true&url=###URL###&title=###TITLE###&ro=false&summary=&source=';
   ppSocialBookmark['linkedin']['img'] = 'linkedin.png';
   ppSocialBookmark['linkedin']['text'] = 'Linkedin';

   ppSocialBookmark['addthis'] = new Array ();
   ppSocialBookmark['addthis']['url'] = 'http://www.addthis.com/bookmark.php?url=###URL###&title=###TITLE###&d=###DESCRIPTION###';
   ppSocialBookmark['addthis']['img'] = 'addthis.gif';
   ppSocialBookmark['addthis']['text'] = 'AddThis';

   ppSocialBookmark['yahoo'] = new Array ();
   ppSocialBookmark['yahoo']['url'] = 'http://bookmarks.yahoo.com/myresults/bookmarklet?u=###URL###&t=###TITLE###&d=###DESCRIPTION###&tag=###TAGS###';
   ppSocialBookmark['yahoo']['img'] = 'Yahoo.png';
   ppSocialBookmark['yahoo']['text'] = 'Yahoo';

   ppSocialBookmark['config'] = new Array ();
   ppSocialBookmark['config']['socialBookmarkGenerated'] = 0;
   ppSocialBookmark['config']['socialBookmarkServices'] = 'facebook,twitter,myspace,linkedin,mister-wong,meinvz,studivz,google,yahoo,addthis';
   ppSocialBookmark['config']['socialBookmarkUrl'] = encodeURIComponent(location.href) ? encodeURIComponent(location.href) : escape(location.href);
   ppSocialBookmark['config']['socialBookmarkTitle'] = encodeURIComponent(document.title) ? encodeURIComponent(document.title) : escape(document.title);
   ppSocialBookmark['config']['useMetatags'] = false;


   //style config
   ppSocialBookmark['config']['imgPath'] = 'res/';
   ppSocialBookmark['config']['socialBookmarkIconPath'] = ppSocialBookmark['config']['imgPath']+'bookmarkicons/';

   ppSocialBookmark['config']['socialBookmarkButton'] = 'ppSocialBookmarkButton01.png';
   ppSocialBookmark['config']['socialBookmarkLinksBg'] = 'ppSocialBookmarkLinksBg01.png';


   ppSocialBookmark['config']['style'] = new Array ();
   ppSocialBookmark['config']['style']['bookmarkText'] = true;
   ppSocialBookmark['config']['style']['addBr'] = true;
   ppSocialBookmark['config']['style']['rows'] = 2;

   var metaTags = ppSocialBookmark['config']['useMetatags'] ? ppGetMetaTagContent() : new Array ();
   ppSocialBookmark['config']['socialBookmarkTags'] = metaTags['keywords'] ? metaTags['keywords'] : '';
   ppSocialBookmark['config']['socialBookmarkDescription'] = metaTags['description'] ? metaTags['description'] : '';

   function ppGetMetaTagContent () {
	var metaTagsContent = new Array ();
	if (document.getElementsByTagName("meta")) {
		var metaTags = document.getElementsByTagName("meta");
		for ( var i = 0; i < metaTags.length; i++) {
    			metaTagsContent[metaTags[i].name.toLowerCase()] = encodeURIComponent(metaTags[i].content) ? encodeURIComponent(metaTags[i].content) : escape(metaTags[i].content);
		}
	}
	return metaTagsContent;
   }
   
   function ppGenerateSocialBookmarkLinks() {
        var socialBookmarkServices = ppSocialBookmark['config']['socialBookmarkServices'].split(",");
        var htmlContent = '';
        var linkList = new Array ();
	for (var ppKey in socialBookmarkServices ) {
	        var socialBookmarkName = socialBookmarkServices[ppKey].toLowerCase();
	        var socialBookmarkUrl = ppSocialBookmark[socialBookmarkName]['url'];
                socialBookmarkUrl = socialBookmarkUrl.replace('###URL###', ppSocialBookmark['config']['socialBookmarkUrl']);
                socialBookmarkUrl = socialBookmarkUrl.replace('###TITLE###', ppSocialBookmark['config']['socialBookmarkTitle']);
                socialBookmarkUrl = socialBookmarkUrl.replace('###TAGS###', ppSocialBookmark['config']['socialBookmarkTags']);
                socialBookmarkUrl = socialBookmarkUrl.replace('###DESCRIPTION###', ppSocialBookmark['config']['socialBookmarkDescription']);
		var socialBookmarkTitle = ppSocialBookmark['config']['socialBookmarkTitle'];
                var socialBookmarkImgSrc = ppSocialBookmark['config']['socialBookmarkIconPath'] + ppSocialBookmark[socialBookmarkName]['img'];
                var socialBookmarkText = ppSocialBookmark[socialBookmarkName]['text'];
                if (socialBookmarkUrl && socialBookmarkText) {

			linkList[ppKey]  = document.createElement("a");
			linkList[ppKey].setAttribute("href", socialBookmarkUrl);
			linkList[ppKey].setAttribute("title", socialBookmarkText);
			linkList[ppKey].setAttribute("target", "_blank");
			linkList[ppKey].setAttribute("rel", "nofollow");
			linkList[ppKey].className = "ppSocialBookmarkA";

			var imgTag  = document.createElement("img");
			imgTag.setAttribute("alt", socialBookmarkText);
			imgTag.setAttribute("src", socialBookmarkImgSrc);
			imgTag.setAttribute("border", 0);
			imgTag.className = "ppSocialBookmarkImg";
			linkList[ppKey].appendChild(imgTag);

			if ( ppSocialBookmark['config']['style']['bookmarkText'] ) {
				var spanTag  = document.createElement("span");
				spanTag.className = "ppSocialBookmarkSpan";
				spanTag.appendChild(document.createTextNode(socialBookmarkText));
				linkList[ppKey].appendChild(spanTag);
			}

                        if (ppSocialBookmark['config']['style']['addBr']) {
				var brTag  = document.createElement("br");
				linkList[ppKey].appendChild(brTag);
			}

  		}
	}
        var linkListLength = linkList.length;
        var linkContent = '';
        var ppSocialBookmarkDiv = document.getElementById("ppSocialBookmarkLinks");
        if (ppSocialBookmark['config']['style']['rows']) {

                var divWidth = ppGetStyleValue('ppSocialBookmarkLinks','width', 'num');

                var divPadding = ppGetStyleValue('ppSocialBookmarkLinks','padding', 'num');
		divWidth['value'] = divWidth['value'] ? (divWidth['value']-(divPadding['value']*2)) : 100;
                divWidth['unit'] = divWidth['unit'] ? divWidth['unit'] : '%';
     		var rowEntryWidth = Math.floor( divWidth['value'] / ppSocialBookmark['config']['style']['rows'] );
     		var rowEntrys = Math.floor( linkListLength / ppSocialBookmark['config']['style']['rows'] );
     		var rowEntryCount = 1;
     		var rowCount = 1;
     		var rowDivTag = new Array();
		rowDivTag[rowCount]  = document.createElement("div");
		rowDivTag[rowCount].style.width = rowEntryWidth+divWidth['unit'];
		ppSocialBookmarkDiv.appendChild(rowDivTag[rowCount]);
	}
        for ( var i = 0; i < linkListLength; i++) {
                if (ppSocialBookmark['config']['style']['rows']) {
                      rowDivTag[rowCount].appendChild(linkList[i]);
                      if (rowEntrys==rowEntryCount) {
                        rowEntryCount = 1;
                        rowCount++;
                        if (i!=(linkListLength-1)) {
				rowDivTag[rowCount]  = document.createElement("div");
				rowDivTag[rowCount].style.width = rowEntryWidth+divWidth['unit'];
				ppSocialBookmarkDiv.appendChild(rowDivTag[rowCount]);
			}
		      } else {
		        rowEntryCount++;
		      }
		} else {
                      ppSocialBookmarkDiv.appendChild(linkList[i]);
		}
	}
   }
   
   function ppGenerateSocialBookmark() {
	if (document.getElementById) document.writeln('<div id="ppSocialBookmark"><div id="ppSocialBookmarkButton"><a href="javascript:ppSocialBookmarkSwitchVisibility(\'ppSocialBookmarkLinks\')"><img border="0" src="'+ppSocialBookmark['config']['imgPath']+ppSocialBookmark['config']['socialBookmarkButton']+'" /></a></div><div style="visibility:hidden;background: #FFFFFF url('+ppSocialBookmark['config']['imgPath']+ppSocialBookmark['config']['socialBookmarkLinksBg']+') repeat-x top left;" id="ppSocialBookmarkLinks"></div></div>');
   }


   function ppGetStyleValue( tagId, styleName, styleTyp ) {
        var ppStyle = new Array();
        ppStyle['value'] = null;
        var tagObjekt = document.getElementById(tagId);
	if (tagObjekt.currentStyle) ppStyle['value'] = tagObjekt.currentStyle[styleName];
	else if (window.getComputedStyle) ppStyle['value'] = window.getComputedStyle( tagObjekt, null ).getPropertyValue(styleName);

	if (styleTyp=='num') {
	        ppStyle['unit'] = ppStyle['value'].replace(/[0-9\.]+/g, "");
		ppStyle['value'] = ppStyle['value'].replace(/[a-zA-Z%;,]+/g, "");
	}
	return ppStyle;
   }
	
   function ppSocialBookmarkSwitchVisibility ( tagId ) {
	if (document.getElementById) {
		if ( document.getElementById(tagId).style.visibility == "visible") {
		        document.getElementById(tagId).style.visibility = "hidden";
		} else {
   			if (ppSocialBookmark['config']['socialBookmarkGenerated']==0) {
            			ppGenerateSocialBookmarkLinks();
            			ppSocialBookmark['config']['socialBookmarkGenerated']=1;
			}
                   	document.getElementById(tagId).style.visibility = "visible";
		}
    	}
   }
