
var spTimerid = null;
var currentStone = 1;
var nbStones = 10;

function completeDocument() {
  $('#splayer').append('<div id="sp4" class="spphoto" style="left: 330px;"><a href="/search-gems/new-gems.php"><img src="/images/gem-4.jpg" /></a></div><div id="sp5" class="spphoto" style="left: 330px;"><a href="/search-gems/new-gems.php"><img src="/images/gem-5.jpg" /></a></div><div id="sp6" class="spphoto" style="left: 330px;"><a href="/search-gems/new-gems.php"><img src="/images/gem-6.jpg" /></a></div><div id="sp7" class="spphoto" style="left: 330px;"><a href="/search-gems/new-gems.php"><img src="/images/gem-7.jpg" /></a></div><div id="sp8" class="spphoto" style="left: 330px;"><a href="/search-gems/new-gems.php"><img src="/images/gem-8.jpg" /></a></div><div id="sp9" class="spphoto" style="left: 330px;"><a href="/search-gems/new-gems.php"><img src="/images/gem-9.jpg" /></a></div><div id="sp10" class="spphoto" style="left: 330px;"><a href="/search-gems/new-gems.php"><img src="/images/gem-10.jpg" /></a></div>');
  for (i = 1; i <= $('#news div.new').length; i++) {
    if ($('#n'+i+' img').height() > 180) {
      w = $('#n'+i+' img').width();
      w = w * 180 / $('#n'+i+' img').height();
      $('#n'+i+' img').css({width: parseInt(Math.floor(w)) + 'px', height: '180px'});
    }
  }
  $('#tplayer #test1').css('left', '0px');
  $('#nlok').click(nlSubmit);
  $('#nlemail').keypress(nlKeyPress);
}

function checkVariety() {
  if ($('#ccontent').height() < 957)
    $('#ccontent').css('height', '957px');
}

function splayerNext() {
  next = currentStone + 1;
  if (next == nbStones + 1) next = 1;
  $('#sp'+currentStone).animate({left: '-330px'}, 1000, '', function(){
    $('#sp'+currentStone).css('left', '330px');
  });
  $('#sp'+next).animate({left: '0'}, 1000);

  $('#test'+currentStone).animate({left: '-330px'}, 1000, '', function(){
    $('#test'+currentStone).css('left', '330px');
    currentStone = next;
    splayerStart();
  });
  $('#test'+next).animate({left: '0'}, 1000);
}

function splayerStart() {
  if (nbStones < 2) return;
  if (spTimerid) clearTimeout(spTimerid);
  spTimerid = setTimeout("splayerNext()", 4000);
}

function emailIsValid( email ) {
  var e = email.toLowerCase(); 
  e = e.replace( /(^\s+|\s+$)/g, '' );
  if (!e.match(/[a-z0-9\.\-]+@[a-z0-9\.\-]+\.[a-z]{2,4}/))
    return null;
  return e;
}

function nlSubmit() {
  var f = document.nlform;
  if (f.email.value) f.email.value = f.email.value.replace(/^(\s+)/, '').replace(/(\s+)$/, '');
  if (!f.email.value) {
    alert('Please indicate your email address.');
    return false;
  }
  var e = emailIsValid(f.email.value);
  if (e == null) {
    alert('Bad email. Please correct it.');
    return false;
  }
  f.email.value = e;
  $('#nlok, #nlemail').unbind();
  $.ajax({
    type: "POST",
    cache: false,
    url: 'nl-register.php',
    data: 'email='+e,
    success: function(data){
      alert('Registration completed! Thank you!');
      $('#nlok').click(nlSubmit);
      $('#nlemail').keypress(nlKeyPress);
    }
  });
  return false;
}

function nlKeyPress(e) {
  if (e.which == 13)
    nlSubmit();
}


