var currentSpa = '', isSport = false, currentSkirt = 'mahogany', currentShell = 'arctic', imageUrl = 'http://freeflowspas.com/images/new-spas/';
$(function() {

currentSpa = $('#productBlockImage img')[0].className;

if ($('#sport-colors')[0]) {
	isSport = true;
}

var skirts = ['mahogany', 'redwood', 'gray'];
var shells = ['granite', 'pacific', 'arctic', 'sahara'];
var sportShells = ['granite', 'sahara'];

// Image preloading
var i, j;
if (isSport) {
	for (i=0;i<sportShells.length;i++) {
		$('<img>').attr('src', imageUrl + currentSpa + '-' + sportShells[i] + '.png');
	}
	
} else {
	for (i=0;i<skirts.length;i++) { 
		for (j=0;j<shells.length;j++) {
			$('<img>').attr('src', imageUrl + currentSpa + '-' + skirts[i] + '-' + shells[j] + '.png');
		}
	}
}

// Hover events
if (isSport) {
	$('#sport-colors .color').hover(function() {
		$(this).addClass('hover');
		currentShell = this.className.split(' ')[1];
		$('#productBlockImage img').attr('src', imageUrl + currentSpa + '-' + currentShell + '.png');
		$('#productBlockImage .top').attr('href', imageUrl + currentSpa + '-big-' + currentShell + '-top.jpg');
		$('#productBlockImage .side').attr('href', imageUrl + currentSpa + '-big-' + currentShell + '-side.jpg');
	}, function () {
		$(this).removeClass('hover');
	});
	
} else {
	$('#skirt-colors .color').hover(function() {
		$(this).addClass('hover');
		currentSkirt = this.className.split(' ')[1];
		$('#productBlockImage img').attr('src', imageUrl + currentSpa + '-' + currentSkirt + '-' + currentShell + '.png');
		$('#productBlockImage .side').attr('href', imageUrl + currentSpa + '-big-' + currentSkirt + '-' + currentShell + '.jpg');
	}, function () {
		$(this).removeClass('hover');
	});
	
	$('#premier-colors .color').hover(function() {
		$(this).addClass('hover');
		currentShell = this.className.split(' ')[1];
		$('#productBlockImage img').attr('src', imageUrl + currentSpa + '-' + currentSkirt + '-' + currentShell + '.png');
		$('#productBlockImage .top').attr('href', imageUrl + currentSpa + '-big-' + currentShell + '.jpg');
		$('#productBlockImage .side').attr('href', imageUrl + currentSpa + '-big-' + currentSkirt + '-' + currentShell + '.jpg');
	}, function () {
		$(this).removeClass('hover');
	});
	
	$('#premier-colors .color').eq(2).hover();
}

$('#productBlockImage a').lightBox();

});