function left(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}
function right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}
function togD(id) {
 if(right(document.getElementById('i_' + id).src,5)=='p.gif') {
 	document.getElementById('i_' + id).src='/media/images/m.gif';
	document.getElementById('d_' + id).style.display='inline';
 } else {
 	document.getElementById('i_' + id).src='/media/images/p.gif';
	document.getElementById('d_' + id).style.display='none';
 }
}

function init() {
	if (document.images) {
		for (var i=0;i<document.images.length;i++) {
		//If this one starts with thumbPrefix
			if (document.images[i].id.substring(0, 2) == "i_") {
				imageID = right(document.images[i].id,document.images[i].id.length-2);
				togD(imageID);
			}
		}
	}
}
window.onload = init; 
