$.extend({
    chiudiTuttiMenu: function(callbackFnk){

      $(".social-brick-content").each(function(i, el){
        $(el).hide();
      })

      if(typeof callbackFnk == 'function'){
        callbackFnk.call(this);
      }
    }
  });

function elaboraFacebook()
  {
    if (trim($("#social-brick-content-fb").html()) == "")
      {
        $.post("html/layout/socialContainer.php", {rec_fb: ""},
          function(data){
            $("#social-brick-content-fb").html(data.contenuto);
            $.getScript("http://connect.facebook.net/en_US/all.js#xfbml=1", function(){
              $("#framefacebook").contents().find(".connections_grid").each(function(i, el){
                $(el).css("padding-left", "10px");
              });
            });
          }, "json");
      }
  }

function elaboraFlickr()
  {
    location.reload(true);

    /*$.post("html/layout/socialContainer.php", {rec_fkr: ""},
      function(data){
        $("#social-brick-content-fkr").html(data.contenuto);
        //$.getScript("http://www.flickr.com/badge_code_v2.gne?count=10&display=latest&size=s&layout=x&source=user&user=59375725%40N08", function(){
          //stLight.options({publisher:'f6f3aa96-4ff3-4f4b-8d27-527d695728da'});
        //});
        //stLight.options({publisher:'f6f3aa96-4ff3-4f4b-8d27-527d695728da'});
      }, "json");*/
  }

function elaboraYoutube()
  {
    if (trim($('#social-brick-content-yt').html()) == "")
      {
        $('#social-brick-content-yt').youTubeChannel({
          //userName: 'scatolaperta',
          userName: 'koinecoop',
          hideNumberOfRatings: false,
          removeBordersFromImage: false,
          linksInNewWindow: false,
          hideVideoLength: true,
          hideFrom: true,
          hideViews: true,
          hideRating: true
        });
      }
  }
  
function elaboraSocialContainer()
  {
    $(".brick").each(function(i, el){

      $(el).unbind("click");

      $(el).bind("click", function(evt){
        evt.preventDefault();

        var id = $(this).attr("id");
        var suffisso = id.substr(13);
        var idDiv = "social-brick-content-" + suffisso;

        $.chiudiTuttiMenu(function(){
          $("#" + idDiv).fadeIn(1000);

          $.post("html/layout/socialContainer.php", {socialAperto: suffisso}, function(data){
            /*if (suffisso == "fb")
              elaboraFacebook();*/

            if (suffisso == "fkr")
              elaboraFlickr();

            if (suffisso == "yt")
              elaboraYoutube();
          });
        });
      });
    });

    if ($('#social-brick-content-yt').css("display") == "block")
      elaboraYoutube();

    /*$('#social-brick-content-yt').youTubeChannel({
      //userName: 'scatolaperta',
      userName: 'koinecoop',
      hideNumberOfRatings: false,
      removeBordersFromImage: false,
      linksInNewWindow: false,
      hideVideoLength: true,
      hideFrom: true,
      hideViews: true,
      hideRating: true
    });*/

    $("#flickr_badge_wrapper").css("padding-left", "11px");

    $(".flickr_badge_image").each(function(i, el){
      $(el).css("padding-bottom", "10px");

      $(el).find("a").each(function(j, ele){
        $(ele).attr("target", "_blank");
      });
    });

  }



