$(function () {
	if($('#facebook-profile-images').size()){
	  scramble();
	}
	
	/* this function from:
   * http://www.admixweb.com/2010/08/24/javascript-tip-get-a-random-number-between-two-integers/
   */
  function randomFromTo(from, to){
      return Math.floor(Math.random() * (to - from + 1) + from);
  }

  function scramble() {
      var children = $('#facebook-profile-images').children();
      $('#facebook-profile-images .facebook-profile-image').each(function(){
        $(this).css("position", "absolute");
        /* get container position and size
         * -- access method : cPos.top and cPos.left */
        var cPos = $('#facebook-profile-images').offset();
        var cHeight = $('#facebook-profile-images').height();
        var cWidth = $('#facebook-profile-images').width();

        // get box padding (assume all padding have same value)
        var pad = parseInt($('#facebook-profile-images').css('padding-top').replace('px', ''));

        // get movable box size
        var bHeight = $(this).height();
        var bWidth = $(this).width();

        // set maximum position
        var maxY = cPos.top + cHeight - bHeight - bHeight - pad;
        var maxX = cWidth - bWidth - pad;

        // set minimum position
        var minY = cPos.top - bHeight + pad;
        var minX = pad;

        // set new position			
        newY = randomFromTo(minY, maxY);
        newX = randomFromTo(minX, maxX);
        console.log(cPos.top);
        console.log(cHeight);
        console.log(bHeight);
        console.log(pad);

        $(this).animate({
            top: newY,
            left: newX
            }, 'slow', function() {
        });
      });
  }
  
	
});
