function fullGrayOn ()
{
  document.getElementById('fullScreenGray').className='fullGrayOn'
}


function fullGrayOff ()
{
  document.getElementById('fullScreenGray').className='fullGrayOff'
}


function linktest (containerId)
{
 var current = document.URL;
 current = current.replace(/\\/g,"/");
 if (current.search(".html") == -1) {current = "/index.html";}
 if (current.lastIndexOf("/") < current.length)
    {current = current.substring(current.lastIndexOf("/")+1);}
 var container = document.getElementById(containerId);
 var links = container.getElementsByTagName("a");
 for (i = 0; i < links.length; i++)
  {
    var element = links[i];

    if (element.href.search(current) != -1)
    {
      element.parentNode.className="currentURL";
      element.parentNode.innerHTML=element.innerHTML;
    }
  }

}


function toggleDisplay (text1,text2,className)
{
// toggles previous <span> element
var tag = "<span onClick=\"toggleDisplay2(this,'"+text1+"','"+text2+"');\" class='"+className+" hoverPointer'>";
document.write(tag+text1+"</span>");
}


function toggleDisplay2 (element,text1,text2)
{
  var targetNode = element.previousSibling
  while (targetNode.tagName != "SPAN") {targetNode = targetNode.previousSibling;}
  if    (targetNode.style.display == "none") 
        {element.innerHTML = text2; targetNode.style.display = "inline";}
  else  {element.innerHTML = text1; targetNode.style.display = "none";}
}


function toggleDisplayID (displayID,text1,text2,className)
{
var tag = "<span onClick=\"toggleDisplayID2(this,'"+displayID+"','"+text1+"','"+text2+"');\" class='"+className+" hoverPointer'>"
document.write(tag+text1+"</span>");
}


function toggleDisplayID2 (elementText,elementDisplay,text1,text2)
{
  var targetNode = document.getElementById(elementDisplay);
  if    (targetNode.style.display == "none") 
        {elementText.innerHTML = text2; targetNode.style.display = "inline";}
  else  {elementText.innerHTML = text1; targetNode.style.display = "none";}
}


function toggleZindex (displayID,text1,text2,className)
{
var tag = "<span onClick=\"toggleZindex2(this,'"+displayID+"','"+text1+"','"+text2+"');\" class='"+className+" hoverPointer'>"
document.write(tag+text1+"</span>");
}


function toggleZindex2 (elementText,elementDisplay,text1,text2)
{
  var targetNode = document.getElementById(elementDisplay);
  if    (targetNode.style.zIndex < 0) 
        {elementText.innerHTML = text2; targetNode.style.zIndex = 1000;}
  else  {elementText.innerHTML = text1; targetNode.style.zIndex = -1000;}
}


function gallerySimpleTest (gallClass,gallImgID,gallPath,gallList)
{
 var imgArray = gallList.split(" ");
 var imgWidth = new Array ();
 var imgHeight = new Array ();
 var i = 0
 var imgLoad = new Array();
 for (i=0;i<imgArray.length;i++)
   {
      imgLoad[i] = new Image ();
      imgLoad[i].src = gallPath+imgArray[i];
      while (imgLoad[i].width==0) {alert (imgArray[i]+" "+imgLoad[i].width);}
      imgWidth[i] = imgLoad[i].width;
      imgHeight[i] = imgLoad[i].height;
      // alert (imgArray[i]+" "+imgWidth[i]+" "+imgHeight[i]);
   }
 for (i=0;i<imgArray.length;i++)
   {
     // alert(imgArray[i]+" "+imgWidth[i]+" "+imgHeight[i]);
     document.write('<img src="'+gallPath+imgArray[i]+'" class="'+gallClass+'" onclick="gallerySimple2 (this,\''+gallImgID+'\')">');
   }
}


