﻿/*
#==============================================================================#
# Unit Name: TBFGFunctions.js                                                  #
# Author:    Valentin Green - The Brand Factory Group Ltd.                     #
# Date: 04.03.2007                                                             #
# Purpose: Hold functions for the corresponding site                           #
#==============================================================================#
# History:                                                                     #
# Ver      Date     Name   Description                                         #
# 1.xx   00.00.00 yyyyyy   z                                                   #
# 1.00   04.03.07 valieg   Creation of the unit                                #
#==============================================================================#
*/

function initPage()
{
  try{
    if( !W3CDOM) return;
    //now, the current menu is decided by php
    currActiveMnu = arguments[0];
    setMainMnuListener();
    setCurrentMainMnuMover(currActiveMnu);
    //let's set the sub menus listeners
    if( currActiveMnu == 2 ) {
      //services
      setServicesMnuListener();
    } else if( currActiveMnu == 3 ) {
      //portfolio
      
      activeGallery = 8; //branding...!!!
      nextActGallery = 8; //workaround...
      xmlSupplier( 8);
      setPortfolioMnuListener();
      setGalleryListener();
      setGroupListener();
    } else if( currActiveMnu == 4 ) {
      //clients
      setClientsMnuListener();
    };
    initLists();
    if( (currActiveMnu > 1) && (currActiveMnu < 5) ) {
      openWall = isWall( isMainMnuItem( MENUITEMROOTNAME.concat( currActiveMnu)));
      bricksList[currActiveMnu].childIsVisible = true;
      setFirstSubMnuMover(currActiveMnu);
    };
  } catch( err ) {
    MsgBox( "initPage()", err);
  };

}; //function initPage()

/*************************************************************************
    dw_event.js (version date Feb 2004)

    This code is from Dynamic Web Coding at http://www.dyn-web.com/
    See Terms of Use at http://www.dyn-web.com/bus/terms.html
    regarding conditions under which you may use this code.
    This notice must be retained in the code as is!
*************************************************************************/

var dw_event = {

  add: function(obj, etype, fp, cap) {
				try {
						cap = cap || false;
						if( obj.addEventListener ) obj.addEventListener(etype, fp, cap);
						else if( obj.attachEvent ) obj.attachEvent("on" + etype, fp);
				}	catch( err ) {
      MsgBox( "dw_event.add()", err);
				};
  },

  remove: function(obj, etype, fp, cap) {
				try {
						cap = cap || false;
						if( obj.removeEventListener ) obj.removeEventListener(etype, fp, cap);
						else if ( obj.detachEvent ) obj.detachEvent("on" + etype, fp);
				}	catch( err ) {
      MsgBox( "dw_event.remove()", err);
				};
  },

  DOMit: function(e) {
				try {
						e = e ? e: window.event;
						e.tgt = e.srcElement ? e.srcElement: e.target;
		
						if( !e.preventDefault ) e.preventDefault = function () { return false; }
						if( !e.stopPropagation ) e.stopPropagation = function () { if( window.event ) window.event.cancelBubble = true; }
		
						return e;
				}	catch( err ) {
      MsgBox( "dw_event.DOMit()", err);
				};
  }

}; //dw_event()

// stores the reference to the XMLHttpRequest object
var xmlHttp = createXmlHttpRequestObject();

// retrieves the XMLHttpRequest object
function createXmlHttpRequestObject()
{	
  // will store the reference to the XMLHttpRequest object
  var xmlHttp;
  // if running Internet Explorer
  if( window.ActiveXObject ){
    try
    {
      xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    } catch(e) {
      alert("Error in createXmlHttpRequestObject(). IE section !");
      //this is original: xmlHttp = false;
      xmlHttp = null; //valieg
    };
  } else {
    // if running Mozilla or other browsers
    try
    {
      xmlHttp = new XMLHttpRequest();
    } catch(e) {
      alert("Error in createXmlHttpRequestObject(). Mozilla section !");
      //this is original: xmlHttp = false;
      xmlHttp = null; //valieg
    };
  };
  // return the created object or display an error message
  //this is original: if( !xmlHttp )
  if( xmlHttp == null )
    alert("Error creating the XMLHttpRequest object.");
  else
    return xmlHttp;

}; //function createXmlHttpRequestObject()

//=============================================================================================

