$(document).ready(function(){
	$("form.jqtransform").jqTransform();
	
	setTimeout("slideshow_next()", 5000);
	
	  
});	  
	

function slideshow_next() {
			if ($('#slideshow').find('li').length<2)
				return false;
				
				
			var $active = $('#slideshow li.active');
			
			 if ( $active.length == 0 ) $active = $('#slideshow li:last');
 
			 var $next =  $active.next().length ? $active.next()
				: $('#slideshow li:first');
 
			$active.animate({opacity: 0}, 1000,function() {
					$active.removeClass('active');
				});
				
			$next.css({opacity: 0.0})
					.addClass('active')
					.animate({opacity: 1.0}, 1000,function() {
						$next.addClass('active');
						
					});
					
			setTimeout("slideshow_next()", 5000);
		}
		

		

function change_lang(lang){
	location.href = "/"+lang+"/";
}

function calculate(){
	var money = document.getElementById('money');
	var families = document.getElementById('families');
	var results = document.getElementById('results');

	do_calculate = true;

	if(money.value == 0 || families.value == 0) return;

	money.style.borderColor = (money.value == '' || !isNumeric('money')) ? '#ec3838' : '#cccccc';
	families.style.borderColor = (families.value == '' || !isNumeric('families')) ? '#ec3838' : '#cccccc';

	if(money.value == '' || families.value == '' ||
	 !isNumeric('money') || !isNumeric('families')) do_calculate = false;

	if(do_calculate)
	results.innerHTML = 'Varje familj behöver sälja: <strong>' + Math.round(money.value/90/families.value) + 'st</strong>';
}

function isNumeric(fieldId) {
	var tmpStr = document.getElementById(fieldId);
	var sText = tmpStr.value;
	var ValidChars = "0123456789-/\\.";
	var Char;

	for (var i = 0; i < sText.length; i++) {
		Char = sText.charAt(i);
		if (ValidChars.indexOf(Char) == -1) { return false; }
	}
	return true;
}
