//preload images for the slideshow
var imageList = [
	'businessEntities',
	'columns',
	'commercialContracts',
	'commercialFinance',
	'copyrightGavel',
	'downtown',
	'employmentAgreements',
	'entrance',
	'finances',
	'leaseContract',
	'lobby',
	'realProperty',
	'signing'
];
var il = imageList.length;
var images = [];
var loaded = 0;
var totalImages = il;
for (var i=0; i<il; i++) {
	var img = new Image;
	img.onload = function() {
		loaded++;
	};
	img.onerror = 	function() {
		totalImages --;
	};
	img.src = webroot+'assets/'+imageList[i]+'.jpg';
	images.push(img);
}

function overrideSlideshow(image) {
	clearTimeout(pause);
	var src = webroot+'assets/'+image;
	if ($('#overlay').length) {
		$('#overlay img').attr('src', src);
	} else {
		//add the thing
		$('#slideshow').prepend('<div id="overlay"><img src="'+src+'" /></div>');
	}
}
var pause = '';
var ss = '';

function backToSlideshow() {
	pause = setTimeout('removeOverlay()',750);
	console.log(ss);
}

function removeOverlay() {
	$('#overlay').fadeOut('fast', function() {
		$(this).remove();
	});
}


$(function() {
	$('#content').css('opacity', 0);
	$('#content').animate({
		opacity: 1
	}, 500);
	$('a.hover').hover(
		function() {
			var href = $(this).attr('href');
			var hrefA = href.split('/');
			var hrefL = hrefA.length - 1;
			var page = hrefA[hrefL];
			//get the image
			for (var i=0; i<il; i++) {
				if (imageList[i] == page) {
					overrideSlideshow(page+'.jpg');
					break;
				}
			}
		},
		function() {
			backToSlideshow();
		}
	);
	$('#slideshow').slideshow({
		timeout: 3500
	});
});
