$.fn.createGrid = function(){
  var element = $(this).children();
  for(projeto in projetosReais) {
    var clonedElement = element.clone().appendTo($(this));
    clonedElement.removeClass("exemplo");
    $(".exemplo").remove();
  }
  $(this).gridBreak();
}

$.fn.gridBreak = function(){
  if(typeof(blockwidth)== "undefined") blockwidth = 400;
  limit = Math.floor($(".grid").width()/blockwidth);
  z = 0;
  var nBlocos = 0;
  $(".modulo").each(function(index){
    $(this).css('z-index', z);

    if(index % (limit*2) == 0){
      z += 3;
      $(this).addClass("break");
    }
    nBlocos++
    if(index % (limit) == 0){
      nBlocos = 0;
    }
  });
  $(".modulo").raise(-20, undefined, true).eq(0).loadImage();
}

$.fn.loadImage = function(){
  var modulo = $(this);
  var index = modulo.index();
  var img = $("<img class='image_front' src='images/projetos/blocos/"+projetosReais[index]['imagem']+"'/>");
  img.appendTo($(this).find(".faces")).attr("width", "400").hide()
  .load(function(){
      $(this).fadeIn(600);
      var proximoModulo = $(".modulo").eq(index+1);  
      if(proximoModulo.size() > 0){
        proximoModulo.raise(0, undefined, true).loadImage();
        refreshPreloader(index+2);
      } else {
        $(".modulo").delay(1000).
        randomize();
        unlock("all");
        blackout(0);
        checkHash();
    }
  });
}

