
  $(document).ready(function() {
      checkViewportDimensions(0, 0);
      setTimeout(function() { positionFacebookLikeWidget(); }, 100);
      setTimeout(function() { positionFacebookLikeWidget(); }, 1000);
      setTimeout(function() { positionFacebookLikeWidget(); }, 3000);
  });

  function positionFacebookLikeWidget() {

    var facebook_widget_width = 200; // needs to bechanged in iframe as well
    var window_width = $(window).width();

    

    // position the widget on the top right of the content div if the screen is wide enough
    $('#facebook_like_widget').alignWith($('#content'), 'tltr', {x: 20, y: 0, appendToBody: true});

    // then check if the widget would be fully visible without scroll bars
    var left = parseInt($('#facebook_like_widget').css('left'));
    if (left + facebook_widget_width < window_width && false) {

    // if so, show it, otherwise, put the widget below the content
      $('#facebook_like_widget').hide()
	.html('<iframe src="http://www.facebook.com/plugins/likebox.php?id=323610026825&amp;width=190&amp;connections=6&amp;stream=false&amp;header=true&amp;height=287" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:190px; height:287px;" allowTransparency="true"></iframe>');

      // hide the larger widget and its border overlays
      $('#facebook_like_widget_wide').hide().html('');
      $('#hori1').hide(); $('#hori2').hide(); $('#verti1').hide(); $('#verti2').hide();


    } else {
      // hide the sidebar like widget
      $('#facebook_like_widget').hide().html('');


      // else we append it (in a larger version) below the Users About Cronimon section
      $('#hori1').show().alignWith('#facebook_like_widget_wide', 'tl', {appendToBody: true});
      $('#hori2').show().alignWith('#facebook_like_widget_wide', 'bl', {appendToBody: true});
      $('#verti1').show().alignWith('#facebook_like_widget_wide', 'tl', {appendToBody: true});
      $('#verti2').show().alignWith('#facebook_like_widget_wide', 'tr', {appendToBody: true});

    }


  }

    function checkViewportDimensions(width, height) {
      var thisWidth = $(window).width();
      var thisHeight = $(window).height();
      if (width != thisWidth || height != thisHeight) {

         positionFacebookLikeWidget();

      }
      // Start the timer all over
      setTimeout(function() {checkViewportDimensions(thisWidth, thisHeight)}, 1000);
    } 


