/* General Config */
/* *********************************************************************************/

var WEB_ROOT = ((document.location.protocol == 'https:') ? 'https://' : 'http://') + document.location.host;
var BASE_SERVER = location.host.substr(location.host.indexOf('.') + 1);
var SOAK = {};

/* Window onload events */
/* *********************************************************************************/

$(window).load(function(){

	// Label new window links
	$('a.newwindow').each(function(){
		$(this).attr('title',$(this).attr('title') ? $(this).attr('title') + ' (opens in a new window)' : '(This link opens in a new window)');
	});

});

$(function(){
	
	// .newwindow links to open in new window
	$('a.newwindow').live('click', function(){
		window.open(this.href);
		return false;
	});
	
	// preload homepage images (see function below)
	if ($('#content-container').hasClass('home')) {
		jQuery.preLoadImages("img-feature-1.jpg","img-feature-2.jpg","img-feature-3.jpg","img-feature-4.jpg","img-feature-5.jpg");
	}
	
	// initialise multiple select prettifier plugin (toChecklist)
	$('#categories').toChecklist();
	
	$('#slideshow-nav a').live('click', function(){
		if (!$('#slideshow-nav').hasClass('working') && !$(this).hasClass('selected')) {
			$('#slideshow-nav').addClass('working');
			var index = $('#slideshow-nav a').index($(this)) + 1;
			$('#slideshow-nav a').removeClass();
			$(this).addClass('selected');
			$('#slideshow img').fadeOut(500);
			$('#slideshow div').slideUp(500, function(){
				$('#slideshow').load(WEB_ROOT + '/index/slideshow/format/html/id/' + index, function(){
					$('#slideshow img').hide().fadeIn(300);
					$('#slideshow div').hide().slideDown(300);
					$('#slideshow-nav').removeClass('working');
					Cufon.refresh();
				});
			});
		}
		return false;
	});
	
	// Gallery lightbox
	$('ul.gallery a').lightBox({fixedNavigation:true});
	
});
	
// preload images - arguments are image paths relative to the current page.
var cache = [];
$.preLoadImages = function() {
	var args_len = arguments.length;
	for (var i = args_len; i--;) {
		var cacheImage = document.createElement('img');
		cacheImage.src = 'static/images/'+arguments[i];
		cache.push(cacheImage);
	}
}