function addListener()
{
// arguments[0] - table ID with the menu items
// arguments[1] - menu items root name
// arguments[2] - true/false for add/remove
// arguments[3] - handlers set

  var nav = document.getElementById( arguments[0]);
  var tmpStr = null;
  var tmpObj = null;
  var mnuID = -1;
  var HANDLERPREFIX = arguments[3];

  for( var i = 0; i < nav.rows.length; i++ ) {
    for( var j = 0; j < nav.rows[ i].cells.length; j++ ) {
      tmpStr = nav.rows[ i].cells[j].id;
      if( tmpStr.length > 0 ) {
    				mnuID = 1*TBFGreplacer( tmpStr,
  																														arguments[1],
  																														"");
        if( isNaN( mnuID) ) {
          continue;
        } else {
          tmpObj = nav.rows[ i].cells[j];
          if( tmpObj.firstChild.nodeName == "IMG" ) {
            tmpStr = ITEMPICTURE.concat( mnuID);
            tmpObj = document.getElementById( tmpStr);
          };
          if( typeof( tmpObj) != "undefined" ) {
            if( arguments[2] ) {
              switch( HANDLERPREFIX ) {
                case 0:
                //classic
                  dw_event.add( tmpObj, "click", mainMnuOnClick, true );
                  dw_event.add( tmpObj, "mouseover", mainMnuGoesOver, true );
                  dw_event.add( tmpObj, "mouseout", mainMnuGoesOut, true );
                break;
                case 1:
                //top menu
                  dw_event.add( tmpObj, "click", topMnuOnClick, true );
                  dw_event.add( tmpObj, "mouseover", topMnuGoesOver, true );
                  dw_event.add( tmpObj, "mouseout", topMnuGoesOut, true );
                break;
                case 2:
                //portfolio submenu
                  dw_event.add( tmpObj, "click", portfSubMnuOnClick, true );
                  dw_event.add( tmpObj, "mouseover", portfSubMnuGoesOver, true );
                  dw_event.add( tmpObj, "mouseout", portfSubMnuGoesOut, true );
                break;
                case 3:
                //clients submenu
                  dw_event.add( tmpObj, "click", clientSubMnuOnClick, true );
                  dw_event.add( tmpObj, "mouseover", clientSubMnuGoesOver, true );
                  dw_event.add( tmpObj, "mouseout", clientSubMnuGoesOut, true );
                break;
                case 4:
                //gallery pictures
                  dw_event.add( tmpObj, "click", gallPicOnClick, true );
                  dw_event.add( tmpObj, "mouseover", gallPicGoesOver, true );
                  dw_event.add( tmpObj, "mouseout", gallPicGoesOut, true );
                break;
                case 5:
                //gallery navigation button
                  dw_event.add( tmpObj, "click", gallNavOnClick, true );
                  dw_event.add( tmpObj, "mouseover", gallNavGoesOver, true );
                  dw_event.add( tmpObj, "mouseout", gallNavGoesOut, true );
                break;
                case 6:
                //group "number cells"
                  dw_event.add( tmpObj, "click", groupCellOnClick, true );
                  dw_event.add( tmpObj, "mouseover", groupCellGoesOver, true );
                  dw_event.add( tmpObj, "mouseout", groupCellGoesOut, true );
                break;
                case 7:
                //group navigation button
                  dw_event.add( tmpObj, "click", groupNavOnClick, true );
                  dw_event.add( tmpObj, "mouseover", groupNavGoesOver, true );
                  dw_event.add( tmpObj, "mouseout", groupNavGoesOut, true );
                break;
                case 8:
                //services submenu
                  dw_event.add( tmpObj, "click", serviSubMnuOnClick, true );
                  dw_event.add( tmpObj, "mouseover", serviSubMnuGoesOver, true );
                  dw_event.add( tmpObj, "mouseout", serviSubMnuGoesOut, true );
                break;
              };
            } else {
              dw_event.remove( tmpObj, "click", mainMnuOnClick, true );
              dw_event.remove( tmpObj, "mouseover", mainMnuGoesOver, true );
              dw_event.remove( tmpObj, "mouseout", mainMnuGoesOut, true );
            };
          } else {
            continue;
          };
        };
      };
    };
  };

}; //addListener()

/* main menu group */

function mainMnuOnClick( event)
{
  var mnuID = DOMitNew( event);
  var mnuIDnr = isMainMnuItem( mnuID);

		if( mnuIDnr == currActiveMnu ) {
    //the same, current page
				if( bricksList[ mnuIDnr].isParent ) {
						if( bricksList[ mnuIDnr].childIsVisible ) {
        //hide it
								expandCompressWall( false, isWall( mnuIDnr))
								bricksList[ mnuIDnr].childIsVisible = false;
						}	else {
        //open it
								expandCompressWall( true, isWall( mnuIDnr))
								bricksList[ mnuIDnr].childIsVisible = true;
						};
				};
		} else {
    //another page
    document.location = "index.php?mpage=" + mnuIDnr;
		};
		
		return;

}; //mainMnuOnClick()

function mainMnuGoesOver( event)
{
  var mnuID = DOMitNew( event);
  var tmpID = isMainMnuItem( mnuID);
  if( tmpID > 0 ) {
    document.getElementById( MENUITEMROOTNAME.concat( tmpID)).className = "mainMenuItemMover";
    document.getElementById( MENUITEMICONNAME.concat( tmpID)).className = "mnuMainIconMover";
  } else {
    //error message
  };

}; //mainMnuGoesOver()

