function changeModelImage(modelid,index) {
    var product_thumbnail_box = document.getElementById('product_thumbnail') ;
    if(product_thumbnail_box) {
        product_thumbnail_box.src = models_images[modelid][index];
        currentModelImageIndex = index;
    }
}

function processSelection(model_id,model_numba,index) {
	var funcProcess = processSelectionFunc;

	funcProcess(model_id,model_numba,index);
}

function processSelectionFunc(model_id,model_numba,index) {
//  change model image
//	var s = new Date().getTime();
    if(model_numba > 0)
        gmodelid = false ;
    var product_thumbnail_box = document.getElementById('product_thumbnail') ;
    if(product_thumbnail_box) {
        default_URL = product_thumbnail_box.src ;
        default_width = product_thumbnail_box.width ;
        default_height = product_thumbnail_box.height ;
        if(model_numba > 0) {
            if (modelsParams[index]['image'])
                product_thumbnail_box.src = modelsParams[index]['image'];
            else
                product_thumbnail_box.src = 'product_model.php?modelid='+model_id;
            product_thumbnail_box.width = '285' ;
            gmodelid = model_id ;
        } else if(model_numba > 0) {
            gmodelid = model_id ;
        }
    }

//  change current model cell
    document.getElementById(modelSelectedCell).className="SmallModelPassive";
    if (document.getElementById('modelCell_'+model_id)) {
        document.getElementById('modelCell_'+model_id).className="SmallModelSelected";
        modelSelectedCell = 'modelCell_'+model_id;
    }

//	change model details
    if (modelActiveDetails!='modelDetails_'+model_id) {
        document.getElementById('modelDetails_'+model_id).style.display = "block";
        document.getElementById(modelActiveDetails).style.display = "none";
        modelActiveDetails = 'modelDetails_'+model_id;
    }

//	create model thumbnails
    if (models_thumbs[model_id]!='') {
        for (var x in models_thumbs[model_id]) { 
			document.getElementById('model_thumb_'+model_id+x).src = models_thumbs[model_id][x];
        }
    }

// 	display current model images
    if (model_numba>0) {
        if (modelActiveImageBox!='detailedImages_'+model_id) {
            document.getElementById('detailedImages_'+model_id).style.display = "block";
            document.getElementById(modelActiveImageBox).style.display = "none";
            modelActiveImageBox = 'detailedImages_'+model_id;
            currentModelImageIndex = 0;
        }
    }

// 	check availability
    if (avail>0) {
   	    if (modelsParams[index]['out_of_stock']=="Y")
       	    document.getElementById('add2cart').style.display = "none";
        else
   	        document.getElementById('add2cart').style.display = "block";
	}
//	var e = new Date().getTime();
//	alert ("Cached method: "+(e-s));
}
