/**
 * Spotlight
 *
 * @link http://www.feature.fi
 * @copyright 2009, Feature
 * @package Content4
 * @version 1.00
 */
var spotlightCurrentImage = 1;
var spotlightImagePath = '/files/spotlight/';
var spotlightUrls = [
						'/tuotteetjapalvelut/veneveistamot/', 
						'/tuotteetjapalvelut/venetarvikeosastot/',
						'/tuotteetjapalvelut/venetarvikeliikkeet/',
						'/tuotteetjapalvelut/laituritjasatamat/'
					];
var spotlightInt = false;
var spotlightSwapSeconds = 4;
var spotlightImages = [
						'/files/spotlight/fi/1.jpg?v102',
						'/files/spotlight/fi/2.jpg?v102',
						'/files/spotlight/fi/3.jpg?v102',
						'/files/spotlight/fi/4.jpg?v102'
					];

jQuery.fn.preloadImages = function() {
    var args = arguments[0] || {}; // It's your object of arguments

	imagesLoaded = 0;
	for(i = 0; i < args.length; i++) {
		$('<img />').attr('src',args[i]).load(function() {
			imagesLoaded++;
			if(imagesLoaded == args.length) {
				spotlightInt = setInterval("swapSpotlightImg()",spotlightSwapSeconds * 1000);
				return true;
			}
		});
    }
}

$(document).ready(function() {
	if(spotlightUrls[spotlightCurrentImage-1]) {
		$('#spotlight img').css('cursor','pointer');
		$('#spotlight img').click(function() {
			document.location = spotlightUrls[spotlightCurrentImage-1];
		});
	} else {
		$('#spotlight').css('cursor','inherit');
	}

	// Preload images
	$("body").preloadImages(spotlightImages);
});

function swapSpotlightImg() {
	spotlightCurrentImage++;
	if(spotlightCurrentImage > spotlightImages.length) spotlightCurrentImage = 1;

	$('#spotlight img').fadeOut(350,function() {
		$('#spotlight img').attr('src',spotlightImages[spotlightCurrentImage-1]);
		$('#spotlight img').fadeIn(200);
			
		if(spotlightUrls[spotlightCurrentImage-1]) {
			$('#spotlight img').css('cursor','pointer');
			$('#spotlight img').click(function() {
				document.location = spotlightUrls[spotlightCurrentImage-1];
			});
		}
	});
}