function mainMnuGoesOut( event)
{
  var mnuID = DOMitNew( event);
  var tmpID = isMainMnuItem( mnuID);
  if( tmpID > 0 ) {
    document.getElementById( MENUITEMROOTNAME.concat( tmpID)).className = "mainMenuItemMout";
    document.getElementById( MENUITEMICONNAME.concat( tmpID)).className = "mnuMainIconMout";
  } else {
    //error message
  };

}; //mainMnuGoesOut()

/* top menu group */

function topMnuOnClick( event)
{
  var mnuID = DOMitNew( event);
  //set the top banner
  document.location = "index.php?mpage=0";

}; //topMnuOnClick()

function topMnuGoesOver( event)
{
  document.getElementById( DOMitNew( event)).className = "mnuTopIconMover";
  return;
}; //topMnuGoesOver()

function topMnuGoesOut( event)
{
  document.getElementById( DOMitNew( event)).className = "mnuTopIconMout";
  return;

}; //topMnuGoesOut()

/* portfolio menu group */

function portfSubMnuOnClick( event)
{
  var mnuID = DOMitNew( event);
  var tmpID = isSubMnuItem( mnuID);

debugTimer(" portfSubMnuOnClick()>>>>>>>>>>>>>>"+mnuID);

  if( ( tmpID < 8 ) || ( tmpID > 13 ) ) {
    //the sub menu is not a part of portfolio main menu item !
    return;
  };
  /*
  */
  var targetID = "kernelArea";
  if( document.getElementById( targetID) ) {
    nextActGallery = tmpID;
    xmlSupplier( tmpID );

debugTimer(" xmlSupplier("+mnuID+") already called in portfSubMnuOnClick() GALLERY_LIST(1)= "+GALLERY_LIST[1]);

    activeGallery = tmpID;

    setGalleryListener();
    if( getGalleryType() == 0 ) {
      setGroupListener();
    };
    setCurrGallPicPath();

  } else {
    //error message
  };

}; //portfSubMnuOnClick()

function portfSubMnuGoesOver( event)
{
  var mnuID = DOMitNew( event);
  var tmpID = isMainMnuItem( mnuID);
  if( tmpID > 0 ) {
    document.getElementById( MENUITEMROOTNAME.concat( tmpID)).className = "mainSubMnuItemMover";
    document.getElementById( MENUITEMICONNAME.concat( tmpID)).className = "mnuSubMnuIconMover";
  } else {
    //error message
  };

}; //portfSubMnuGoesOver()

function portfSubMnuGoesOut( event)
{
  var mnuID = DOMitNew( event);
  var tmpID = isMainMnuItem( mnuID);
  if( tmpID > 0 ) {
    document.getElementById( MENUITEMROOTNAME.concat( tmpID)).className = "mainSubMnuItemMout";
    document.getElementById( MENUITEMICONNAME.concat( tmpID)).className = "mnuSubMnuIconMout";
  } else {
    //error message
  };

}; //portfSubMnuGoesOut()

/* clients menu group */

function clientSubMnuOnClick( event)
{
  var mnuID = DOMitNew( event);
  var tmpID = isSubMnuItem( mnuID);

  if( ( tmpID < 14 ) || ( tmpID > 18 ) ) {
    //the sub menu is not a part of clients main menu item !
    return;
  };

  var targetID = "kernelArea";
  if( document.getElementById( targetID) ) {
    xmlSupplier( tmpID );
  };  
  
  
}; //clientSubMnuOnClick()

function clientSubMnuGoesOver( event)
{
  var mnuID = DOMitNew( event);
  var tmpID = isMainMnuItem( mnuID);
  if( tmpID > 0 ) {
    document.getElementById( MENUITEMROOTNAME.concat( tmpID)).className = "mainSubMnuItemMover";
    document.getElementById( MENUITEMICONNAME.concat( tmpID)).className = "mnuSubMnuIconMover";
  } else {
    //error message
  };

}; //clientSubMnuGoesOver()

function clientSubMnuGoesOut( event)
{
  var mnuID = DOMitNew( event);
  var tmpID = isMainMnuItem( mnuID);
  if( tmpID > 0 ) {
    document.getElementById( MENUITEMROOTNAME.concat( tmpID)).className = "mainSubMnuItemMout";
    document.getElementById( MENUITEMICONNAME.concat( tmpID)).className = "mnuSubMnuIconMout";
  } else {
    //error message
  };

}; //clientSubMnuGoesOut()

/* services menu group */

function serviSubMnuOnClick( event)
{
  var mnuID = DOMitNew( event);
  var tmpID = isSubMnuItem( mnuID);

  if( ( tmpID < 19 ) || ( tmpID > 24 ) ) {
    //the sub menu is not a part of services main menu item !
    return;
  };

  var targetID = "kernelArea";
  if( document.getElementById( targetID) ) {
    xmlSupplier( tmpID );
  };  

}; //serviSubMnuOnClick()

