/**
 * @author Rickard Claeson
 */

// From http://jonraasch.com/blog/a-simple-jquery-slideshow
function slideSwitch() {
    var $active = $('#slideshow img.active');

    if ( $active.length == 0 ) $active = $('#slideshow img:last');

    var $next =  $active.next().length ? $active.next()
        : $('#slideshow img:first');

    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}
$(function() {
	if($("#slideshow img").length > 1) setInterval( "slideSwitch()", 5000 );
});

// Lightbox
$(function() {
	// Fix to support the lightbox functionality
	$('.lightbox').each(function (index, node) {
		if(node.nodeName == 'IMG') node.setAttribute('href',  $(node).attr('alt'));
	});

	$('.lightbox').lightBox({
		fixedNavigation      : false,
		overlayBgColor       : '#000',
		overlayOpacity       : 0.8,
		imageLoading         : '/js/lightbox/images/lightbox-ico-loading.gif',
		imageBtnClose        : '/js/lightbox/images/lightbox-btn-close.gif',
		imageBtnPrev         : '/js/lightbox/images/lightbox-btn-prev.gif',
		imageBtnNext         : '/js/lightbox/images/lightbox-btn-next.gif',
		containerBorderSize  : 10,
		containerResizeSpeed : 400,
		txtImage             : 'Image',
		txtOf                : 'of',
		imageBlank           : '/js/lightbox/images/lightbox-blank.gif'
	});
});
