$(document).ready(function(){

	var template_dir = 'wp-content/themes/skipping_infinity';
	
	//Preload Images
	var preloadImages = readEmbeddedFiles();
	
	//loop to build "new Image()" objects
	var imgs = new Array();
	var cycleImgs = '';
	for (var i=0; i < preloadImages.length; i++) {
		imgs[i] = new Image();
		imgs[i].src = preloadImages[i]; //preload image
		cycleImgs += '<img src="' + preloadImages[i] + '" />';//build code string to insert images
					  
	}

	$('#cycle').html(cycleImgs); //Insert Images
	
//Cycle
	$('#cycle').cycle({
		fx: 'fade',
		prev: '#previous',
		next: '#next'
	});

//Lightbox
	$('#thumbs a').lightBox({
		imageBtnClose: 'wp-content/themes/skipping_infinity/images/lightbox-btn-close.gif',
		imageBtnPrev: 'wp-content/themes/skipping_infinity/images/lightbox-btn-prev.gif',
		imageBtnNext: 'wp-content/themes/skipping_infinity/images/lightbox-btn-next.gif',
		imageLoading: 'wp-content/themes/skipping_infinity/images/lightbox-ico-loading.gif',
		imageBlank: 'wp-content/themes/skipping_infinity/images/lightbox-blank.gif'	
	});
	
//Gallery Home
	//set thumbs to off
	$('#concept img').attr('src', template_dir + '/images/concept_gallery_thumb_off.png');
	$('#editorial img').attr('src', template_dir + '/images/editorial_gallery_thumb_off.png');
	$('#sequential img').attr('src', template_dir + '/images/sequential_gallery_thumb_off.png');
	$('#sketches img').attr('src', template_dir + '/images/sketches_gallery_thumb_off.png');
	$('#design img').attr('src', template_dir + '/images/design_gallery_thumb_off.png');
	
	function turnon(name, id){
		var oldImage = $('#' + name +' img');
		var newImage =  $('<a href="?page_id='+id+'"><img src="'+template_dir+'/images/'+name+'_gallery_thumb.png"/></a>');
		newImage.hide();
		$('#'+name).append(newImage);
		newImage.fadeIn(500, function(){ oldImage.remove();});
	}	
	function turnoff(name){
		var oldImage = $('#' + name +' img');
		var newImage =  $('<img src="'+template_dir+'/images/'+name+'_gallery_thumb_off.png"/>');
		newImage.hide();
		$('#'+name).append(newImage);
		newImage.fadeIn(500, function(){ oldImage.remove();});
	}
	
	
	$('#concept').hover(function(){turnon('concept','8');},function(){turnoff('concept');});
	$('#editorial').hover(function(){turnon('editorial','13');},function(){turnoff('editorial');});
	$('#sequential').hover(function(){turnon('sequential','11');},function(){turnoff('sequential');});
	$('#sketches').hover(function(){turnon('sketches','15');},function(){turnoff('sketches');});
	$('#design').hover(function(){turnon('design','58');},function(){turnoff('design');});
	
	
	
		
	
}); //end ready