$(document).ready(function() {
	// Initialisoi pretty photo
	$("a[rel^='prettyPhoto']").prettyPhoto();	
	
	$(window).resize(function() {
		fit();
	});
	fit();
	
	/*  Muut komennot tähän */
	$('.linkki').css({'opacity' : '0.8', 'cursor' : 'pointer'});			
	$('.linkki').hover(function(){
		$(this).css('opacity','1.0');
	},function(){
		$(this).css('opacity','0.8');
	});
	
	// geneerinen hover stylen mouseover
	$("body").delegate(".hover", "mouseover", function(){
		try{
			lastBgPosition = determine_bg_pos($(this));
			var newPos = lastBgPosition.substr(0, lastBgPosition.indexOf(' '))+' bottom';
  			$(this).css({'background-position' : newPos, 'cursor' : 'pointer'});
		}catch(e){
			alert(e.message);
		}
	});
	$("body").delegate(".hover", "mouseout", function(){
		$(this).css('background-position',lastBgPosition);
	});	
	/* Init main menu */
	var i = 0;
	$('#mainMenuBgs > div').each(function(){
		pos = parseInt(i * 80);
		$(this).css('left', pos);
		i++;			
	});
	var i = 0;
	$('#mainMenuLinks > div').each(function(){
		pos = parseInt(60 + i * 80);
		$(this).css('left', pos);
		i++;			
	});
	$('.mm').hover(function(){
		$('#mainMenuBgs div').eq(this.id -1).fadeTo('fast', 1.0);
		
	},function(){
		$('#mainMenuBgs div').eq(this.id-1).fadeTo('fast', 0.7);
	});
	$('.mmSel').fadeIn('slow');
	$('.mmBgSel').fadeIn('slow');
	
	$('.mm').delay(500).fadeTo('slow', 0.7);
	$('.mmBg').delay(500).fadeTo('slow', 0.7);
});

function determine_bg_pos(obj){
	// parameter obj is something like $('#my-div')
   	var pos = $(obj).css("background-position");
   	if (pos == 'undefined' || pos == null) {
      		pos = $(obj).css("background-position-x") +' ' +  $(obj).css("background-position-y"); //die in hell
   	}
   	return pos;
}
function popitup(url) {
	newwindow=window.open(url,'name','height=440,width=680');
	if (window.focus) {newwindow.focus()}
	return false;
}
function fit(){
	/* skaalaa yläpalkit */
	var contentHeight = $(window).height();
	//var headerHeight = Math.ceil((contentHeight-438)/3);
	var tabsHeight = Math.ceil(contentHeight-590);
	/*
	if(headerHeight > 130){
		$('#header').css('height',headerHeight);
		$('#headerContainer').css('height',headerHeight);
		$('#slideshow').css('top',headerHeight-22);
	}
	*/
	if(tabsHeight > 150){
		$('#tabs').css('height',tabsHeight);
	}			
	/*
	if(contentHeight > 700){
		$('#footer').css('height',contentHeight);
	}
	*/
	//$('#welcomeContainer').css('height',contentHeight);
}
function inputClick(elem){
	elem.style.background = '#fff';
	try{
		if(elem.value == elem.title){
			elem.value = '';
		}	
	}catch(e){}
}
function inputBlur(elem){
	elem.style.background = '#f4eede';
	try{
		if(elem.value == ''){
			elem.value = elem.title;		
		}
	}catch(e){}
}
/*
function facebookSite() {
	$('#__ss_9387593').hide();
	
	$('.readMore').click(function(){
		$('#__ss_9387593').fadeIn();
		$('.readMore').fadeOut();
	});
	$('.hidePowerpoint').click(function(){
		$('#__ss_9387593').fadeOut();
		$('.readMore').fadeIn();
	});
}
*/
