/* ########################################################## */
/*							                       					              */
/*	  Aucor Oy								                                */
/*	  Javascript design by Aucor Oy 2009                      */
/*	  www.aucor.fi                                            */
/*	  antti@aucor.fi 							                            */
/*											                                      */
/* ########################################################## */

$(function() {
	// initialize scrollable
	$("div.scrollable").scrollable();
	$("img.reflect").reflect();
	$("div.scrollable img").reflect();
});

/* Any menu list element behaves as hover */
$('ul#menu li').hover(function() {
  $(this).addClass('hover');
}, function() {
  $(this).removeClass('hover');
});

/* TUOTEKARUSELLI */
$(function() {
//$(".items img.active").css( { width: "50px", height: "50px",  } ).reflect();
  $(".items img").click(function() {
	// calclulate large image's URL based on the thumbnail URL (flickr specific)
	var url = $(this).attr("src").replace("_t", "");

	// get handle to element that wraps the image and make it semitransparent
	var wrap = $("#image_wrap").fadeTo("medium", 0.3);

	// the large image
	var img = new Image();
	// call this function after it's loaded
	img.onload = function() {
		// make wrapper fully visible
		wrap.fadeTo("fast", 1);
		// change the image and create reflection
		wrap.find("img").attr("src", url).reflect();
		wrap.find("canvas").css({margin: "0"});
	};

	// begin loading the image
	img.src = url;
  // when page loads simulate a "click" on the first image
  }).filter(":first").click();
});

/*
  PUDOTUSVALIKKO
*/
$('ul#menu li.expanded').hover(
			function() { $('ul', this).css('display', 'block'); },
			function() { $('ul', this).css('display', 'none'); }
);
/*
  AMBIENT 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}, 3000, function() {
            $active.removeClass('active last-active');
        });
}

$('a.toggleslideshow').removeAttr("href");

$(".toggleslideshow").click(function() { slideSwitch();});