
var homeRatio = 2;
var logoRatio1 = 1.674864732;
var logoRatio2 = 1.574520413;
var logoRatio3 = 1.062;

var contentId = 1600;


function homePrepare() {
  $('h1').css('display', 'none');
  $('body').append('<div id="cache1" class="cache"><div><img src="/images/loading.gif" alt="Hourra Models Paris" /></div></div>');
}

function homeInitSizes(w, h) {
  photoHeight = Math.floor(contentHeight / 3) - 20;
  contentHeight = 3 * (photoHeight + 20);
  photoWidth = Math.ceil(photoHeight * photoRatio);

  var o = $('#header h2:last').offset();
  var p = $('#footer').offset();
  var l = Math.floor(siteWidth * menusRatio);
  var m = 5 * photoWidth + 4*20 + 5;

  if (m + o.left > w) {
    var eps = (m + o.left - w) + Math.floor((w - m - 138 - 63)/2);
    if ($('#header h2').length) {
      $('#header h2:first').css('marginRight', 
	eps+parseInt($('#header h2:first').css('marginRight').replace('px', ''))+'px');
      $('#footer h3:first').css('marginRight', 
	eps+parseInt($('#footer h3:first').css('marginRight').replace('px', ''))+'px');
    }
    o.left -= eps;
  }
  else {
    var eps = Math.floor((w - m - 138 - 63)/2);
    var k = o.left - eps - 138 - 63;
    if ($('#header h2').length) {
      $('#header h2:first').css('marginRight', 
	k+parseInt($('#header h2:first').css('marginRight').replace('px', ''))+'px');
      $('#footer h3:first').css('marginRight', 
	k+parseInt($('#footer h3:first').css('marginRight').replace('px', ''))+'px');
    }
    o.left = eps + 138 + 63;
  }

  $('#logo img').height(contentHeight);
  $('#logo').css({marginLeft: '-'+Math.ceil(siteWidth / 2)+'px', 
	top: headerHeight+'px', height: contentHeight+'px', width: siteWidth+'px'});
  // animate home
  if ($('#cache1').length) {
    $('#cache1').fadeOut(400, function(){
      $('#cache1').remove();
    });
  }
  else gotoHomeTerminate();
}

function gotoHome() {
  if (siteCurPage == 'home')
    return false;
  if (!$('#logo').length)
    $('body').append('<div id="logo"></div>');
  sitePreviousPage = siteCurPage;
  siteCurPage = 'home';
  initSizes();
  $('body').append('<div id="cache2" class="cache"><div><img src="/images/loading3.gif" /></div></div>');
  $('#cache2 div').css({width: $('#content').css('width'), marginLeft: $('#content').css('marginLeft'), 
	top: (2*headerHeight+contentHeight-38)+'px'});
  return false;
}

function gotoHomeTerminate() {
  // animate
  if (sitePreviousPage == 'liste') {
    $('h1, #pages'+listeCurId).css('display', 'none');
    $('#ldetails'+listeCurId+', #liste'+listeCurId).animate({top: '-'+($('#liste'+listeCurId).height()+5)+'px'}, 
	400, '', function(){
      if (listeCurId == 1000)
	$('#ldetails1000, #liste1000').remove();
    });
  }
  else if (sitePreviousPage == 'fiche') {
    $('h1, #back').css('display', 'none');
    $('#fdetails'+ficheCurId+', #photo'+ficheCurId+', #thumbs'+ficheCurId).animate({top: '-'+($('#photo'+ficheCurId).height()+5)+'px'}, 400);
  }
  $('#content img.home').animate({top: '0px'}, 400, '', function(){
    $('#logo').css('display', 'block');
    $('#cache2').remove();
    $('#logo').css({top: '-'+($('#logo img:last').height() - 	contentHeight - headerHeight - footerHeight)+'px', 
	height: $('#logo img:last').height()+'px'});
  });
}


