$(document).ready(function(){


//gallery
//$(this).siblings('.images').animate({ marginRight : "+="+image},500);


	var images = $('#images').children().size();
	var image = $('#images .image').width();
	var current = 1;
	var imagesWidth = images * image;
	$('#images').width(imagesWidth);
	$('#navigator .text').text(current+" / "+images);

	$('.nuoli-vasen').click(function(){
		if(current-1>0){
		current --
		$('#navigator .text').text(current+" / "+images);
		$(this).parent().siblings('.raami').find('#images').animate({ marginLeft : "+="+image},500);
		}
	});
	$('.nuoli-oikea').click(function(){
		if(current<images){
		current ++
		$('#navigator .text').text(current+" / "+images);
		$(this).parent().siblings('.raami').find('#images').animate({ marginLeft : "-="+image},500);
		}
	});

//blog 

	$('.nuoli-ylos').click(function(ev) {
		$(this).siblings('.nuoli-alas').fadeIn('slow');
		singlepostheight = $(this).siblings('.raami').find('.post').attr('offsetHeight')*2;
		postsheight = $(this).siblings('.raami').find('.posts').attr('offsetHeight');
		currenttop = parseInt($(this).siblings('.raami').find('.posts').css('marginTop'));
       	if(currenttop < 0 && ev.detail == 1){
      	$(this).siblings('.raami').find('.posts').animate({ marginTop : "+="+singlepostheight},500);
      			if(currenttop >= -1*singlepostheight){
					$(this).fadeOut('slow');
				}
      	}
      	});
		
	$('.nuoli-alas').click(function(ev) {
		$(this).siblings('.nuoli-ylos').fadeIn('slow');
	    singlepostheight = $(this).siblings('.raami').find('.post').attr('offsetHeight')*2;
		postsheight = $(this).siblings('.raami').find('.posts').attr('offsetHeight');
		currenttop = parseInt($(this).siblings('.raami').find('.posts').css('marginTop'));
		if(currenttop > (-1*postsheight+singlepostheight) && ev.detail == 1){	
		$(this).siblings('.raami').find('.posts').animate({ marginTop : "-="+singlepostheight },500);
			//Fade the button
				if(currenttop <= (-1*postsheight+singlepostheight+singlepostheight)){
					$(this).fadeOut('slow');
				}
		}
		});
		
		
//events
	$('#showform').click(function(){
		$('#form').fadeIn('slow');
		});

	$('#past .nuoli-ylos').click(function(ev) {
		$(this).siblings('.nuoli-alas').fadeIn('slow');
		singlepostheight = $(this).siblings('.raami').find('.event').attr('offsetHeight')*2;
		postsheight = $(this).siblings('.raami').find('.events').attr('offsetHeight');
		currenttop = parseInt($(this).siblings('.raami').find('.events').css('marginTop'));
       	if(currenttop < 0 && ev.detail == 1){
      	$(this).siblings('.raami').find('.events').animate({ marginTop : "+="+singlepostheight},500);
      			if(currenttop >= -1*singlepostheight){
					$(this).fadeOut('slow');
				}
      	}
      	});
		
	$('#past .nuoli-alas').click(function(ev) {
		$(this).siblings('.nuoli-ylos').fadeIn('slow');
	    singlepostheight = $(this).siblings('.raami').find('.event').attr('offsetHeight')*2;
		postsheight = $(this).siblings('.raami').find('.events').attr('offsetHeight');
		currenttop = parseInt($(this).siblings('.raami').find('.events').css('marginTop'));
		if(currenttop > (-1*postsheight+singlepostheight) && ev.detail == 1){	
		$(this).siblings('.raami').find('.events').animate({ marginTop : "-="+singlepostheight },500);
			//Fade the button
				if(currenttop <= (-1*postsheight+singlepostheight+singlepostheight)){
					$(this).fadeOut('slow');
				}
		}
		});
});
