$(document).ready(function(){
    setdowloadinformation();
	refreshTotal();
	
	$(".downloadList input").click(function(){
		refreshTotal();
	});
	
});


function setdowloadinformation()
{
    $("#dowloadinformation").attr("class","dowloadinformation");
}
	

function refreshTotal()
{
	var total = 0.0;
	var arrInput = $(".downloadList li input");
	
	for(var i=0; i<arrInput.length; i++)
	{
		var elmLi = arrInput[i].parentNode.parentNode;
		if(arrInput[i].checked)
		{
			var elmSize = elmLi.getElementsByTagName("strong")[0];
			var intInc = 0;
			if(elmSize.parentNode.innerHTML.indexOf(" KB")!=-1)
				intInc = parseFloat(elmSize.firstChild.nodeValue);
			else
				intInc = parseFloat(elmSize.firstChild.nodeValue) * 1000;
			
			total += intInc;
			$(elmLi).addClass("selected");
		}
		else
		{
			$(elmLi).removeClass("selected");
		}
		
	}
	if(total > 1000)
		total = Math.round(total/100) / 10 + " MB";
	else
		total = Math.round(total) + " KB"
	if (!total)
		total = "Ingen fil vald";
	
	$("#totalFilesize").html(total)
	
}