function serviSubMnuGoesOver( event)
{
  var mnuID = DOMitNew( event);
  var tmpID = isMainMnuItem( mnuID);
  if( tmpID > 0 ) {
    document.getElementById( MENUITEMROOTNAME.concat( tmpID)).className = "mainSubMnuItemMover";
    document.getElementById( MENUITEMICONNAME.concat( tmpID)).className = "mnuSubMnuIconMover";
  } else {
    //error message
  };

}; //serviSubMnuGoesOver()

function serviSubMnuGoesOut( event)
{
  var mnuID = DOMitNew( event);
  var tmpID = isMainMnuItem( mnuID);
  if( tmpID > 0 ) {
    document.getElementById( MENUITEMROOTNAME.concat( tmpID)).className = "mainSubMnuItemMout";
    document.getElementById( MENUITEMICONNAME.concat( tmpID)).className = "mnuSubMnuIconMout";
  } else {
    //error message
  };

}; //serviSubMnuGoesOut()

/* gallery pictures group */

function gallPicOnClick( event)
{
  var mnuID = DOMitNew( event);
  var gallType = getGalleryType();
  if( gallType < 0 ) {
    //wrong gallery type
    return;
  } else {
    if( gallType == 0 ) {
      //8 and 9 portfolio sub menu items
      fillGroupLargePicList( mnuID);

    } else {
      //10 - 13 portfolio sub menu items
      setBigPic( mnuID);
    };
  };

  return;

}; //gallPicOnClick()

function gallPicGoesOver( event)
{
  document.getElementById( DOMitNew( event)).className = "thumbFrameMover";
  return;

}; //gallPicGoesOver()

function gallPicGoesOut( event)
{
  document.getElementById( DOMitNew( event)).className = "thumbFrameMout";
  return;

}; //gallPicGoesOut()

/* gallery navigation buttons */

function gallNavOnClick( event)
{
  var mnuID = DOMitNew( event);
  var mnuIDnr = 1*TBFGreplacer( mnuID, GALLNAVIGICON, "");
  if( ( mnuIDnr == 0) || ( mnuIDnr == 1) ) {
    picIndex = getTopLeftIndex();
    if( picIndex < GALLERY_LIST.length ) {
      // let's "repaint" the gallery
      galleryRepainter( picIndex, mnuIDnr);
    };
    setPrevNext();
    } else {
      alert( "Wrong navigation ID !");
    };

}; //gallNavOnClick()

function gallNavGoesOver( event)
{
  document.getElementById( DOMitNew( event)).style.cursor = "pointer";
  return;

}; //gallNavGoesOver()

function gallNavGoesOut( event)
{
  document.getElementById( DOMitNew( event)).style.cursor = "default";
  return;

}; //gallNavGoesOut()

/* "number cells" group pictures */

function groupCellOnClick( event)
{
  var mnuID = DOMitNew( event);
  document.getElementById( mnuID).className = "countNrMover";
  var currGallCell = document.getElementById( mnuID).innerHTML;
  if( isNaN( currGallCell) ) {
    alert( "Wrong group left ID !");
    return;
  } else {
    currGallCell *= 1;
  };

  //instead of setBigPic( mnuID);
  document.getElementById( THUMBBIGPIC).src = GALLERY_LARGE_LIST[currGallCell];
  
  return;

}; //groupCellOnClick()

function groupCellGoesOver( event)
{
  document.getElementById( DOMitNew( event)).className = "countNrMover";
  return;

}; //groupCellGoesOver()

function groupCellGoesOut( event)
{
  document.getElementById( DOMitNew( event)).className = "countNrMout";
  return;

}; //groupCellGoesOut()

/* group navigation buttons */

function groupNavOnClick( event)
{
  var mnuID = DOMitNew( event);
  var mnuIDnr = 1*TBFGreplacer( mnuID, GROUPNAVIGICON, "");
  if( ( mnuIDnr == 0) || ( mnuIDnr == 1) ) {
    // the content of the first group cell !
    var groupIndex = document.getElementById("gallCellID1").innerHTML;
    if( isNaN( groupIndex) ) {
      alert( "Wrong group left ID !");
      return;
    } else {
      groupIndex *= 1;
    };
    var groupMembers = GALLERY_GROUP_LIST[currGroupIdx] + 1; //!!??
    if( groupMembers < 4 ) {
      // if are less than 4 items, NO navigation arrows !!!
      return;
    } else {
      // let's "repaint" the group
      groupRepainter( groupIndex, mnuIDnr, groupMembers);
    };
    setPrevNext();
    } else {
      alert( "Wrong group navigation ID !");
    };

}; //groupNavOnClick()

function groupNavGoesOver( event)
{
  document.getElementById( DOMitNew( event)).style.cursor = "pointer";
  return;

}; //groupNavGoesOver()

function groupNavGoesOut( event)
{
  document.getElementById( DOMitNew( event)).style.cursor = "default";
  return;

}; //groupNavGoesOut()



