/* ---------- gallery scripts ---------- modified 18 May 2008  ------------- */
// expand thumbnails
var currentObj, ind, prevButtonObj;                // global save of clicked thumbnail
 function expandPics(obj,referrer)
  { // check if all images loaded
    if(lastBorderObj==0){ return; }          // remains zero until full page loads
    // -----------------------------------------
  // If first time through
    if(referrer==1)
        { // save clicked thumbnail object ref to global
            currentObj=obj;     
          // save index of current clicked thumbnail              
            ind=currentObj.name;      
          // clear extra pic buttons before starting if first time through
          document.getElementById("pXtra").innerHTML="";   
          currentFirstPart=currentLastPart=null;         
         }
//
  // If NOT first time through
  // Check hover situation on small buttons
   if(referrer==2)
     { if(currentLastPart=="M_3.jpg")
       {return true }                                                // already clicked, so no changes
    else
       { // show button in clicked state. Mouseout will return it
           currentLastPart="M_3.jpg";                    
         // return any previous clicked button to neutral
            if(prevButtonObj)
               {  var oldSrc=prevButtonObj.src;
                  var pnt=oldSrc.lastIndexOf("/")+1;
                  var firstPart=oldSrc.substring(0,pnt);
                  prevButtonObj.src=firstPart+"M_1.jpg";
               }
          // save this object ref for later                            
            prevButtonObj=obj;                        
        }
   } 
//
    // write pic to div picL 
    var pnt=currentObj.src.lastIndexOf("/");
    var firstPart=currentObj.src.substring(0,pnt+1)
    var lastPart;
        if(referrer==1)
          { lastPart={pic:K[ind][K[ind].length-1].pic, w:K[ind][K[ind].length-1].w, h:K[ind][K[ind].length-1].h} }
        else if(referrer==2)
          { lastPart={pic:K[ind][obj.name].pic, w:K[ind][obj.name].w, h:K[ind][obj.name].h } }
//
     var newSrc=firstPart+lastPart.pic;  
//
     var build='<p class><img id="mainPic" border="0" onload="loaded()" src="'+newSrc+'" width="'+lastPart.w+'" height="'+lastPart.h+'"><\/p>\n<p class="smlRT">Copyright &copy; Rod Tickle 2008<\/p>\n';    
    var elem=document.getElementById("picL")
      elem.innerHTML=build;
//
//   display extra pic buttons if appropriate
        if( referrer==1 && K[ind].length>1)
            { build='<p class><span style="vertical-align:8px;background-color:#000;">&nbsp;Click these for '+K[ind].length+' more Pics:&nbsp;<\/span>';
//
  // NOTE: using expandPic(obj,referrer) function below, but the object is the button, not the thumbnail. 
  // conflicts resolved by using different referrer reference here [not the first time through this time]
//                 
                   for(var i=0;i<K[ind].length;i++)
                    { build+='<img name="'+i+'" border="0" src="images/M_1.jpg" onmouseover="MOver(this)" onmouseout="MOut(this)" ';
                      build+='onclick="return expandPics(this,2)" width="26" height="26">';
                    } 
               build+='<\/p>\n';
              document.getElementById("pXtra").innerHTML=build;
             }
//
// display loader image
    document.getElementById("ldr").style.visibility="visible";       
   // change border colours
  if(referrer==1)
     { lastBorderObj.style.border="2px solid #FFF";     // return previous to white
       obj.style.border="2px solid #FF0";            // set this border to hilite
       lastBorderObj=obj;                               // save object ref
     }
//
 // move page down or up to view text below pics
 if(document.body.scrollTop !=180)    
  {  var currentPosn=document.body.scrollTop;                    // page here now
      currentPosn=(currentPosn<180)?currentPosn : 160;     //  less or more than 150
      for(var i=currentPosn; i<181; i=i+3) {  scrollTo(0,i); }        // scroll into posn
  }
    return true;
  }
// ---------------
// set first border on thumbnails
var lastBorderObj=0;    // global remains zero until page onload fires
 function firstBdr()
  { var elem=document.getElementById("bdr1");
    elem.style.border="2px solid #FF0";           
    lastBorderObj=elem;    
  }
// ---------------
// displays loading bar
 function loaded()
  { document.getElementById("ldr").style.visibility="hidden";    
  }
// ---------------
// process mouse events for small buttons
var currentFirstPart, currentLastPart;       // global
//
function MOver(obj)
  {  var oldSrc=obj.src;
   // split src string to give image ref 
    var pnt=oldSrc.lastIndexOf("/")+1;
    var firstPart=oldSrc.substring(0,pnt);
    var lastPart=oldSrc.substring(pnt);
  // save oldSrc info for mouseout and any click on this button
    currentFirstPart=firstPart; 
    currentLastPart=lastPart; 
// 
    lastPart=(lastPart=="M_3.jpg")?"M_3.jpg" : "M_2.jpg";
    var newSrc=firstPart+lastPart;
    obj.src=newSrc;
  }
//
function MOut(obj) 
  {   obj.src=currentFirstPart+currentLastPart;
  }
//
// -----------------------



