The following code should answer your first question (I did not test it, though):

float detailBlend = 0.5;
float4 Color = colorMapping*( 1-detailBlend + detailBlend*detailMapping);


What do you mean by average color? When you've got a texture that's mostly red, the shader should color the model completely in red? I don't think that's possible in a shader, you'd have to calculate it with pixel-instructions, I think.
Btw. calculateAverage wastes way too many resources, the following line should produce the same (monochrome) result:

float Color = tex2D(ColorMapSampler,InTex).rgb;


"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual

Check out my new game: Pogostuck: Rage With Your Friends