// JavaScript Document

$(document).ready(function() {

  $("#content").center();
  $(window).bind('resize', function() {
    $('#content').center({
      transition:300
    });
  });

  preload([
    '/img/background.png',
    '/img/next-hover.png'
    ]);

  $('#b1').mouseenter(function(){
      $(this).attr('src', '/img/b1-hover.png');
  }).mouseleave(function(){
      $(this).attr('src', '/img/b1.png');
  });
  
  setTimeout("$('#q1').fadeIn('slow'); ", 2000);
  setTimeout("$('#a1').fadeIn('slow'); ", 4000);
  setTimeout("$('#q2').fadeIn('slow'); ", 7000);
  setTimeout("$('#a2').fadeIn('slow'); ", 9000); 
  setTimeout("$('#b1').fadeIn('slow'); ", 12000);

 

  function preload(arrayOfImages) {
    $(arrayOfImages).each(function(){
      $('<img/>')[0].src = this;
    // Alternatively you could use:
    // (new Image()).src = this;
    });
  }

  
  function pageThree() {
    var subject = window.location.href;
    var myregexp = /\?[A-Z0-9+&@#\/%=~_|!:,.;]*/i;
    var match = myregexp.exec(subject);

    if(match) {
      window.location.href = '/final/' + match;
    } else {
      window.location.href = '/final/';
    }
  }
});

jQuery.fn.center = function () {
  this.css("position","absolute");
   this.css("bottom", (($(window).height() - this.outerHeight()  - 300 / 2  )  ) + $(window).scrollTop() + "px");
  //this.css("top", "0px")
  this.css("left", (($(window).width() - this.outerWidth()) / 2  ) + $(window).scrollLeft() + "px");
  return this;
}

function positionObj(image, offsetleft, offsettop) {
  var myoffset = $(image).offset();
  this.top = offsettop;
  this.left = myoffset.left + offsetleft;
}
