// ta daa..
$(document).ready(function() {
	
	$('#karuselli').cycle({
		speed:		1000,
	    timeout:	2000,
		random:		1
	});
	
	
	$('.email').each(function() {
		var sposti = $(this).text().replace('[]','@');
		$(this).text(sposti);
		$(this).attr('href','mailto:'+sposti);
	});
	
	$('.laatikko .vasemmalle, .laatikko .oikealle').each(function() {
			var otsikko = encodeURI($(this).find('h2').text());
			var kuva = $(this).parent().find('img').attr('src');
			var sisalto = '';
			$(this).find('p').each(function() {
				sisalto += $(this).text();
			});
			sisalto = encodeURI(sisalto);
			$(this).append('<a href="http://www.facebook.com/dialog/feed?app_id=132954063449817&link=http://www.rili.fi/&picture=http://www.rili.fi'+kuva+'&name='+otsikko+'&caption=Rilin tervajuomatarinat&description='+sisalto+'&redirect_uri=http://rili.fi/Rili" target="_blank" class="fb">Jaa tarina&rsaquo;</a><br class="cb" />');
	});
	

	$('#submit_rilitarina').click(function(event) {
		var formi = $(this).parent().parent();
		
		$('.kentta').each(function() {
			if($(this).val() == '')
			{
				$(this).focus();
				event.preventDefault();
				return false;
			}
		});
	});
	
	$('#laheta_palaute').click(function(event) {
		var formi = $(this).parent().parent();
		
		$('.kentta').each(function() {
			if($(this).val() == '')
			{
				$(this).focus();
				event.preventDefault();
				return false;
			}
		});
	});

});
