function findPos(obj)
{
    var curleft = curtop = 0;
    if (obj.offsetParent) {
        curleft = obj.offsetLeft;
        curtop = obj.offsetTop;
        while (obj = obj.offsetParent) {
	        curleft += obj.offsetLeft;
	        curtop += obj.offsetTop;
	        if (obj.style.overflowY == 'auto' || obj.style.overflowY == 'scroll') {
	            curtop -= obj.scrollTop;
	        }
        }
    }
    return [curleft,curtop];
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr;
  for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++)
    x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document;
  if(d.images){
    if(!d.MM_p)
      d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments;
    for(i=0; i<a.length; i++)
    {
      if (a[i].indexOf("#")!=0)
      {
        d.MM_p[j]=new Image;
        d.MM_p[j++].src=a[i];
      }
    }
  }
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;
  if(!d)
    d=document;
  if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document;
    n=n.substring(0,p);
  }
  if(!(x=d[n])&&d.all)
    x=d.all[n];
  for (i=0;!x&&i<d.forms.length;i++)
    x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++)
    x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById)
    x=d.getElementById(n);
  return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments;
  document.MM_sr=new Array;
  for(i=0;i<(a.length-2);i+=3)
  {
    if ((x=MM_findObj(a[i]))!=null)
    {
      document.MM_sr[j++]=x;
      if(!x.oSrc)
        x.oSrc=x.src;
      x.src=a[i+2];
    }
  }
}

var bgVisible = 1;
var idActiveClip = 'clip1';

function doClipOver(imgClipID)
{
	var imgClip = document.getElementById(imgClipID);
	imgClip.style.position = 'relative';
	imgClip.style.top = '-5px';
	imgClip.className = 'clipOver';
}

function doClipOut(imgClipID)
{
	var imgClip = document.getElementById(imgClipID);
	if (imgClip.id != idActiveClip)
	{
		imgClip.style.top = '0px';
		imgClip.className = 'clip';
	}
}

function doClipClick(imgName, idOn)
{
	bgVisible = 0;
	var oIdActiveClip = idActiveClip;
	idActiveClip = idOn;
	doClipOut(oIdActiveClip);
	Fade('imgGallery',100,0,10,imgName);
}

var tempImage = new Image();

function Fade(objID,CurrentAlpha,TargetAlpha,steps, imgName)
{

    var obj = document.getElementById(objID);

    CurrentAlpha = parseInt(CurrentAlpha);
    if (isNaN(CurrentAlpha)){
          CurrentAlpha = parseInt(obj.style.opacity*100);
          if (isNaN(CurrentAlpha))CurrentAlpha=100;
    }
    var DeltaAlpha=parseInt((CurrentAlpha-TargetAlpha)/steps);
    var NewAlpha = CurrentAlpha - DeltaAlpha;

    obj.style.opacity = (NewAlpha / 100);
    obj.style.MozOpacity = obj.style.opacity;
    obj.style.filter = 'alpha(opacity='+NewAlpha+')';

    if (steps>1){
          setTimeout('Fade("'+objID+'",'+NewAlpha+','+TargetAlpha+','+(steps-1)+',"'+imgName+'")', 50);
    }
    else if (bgVisible == 0) //Finished fading out
    {
      document.getElementById('spanLoadingText').innerHTML='Loading...';
      bgVisible = 1;
      //document.getElementById('tdMain_bg').style.backgroundImage = "url('images/gallery/" + imgName + "')";
      //tempImage.id = imgName;
      document.getElementById('imgGallery').onload = function(){Fade(objID,0,100,10,imgName);document.getElementById('spanLoadingText').innerHTML='&nbsp;';};
      document.getElementById('imgGallery').src = "images/gallery/" + imgName;
      //tempImage.src = "images/gallery/" + imgName;
    }
}

function doNavButtonOver(navObj)
{
	navObj.style.color = "#ffffff";
}
function doNavButtonOut(navObj)
{
	navObj.style.color = "";
}
function doModalPopup(strTitle,strBody)
{
	document.getElementById('tdModalPopupTitle').innerHTML = strTitle;
	document.getElementById('divModalPopupBody').innerHTML = strBody;
	ShowModalPopup('tblModalPopup', '', 'closeButton', 'tdModalPopupTitle')
}

function doMdlMinMax()
{
	var theButton = document.getElementById('minmaxButton');
	if (theButton.className == "mdlMinButton")
	{
		theButton.className = "mdlMaxButton";
		document.getElementById('trModalPopupBody').style.display = 'none';
		document.getElementById('tblModalPopup').style.height = '22px';
	}
	else
	{
		theButton.className = "mdlMinButton";
		document.getElementById('trModalPopupBody').style.display = 'inline';
		document.getElementById('tblModalPopup').style.height = '296px';
	}
}
