if (doSitePreload) {

var images = new Array(
templateDirectory + '/images/article-bg-1.png', 
templateDirectory + '/images/bg-shadow.png',
templateDirectory + '/images/bg-sm.jpg',
templateDirectory + '/images/figureandgroove.gif',
templateDirectory + '/images/grillbg.jpg',
templateDirectory + '/images/icn-fax.gif',
templateDirectory + '/images/icn-fbook.gif',
templateDirectory + '/images/icn-mail.gif',
templateDirectory + '/images/icn-phone.gif',
templateDirectory + '/images/icn-print.gif',
templateDirectory + '/images/post-alt-bg.png',
templateDirectory + '/images/row-alt-bg.png',
templateDirectory + '/images/scrollbar-bg.png',
templateDirectory + '/images/scrolldown-bg.gif',
templateDirectory + '/images/scrollup-bg.gif',
templateDirectory + '/images/scrollup-bg.png',
templateDirectory + '/images/triangle.png');

window.addEvent('load', function(){

	//$('window-container').setStyle('opacity', 0);

	var preloadWrapper = new Element('div', {
		'id': 'preloadWrapper', 
		'text' : 'Figure&Groove '		
	});

	var preloadCounter = new Element('span', {
		'id': 'preloadCounter', 
		'text' : 'Loading'		
	});
	
	var percentWrapper = new Element('div', {
		'id': 'percentWrapper'
	});
	
	var percentBar = new Element('div', {
		'id': 'percentBar'
	});
	
	preloadWrapper.inject(document.body, 'top');
	preloadCounter.inject(preloadWrapper, 'bottom');
	percentWrapper.inject(preloadCounter, 'after');
	percentBar.inject(percentWrapper);
	
	justifyElement(preloadWrapper, 300, 100);

});

window.addEvent('load', function(){
var loader = new Asset.images(images, {  
        onProgress: function(counter,index) {  
            $('preloadCounter').innerHTML = Math.floor((counter + 1) * (100 / images.length))+'%';
            $('percentBar').setStyle('width', Math.floor((counter + 1) * (100 / images.length))+'%');
        },  
        onComplete: function() { 
        	setUpContent();
        }  
    });
 });
 
}

function setUpContent() {

//var myScript = new Asset.javascript(templateDirectory + '/js/fg.js', { id: 'fgScripts' });
window.location = location.href;

}


/* begin background image stuff */

var whRatio = 0;
var w = 0;
var h = 0;
	
	
function getWinDims() {
/*
	//IE
	if(!window.innerWidth)
	{
		//strict mode
		if(!(document.documentElement.clientWidth == 0))
		{
			w = document.documentElement.clientWidth;
			h = document.documentElement.clientHeight;
		}
		//quirks mode
		else
		{
			w = document.body.clientWidth;
			h = document.body.clientHeight;
		}
	}
	//w3c
	else
	{
		w = window.innerWidth;
		h = window.innerHeight;
	}
*/

var size = window.getSize();
w = size.x;
h = size.y;
	
}


function setDims() {

getWinDims();

$('window-container').setStyle('height', h);
$('window-container').setStyle('width', w);

if ($chk($('bgDiv'))) {
$('bgDiv').setStyle('height', h);
$('bgDiv').setStyle('width', w);
}

if ($chk($('audioOverlay'))) {
$('audioOverlay').setStyle('height', h);
$('audioOverlay').setStyle('width', w);
}

if (w/h < whRatio) {

if ($chk($('bgImg'))) {
$('bgImg').setStyle('height', h);
$('bgImg').setStyle('width', h*whRatio);
}

} else {

if ($chk($('bgImg'))) {
$('bgImg').setStyle('width', w);
$('bgImg').setStyle('height', w/whRatio);
}

}

}

function justifyElement(theElement, elWidth, elHeight, offX, offY) {

	if ($chk(theElement)) {
	getWinDims();
	var theTop;
	var theLeft;
	var offsetX = 0;
	var offsetY = 0;
	var theWidth;
	var theHeight;
	
	if (offX) {
	offsetX = offX;
	}
	
	if (offY) {
	offsetY = offY;
	}
	
	if (elWidth) {
		if (elWidth=='inherit') {
			theWidth = parseInt(theElement.getStyle('width'));
		} else {
			theWidth = elWidth;
		}
	} else {
		theWidth = parseInt(theElement.getStyle('width'));
	}
	
	if (elHeight) {
		if (elHeight=='inherit') {
			theHeight = parseInt(theElement.getStyle('height'));
		} else {
			theHeight = elHeight;
		}
	} else {
		theHeight = parseInt(theElement.getStyle('height'));
	}
	
	/*if (h <= 600) { h=600; }
	if (w <= 1000) { w=1000; }*/

	/*if (h <= theHeight) { h=theHeight; }
	if (w <= theWidth) { w=theWidth; }
	
	theTop = Math.ceil((h - theHeight)/2) + offsetY;
	theLeft = Math.ceil((w - theWidth)/2) + offsetX;*/
	
	if (h <= theHeight) {
	theTop = 1;
	} else {
	theTop = Math.ceil((h - theHeight)/2) + offsetY;
	}
	
	if (w <= theWidth) {
	theLeft = 1;
	} else {
	theLeft = Math.ceil((w - theWidth)/2) + offsetX;
	}
	
	theElement.setStyles({
	'top' : theTop,
	'left' : theLeft
	});
	}
	
	//$('test').innerHTML = $('main-container').getPosition().y;

}



// if font face isn't supported, use cufon to style the font in cicle

var isFontFaceSupported = function(){
 
  var ua = navigator.userAgent, parsed;
 
  if (/*@cc_on@if(@_jscript_version>=5)!@end@*/0) 
      return true;
  if (parsed = ua.match(/Chrome\/(\d+\.\d+\.\d+\.\d+)/))
      return parsed[1] >= '4.0.249.4';
  if ((parsed = ua.match(/Safari\/(\d+\.\d+)/)) && !/iPhone/.test(ua))
      return parsed[1] >= '525.13';
  if (/Opera/.test({}.toString.call(window.opera)))
      return opera.version() >= '10.00';
  if (parsed = ua.match(/rv:(\d+\.\d+\.\d+)[^b].*Gecko\//))
      return parsed[1] >= '1.9.1';    
 
  return false;
 
}	
