/***********************************************
* Drop Down/ Overlapping Content- © Dynamic Drive (www.dynamicdrive.com)
* This notice must stay intact for legal use.
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/

function getposOffset(overlay, offsettype)
{
overlay.offsetRight=overlay.offsetLeft + overlay.offsetWidth;
overlay.offsetBottom=overlay.offsetTop + overlay.offsetHeight;
//alert(overlay.offsetLeft + " ... " + overlay.offsetWidth + " ... " + offsettype);
var totaloffset=(offsettype=="left")? overlay.offsetLeft : (offsettype=="right")? overlay.offsetRight : (offsettype=="bottom")? overlay.offsetBottom : overlay.offsetTop;
var parentEl=overlay.offsetParent;
//parentEl.offsetRight=parentEl.offsetLeft + parentEl.offsetWidth;
//parentEl.offsetBottom=parentEl.offsetTop + parentEl.offsetHeight;
//alert(offsettype);
while (parentEl!=null){

if(offsettype=="left") {
	//alert(totaloffset + " ... " + parentEl.offsetLeft + " ... " + offsettype)
	totaloffset=totaloffset+parentEl.offsetLeft;
} else if(offsettype=="right"){
	//alert(totaloffset + " ... " + offsettype)
	//totaloffset=totaloffset + parentEl.offsetRight;
	totaloffset=totaloffset +  parentEl.offsetLeft ;
} else if(offsettype=="bottom") {
	//alert(totaloffset + " ... " +  offsettype)
	totaloffset=totaloffset + parentEl.offsetTop ;
//	totaloffset=totaloffset + parentEl.offsetBottom;
} else{
	//alert(totaloffset + " ... " + parentEl.offsetTop + " ... " + offsettype)
	totaloffset=totaloffset+parentEl.offsetTop;
}
parentEl=parentEl.offsetParent;

/*var totaloffset=(offsettype=="left")? overlay.offsetLeft : overlay.offsetTop;
var parentEl=overlay.offsetParent;
while (parentEl!=null)
totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
parentEl=parentEl.offsetParent;
*/

} 
return totaloffset;
}


function findPos(obj) {
	var curleft = curtop = 0;
	
	if (obj.offsetParent) {
		do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
	
		return [curleft,curtop];
	}

}

function overlay(curobj, subobjstr, opt_position,img_no,enldiv)
{
	//alert(curobj);
////added on 21st of May by vv////////////////////////////////////////////
var temp_v = eval(document.getElementById(curobj));
//alert(temp_v);//return false;
var curobj = temp_v;
//alert(curobj)
////////////////////////////////////////////////////////////////////////////////
		//alert(temp_v)
	  element=eval(document.getElementById(enldiv));
	 // alert(element)
	  a=findPos(element);
		//alert(a);//return false;
	var ScrollTop = document.body.scrollTop;

	if (ScrollTop == 0)
	{
		if (window.pageYOffset)
			ScrollTop = window.pageYOffset;
		else
			ScrollTop = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
	}
	//alert(ScrollTop - a[1]);
	
	if((a[1] - ScrollTop) < 0)
	{//alert('hi');
		document.getElementById(subobjstr).style.marginTop = (a[1] - ScrollTop)+"px";
		document.getElementById('aryimg'+img_no).style.marginTop = -(a[1] - ScrollTop -1)+"px";
	}
	else
	{//alert(a[1] - ScrollTop);

		vClient = alertSize();//alert(a)
		if(document.getElementById('img'+img_no).height != 0)
		{
			vImgHeight = document.getElementById('img'+img_no).height;
		}
		else
		{
			var newImg1 = new Image();
			newImg1.src = document.getElementById('img'+img_no).src;	
			vImgHeight = newImg1.height;
	  	}
		
		if((vClient[0] - vImgHeight) > 0)
		{//alert(a[1])
			//alert(document.getElementById('enlrg'+img_no).);//getScrolltop('enlrg'+img_no)//alert(a[1]+'~~'+(vClient[0]/2))
			if((a[1] - ScrollTop) > (vClient[0]/2))
			{//alert(777)
				vDiff = ScrollTop + vClient[0] - vImgHeight;
			//alert(a[1] +'<>'+ vDiff +'==='+ScrollTop +'+'+ vClient[0] +'-'+ vImgHeight)
				vDiff_ = a[1]-vDiff;
				if(vDiff_ > 0)
				{
					document.getElementById(subobjstr).style.marginTop = -(vDiff_ + 30)+"px";
					document.getElementById('aryimg'+img_no).style.marginTop = (vDiff_ + 30 )+"px";			
				}
				else
				{
					document.getElementById(subobjstr).style.marginTop = -(vClient[0] - vImgHeight)+"px";
					document.getElementById('aryimg'+img_no).style.marginTop = (vClient[0] - vImgHeight)+"px";				
				}		
			}
			else
			{
				document.getElementById(subobjstr).style.marginTop = -(a[1] - ScrollTop)+"px";
				document.getElementById('aryimg'+img_no).style.marginTop = (a[1] - ScrollTop -1)+"px";
			}
		}
		else
		{
			document.getElementById(subobjstr).style.marginTop = -(a[1] - ScrollTop)+"px";
			document.getElementById('aryimg'+img_no).style.marginTop = (a[1] - ScrollTop -1)+"px";
		}
	}

		document.getElementById('aryimg'+img_no).style.visibility = 'visible';

///var xpos = 0;
//var ypos = 0;
	  

	if (document.getElementById)
	{ 
		var subobj=eval('subobjstr');
		var xpos
		var ypos
		
		var subobj=document.getElementById(subobj);
	
		subobj.style.display=(subobj.style.display!="block")? "block" : "none"
		
		if(opt_position=="left") 
		{//alert('hi')
			xpos=getposOffset(curobj, "right")+80;//20
			ypos=getposOffset(curobj, "bottom")+((typeof opt_position!="undefined" && opt_position.indexOf("top")!=-1)? curobj.offsetHeight : 0)
			ypos=ypos-curobj.offsetHeight;
		}
		else 
		{
			xpos=getposOffset(curobj, "left") -(parseInt(subobj.offsetWidth) + 30);
			ypos=getposOffset(curobj, "top")+((typeof opt_position!="undefined" && opt_position.indexOf("bottom")!=-1)? curobj.offsetHeight : 0)
		 	ypos=ypos-curobj.offsetHeight;	
		
		}
		
		if( ! isNaN(xpos)&& ! isNaN(ypos)) 
		{	
			subobj.style.left=xpos+"px";
			subobj.style.top=ypos+"px";//alert(subobj.style.top)
			//alert(ypos);return false;
		}
			return false
	}
	else
		return true
		
		
		
}

function overlayclose(subobj)
{
	var subobj=eval('subobj');
	var subobj=document.getElementById(subobj);
	subobj.style.display="none"
//document.getElementById(subobj).style.display="none"
}

function alertSize() {

  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {//alert(7+'FF')
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
	//alert(7+'IE')
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
	//alert(7+'IE7')
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  //window.alert( 'Width = ' + myWidth );
  //window.alert( 'Height = ' + myHeight );
  
  return[myHeight,myWidth];
}
