﻿var holdingImage;
var NS4=false;
function setLayer(o, container, textContainer, textheigth, r)
{
    BrowserDetect.init
    var thisBrowser = getBrowser()
    var thisVersion = BrowserDetect.version    
    if (thisBrowser == 'Netscape')
    {
        if (parseInt(thisVersion) == 4)
        {NS4=true}
    }
    var textC = document.getElementById(textContainer) 
    var imageObj = document.getElementById(o)

    holdingImage = document.images[container];

    var height = docjslib_getImageHeight(imageObj)
    var start = height - textheigth
    var top = docjslib_getRealTop(imageObj)
    var left = docjslib_getImageXfromLeft(imageObj)

    
    if (thisBrowser == 'Firefox') {
        textC.style.top = ((top + start) - 10) + 'px';   
        if (r == 'True') {
            textC.style.left = (left - 6) + 'px';
        }
        else
        { textC.style.left = (left - 8) + 'px'; }
        textC.style.height = textheigth + 10 + 'px';
        textC.style.width = (docjslib_getImageWidth(imageObj)) + 'px'
    }
    if (thisBrowser == 'Mozilla') {
        textC.style.top = (top + start) + 'px';
        textC.style.left = (left) + 'px';
        textC.style.height = textheigth + 'px';
        textC.style.width = (docjslib_getImageWidth(imageObj)) + 'px'
    }

    if (thisBrowser == 'Explorer') {
        if (parseInt(thisVersion) < parseInt(9))
        {
            textC.style.top = (top + start) + 'px';
            textC.style.left = docjslib_getImageXfromLeft(imageObj) - 1 + 'px';
            textC.style.height = textheigth + 'px';
            textC.style.width = (docjslib_getImageWidth(imageObj)) + 'px'
        }
        else {
            if (r == 'True') {
                textC.style.top = (top + start) + 'px';
                textC.style.left = (docjslib_getImageXfromLeft(imageObj) - 0) + 'px';
                textC.style.height = textheigth + 'px';
                textC.style.width = (docjslib_getImageWidth(imageObj)) + 'px'
            }
            else {
                textC.style.top = (top + start) + 'px';
                textC.style.left = (docjslib_getImageXfromLeft(imageObj) - 8) + 'px';
                textC.style.height = textheigth + 'px';
                textC.style.width = (docjslib_getImageWidth(imageObj)) + 'px'
            }
        }
    }  
    /*else {
        textC.style.top = (top + start) + 'px';   
        textC.style.left = (left) + 'px';
        textC.style.height = textheigth + 'px';
        textC.style.width = (docjslib_getImageWidth(imageObj)) + 'px'   
    }*/
        
    
}   

function docjslib_getImageWidth(imgID) {
  return eval(imgID).width;
}

function docjslib_getImageHeight(imgID) {
  return eval(imgID).height;
}
function docjslib_getImageXfromLeft(imgID) {
  if (NS4) return eval(imgID).x
  else return docjslib_getRealLeft(imgID);
}

function docjslib_getImageYfromTop(imgID) {
  if (NS4) return eval(imgID).y
  else return docjslib_getRealTop(imgID);
}
function docjslib_getRealLeft(imgElem) {
	xPos = eval(imgElem).offsetLeft;
	tempEl = eval(imgElem).offsetParent;
  	while (tempEl != null) {
  		xPos += tempEl.offsetLeft;
  		tempEl = tempEl.offsetParent;
  	}
	return xPos;
}

function docjslib_getRealTop(imgElem) {
	yPos = eval(imgElem).offsetTop;
	tempEl = eval(imgElem).offsetParent;
	while (tempEl != null) {
  		yPos += tempEl.offsetTop;
  		tempEl = tempEl.offsetParent;
  	}
	return yPos;
}

