//Cufon.replace('ul#mainmenu-dark, div.copy');

$(window).load(function() {
	initBigImage();
});

$(document).ready(function() {
	//initSplash();
	
	initMainmenu();
	//initBigImage();
		
	/*$('a#change-style').click(function(e) {
		e.preventDefault();
		if ($('header ul').attr('id') == 'mainmenu')
		{
			$.backstretch("img/img003_iso.jpg");
			$('header ul').attr('id', 'mainmenu-dark');
			$('header h1').attr('id', 'logo-dark');
		}
		else
		{
			$.backstretch("img/0894_DSC0581_iso.jpg");
			$('header ul').attr('id', 'mainmenu');
			$('header h1').attr('id', 'logo');
		}
	});*/
	
	$('div#thumbs a').mouseover(function() {
		$(this).find('div').css({ opacity: 0.8, background: '#FFD800' });
	});
	
	$('div#thumbs div').live('mouseout', function() {
		$(this).css({ opacity: 0 });
	});
	
	$('div#thumbs div').live('click', function() {
		$(this).css({ opacity: 0 });
	});
	
	/*$('ul#mainmenu-dark a').click(function() {
	
		if ($('div#splash').length != 0)
		{
			$('div#splash').remove();
			$('div#wrap').fadeIn();
		}
	});*/
	
	/*$('div#thumbs a#thumb-1').click(function(e) {
		e.preventDefault();
		$('div#thumbs').hide();
		$('div#suurennos1').show();
	});
	
	$('div#thumbs a#thumb-2').click(function(e) {
		e.preventDefault();
		$('div#thumbs').hide();
		$('div#suurennos2').show();
	});*/
	
	/*$('div.suurennos').click(function() {
		$(this).fadeOut();
		$('div#thumbs').fadeIn();
	});*/
	
	
	
});

$(window).resize(function() {
	initSplash();
	initMainmenu();
	initBigImage();
	//initThumbs();
});

function initBigImage() {
	if ($(window).width() > 400)
	{
		var suur_w = $('div.suurennos img').width();
		var suur_h = $('div.suurennos img').height();
		
		if (suur_w <= suur_h) // pystykuva
		{
			$('div.suurennos img').css({ height: $(window).height() - 210 + 'px', minHeight: '200px' });
		}
		else // vaakakuva
		{
			if ($(window).width() > $(window).height()) // landscape screen
				$('div.suurennos img').css({ height: $(window).height() - 210 + 'px', maxHeight: '566px', minHeight: '200px' });
			else // portrait screen
				$('div.suurennos img').css({ height: $(window).height() - 500 + 'px', maxHeight: '566px', minHeight: '200px' });
		}
	}	
	$('div.suurennos').css({
		width: $('div.suurennos img').width() + 'px'
	});
}

function initSplash() {
	var new_top = parseInt(($(window).height() - $('div#splash img').height()) / 2);
	$('div#splash').css({top: new_top + 'px'});
}

function initMainmenu() {
	var new_left = parseInt(($(window).width() - 945) / 2);
	$('div#wrap').css({left: new_left + 'px'});
}

function initThumbs() {
	var new_w = $('div#wrap').width();
	if (new_w < 945)
	$('div#wrap').css('width', new_w + 'px');
}

function fadeInBg() {
	$('body').append('<div id="popup-bg"></div>');	
	$('div#popup-bg').css({
		opacity: '0.7',
		width: $(document).width(),
		height:	$(document).height()
	}).fadeIn();
}