function DOMitNew()
{
  var evnt = ( arguments[0]) ? arguments[0] : windows.event;
  var tgt = ( evnt.srcElement) ? evnt.srcElement : evnt.target;
  var evntType = null;
		if( !evnt.preventDefault) evnt.preventDefault = function () { return false; }
		if( !evnt.stopPropagation) evnt.stopPropagation = function () { if( window.event) window.event.cancelBubble = true; }

  if( tgt ) {
    //Non IE
    if ( tgt.nodeType == 3 ) {
      // defeat Safari bug
      tgt = tgt.parentNode;
    };
  } else {
    //IE
  };
  //not necessary, for the moment - evntType = evnt.type;

  return tgt.id;

}; //DOMitNew()

//==================================

function expandCompressWall()
{
// arguments[0] == true, expand the wall
// arguments[0] == false, compress the wall
// arguments[1] == wall ID

  try{
    if( arguments[1] < 0 ) {
      //no wall
      return;
    };
    var dynMnuID = DYNMNUBASE.concat( arguments[1]);
    if( document.getElementById( dynMnuID) ) {
      //be gentle
      if( arguments[0] ) {
        //expand
        if( currentChildHTML != "" ) {
          document.getElementById( dynMnuID).innerHTML = currentChildHTML;
          setFirstSubMnuMover(currActiveMnu);
        };
      } else {
        //compress
        if( currentChildHTML == "" ) currentChildHTML = getChildContent(arguments[1]);
        document.getElementById( dynMnuID).innerHTML = "";
      };

      openWall = ( arguments[0] ) ? arguments[1] : -1;

      //add listener for the open child
      if( arguments[0] ) {
        if( arguments[1] == 1 ) {
          //portfolio
          setPortfolioMnuListener();
        } else if( arguments[1] == 2 ) {
          //clients
          setClientsMnuListener();
        } else if( arguments[1] == 3 ) {
          //services
          setServicesMnuListener();
        };
      };
    };
  } catch( err ) {
    MsgBox( "expandCompressWall()", err);
  };

}; //function expandCompressWall()

function getTopLeftIndex() {

  try
  {
    // the content of the first cell !
    if( document.getElementById("thumbCellID1").firstChild.nodeName == "IMG" ) {
      var strTemp = document.getElementById("thumbPicID1").src;
      for( var j = 0; j < GALLERY_LIST.length; j++ ) {
        if( exactMatch( strTemp, GALLERY_LIST[j]) ) {
          return j;
        };
      };
    } else {
      //error message
    };
    return -1;
  } catch( err ) {
    MsgBox( "getTopLeftIndex()", err);
  };

}; //function getTopLeftIndex()

function exactMatch(){

// arguments[0] - the full path
// arguments[1] - file name
  try
  {
    return ( arguments[0].match( arguments[1] ) != null ) ? true : false;
  } catch( err ) {
    MsgBox( "exactMatch()", err);
  };

}; //function exactMatch()

function galleryRepainter()
{

// arguments[0] is the top-left pic index:
// arguments[1] is the direction ( 0 = to left = previous;
//                                 1 = to right = next )

  var picIndexOffset = GALLERYROWS * GALLERYCOLS;
  var galleryLen = GALLERY_LIST.length;
  var newTopLeftIndex = -1;
  var cellID = null;
		var picPath = null;
  var strTemp = null;
		
  try{
    // let's see if the repaint is necessary !
    if( ( arguments[1] == 0 && arguments[0] < picIndexOffset) || ( arguments[1] == 1 && arguments[0] + picIndexOffset > galleryLen) ) {
      // repaint is NOT necessary
      return;
    };

    switch( arguments[1] ) {
      case 0:
        // so, previous
        newTopLeftIndex = arguments[0] - picIndexOffset;
        break;

      case 1:
        // so, next
        newTopLeftIndex = arguments[0] + picIndexOffset;
        break;

      default:
        // no action
        txt = "WRONG direction parameter\n";
        txt += "received in galleryRepainter() function !\n";
        txt += "Click OK to continue.\n";
        alert( txt );
        return;
        break;
    };

    for( var j = newTopLeftIndex; j < ( newTopLeftIndex + picIndexOffset); j++ ) {
      cellID = j % picIndexOffset;
      if( cellID == 0 ) {
							  cellID = picIndexOffset;
						};
/*
valieg 13.05.2007
    strTemp = document.getElementById( "thumbPicID1").src;// ID1 is never ever dummy picture !!!!!
    picPath = strTemp.substring( 0, ( strTemp.lastIndexOf( "/") + 1)); //all pic supposed to be in the same folder
*/
    picPath = currentGallPicPath;
    //                                                                                           put the dummy pic
      document.getElementById( THUMBSPICID.concat( cellID)).src = ( j > galleryLen - 1) ? picPath.concat( GALLERY_LIST[ 0]) : picPath.concat(GALLERY_LIST[ j]);
if( DEBUG02 ) {
  alert("pic = "+picPath.concat(GALLERY_LIST[ j])+"<")
};
    };
//valieg 22.03.2007				setGalleryEvent();
  } catch( err ) {
    MsgBox( "galleryRepainter()", err);
  };

}; //function galleryRepainter()

