// JavaScript Document
// Aloitussivun muokkaus ja asetus keskelle ikkunaa

$(window).load(function () {
	$("#frontpage_image").fadeIn(1100, function () {
	   $("#frontpage_fade").show(function () {
	   $("#frontpage_logo").show(function () {	
		  $('#frontpage_fade').animate({left: '+=330'}, 1200, function () {	
			 $("#text_block1, #text_block2").show(function () {
			 $("#wrap li").show().fadeIn('slow', function () {
			 $("#text_block1").fadeOut('slow', function () {
			 $("#text_block2").fadeOut('slow');											 
			 });
			 });
			 });
		  });
	   });
	   });
	});
});

$('body').ready(function() {
    var windowHeight = $(window).height();
    var wrapHeight = $('#wrap').height();
	var windowWidth = $(window).width();
    var wrapWidth = $('#wrap').width();
   
    if(wrapHeight < windowHeight) {
        $('#wrap').css('top', (Math.floor((windowHeight - wrapHeight) / 2) + $(window).scrollTop()) );
    }
	
    if(wrapWidth < windowWidth) {
        $('#wrap').css('left', (Math.floor((windowWidth - wrapWidth) / 2) + $(window).scrollLeft()) );
    }
	
	$(window).resize(function() {
	var windowHeight = $(window).height();
    var wrapHeight = $('#wrap').height();
	var windowWidth = $(window).width();
    var wrapWidth = $('#wrap').width();
		if(wrapHeight < windowHeight) {
        $('#wrap').css('top', (Math.floor((windowHeight - wrapHeight) / 2) + $(window).scrollTop()) );
    }
    if(wrapWidth < windowWidth) {
        $('#wrap').css('left', (Math.floor((windowWidth - wrapWidth) / 2) + $(window).scrollLeft()) );
    }
	});

});

//Etusivun linkit

$(document).ready(function() {
		$("#wrap li a").click(function() {

		if ($("#image, #image2, #page").is(":animated")) { 
        	return false; 
        }
		if ($(this).hasClass('shadow')) { 
			return false; }
			else
			{
			   $('#nav li a, .otsikko').removeClass('shadow');	
			   $(this).addClass("shadow");
			}
		$("#page").empty();
		var img_name = 'img/taustat/' + $(this).attr('id') + '.jpg'
		var name = 'php/' + $(this).attr('id') + '.php'
		var img = new Image();
		img.src=img_name;
		$("#image2").hide();
		$("#image2").empty();
		$("#image2").prepend(img);		
		$("#image").fadeOut(1500);
		$("#image2").fadeIn(1500, function () {
		   $("#image").empty();
		   $("#image").prepend(img);
		   $("#image").show();
			});
		
		$("#page").load(name);
		});	
	});

