hello all
after attempting, and failing, and attempting again, and failing, after several hours im finally seeking help lol.

my goal is to create smooth fading effect for a div element i have on a web app i am developing.
all is well when it comes to the actual fading of the element,
my problem is when the mouse leaves the div and returns onto it before the fading has completed.

my code for the element is as follows:
Code:
<script type="text/javascript">

function opacity(id, opacStart, opacEnd, millisec) {
    var speed = Math.round(millisec / 100);
    var timer = 0;
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    }
}

function changeOpac(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
} 


function doLoad() {
	changeOpac(25, 'theDiv');
	setBackGrad();
}

var theDivMouseCheck = 0;

function DivOver() {
	theDivMouseCheck = 1;
	setTimeout('doDivIn()',250);
}

function DivOut() {
	theDivMouseCheck = 0;
	setTimeout('doDivOut()',250);
}

function doDivIn() {
	if (theDivMouseCheck==1) {
		opacity('theDiv', 25, 100, 1000);
	}
}

function doDivOut() {
	if (theDivMouseCheck==0) {
		opacity('theDiv', 100, 25, 1000);
	}
}

</script>

<body onLoad="doLoad();">

<div id="theDiv" style="background-color:#FF0000; width:200px; height:200px;" onMouseOver="DivOver();" onMouseOut="DivOut();"></div>
if you run the code, and mouse over and out of the red square quickly in several successions, the box will literally **** itself, and will almost appear to blink.

what i believe will solve the problem is a way to stop the fading, once the function is called again, and resume it from the current opacity value but fading towards the new target opacity.

i tried many ways to do this but just cant seem to get it
the timeouts that i have put in the code were an attempt to fix the problem, but i found give a cool delayed effect.

so im asking if any of you guys have any ideas that might help me out here..
i have only had afew problems which i couldn't find the answer to, but i came here and you guys helped me out really quickly.

thanks in advance !!

cheers,
andrew.