
function get_random_num(num_elements){
	// number from 0 . . . (num_elements -1)
	var i = Math.round((num_elements-1)*Math.random());
	return i;
}

function write_album_table(){
	var album_table = '<table border="0" cellspacing="0" cellpadding="0"><tr>' + choose_records() + '</tr></table>';
	document.write(album_table);
}

function get_record_cell(imgname, link){
	return '<td><a href="' + link + '"><img src="imgs/' + imgname + '" alt="audio record ' + imgname + '" width="140" height="140" border="0" class="hm_img_pad" /></a></td>';
}

function choose_records(){

	var slots = new Array(1, 2, 3, 4);			// record slots
	var img_names = new Array( 'img02.gif',  'img03.gif', 'img04.gif', 'img05.gif', 'img06.gif', 'img07.gif' );	// record imgs
	var img_links = new Array('hsr_ind_applaudando.html' ,'hsr_ind_beka49497.html' ,'hsr_ind_asico.html' ,'hsr_ind_asico.html' ,'hsr_ind_artyphon.html', 'hsr_ind_arion.html'  );	// record links
	
	var num_orig_slots = slots.length;
	var finished_slots = new Array(4);
	
	for(var i=0; i < num_orig_slots; i++){

		var chosen_slot = slots.splice( get_random_num(slots.length), 1);					// randomly pick a slot
		if (i==0){
			finished_slots[chosen_slot] = get_record_cell('img01.gif', 'hsr_ind_brunswick_7698.html');		// Image 01 always shows in one of the slots slot
			
		}else{																				// Remaining 6 images picked for other 3 slots
			var img_idx = get_random_num(img_names.length);								// randomly pick an image
			finished_slots[chosen_slot]= get_record_cell( img_names.splice( img_idx, 1),  img_links.splice( img_idx, 1));			
		}
	}
	return finished_slots.join('');
}