function gallerySimple (gallClass,gallImgID,gallPath,gallList,displayValue)
{
 var imgArray = gallList.split(" ");
 for (i=0;i<imgArray.length;i++)
   {
     document.write('<img src="'+gallPath+imgArray[i]+'" class="'+gallClass+'" onclick="gallerySimple2 (this,\''+gallImgID+'\',\''+displayValue+'\')">');
   }
}


function gallerySimple2 (smallImg,bigID,displayValue) 
{
  setOpacity(document.getElementById(bigID),0);
  document.getElementById(bigID).src = smallImg.src;
  if (displayValue) {document.getElementById(bigID).style.display = displayValue;}
  fadeIn(bigID,0);
}


function gallerySimpleBig (maxW,maxH,gallClass,gallImgID,gallDivID,gallPath,gallList,displayValue)
{
 var imgArray = gallList.split(" ");
 for (i=0;i<imgArray.length;i++)
   {
 document.write('<img src="'+gallPath+imgArray[i]+'" style="display:inline; max-width:'+maxW+'px; max-height:'+maxW+'px;" class="'+gallClass+'" onclick="gallerySimpleBig2(this,\''+gallImgID+'\',\''+gallDivID+'\',\''+displayValue+'\')">')
   }
}


function gallerySimpleBig2 (smallImg,bigID,gallDivID,displayValue) 
{
  document.getElementById(bigID).src = smallImg.src;
  setOpacity (document.getElementById(gallDivID),0)
  document.getElementById(gallDivID).style.zIndex = '1000';
  if (displayValue) {document.getElementById(gallDivID).style.display = displayValue;}
  fadeIn (gallDivID,0);
}

function gallerySimpleBigTest (maxsmallW,maxsmallH,gallClass,gallImgID,gallDivID,gallPath,gallList,displayValue,maxbigW,maxbigH)
{
 var imgArray = gallList.split(" ");
 for (i=0;i<imgArray.length;i++)
   {
 document.write('<img src="'+gallPath+imgArray[i]+'" style="display:inline; max-width:'+maxsmallW+'px; max-height:'+maxsmallW+'px;" class="'+gallClass+'" onclick="gallerySimpleBig2Test(this,\''+gallImgID+'\',\''+gallDivID+'\',\''+displayValue+'\','+maxbigW+','+maxbigH+')">')
   }
}


function gallerySimpleBig2Test (smallImg,bigID,gallDivID,displayValue,maxbigW,maxbigH) 
{
  document.getElementById(bigID).src = smallImg.src;
  var newObj = new Image;
  newObj.src = smallImg.src;
  var setW = newObj.width;
  var setH = newObj.height;
  if (setW > maxbigW && maxbigW > 0) {setH = Math.floor(setH*maxbigW/setW); setW = maxbigW;}
  if (setH > maxbigH && maxbigH > 0) {setW = Math.floor(setW*maxbigH/setH); setH = maxbigH;}
  if (maxbigW > 0) {document.getElementById(bigID).width = setW;}
  if (maxbigH > 0) {document.getElementById(bigID).height = setH;}
  setOpacity (document.getElementById(gallDivID),0);
  document.getElementById(gallDivID).style.zIndex = '1000';
  if (displayValue) {document.getElementById(gallDivID).style.display = displayValue;}
  fadeIn (gallDivID,0);
  if (document.getElementById(bigID+"print")) {document.getElementById(bigID+"print").src = smallImg.src;}
}


function changeWidth (elementId)
{
   var element=self.document.getElementById(elementId);
   var button=self.document.getElementById("widthButton");
   if   (element.className=="width70")
        {element.className="width100"; button.innerHTML="narrow format"; document.cookie="100"}
   else {element.className="width70"; button.innerHTML="full width"; document.cookie="70"}
}

function displayButton ()
{
  document.write ("<button id=\"widthButton\" onclick=\"changeWidth('entirePage');\"   onmouseover=\"this.style.textDecoration='underline'\" onmouseout=\"this.style.textDecoration='none'\">narrow format</button><br>")
}

