//global variables that can be used by ALL the function son this page.
var vsiCheckboxiNaStrani;
var imgFalse = '/images/checkbox1.gif';
var imgTrue = '/images/selected.gif';

//this function runs when the page is loaded, put all your other onload stuff in here too.
function init() {

	replaceChecks();
}

function replaceChecks() {
	
	//get all the input fields on the page
	vsiCheckboxiNaStrani = document.getElementsByTagName('input');

	//cycle trough the input fields
	for(var i=0; i < vsiCheckboxiNaStrani.length; i++) {

		//check if the input is a checkbox
		if(vsiCheckboxiNaStrani[i].getAttribute('type') == 'checkbox') {
			
			//create a new image
			var img = document.createElement('img');
			
			//check if the checkbox is checked
			if(vsiCheckboxiNaStrani[i].checked) {
				img.src = imgTrue;
			} else {
				img.src = imgFalse;
			}

			//set image ID and onclick action
			img.id = 'checkImage'+i;
			//set image 
			img.onclick = new Function('checkChange('+i+')');
			//place image in front of the checkbox
			vsiCheckboxiNaStrani[i].parentNode.insertBefore(img, vsiCheckboxiNaStrani[i]);
			
			//hide the checkbox
			vsiCheckboxiNaStrani[i].style.display='none';
			
			// nastavimo njegovo zaporedno stevilko kot alt text
			vsiCheckboxiNaStrani[i].alt = i;
		}
	}
}

//change the checkbox status and the replacement image
function checkChange(i) {

	if(vsiCheckboxiNaStrani[i].checked) {
		vsiCheckboxiNaStrani[i].checked = false;
		document.getElementById('checkImage'+i).src=imgFalse;
	} else {
		vsiCheckboxiNaStrani[i].checked = true;
		document.getElementById('checkImage'+i).src=imgTrue;
	}
	
	if(vsiCheckboxiNaStrani[i].onchange) vsiCheckboxiNaStrani[i].onchange();
}

window.onload = init;