$(document).ready(function(){

  setWidthForMotionGallery();
  createFacebookFanBox();

});

function setWidthForMotionGallery()
{
  var wrapper = $('#trueContainer');
  var length = 0;

  wrapper.find('.item').each(function(){
    length += $(this).width() + parseInt($(this).css('margin-right').replace('px', ''));
  });

  wrapper.width(length);
}

/**
 * Vytvoří facebook fan box.
 * 
 * @author OV
 * @since 20100827
 */
function createFacebookFanBox()
{
  $('.observeFacebookFanBox').each(function(){
    var e           = $(this),
        i           = '',
        id          = $(e).attr('data-id'),
        width       = $(e).attr('data-width'),
        height      = $(e).attr('data-height'),
        colorscheme = $(e).attr('data-colorscheme'),
        connections = $(e).attr('data-connections'),
        stream      = $(e).attr('data-stream'),
        header      = $(e).attr('data-header');

    i += '<iframe src="http://www.facebook.com/plugins/likebox.php?';
    i += 'id=' + id + '&amp;';
    i += 'width=' + width + '&amp;';
    i += 'colorscheme=' + colorscheme + '&amp;';
    i += 'connections=' + connections + '&amp;';
    i += 'stream=' + stream + '&amp;';
    i += 'header=' + header + '&amp;';
    i += 'height=' + height + '" ';
    i += 'scrolling="no" frameborder="0" style="border:none; overflow: hidden; width: ' + width + 'px; height: ' + height + 'px;" allowTransparency="true"></iframe>';

    $(this).html(i);
  });
}
