$(document).ready(function() {

	var imgName		= 'images/kuva_' + window.location.hash.substr(1) + '.jpg';
		
	
	if(!window.location.hash.substr(1)){
		imgName = "images/kuva_etusivu.jpg";  
	}
	
	
	// Check for hash value in URL 
    var hash = window.location.hash.substr(1);  
	
	
    $('#navigation a').each(function(){  
        var href = $(this).attr('href');  
        if(hash==href.substr(0,href.length-4)){  
            var toLoad = hash+'.php';  
            $('#loadContent').load(toLoad)
			$(this).parent().addClass('selected');
        }
		if(!hash){
			var loadFirst = $('#navigation li:first a').attr('href');
			$('#loadContent').load(loadFirst);
			$('#navigation li:first').addClass('selected');	
		}
   });
	
/*NAVIGAATION TOIMINTA*/
	$('#navigation a').click(function () {
		var btn		= this;
		window.location.hash = $(this).attr('href').substr(0,$(this).attr('href').length-4);
		imgName		= 'images/kuva_' + window.location.hash.substr(1) + '.jpg';
		$('#loadContent').fadeOut("fast", function(){
			$('#loadContent').empty();
			$('#loadContent').load($(btn).attr('href'), ff());
		}); 
		$('#navigation li').removeClass('selected');
		$(this).parent().addClass('selected');
		
		loadImg(imgName);  
		return false;								   
	});
	
	function ff(){
		$('#loadContent').fadeIn("fast"); 
	}
	
/* SULJE NAPPULA */	
	$('#phone #sulje').click(function (){
		$('#phone_content').load($(this).attr('href'), function(){ loadImg(imgName); });
		$('#phone_content').css('height', '369px');
		$(this).fadeOut('fast');
		return false;
	});
	
/* PUHELIMEN KUVAN VAIHTUMINEN */
	$('#phone_content').load('phone_content_basic.php', function (){
		loadImg(imgName);  
	});
	
	function loadImg(img){
		$('#phoneImg').attr({ src:img });	
	}
	
/* SULJE POPUP */	
	$('.popupsulje').click(function (){
		$('#popup_bg').fadeOut('fast');
		$('#popup').fadeOut('fast');
		$('#popup_small').fadeOut('fast');
		$('#popup_content').empty();
		$('#popup_content_small').empty();
		return false;
	});
	
	$('.popupsulje_saannot').click(function (){
		$('#popup_saannot').fadeOut('fast');
		return false;
	});

});