//global variables used to replace checkboxes
var inputs;
var imgFalse = 'i/false.png';
var imgTrue = 'i/true.png';

function menuInit(){
	for(a=0; a < document.getElementsByTagName("div").length; a++){
		node=document.getElementById("tempid");
		exist = 1;
		while(exist) {
			rand_id = parseInt(Math.random()*10000);
			exist = document.getElementById("id-"+rand_id);
		}
		node.setAttribute("id","id-"+rand_id);
	}
}
function shift(id, pos){
	target = document.getElementById(id);
	target.extra_pos = pos;
	if (!target.extra_width) {
		target.extra_width = 8;
	}
	clearInterval(target.interval);
	target.interval = setInterval( function() { shiftfunction(id) }, 10);
}

function shiftfunction(id) {
	target = document.getElementById(id);
	target.extra_width = (target.extra_width + target.extra_pos) / 2;
	target.style.paddingLeft = target.extra_width + "px";
}

// the following: http://brainerror.net/scripts/javascript/checkbox/
window.onload = function replaceChecks() {
    
    //get all the input fields on the page
    inputs = document.getElementsByTagName('input');

    //cycle trough the input fields
    for(var i=0; i < inputs.length; i++) {

        //check if the input is a checkbox
        if(inputs[i].getAttribute('type') == 'checkbox') {
            
            //create a new image
            var img = document.createElement('img');
            
			img.style.cssFloat = "right";
			img.style.styleFloat="left"; // in case of IE < 6 users =(
            //check if the checkbox is checked
            if(inputs[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
            inputs[i].parentNode.insertBefore(img, inputs[i]);
            
            //hide the checkbox
            inputs[i].style.display='none';
        }
    }
}

//change the checkbox status and the replacement image
function checkChange(i) {

    if(inputs[i].checked) {
        inputs[i].checked = '';
        document.getElementById('checkImage'+i).src=imgFalse;
    } else {
        inputs[i].checked = 'checked';
        document.getElementById('checkImage'+i).src=imgTrue;
    }
}