function initialWidth (elementId)
{
   var element=self.document.getElementById(elementId);
   var button=self.document.getElementById("widthButton");
   var widthCookie=document.cookie
   if   ((eval((screen.width)<1000) && widthCookie!="70") || widthCookie==100 || self!=top)
        {element.className="width100"; button.innerHTML="narrow format";}
   else {element.className="width70"; button.innerHTML="full width";}
}

function galleryNav (elementId)
{
       var element=self.document.getElementById(elementId);
       document.write (element.innerHTML);
}

function textSizeDisplay(elementId)
{
if (!document.getElementById) {}
   // skip if old browser such as netscape 4
else
   {
   document.write('<div align="right" class="white" style="font-size:11px;"><nobr>text:');

 document.write('<a href="javascript:void(0);" class="white" style="font-size:14px;" onClick="changeTextSize(10,'+elementId+');">&nbsp;+&nbsp;</a>');

   document.write('<a href="javascript:void(0);" class="white" style="font-size:14px;"  onClick="changeTextSize(-10,'+elementId+');">&nbsp;-&nbsp;</a>&nbsp;');

   document.write('</div>');
   }
}

function changeTextSize (amount,elementId)
{
   var amount = Number(amount);
   var size = elementId.style.fontSize;
   if (size.search("%") == -1) {size = "100%";};
   var size = Number(size.replace("%", ""));
   if  ((amount < 0 && size > 60) || (amount > 0 && size < 140)) {size = size+amount;};
   elementId.style.fontSize=size+"%";
}

function selectBanner()
{
   var max = 11;
   var text1 = '<img src="./imgs-main/banner-';
   var text2 = '.gif" id="logo" alt="Hartford Jazz Society\'s Monday Night Jam at Black-eyed Sally\'s, 350 Asylum Street, Downtown Hartford, 860-278-7427">';
   var randomImage = Math.floor(Math.random() * max + 1);
   document.write(text1+randomImage+text2);
}

function getUrlValues ()
{
   var searchString = document.location.search;
   var urlValues=new Array();
   searchString = searchString.substring(1); // remove leading '?'
   var nvPairs = searchString.split("&");
   for (i = 0; i < nvPairs.length; i++)
     {
       var nvPair = nvPairs[i].split("="); // name:nvPair[0] value:nvPair[1]
       urlValues[nvPair[0]] = nvPair[1];
     }
   return urlValues;
}


function setOpacity(obj, opacity) {
  opacity = (opacity == 100)?99.999:opacity;
  
  // IE/Win
  obj.style.filter = "alpha(opacity:"+opacity+")";
  
  // Safari<1.2, Konqueror
  obj.style.KHTMLOpacity = opacity/100;
  
  // Older Mozilla and Firefox
  obj.style.MozOpacity = opacity/100;
  
  // Safari 1.2, newer Firefox and Mozilla, CSS3
  obj.style.opacity = opacity/100;
}

function fadeIn(objId,opacity) {
  if (document.getElementById) {
    var obj = document.getElementById(objId);
    if (opacity <= 100) {
      setOpacity(obj, opacity);
      opacity += 5;
      if (opacity > 100) {opacity == 100;} 
      window.setTimeout("fadeIn('"+objId+"',"+opacity+")",25);
    }
  }
}

function fadeOut(objId,opacity,zValue) {
    var obj = document.getElementById(objId);
    if (opacity >= 0) {
      setOpacity(obj,opacity);
      opacity -= 5;
      if (opacity < 0) {opacity == 0;}
      window.setTimeout("fadeOut('"+objId+"',"+opacity+","+zValue+")",25);
    }
      else if (zValue && zValue < 0) {document.getElementById(objId).style.zIndex = '-1000';}
}

function pauseTest(milliseconds) { 
t = 0
t = setTimeout("alert('from within javascript')", 5000);

}

function pause(milliseconds) {
milliseconds += new Date().getTime();
while (new Date() < milliseconds){}
}