function setPrevNext(){

  var galleryLen = GALLERY_LIST.length; //supposed here that GALLERY_LIST already has the right content

  try{
    // the content of the first cell !
    var strTemp = document.getElementById("thumbCellID1").innerHTML;
    for( var j = 0; j < GALLERY_LIST.length; j++ ) {
      if( exactMatch( strTemp, GALLERY_LIST[j]) ) {
        break;
      };
    };
    var itemObj = document.getElementById( GALLNAVIGITEM.concat( 0));
    var iconObj = document.getElementById( GALLNAVIGICON.concat( 0));
    if( j == 1 ) {
      itemObj.style.visibility = "hidden";
      document.getElementById( GALLNAVIGICON.concat( 0)).style.visibility = "hidden";
    } else {
      itemObj.style.visibility = "visible";
      iconObj.style.visibility = "visible";
    };
    itemObj = document.getElementById( GALLNAVIGITEM.concat( 1));
    iconObj = document.getElementById( GALLNAVIGICON.concat( 1));
    if( ( galleryLen - j) > ( GALLERYROWS * GALLERYCOLS) ) {
      itemObj.style.visibility = "visible";
      iconObj.style.visibility = "visible";
    } else {
      itemObj.style.visibility = "hidden";
      iconObj.style.visibility = "hidden";
    };
  } catch( err ) {
    MsgBox( "setPrevNext()", err);
  };

}; //function setPrevNext()

/* portfolio 10-13 galleries*/
function bigPicValidator10_13()
{
  try
  {
    var currThumbCellSrc = document.getElementById( arguments[0]).src;
    for( var i = 0; i < GALLERY_LIST.length; i++) {
      if( currThumbCellSrc.match( GALLERY_LIST[i]) != null ) {
        return i;
      };
    };
    return -1;

  } catch( err ) {
    MsgBox( "bigPicValidator10_13()", err);
  };

}; //function bigPicValidator10_13()

function setBigPic()
{
  try
  {
    var currentBigPic = document.getElementById( THUMBBIGPIC).src;
    var gallType = getGalleryType();
    if( gallType < 0 ) {
      //wrong gallery type
      return;
    } else {
      if( gallType == 0 ) {
        //8 and 9 portfolio sub menu items
      } else {
        //10 - 13 portfolio sub menu items
        var thumbPicIdx = bigPicValidator10_13( arguments[0]);
        if( thumbPicIdx < 0 ) {
          return;
        } else {
          if( currentBigPic.match( GALLERY_LARGE_LIST[thumbPicIdx] != null )) {
            return;
          } else {
            document.getElementById( THUMBBIGPIC).src = GALLERY_LARGE_LIST[thumbPicIdx];
          };
        };
      };
    };
  } catch( err ) {
    MsgBox( "setBigPic()", err);
  };

}; //function setBigPic()

function groupRepainter()
{
// arguments[0] is the left index:
// arguments[1] is the direction ( 0 = to left = previous;
//                                 1 = to right = next )
// arguments[3] number of group members (groupMembers)

  var groupIndexOffset = 3;
  var newLeftIndex = -1;

  try{
    // let's see if the repaint is necessary !
    switch( arguments[1] ) {
      case 0:
        // so, previous
        newLeftIndex = ( arguments[0] <= groupIndexOffset ) ? 1 : arguments[0] - groupIndexOffset;
        break;

      case 1:
        // so, next
        newLeftIndex = ( arguments[0] + 2*groupIndexOffset <= arguments[2] ) ? arguments[0] + groupIndexOffset : arguments[2] - groupIndexOffset;
        break;

      default:
        // no action
        txt = "WRONG direction parameter\n";
        txt += "received in groupRepainter() function !\n";
        txt += "Click OK to continue.\n";
        alert( txt );
        return;
        break;
    };
    for( var j = 1; j <= groupIndexOffset; j++ ) {
      document.getElementById( GALLCELLID.concat( j)).innerHTML = newLeftIndex++;
    };
  } catch( err ) {
    MsgBox( "groupRepainter()", err);
  };

}; //function groupRepainter()

function setCurrGallPicPath()
{
  try
  {
    // the content of the first cell !
    if( document.getElementById("thumbCellID1").firstChild.nodeName == "IMG" ) {
      var strTemp = document.getElementById("thumbPicID1").src;
      //delete the previous path and set a new one
      currentGallPicPath = TBFGreplacer( strTemp, GALLERY_LIST[1], "");
    };
  } catch( err ) {
    MsgBox( "setCurrGallPicPath()", err);
  };

}; //function setCurrGallPicPath()

