HELP with Infrared emitter + sensor problems

ok so I tried your code john and experimented with different CompareThreshold values and determined it works the best at 250. Here is the problem, it only works in the dark. When a light is on there is too much IR being emitted from the light and causes the LED to always be on. Not sure how to get around that...

const int IRLED = 12;
const int LED = 13;
const int IRInput = A0;
const int SampleSize = 10;
const int CompareThreshold = 17;

void setup()
{
pinMode(13,OUTPUT);
pinMode(12,OUTPUT);
Serial.begin(9600);
}

void loop()
{
int onVal = 0;
int offVal = 0;

// Take 10 samples with the light ON and OFF
for (int i=0; i<SampleSize; i++)
{
digitalWrite(IRLED, HIGH);
onVal += analogRead(IRInput);
digitalWrite(IRLED, LOW);
offVal += analogRead(IRInput);
}

Serial.print("average onVal=");
Serial.print(onVal/SampleSize);
Serial.print(", average offVal=");
Serial.println(offVal/SampleSize);

if ((offVal - onVal) > CompareThreshold) // Value to be determined experimantally
{
digitalWrite(LED,HIGH);
}
else
{
digitalWrite(LED,LOW);
}

}