// Logger variable. Set to true to turn on logging.
var LOG = true;
// Initialization status variable. Helps elimiate duplicate buttons.
var pinitInitInitialized = false;
var dateVar = new Date();

LOG && console.debug(dateVar.getTime() + "    " + "Visioplanet PinIt Initialization script file is locked and loaded.");

(function() {
  try {
    // In case of insite navigation, document.ready will work.
    $(document).ready(function(){
      LOG && console.debug(dateVar.getTime() + "    " + "DOM is ready. Time to start up Pin It.");
      visioplanetPinItInit();
    });
    $(window).load(function() {
      LOG && console.debug(dateVar.getTime() + "    " + "Window load is complete. Time to start up Pin It.");
      visioplanetPinItInit();
    });
  } catch(e) {
    console.error(dateVar.getTime() + "    " + 'Visioplanet Pinit Initialization Exception: ' + e);
    windowLoadMethod();
  }
})();

function windowLoadMethod() {
  try {
    // If this is a direct post load, document.ready may not work and we will have to use window.load
    $(window).load(function() {
      console.debug(dateVar.getTime() + "    " + "Initializing from failsafe.")
      visioplanetPinItInit();
    });
  } catch(e) {
    console.error(dateVar.getTime() + "    " + 'Visioplanet Pinit Initialization Exception: ' + e);
  }
}

function visioplanetPinItInit(){
  setTimeout (
    function() {
      LOG && console.debug(dateVar.getTime() + "    " + "document status: " + document.readyState);
      if (document.readyState !== 'complete') {
        LOG && console.debug(dateVar.getTime() + "    " + "Document's not ready. Waiting...");
        //setTimeout(visioplanetPinItInit,1000);
      } else {
        // The following line will make sure that PinIt button initialization runs only once.
        // So that multiple PinIt buttons don't show up.
        if(pinitInitInitialized == true) {
          LOG && console.debug(dateVar.getTime() + "    " + "PinIt initialization already started. Exiting visioplanetPinItInit() to avoid duplicates.");
          return;
        }
        
        // We're gonna wait for sometime and then do our work (URL remains the old one otherwise).
	    LOG && console.debug(dateVar.getTime() + "    " + "Let's begin PinIt Initialization...");
        // We're gonna put the button on top of the image at the top right corner of it.
        // For that, we'd have to check the width of the image.

        pinitInitInitialized = true;
        var imgURL = "";
        var img = new Image();
        
        $("img").each(
          function(){
            var theWidth = 0;
            var theHeight = 0;
            img.src = $(this).attr('src');
            //img.onload = function() {
            //    theWidth = this.width;
            //    theHeight = this.height;
            //    LOG && console.debug(dateVar.getTime() + "    " + this.width + "x" + this.height);
            //};
            
            theWidth = img.width;
            theHeight = img.height;

            LOG && console.debug(dateVar.getTime() + "    " + $(this).attr("src") + ": " + theWidth + "x" + theHeight);
            if((theWidth >= 400) || (theHeight >= 400)) {
              imgURL = $(this).attr("src");
              LOG && console.debug(dateVar.getTime() + "    " + "Got the image URL: " + imgURL);
              return false;
              LOG && console.debug(dateVar.getTime() + "    " + "This line shouldn't come up.");
            }
        });

        var htmlStr = "<a data-pin-config='beside' data-pin-do='buttonPin' class='visioplanetPinItButton' count-layout='horizontal' href='http://pinterest.com/pin/create/button/?url=";
        htmlStr += document.location;		// URL was already encoded in IE 8.
        htmlStr += "&amp;media=";
        htmlStr += imgURL;
        htmlStr += "'><img border='0' src='http://assets.pinterest.com/images/PinExt.png' title='Pin It'/></a>";

        LOG && console.debug(dateVar.getTime() + "    " + "The tag's as follows:\n\n" + htmlStr);

        $(htmlStr).insertAfter("span.share-facebook.delay");
        // We're placing this button right after the +1 button.
        $("a.visioplanetPinItButton").css("z-index", 1000);
      }
    }
  , 1000);
}

@@ -569,24 +569,26 @@
     %7D);%0A    
+//
 $(window).lo
@@ -599,32 +599,34 @@
 unction() %7B%0A    
+//
   LOG && console
@@ -711,32 +711,34 @@
  Pin It.%22);%0A    
+//
   visioplanetPin
@@ -743,32 +743,34 @@
 inItInit();%0A    
+//
 %7D);%0A  %7D catch(e)
@@ -2679,262 +2679,8 @@
 ');%0A
-            //img.onload = function() %7B%0A            //    theWidth = this.width;%0A            //    theHeight = this.height;%0A            //    LOG && console.debug(dateVar.getTime() + %22    %22 + this.width + %22x%22 + this.height);%0A            //%7D;%0A            
 %0A   
@@ -2751,32 +2751,34 @@
 t;%0A%0A            
+//
 LOG && console.d
@@ -3935,24 +3935,66 @@
 ex%22, 1000);%0A
+        LOG && console.debug(%22%5Cn%5Cn%5Cn%5Cn%22);%0A
       %7D%0A    

Update VisioplanetPinItByImgSizeInShareSection.js