function setCurrentMainMnuMover()
{
  var tmpName = MENUITEMROOTNAME.concat( arguments[0]);
  var tmpIconName = MENUITEMICONNAME.concat( arguments[0]);

  if( document.getElementById( tmpName) ) {
    document.getElementById( tmpName).className = "mainMenuItemMover";
  };
  if( document.getElementById( tmpIconName) ) {
    document.getElementById( tmpIconName).className = "mnuMainIconMover";
  };

}; //setCurrentMainMnuMover()

function setFirstSubMnuMover()
{
  var tmpName = "";
  var tmpIconName = "";
  //very ugly solution !!!

  if( arguments[0] == 2 ) {
    //services
    tmpName = MENUITEMROOTNAME.concat( 19);
    tmpIconName = MENUITEMICONNAME.concat( 19);
  } else if( arguments[0] == 3 ) {
    //portfolio
    tmpName = MENUITEMROOTNAME.concat( 8);
    tmpIconName = MENUITEMICONNAME.concat( 8);
  } else if( arguments[0] == 4 ) {
    //clients - changed to 15 ( from 14 ) valieg 20.06.2007
    tmpName = MENUITEMROOTNAME.concat( 15);
    tmpIconName = MENUITEMICONNAME.concat( 15);
  };
  if( document.getElementById( tmpName) ) {
    document.getElementById( tmpName).className = "mainSubMnuItemMover";
  };
  if( document.getElementById( tmpIconName) ) {
    document.getElementById( tmpIconName).className = "mnuSubMnuIconMover";
  };

}; //setFirstSubMnuMover()

function getChildContent()
{
  var tmpID = DYNMNUBASE.concat( arguments[0]);
  var tmp = "";

  if( document.getElementById( tmpID) ) {
    tmp = document.getElementById( tmpID).innerHTML;
    tmp = TBFGreplacer( tmp, "\r\n", "");
    //Mozilla
    tmp = TBFGreplacer( tmp, "\r", "");
  };

  return tmp;

}; //getChildContent()

function getGalleryType()
{
  if( ( activeGallery > 7 ) && ( activeGallery < 10 ) ) {
      //8 and 9 portfolio sub menu items
    return 0;
  } else if( ( activeGallery > 9 ) && ( activeGallery < 14 ) ) {
      //10 - 13 portfolio sub menu items
    return 1;
  };

  return -1;

}; //getGalleryType()

function getNextGalleryType()
{
  if( ( nextActGallery > 7 ) && ( nextActGallery < 10 ) ) {
      //8 and 9 portfolio sub menu items
    return 0;
  } else if( ( nextActGallery > 9 ) && ( nextActGallery < 14 ) ) {
      //10 - 13 portfolio sub menu items
    return 1;
  };

  return -1;

}; //getNextGalleryType()

/* fill GALLERY_LARGE_LIST for groups */
function fillGroupLargePicList()
{
  var mnuIDnr = 1*TBFGreplacer( arguments[0], THUMBSPICID, "");
  var currThumbCellSrc = document.getElementById( arguments[0]).src;
debugTimer(" fillGroupLargePicList() called for: "+arguments[0]+" and current cell "+currThumbCellSrc);
  var cellPicIdx = -1;
  var firstIdx = 0;
  
  for( var i = 0; i < GALLERY_LIST.length; i++) {
    if( currThumbCellSrc.match( GALLERY_LIST[i]) != null ) {
      cellPicIdx = i;
      break;
    };
  };
  
  currGroupIdx = cellPicIdx; //for the current GALLERY_GROUP_LIST
  
  for( var j = 1; j < cellPicIdx ; j++) {
    firstIdx += GALLERY_GROUP_LIST[j];
  };
  firstIdx += 1; //compensation for the dummy element

  fillArrayFromPart(GALLERY_LARGE_LIST, GALLERY_GROUP_BUFFER_LIST, firstIdx, GALLERY_GROUP_LIST[cellPicIdx]);
  //fill the big picture
  document.getElementById( THUMBBIGPIC).src = GALLERY_LARGE_LIST[1];

  return;
  
}; //fillGroupLargePicList()

