jQuery(function($){

	$(".prodMiniBox label input").click(function(){
		
		var stan = $(this).attr("id").split("_");
		var checkboxes = compareSelected();
		var status = document.getElementById($(this).attr("id")).checked;
		
		if (status == true)
		{
			if (checkboxes > 5)
			{
				alert ('Maksymalnie możesz dodać 5 produktów do porównania');
			}
			else
			{
				$("."+stan[2]).removeClass("prodMiniBox");
				$("."+stan[2]).addClass("prodMiniBoxSelected");
			}
		}
		else
		{
			$("."+stan[2]).removeClass("prodMiniBoxSelected");
			$("."+stan[2]).addClass("prodMiniBox");
		}
		
	});
	
});

function compare()
{
	if (compareSelected() == 0)
	{
		alert ('Zaznacz produkty do porównania');
	}
	else if (compareSelected() > 5)
	{
		alert ('Maksymalnie możesz dodać 5 produktów do porównania');
	}
	else
	{
		document.location.href = 'http://'+location.host+'/_strona/pl/porownywarka';
	}
}

function compareSelected()
{
	var select;
	
	$(".resize .prodMiniBox input").each(function(i)
	{
		if (document.getElementById(this.id).checked == true)
		{
			select = select + parseInt(1);
		}
		else
		{
			select = select + parseInt(0);
		}
	});
	
	return select;
}

function compareChecked()
{
	$(".resize .prodMiniBox input").each(function(i)
	{
		var status = $("#"+this.id).attr("id").split("_")
		
		if (document.getElementById(this.id).checked == true)
		{
			$("."+status[2]).removeClass("prodMiniBox");
			$("."+status[2]).addClass("prodMiniBoxSelected");
		}
	});
}
