
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="logo"></div>');
}

function homeInitSizes(w, h) {
  // found good image
  if (contentHeight <= 400) contentId = 400;
  else if (contentHeight <= 600) contentId = 600;
  else if (contentHeight <= 800) contentId = 800;
  else if (contentHeight <= 1000) contentId = 1000;
  else if (contentHeight <= 1200) contentId = 1200;
  else if (contentHeight <= 1400) contentId = 1400;

  if ($.browser.msie)
    $('#content').append('<img class="home" src="/image.php?id=hourra-models-paris-1-'+contentId+'.jpg&h='+contentHeight+'" />');
  else {
    $('#content').append('<img class="home" src="/images/hourra-models-paris-1-'+contentId+'.jpg" />');
    $('#content img.home:last').height(contentHeight);
  }
  if (!$('#cache1').length)
    $('#content img.home:last').css('top', contentHeight+'px');
  $('#content img.home:last').load(function(){
    $('#content').css({width: $('#content img.home:last').width()+'px', height: $('#content img.home:last').height()+'px', 
      marginLeft: '-'+Math.ceil($('#content img.home:last').width() / 2)+'px'});
    if ($('#content img.home').length > 1)
      $('#content img.home:first').remove();
    // animate home
    if ($('#cache1').length) {
      $('#cache1').fadeOut(400, function(){
        $('#cache1').remove();
      });
    }
    else gotoHomeTerminate();
  });

var lw = Math.ceil(siteWidth * logoRatio3);

  if ($.browser.msie && (contentId <= 1000))
    $('#logo').append('<img src="/image.php?id=logo-'+contentId+'.png&w='+lw+'" />');
  else {
    $('#logo').append('<img src="/images/logo-'+contentId+'.png" />');
    $('#logo img:last').width(lw);
  }

  $('#logo img:last').load(function(){
/*    $('#logo').css({marginLeft: '-'+Math.ceil(siteWidth / 2)+'px', top: '-'+($('#logo img:last').height() - 
	contentHeight - headerHeight - footerHeight)+'px', height: $('#logo img:last').height()+'px', 
	width: siteWidth+'px'});*/
    $('#logo').css({marginLeft: '-'+Math.ceil(siteWidth / 2)+'px', top: '-'+($('#logo img:last').height() - 
	contentHeight - headerHeight - footerHeight)+'px', height: $('#logo img:last').height()+'px', 
	width: siteWidth+'px'});
    if ($('#logo img').length > 1)
      $('#logo img:first').remove();
  });
}

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'});
  });
}