/* */
function xmlResponseHandler( recStr,
                             pGALLERY_LIST,
                             pGALLERY_GROUP_LIST,
                             pGALLERY_LARGE_LIST,
                             pGALLERY_GROUP_BUFFER_LIST)
{
testCall++;
debugTimer(" xmlResponseHandler() called by nr = "+testCall+"<br><br>"+recStr, 0);

  var gallType = getNextGalleryType();

  if( gallType == -1 ) {
    //error message
    alert("xmlResponseHandler() test failure ! Wrong activeGallery.");
    return;
  };

  var tmpArray = recStr.split("|");

  var smallIconNr = 1*tmpArray[0];
  var largeIconNr = 1*tmpArray[1];
  var smallIconPath = tmpArray[2];
  var largeIconPath = tmpArray[3];
  
  var initLength = pGALLERY_LIST.length;
  for( var i = 0; i < initLength; i++ ) {
    pGALLERY_LIST.pop();
  };
  
  var tmpSliceArray = tmpArray.slice( 4, 4+smallIconNr);

  for( var i = 0; i < tmpSliceArray.length; i++ ) {
    pGALLERY_LIST.push( smallIconPath.concat( tmpSliceArray[i])); 
  };
  tmpSliceArray = null;

  if( gallType == 0 ) {
      //8 and 9 portfolio sub menu items
    initLength = pGALLERY_GROUP_BUFFER_LIST.length;
    for( var i = 0; i < initLength; i++ ) {
      pGALLERY_GROUP_BUFFER_LIST.pop();
    };
    initLength = pGALLERY_GROUP_LIST.length;
    for( var i = 0; i < initLength; i++ ) {
      pGALLERY_GROUP_LIST.pop();
    };

    tmpSliceArray = tmpArray.slice( 4+smallIconNr, 4+smallIconNr+largeIconNr);
    //optimize this code after testing !!!
    for( var i = 0; i < tmpSliceArray.length; i++ ) {
      pGALLERY_GROUP_BUFFER_LIST.push( largeIconPath.concat( tmpSliceArray[i]));
    };
    tmpSliceArray = null;

    tmpSliceArray = tmpArray.slice( 4+smallIconNr+largeIconNr, 4+smallIconNr+largeIconNr+smallIconNr);
    //optimize this code after testing !!!
    for( var i = 0; i < tmpSliceArray.length; i++ ) {
      pGALLERY_GROUP_LIST.push( 1*tmpSliceArray[i]); 
    };
    tmpSliceArray = null;
    
    currGroupIdx = 1;

  } else if( gallType == 1 ) {
      //10 - 13 portfolio sub menu items
    initLength = pGALLERY_LARGE_LIST.length;
    for( var i = 0; i < initLength; i++ ) {
      pGALLERY_LARGE_LIST.pop();
    };

    for( var i = 0; i < pGALLERY_LIST.length; i++ ) {
      pGALLERY_LARGE_LIST.push( TBFGreplacer( TBFGreplacer( pGALLERY_LIST[i], smallIconPath, largeIconPath), GALLERYPICSUFFIX, "")); 
    };
  } else {
    // what is going on within getGalleryType() ? 
  };
  
  tmpArray = null;

  return;

}; //xmlResponseHandler()

/* fill out the page entry */
function setFirstScene( actGallery, pGALLERY_LIST)
{
debugTimer(" setFirstScene() called for: actGallery= "+actGallery+" pGALLERY_LIST[1]= "+pGALLERY_LIST[1]);
// arguments[0] is activeGallery

  if( pGALLERY_LIST.length < 2 ) {
    //no gallery to handle ( must be at least ONE, not dummy (!) picture )
    alert("No pictures in GALLERY_LIST ! Length is: "+pGALLERY_LIST.length);
    return;
  };

  var gallType = getNextGalleryType();

  if( gallType == -1 ) {
    //error message
    alert("setFirstScene() failure ! Wrong activeGallery.");
    return;
  };

  if( gallType == 0 ) {
      //8 and 9 portfolio sub menu items
      if( document.getElementById( THUMBBIGPIC) ) {
        document.getElementById( THUMBBIGPIC).width = 397;
      };
      if( document.getElementById( GROUPNAME) ) {
        if( document.getElementById( GROUPNAME).style.visibility == "hidden" ) {
          document.getElementById( GROUPNAME).style.visibility = "visible";
        };
      };
      if( document.getElementById( THUMBBIGPIC) ) {
        document.getElementById( THUMBBIGPIC).src = GALLERY_GROUP_BUFFER_LIST[1];
      };

  } else if( gallType == 1 ) {
      //10 - 13 portfolio sub menu items
      if( document.getElementById( THUMBBIGPIC) ) {
        document.getElementById( THUMBBIGPIC).width = 316;
      };
      if( document.getElementById( GROUPNAME) ) {
        if( document.getElementById( GROUPNAME).style.visibility == "visible" ) {
          document.getElementById( GROUPNAME).style.visibility = "hidden";
        };
      };
      if( document.getElementById( THUMBBIGPIC) ) {
        document.getElementById( THUMBBIGPIC).src = GALLERY_LARGE_LIST[1];
      };
      
  } else {
    // what is going on within getGalleryType() ? 
  };
  //
  var realPicNr = Math.min( GALLERYCOLS, GALLERY_LIST.length)
  for( var j = 1; j <= realPicNr; j++) {
    document.getElementById( THUMBSPICID.concat( j)).src = GALLERY_LIST[j];
  };
  if( realPicNr < GALLERYCOLS ) {
    for( var j = realPicNr+1; j <= realPicNr; j++ ) {
      document.getElementById( THUMBSPICID.concat( j)).src = GALLERY_LIST[0];
    };
  };

  if( gallType == 0 ) {
      //8 and 9 portfolio sub menu items
    fillGroupLargePicList( THUMBSPICID.concat( 1));
  };

  
}; //setFirstScene()
