//IMAGE MOUSEOVER SCRIPT
//only have to change the range in the for loop and array definitions to add menu items
images_array = new Array(7);
images_array_r = new Array(7);
dot_array = new Array(7);
for (i=1; i<8; i++)
{
	images_array[i]=new Image();
	images_array[i].src="/images/interior/r2f_interior_nav_0" + i + "a.gif";
	
	images_array_r[i]=new Image();
	images_array_r[i].src="/images/interior/r2f_interior_nav_0" + i + "b.gif";
	
	//dot_array[i]=new Image();
	//dot_array[i].src="/images/interior/r2f_interior_nav_0" + i + ".gif";
}
        
function swap(num)
{
	image_name = "image" + num
	if(document.getElementById)
	{
	   document.getElementById(image_name).src = images_array_r[num].src;
	   //document.getElementById("dot").src = dot_array[num].src;
	}
	else if(document.images)
	{
	   document.images[image_name].src = images_array_r[num].src;
	   //document.images["dot"].src = dot_array[num].src;
	}
}

function swapOut(num)
{
	image_name = "image" + num
	if(document.getElementById)
	{
		document.getElementById(image_name).src = images_array[num].src;
		//document.getElementById("dot").src = "/images/blank.gif";
	}
	else if(document.images)
	{
		document.images[image_name].src = images_array[num].src;
		//document.images["dot"].src = "/images/blank.gif";
	}
}

/*function swapClick(num)
        {
            image_name = "image" + num;
            if(document.getElementById) document.getElementById(image_name).src = images_array_r[num].src;
            else if(document.images) document.images[image_name].src = images_array_r[num].src;
        }
        
        function swapClickOut(num)
        {
            image_name = "image" + num;
            if(document.getElementById) document.getElementById(image_name).src = images_array[num].src;
            else if(document.images) document.images[image_name].src = images_array[num].src;
        }

        function openBrWindow(theURL,winName,features) { //v2.0
          window.open(theURL,winName,features); }
*/
function init() {
	//make sure we have adequate capabilities or leave if incapable
	if (!document.getElementsByTagName || !document.getElementById || !document.createElement) return;
	
	var d = document.createElement('div');
	d.id = 'holder';
	setOpacity(d,95);
	var b = document.getElementsByTagName('body')[0];
	b.insertBefore(d,b.firstChild );
	
	dfns = document.getElementsByTagName('dfn');
	
	for (i = 0; i < dfns.length; i++) {
		dfns[i].onmouseover = EnterDefn;
		dfns[i].onmouseout = LeaveDefn;
	}
}

var lastDef = '';
function EnterDefn() {
	var h = document.getElementById('holder');
	if (!h) return;
	setLyr(this, h);
	p = document.createElement('p');
	p.appendChild( document.createTextNode(this.title) );
	h.appendChild( p );
	h.className = 'over';
	lastDef = this.title;
	this.title = '';
	//fadeIn(h.id,0);
}

function LeaveDefn() {
	var h = document.getElementById('holder');
	if (!h) return;
	h.className = 'out';
	h.style.left = '-3000px';
	this.title = lastDef;
	lastDef = '';
	removeAllChildren(h);	
}

function removeAllChildren(obj) {
	while( obj.hasChildNodes() )
			obj.removeChild(obj.firstChild);
}

window.onload = init;

function setLyr(obj, x) {
	var newX = findPosX(obj);
	var newY = findPosY(obj) + 20;
	x.style.top = newY + 'px';
	if (document.body.clientWidth) {
		if ((newX + x.offsetWidth ) >= document.body.clientWidth) {
			newX = document.body.clientWidth - x.offsetWidth;
		}
	}
	else if (window.innerWidth) {
		newX =  ((newX + x.offsetWidth) > window.innerWidth) ? newX = window.innerWidth - 20 - x.offsetWidth : newX;
	}
	x.style.left = newX + 'px';
}


function findPosY(obj) {
	var curtop = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

function findPosX(obj) {
	var curleft = 0;
	if (obj.offsetParent)	{
		while (obj.offsetParent) {
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

//****************************
//** FROM: somewhere. Seen these functions elsewhere too many times to properly credit
//***************************
function setOpacity(obj, opacity) {
  opacity = (opacity == 100)?99.999:opacity;
  // IE/Win
  obj.style.filter = "alpha(opacity:"+opacity+")";
  // Safari<1.2, Konqueror
  obj.style.KHTMLOpacity = opacity/100;
  // Older Mozilla and Firefox
  obj.style.MozOpacity = opacity/100;
  // Safari 1.2, newer Firefox and Mozilla, CSS3
  obj.style.opacity = opacity/100;
}

function fadeIn(objId,opacity) {
  if (document.getElementById) {
    obj = document.getElementById(objId);
    if (opacity <= 90) {
      setOpacity(obj, opacity);
      opacity += 20;
      window.setTimeout("fadeIn('"+objId+"',"+opacity+")", 100);
    }
  }
}
