/** M fucking V C...
 **
 ** MMMMMMModel			
 ** VVVVVVView			-html/javascript
 ** CCCCCCController	-rolled
 **
 **/








// Detect if the browser is IE or not.
// If it is not IE, we assume that the browser is NS.
var IE = document.all?true:false

// If NS -- that is, !IE -- then set up for mouse capture
if (!IE) document.captureEvents(Event.MOUSEMOVE)

// Set-up to use getMouseXY function onMouseMove
document.onmousemove = getMouseXY;

// Temporary variables to hold mouse x-y pos.s
var tempX = 0
var tempY = 0

// Main function to retrieve mouse x-y pos.s

function getMouseXY(e) {
  if (IE) { // grab the x-y pos.s if browser is IE
    tempX = event.clientX + document.body.scrollLeft
    tempY = event.clientY + document.body.scrollTop
  } else {  // grab the x-y pos.s if browser is NS
    tempX = e.pageX
    tempY = e.pageY
  }
//  alert("x: "+tempX+", y: "+tempY);
  // catch possible negative values in NS4
/*  if (tempX < 0){tempX = 0}
  if (tempY < 0){tempY = 0}  */
  // show the position values in the form named Show
  // in the text fields named MouseX and MouseY
//  document.Show.MouseX.value = tempX
 // document.Show.MouseY.value = tempY
  

	if (IE) { // grab the x-y pos.s if browser is IE
		var rem = document.all['foreDiv'];
		if(rem !=null){
			tempY += document.documentElement.scrollTop;
			tempX += document.documentElement.scrollLeft;
		
			//rem.style="position:absolute; top:"+(tempY+10)+"px; left:"+(tempX+10)+"px;";
//			rem.setAttribute('cssText',"position:absolute; top:"+(tempY+10)+"px; left:"+(tempX+10)+"px;", 0);
			rem.style.position="absolute";
			rem.style.top=tempY+10;
			rem.style.left=tempX+10;
		}
	} else{
		var rem = document.getElementById('foreDiv');
		if(rem !=null){
			rem.setAttribute('cssText',"position:absolute; top:"+(tempY+10)+"px; left:"+(tempX+10)+"px;", 0);
		}
	}
	
	if(rem !=null){
		rem.setAttribute('style',"position:absolute; top:"+(tempY+10)+"px; left:"+(tempX+10)+"px;");
	}
	  
  return true
}














/**
 ** Need to pass the img calling...
 **
 **/
function rolledOn(p1){
//			alert('rolled on: '+p1.src);
	createView(copyImg(p1));
}

/**
 ** Kills the image thats super imposed...
 **
 **/
function rolledOut(){
//	alert("On");
/*	if(IE)
		alert("foreDiv: "+document.all['foreDiv'].style);
	else
		alert("foreDiv: "+document.getElementById('foreDiv').style.top);
*/
	removeView();
//			alert('rolled out');

}


/**
 ** Creates a div in the foreground
 ** should be able to display text or image...
 **
 **/
function createView(p1){

	//alert('create view');

	var theDiv = 	document.createElement('div');
//	var theData =	document.createTextNode('test test test test test');
	theDiv.setAttribute('class','foreDiv');
	theDiv.setAttribute('name','foreDiv');
	theDiv.setAttribute('id','foreDiv');

	if(p1!=null){
		theDiv.appendChild(p1);
	}

	
//	theDiv.appendChild(theData);
	document.body.appendChild(theDiv);
	
	diveTrace = theDiv;
}

function removeView(){

	var rem = document.getElementsByName('foreDiv');
	
//	if(rem!=null){
	for(r=0; rem.length; r++){
//		alert(r+" : "+rem[r]);
		document.body.removeChild(rem[r]);

	}
}


/*
 * duplicates an image
 */
function copyImg(p1){
	var theImg = 	document.createElement('img');
	theImg.setAttribute('src',p1.src);
	theImg.setAttribute('onClick','removeView();');

	
	return theImg;
}

function getPosition(e) {
    e = e || window.event;
    var cursor = {x:0, y:0};
    if (e.pageX || e.pageY) {
        cursor.x = e.pageX;
        cursor.y = e.pageY;
    } 
    else {
        var de = document.documentElement;
        var b = document.body;
        cursor.x = e.clientX + 
            (de.scrollLeft || b.scrollLeft) - (de.clientLeft || 0);
        cursor.y = e.clientY + 
            (de.scrollTop || b.scrollTop) - (de.clientTop || 0);
    }
    return cursor;
}