//
// my_background.js for
//
// Made by Leurent Sylvain
// sylvain.leurent@laposte.net
//
// Started on  Sat Sep 18 14:55:40 2010 Leurent Sylvain
// Last update Sat Jan 21 16:23:32 2012 Leurent Sylvain
//

function        my_background()
{
  var win = $(window).height();
  var tmp_w = $('#background-img').width();
  if (typeof tmp_w != 'number' || tmp_w <= 0)
    tmp_w = my_background.width;
  var tmp_h = tmp_w * my_background.height / my_background.width;
  if (typeof tmp_h != 'number' || tmp_h <= 0)
    tmp_h = my_background.height;
  $('#background-img').height(win);
  var body = $(document).height();
  $('#background-img > img:gt(0)').remove();
  var save = body;
  while (save > 0)
    {
      var img = $('#background-img > img:first-child').clone();
      $('#background-img').append(img);
      save -=  tmp_h;
    }
  if (body > win)
    $('#background-img').height(body);
  else
    $('#background-img').height(win);
}

my_background.width = 0;
my_background.height = 0;

//set up the background's size
$(document).ready(
  function() {
    my_background.width = trim($('#background-img > p:first').text());
    $('#background-img > p:first').remove();
    my_background.height = trim($('#background-img > p:first').text());
    $('#background-img > p:first').remove();
    my_background();
    $(window).resize(my_background);
    $(document).resize(my_background);
  });

//when it's completly download, check the background's size
$(window).load(
  function() {
    my_background();
  });

