var page_w = 960;
var spot_h = 1150;
var spot_w = 2100;

$(document).ready(function() {
  $('body').css('visibility','hidden');
  document.getElementById('page').style.visibility  = 'hidden';
  document.getElementById('spotlight').style.visibility  = 'hidden';
  $(window).load(function(){
    addMask();
  });
  //checkOverlay();
  revealContent();
});
$(window).resize(function() {
  //hideContent();
  //dotimeout op checkoverlay
  //checkOverlay();
  //revealContent();
});

function addMask(){
  $("#page").clone().attr('id', 'mask').appendTo('body');
  pagelinks = $("#page a");
  $("#mask a").each(function(index, element){
    $(element).hover(function(){$(pagelinks[index]).toggleClass("hover");});
    $(element).mousedown(function(){$(pagelinks[index]).toggleClass("active");});
  });
}

function hideContent(){
  document.getElementById('page').style.visibility  = 'hidden';
  document.getElementById('spotlight').style.visibility  = 'hidden';
  document.getElementById('mask').style.visibility  = 'hidden';
}

function removePreloadElements(){
  //var d = document, e = d.documentElement, p = d.createElement('style');
  //p.textContent = "#spotlight,#page{visibility:hidden}html{background-image:url('assets/images/backgrounds/3stripes.png');}.pl01{background-image:url('assets/images/spotlight/spotlight.png');}.pl02{background-image:url('assets/images/pronksnor-logo.png');}.pl03{background-image:url('assets/images/spotlight/pixel.png');}.pl04{background-image:url('assets/images/backgrounds/3stripes.png');}";
  //e.firstChild.appendChild(p);
  //$('#font-bg').remove();
  $('#loading').remove();
}

function revealContent(){
  $('body').delay(100).css('visibility','visible');
  $('#spotlight').fadeIn(400).delay(100).css('visibility','visible');
  $('#page').fadeIn(400).delay(100).css('visibility','visible');
  $('#mask').fadeIn(400).delay(100).css('visibility','visible');
  //body background 3stripes
  //document.getElementById('mask').style.visibility  = 'visible';
  //transtion?
  $('body').delay(400).css('background-image',"url('/assets/images/backgrounds/3stripes.png')");
  removePreloadElements();

}


function checkOverlay(){
  height = $(window).height();
  width = $(window).width();
  if (height <= spot_h || width <= spot_w) { removeBorders(); }
  if (height > spot_h) { addBottom(height); }
  if (width > spot_w) { addSides(width); }
}

function addBottom(height) {
  //alert('adding bottom!');
  bottom_h = height - spot_h;
  $("#spotlight-bottom").height(bottom_h);
  window_h = $(window).height();
  if (height != window_h) setHeight(window_h);
}

function addSides(width) {
  //alert('adding sides!');
  $("#spotlight-center").addClass('sides')
  border_w = (width > spot_w ? (width - spot_w) / 2 : 0);
  $("#spotlight-left").width(Math.ceil(border_w));
  $("#spotlight-right").width(Math.floor(border_w));
  window_w_new = $(window).height();
  if (width != window_w_new) setHeight(window_w_new);
}
function removeBorders(){
  //alert('removing borders!');
  $("#spotlight-center").removeClass('sides');
}
