$(document).ready(function(){
	
	$('#main-nav li').each(function ()
	{
		if ($(this).hasClass('active'))
		{
			$(this).ftr("/swf/sifr/GillSansExtraBold.swf",{color:"#686664", size:12, transform:"uppercase", multiline:true, topOffset:4});
		}
		else
		{
			$(this).ftr("/swf/sifr/GillSansExtraBold.swf",{color:"#9c9a97", size:12, transform:"uppercase", multiline:true, topOffset:4});
		}
	});
	
	//$('#main-nav li span.amout-of-wishes').ftr("/swf/sifr/GillSansExtraBold.swf",{color:"#D18569", size:12, transform:"uppercase", multiline:true});
	
	$('#page-level-nav li').each(function ()
	{
		if ($(this).hasClass('active'))
		{
			$(this).ftr("/swf/sifr/GillSansExtraBold.swf",{color:"#686664", size:11, transform:"uppercase", topOffset:4});
		}
		else
		{
			$(this).ftr("/swf/sifr/GillSansExtraBold.swf",{color:"#9c9a97", size:11, transform:"uppercase", topOffset:4});
		}
	});	
	
	$('.contextual-nav li').ftr("/swf/sifr/GillSansStandard.swf", {size:11, transform:"uppercase", multiline:true, topOffset:2});
	$('.legend h2').ftr("/swf/sifr/GillSansLight.swf",{size:19, transform:"uppercase", multiline:true, topOffset:5});
	$('.legend h3').ftr("/swf/sifr/GillSansStandard.swf",{size:11, transform:"uppercase", multiline:true, topOffset:2});
});

// Tuotekategorian paasivun tuotenosto linkiksi
$(document).ready(function(){
	$('#product-list li').each(function(){
		if ($(this).find('a').length)
		{
			$(this).click(
			function(){
				window.location.href = $(this).find('a:first').attr('href');
			})
			$(this).hover(
			function(){
				$(this).toggleClass('hover');
				$(this).find('img').animate({opacity: 0.8},100);
			},
			function(){
				$(this).toggleClass('hover');
				$(this).find('img').animate({opacity: 1},100);
			})
		}
	})
});


// Linkkien esiintuonti kuvien yhteydessa
$(document).ready(function() {
	$('.current-item, ul#latest-items li, .figure').each(function(){
		if ($(this).find('.legend p').length)
		{
			$(this).find('.legend p').hide()
			$(this).click(
			function(){
				window.location.href = $(this).find('p:last a').attr('href');
			});
			$(this).hover(
			function(){
				$(this).find('p:last').slideToggle(200);
				$(this).toggleClass('hover');
			}, function(){
				$(this).find('p:last').slideToggle(200);
				$(this).toggleClass('hover');
			});
		}
	})
});


// Nayttaa / sulkee tuotesivulla listiedot & varit
$(document).ready(function(){
	$('.product-details, .product-colours, .product-extra-details').addClass('hidden');
	$('.sidebar .open-info').click(function(){
		var id = $(this).attr('href');
		var $details = $(id)
		$details.slideToggle('slow');
		if (!$details.children(".toggle-link").length)
		{
			$details.prepend('<a class="toggle-link" href="#">Close</a>');
			$details.children('.toggle-link').click(function(){
				$details.slideToggle('slow');
				return false;
			});
		}
		return false;
	});
	
	// Kuvakaruselli tuotesivuilla
	$('.picture-nav a').click(function(event) {
		var $gallery = $(this).parent().parent().parent();
		var nr = parseInt($(this).text());
		changeImage($gallery, nr);
		event.preventDefault();
	})
	$('.picture img').click(function (){
		var $gallery = $(this).parent().parent();
	 changeImage($gallery);
	}).addClass("hover")
	
	function changeImage($gallery, picnr)
	{
		if (!$gallery.data("current"))
		{
			$gallery.data("current", 1);
			$gallery.find('img').load(function(){
				$(this).hide();
				$(this).fadeIn('slow');
			});
		}
	 var current = parseInt($gallery.data("current"));
		if (!picnr)
		{
			picnr = current + 1;
		}
		var total = $gallery.find('a').length;
		if (picnr > total)
		{
			picnr = 1;
		}
		if (picnr == current)
		{
			return;
		}
		$gallery.find('a').removeClass('active');
		var $currentLink = $gallery.find('a:eq('+(picnr-1)+')')
		$currentLink.addClass('active');
		var href =	$currentLink.attr('href');

		$gallery.find('img').fadeOut("fast", function(){
			$(this).attr('src',href);
		})
		
		$gallery.data("current", picnr);
	}
});

// Kuva haivytykset
$(document).ready(
	function(){
		$('.images').innerfade({
		speed: 1500,
		timeout: 6200,
		type: 'sequence',
		containerheight: '482px'
	});
		$('body#news-page .news-pics').innerfade({
		speed: 1500,
		timeout: 6200,
		type: 'sequence',
		containerheight: '482px'
	});
});