leftdisabled = true
rightdisabled = true
widthLength = 640

//BPHR VERSION

function fp_ns6()
{
  return false;
}

function fp_ie4()
{
  return true;
}

function _isMSIE()
{
  if (navigator.userAgent.indexOf("MSIE") != -1)
    return true;
  else
    return false;
}

function _getElement(p_name)
{
  if (_isMSIE())
    return document.all[p_name];
  else
    return document.getElementById(p_name);
}

function _getTags(p_element, p_tag)
{
  if (_isMSIE())
    return p_element.all.tags(p_tag);
  else
    return p_element.getElementsByTagName(p_tag);
}

function _getCTags(p_element, p_tag)
{
  if (_isMSIE())
    return p_element.children.tags(p_tag);
  else
    return p_element.getElementsByTagName(p_tag);
}

function _fix()
{
  window.clearTimeout(1);

  v_gid  = -1;
  v_tags = _getTags(document, "img");
  for (i=0; i<v_tags.length; i++)
  {
    if (v_tags[i] != null && v_tags[i].id.indexOf("fpGalleryLeftBtn_") > -1)
    {
      v_gid = v_tags[i].id.substring(17);
      break;
    }
  }

  if (!_isMSIE())
    for (i=0; i<v_tags.length; i++)
    {
      if (v_tags[i] != null && 
            (v_tags[i].id.indexOf("fpGalleryLeftBtn_") > -1 ||
             v_tags[i].id.indexOf("fpGalleryRightBtn_") > -1)
         )
           v_tags[i].style.visibility = "visible";
    }

  fp_ScrollRight(v_gid);
  fp_ScrollLeft(v_gid);
}

function _setFixHook()
{
  if (!_isMSIE())
    window.setTimeout(_fix, 0);
  else
    window.setTimeout("_fix()", 250);
}

function fp_ShowImg(src, sWidth, sHeight, sID, iIndex)
{	
	var el = _getElement("fpGalleryMainImg_" + sID);
	if (el) {
			el.style.visiblity = "hidden";
			el.src = src.getAttribute ? src.getAttribute("lowsrc") : src.lowsrc;
			el.width = sWidth;
			el.height = sHeight;
				
			var caption = _getTags(_getElement("fpGalleryCaptions_" + sID), "div");
			var sCaptionTxt;
			var sCaptionHTML;
			
			if (caption && caption[iIndex]) {
				sCaptionTxt = caption[iIndex].innerText
				sCaptionHTML = caption[iIndex].innerHTML
			} else {
				sCaptionTxt = "";
				sCaptionHTML = "";
			}
			
			el.title = sCaptionTxt;
			el.style.visiblity = "visible";
			
			var el = _getElement("fpGalleryCaptionCell_" + sID);
			if (el) {
				el.innerHTML = sCaptionHTML;
			}
			
			var el = _getElement("fpGalleryDescCell_" + sID);
			if (el) {
				var sDesc = _getTags(_getElement("fpGalleryDescriptions_" + sID), "div");
				el.innerHTML = sDesc && sDesc[iIndex]?sDesc[iIndex].innerHTML:"";
			}

		}
}

function fp_ScrollLeft(sID) {
	var el = _getElement("fpGalleryListCell_" + sID);
	if (el) {
          if (!leftdisabled)
          {
                var coll = _getCTags(el, "A");
		var count = 20;

		if (coll) {
			for (i=1;i<coll.length;i++) {
				if (coll[i].style.display != "none") {
					coll[i-1].style.display = "inline";
					break;	
				}
			}
			
			for (i=0;i<coll.length;i++) {
				if (coll[i].style.display != "none") {
                                        var images = _getCTags(coll[i], "img");
					count = count + 20 + images[0].width;
					
					if (count > widthLength)				
						coll[i].style.display = "none";
				}
			}

			if ((el.scrollWidth - 5) >= el.clientWidth) {
				var btn = _getElement("fpGalleryRightBtn_" + sID)
				if (btn && rightdisabled) {
					rightdisabled = false;
					te = btn.src
					btn.src = btn.getAttribute ? btn.getAttribute("lowsrc") : btn.lowsrc
					btn.lowsrc = te
				}
			}
			
			if (coll[0].style.display != "none") {
				var btn = _getElement("fpGalleryLeftBtn_" + sID);
				if (btn && !leftdisabled) {
					leftdisabled = true;
					te = btn.src
					btn.src = btn.getAttribute ? btn.getAttribute("lowsrc") : btn.lowsrc
					btn.lowsrc = te
				}
			}
		}
	  }	
	}
}

function fp_ScrollRight(sID) {
	var el = _getElement("fpGalleryListCell_" + sID);
	if (el) {
		if (!rightdisabled)
		{
                        var coll = _getCTags(el, "A");
			if (coll) {
			    var state = 0;
				var count = 20;
				for (i=0;i<coll.length;i++) {
					if (state == 0)
					{
						if (coll[i].style.display != "none") {
							coll[i].style.display = "none";	
							state = 1;
						}
					}
					else{
                                                var images = _getCTags(coll[i], "img");
						count = count + 20 + images[0].width;
						if (count <= widthLength)
							coll[i].style.display = "inline";
						else
							coll[i].style.display = "none";
					}
				}
			}
		
			var btn = _getElement("fpGalleryRightBtn_" + sID);
			if (btn && coll[coll.length - 1].style.display != "none") {
				rightdisabled = true;
				te = btn.src;
				btn.src = btn.getAttribute ? btn.getAttribute("lowsrc") : btn.lowsrc;
				btn.lowsrc = te;
			}
			
			var btn = _getElement("fpGalleryLeftBtn_" + sID);
			if (btn && leftdisabled) {
				te = btn.src;
				btn.src = btn.getAttribute ? btn.getAttribute("lowsrc") : btn.lowsrc;
				btn.lowsrc = te;
				leftdisabled = false;

			}
		}		
	}
}

_setFixHook();

