You can cut down on your 'itemSelected' code with catchevent. I.e:
PHP Code:
new GuiShowImgCtrl("Shop_Item_Fireball") {
// existing code...
thiso.catchevent(this.name, "onMouseDown", "onItemSelected");
}
// other code...
// The first parameter passed from a 'caught event' is the object that received it.
function onItemSelected(selected) {
// Loop through Items
for (temp.item: this.listofitems) {
// Change Image
temp.item.image = (temp.item == selected ? temp.item.imageselected : temp.item.imagenotselected);
}
// Set Selected to Item's Name (w/o the Shop_Item_ part)
this.itemselected = selected.name.substring("Shop_Item_".length());
}
I also used the ternary operator, which is just:
value = (condition ? true_result : false_result);
It would also fix your problem where you're passing an object to the server-side instead of string.
Objects behave weirdly (as you can see) resulting in their name getting passed or it passes null/0.