$(function() {
	if(window.location.href.match(/(asuinalue\/)|(aktiviteetit\/)|(yhteystiedot)/))
		$('.contact').hide();
	
	$('.ban-25').each(function(e) {
		var imgs = $(this).children('img');
		
		if(imgs.length > 1) {
			var i = 0;
			
			imgs.slice(1).hide();
			
			setTimeout(function() {
				setInterval(function() {
					imgs.eq(i++ % imgs.length).fadeOut(1000);
					imgs.eq(i % imgs.length).hide().css({'z-index': i}).fadeIn(2000);
				}, 7500);
			}, e * 1500);
		}
	});
	
	
	var videos = {
		'/etusivu': 'qmIT0Uu0iTE',
		'/asuinalue': 'GcpFHgycaXU',
		'/asuinalue/historia': 'HQ8DvRaXg0s',
		'/aktiviteetit/ratsastus': 'ytMj9LBk8eM',
		'/aktiviteetit/golf': 'h6YVlg8b39k',
		'/aktiviteetit/luontomatkailu': 'xGgDXiDKaR8'
	};
	
	if(videos[window.location.pathname]) {
		var banner = $('header').next('div:not(#main)');
		if(!banner.length)
			banner = $('#image-wrap');
		
		var video = videos[window.location.pathname];
		
		var code = '<object style="width: 900px; height: 410px;"><param name="movie" value="http://www.youtube.com/v/'+video+'?version=3&feature=player_detailpage&autoplay=1"><param name="allowFullScreen" value="true"><param name="allowScriptAccess" value="always"><embed src="http://www.youtube.com/v/'+video+'?version=3&feature=player_detailpage&autoplay=1" type="application/x-shockwave-flash" allowfullscreen="true" allowScriptAccess="always" width="900" height="410"></object>';
		
		$('header').after('<div id="video" style="position: relative; margin: 0 -100px; padding: 0 100px; background: #000; display: none;"></div>');
		
		$('header').after('<a class="open-video">» Käynnistä video</a>');
		
		$('a.open-video').click(function() {
			banner.hide();
			$(this).hide();
			
			$('#video').html(code).show();
			
			$('#video').append('<a class="x" style="position: absolute; top: 0; right: 0; color: #fff; font-size: 18px; font-weight: bold; width: 40px; text-align: center; line-height: 40px; cursor: pointer;">X</a>');
		});
		
		$('#video a.x').live('click', function() {
			$('#video').empty().hide();
			banner.show();
			$('a.open-video').show();
		})
	}
	
	
	
	// initialize scrollable
	var elems = $(".items img");
	for(var i = 0; i < elems.length; i+=6) {
	elems.slice(i, i+6).wrapAll("<div></div>");
	}

	$(".scrollable").scrollable();
	
	$(".items img").click(function() {
	
		// see if same thumb is being clicked
		if ($(this).hasClass("active")) { return; }
	  var timeOut;
	
		var url = $(this).attr("src").replace("Fthumb5", "Fthumb4");
	
		// get handle to element that wraps the image and make it semi-transparent
		var wrap = $("#image-wrap").fadeTo(200, 0.5, function() {
		
		
	
	
		// the large image from www.flickr.com
		var img = new Image();
	
	
		// call this function after it's loaded
		img.onload = function() {
	
			// make wrapper fully visible
			
			
			  wrap.fadeTo(200, 1);
			
				
			// change the image
			wrap.find("img").attr("src", url);
	
		};
	
		// begin loading the image from www.flickr.com
		img.src = url;
		
			});
	
		// activate item
		$(".items img").removeClass("active");
		$(this).addClass("active");
	
	// when page loads simulate a "click" on the first image
	}).filter(":first").click();
	
});



  

