//var targ = new Array();

var curleft;
var curtop;

function findPosX(obj)
  {
    curleft = 0;
    if(obj.offsetParent)
        while(1) 
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    //alert(obj['id'] + '\'s left position is ' + curleft + 'px');
    //return curleft;
  }

function findPosY(obj)
	{
	curtop = 0;
	if(obj.offsetParent)
	    while(1)
	    {
	      curtop += obj.offsetTop;
	      if(!obj.offsetParent)
	        break;
	      obj = obj.offsetParent;
	    }
	else if(obj.y)
	    curtop += obj.y;
	//return curtop;
}

function addShadow(){

	for(i=0; i<targ.length; i++){
		var target = document.getElementById(targ[i]);
		//alert(target['id']);
		findPosX(target);
		findPosY(target);
		var tarTop = curtop;//target.offsetTop;
		var tarLeft = curleft;//target.offsetLeft;
		var tarHeight = target.clientHeight;
		var tarWidth = target.clientWidth;
		
		//alert('target: ' + target['id'] + '\n top: ' + tarTop + '\n left: ' + tarLeft + '\n height: ' + tarHeight);
		//left side
		var cornerTL_t = tarTop-10;
		var cornerTL_l = tarLeft-10;
		//document.write('<img src="images/bodyShado_01.png" id="' + target['id'] + 'cornerTL" style="position: absolute; top:' + cornerTL_t + 'px; left:' + cornerTL_l +'px;" />');
		var sideL_t = tarTop;
		var sideL_l = tarLeft-10;
		document.write('<img src="images/bodyShado_04.png" id="' + target['id'] + 'sideL" style="position: absolute; top:' + sideL_t + 'px; left:' + sideL_l +'px; height: ' + tarHeight +'px; width: 10px;" />');
		var cornerBL_t = tarTop+tarHeight;
		var cornerBL_l = tarLeft-10;
		document.write('<img src="images/bodyShado_07.png" id="' + target['id'] + 'cornerBL" style="position: absolute; top:' + cornerBL_t + 'px; left:' + cornerBL_l +'px;" />');
		//right side
		var cornerTR_t = tarTop-10;
		var cornerTR_l = tarLeft+tarWidth;
		//document.write('<img src="images/bodyShado_03.png" id="' + target['id'] + 'cornerTR" style="position: absolute; top:' + cornerTR_t + 'px; left:' + cornerTR_l +'px;" />');
		var sideR_t = tarTop;
		var sideR_l = tarLeft+tarWidth;
		document.write('<img src="images/bodyShado_06.png" id="' + target['id'] + 'sideR" style="position: absolute; top:' + sideR_t + 'px; left:' + sideR_l +'px; height: ' + tarHeight +'px; width: 10px;" />');
		var cornerBR_t = tarTop+tarHeight;
		var cornerBR_l = tarLeft+tarWidth;
		document.write('<img src="images/bodyShado_09.png" id="' + target['id'] + 'cornerBR" style="position: absolute; top:' + cornerBR_t + 'px; left:' + cornerBR_l +'px;" />');
		//top and bottom
		//document.write('<img src="images/bodyShado_02.png" id="' + target['id'] + 'top" style="position: absolute; top:' + cornerTL_t + 'px; left:' + tarLeft + 'px; width:' + tarWidth +'px; height: 10px;" />');
		document.write('<img src="images/bodyShado_08.png" id="' + target['id'] + 'bottom" style="position: absolute; top:' + cornerBL_t + 'px; left:' + tarLeft + 'px; width:' + tarWidth +'px; height: 10px;" />');
	}
	//correctPNG();
}

function shadowOnResize(){
	for(i=0; i<targ.length; i++){
		var target = document.getElementById(targ[i]);
		findPosX(target);
		findPosY(target);
		var tarHeight = target.clientHeight;
		var tarWidth = target.clientWidth;
		curId = target['id'];
		var absTop = curtop-10;
		var absLeft = curleft-10;
		var absBottom = curtop+tarHeight;
		var absRight = curleft+tarWidth;
		
		//var dom = document.getElementById;
		
		//document.getElementById(curId + 'cornerTL').style.visibility = "hidden";
		document.getElementById(curId + 'sideL').style.visibility = "hidden";
		document.getElementById(curId + 'cornerBL').style.visibility = "hidden";
		//document.getElementById(curId + 'cornerTR').style.visibility = "hidden";
		document.getElementById(curId + 'sideR').style.visibility = "hidden";
		document.getElementById(curId + 'cornerBR').style.visibility = "hidden";
		//document.getElementById(curId + 'top').style.visibility = "hidden";
		document.getElementById(curId + 'bottom').style.visibility = "hidden";
				
		//document.getElementById(curId + 'cornerTL').style.top = absTop + "px";
		//document.getElementById(curId + 'cornerTL').style.left = absLeft + "px";
		document.getElementById(curId + 'sideL').style.top = curtop + "px";
		document.getElementById(curId + 'sideL').style.left = absLeft + "px";
		document.getElementById(curId + 'cornerBL').style.top = absBottom + "px";
		document.getElementById(curId + 'cornerBL').style.left = absLeft + "px";
		
		//document.getElementById(curId + 'cornerTR').style.top = absTop + "px";
		//document.getElementById(curId + 'cornerTR').style.left = absRight + "px";
		document.getElementById(curId + 'sideR').style.top = curtop + "px";
		document.getElementById(curId + 'sideR').style.left = absRight + "px";
		document.getElementById(curId + 'cornerBR').style.top = absBottom + "px";
		document.getElementById(curId + 'cornerBR').style.left = absRight + "px";
		
		//document.getElementById(curId + 'top').style.top = absTop + "px";
		//document.getElementById(curId + 'top').style.left = curleft + "px";
		document.getElementById(curId + 'bottom').style.top = absBottom + "px";
		document.getElementById(curId + 'bottom').style.left = curleft + "px";
		
		//document.getElementById(curId + 'cornerTL').style.visibility = "visible";
		document.getElementById(curId + 'sideL').style.visibility = "visible";
		document.getElementById(curId + 'cornerBL').style.visibility = "visible";
		//document.getElementById(curId + 'cornerTR').style.visibility = "visible";
		document.getElementById(curId + 'sideR').style.visibility = "visible";
		document.getElementById(curId + 'cornerBR').style.visibility = "visible";
		//document.getElementById(curId + 'top').style.visibility = "visible";
		document.getElementById(curId + 'bottom').style.visibility = "visible";
	
		//alert(document.getElementById(curId + 'cornerTL').style.top + " -- " + document.getElementById(curId + 'cornerTL').style.left);
	}
}

function shadowBottom(theTar){
	var tar = document.getElementById(theTar);
	var t = tar.offsetTop;
	var l = tar.offsetLeft;
	var h = tar.clientHeight;
	var w = tar.clientWidth;
	var to = t+h;
	//alert(t);
	document.write('<img src="images/bodyShado_08.png" id="' + tar['id'] + 'bottom" style="position: absolute; top:' + to + 'px; left:' + l + 'px; width:' + w +'px; height: 10px;" />');
}