var vpX, vpY;
var prerender = '<style type="text/css" id="prerender">\n';
    prerender+= '\tbody{\n';
    prerender+= '\t\tdisplay: none;\n';
    prerender+= '\t}\n';
    prerender+= '</style>';

document.write(prerender);

// Get current viewport size:
function vpMeasure(){
  if (typeof window.innerWidth != 'undefined') {
    vpX = window.innerWidth;
    vpY = window.innerHeight;
  } else if (typeof document.documentElement != 'undefined'
    && typeof document.documentElement.clientWidth !=
    'undefined' && document.documentElement.clientWidth != 0) {
      vpX = document.documentElement.clientWidth;
      vpY = document.documentElement.clientHeight;
  } else {
     vpX = document.getElementsByTagName('body')[0].clientWidth;
     vpY = document.getElementsByTagName('body')[0].clientHeight;
  }
}

// Fade the page content out while waiting for unload:
function fadeOut(){
  $('html').css({
    'background-image' : 'url('+loadGifUrl+')',
    'cursor' : 'progress'
  });
  $('body').css('cursor', 'progress');
  $('body').fadeOut('200');
}

// Slide showcase items:
function showcaseSlide(dir){
  var showcaseImgs = document.getElementById('showcase').getElementsByTagName('img');
  var maxLength = 0 - (showcaseImgs.length - 1) * 564;
  var curLeft = $('#showcase ul').css('left');
  curLeft = (curLeft.split('px')[0])*1;
  $('.showcase span').fadeOut(250);
  if(dir == 'prev' && curLeft < 0){
    $('#showcase').append('<div class="mask"></div>');
    $('#showcase ul').animate({'left': curLeft + 564 + 'px'}, 500, 'linear', function(){
      $('#showcase .mask').remove();
    });
  } else if(dir == 'next' && curLeft > maxLength){
    $('#showcase').append('<div class="mask"></div>');
    $('#showcase ul').animate({'left': curLeft - 564 + 'px'}, 500, 'linear', function(){
      $('#showcase .mask').remove();
    })
  }
  $('.showcase span').fadeIn(250);
}
  
// When all page elements are loaded and positioned, reveal the page body:
$(window).bind('load', function() {
  $('body').hide().fadeIn('200');
  $('#prerender').remove();
})

$(document).ready(function(){
  $('.blockLink').hover(function(){if($(this).find('a')) $(this).addClass('hover')}, function(){$(this).removeClass('hover')})
  $('.blockLink').click(function(){
    var href = $(this).find('a').attr('href');
    if((href.indexOf('http://www.clickwork.net') == 0 || href.indexOf(':') <= 0) && href.indexOf('#') < 0) var httpLink = 1;
    if(httpLink >= 0){
      $('body').fadeOut('200', function(){location.href = href});
    } else location.href = href;
  })
  $('a').click(function(){
    var href = $(this).attr('href');
    if((href.indexOf('http://www.clickwork.net') == 0 || href.indexOf(':') <= 0) && href.indexOf('#') < 0) var httpLink = 1;
    if(httpLink >= 0){
      $('body').fadeOut('200', function(){location.href = href});
    } else location.href = href;
    return false;
  })
  $('#showcase .prev').click(function(){showcaseSlide('prev')});
  $('#showcase .next').click(function(){showcaseSlide('next')});
});