

/***********************************

*   http://javascripts.vbarsan.com/

*

*   modified by me 20 sept 2006

***********************************/



//-- Begin Scroller's Parameters and messages -->

//scroller's width

var swidth=920;



//scroller's height

var sheight=20;



//scroller's speed 

var sspeed=0;

var step = 5

var restart=step;  //sspeed;

var rspeed=step;   //sspeed;

var iScrollInterval = 200;

var ns6div, ns4layer, iediv



//scroller's pause 

var spause=2000;



//setInterval and setTiomeout ids

var delay=0;

var toid=0;



//messages: change to your own; use as many as you'd like; set up Hyperlinks to URLs as you normally do: <a target=... href="... URL ...">..message..</a>

var GalleriesContent;

	//// var actGalleryID = 'gid$$GalleryID$$'; - this is moved in the template

var arGalleryWidths = new Array("2");

var bAreSetWidths = false;



    

function ShowPrevGals() {

    var newAGID, tdG;

    var iGWidths = 0;

    var startInd=0;

        //1. fill the div with the whole galleries list

    document.getElementById('iens6div').innerHTML = GalleriesContent;

   

    //2. find the index of the current active gallery id

    for (j=0; j<arGalleryWidths[0].length; j++) {

        if (arGalleryWidths[j][0] == actGalleryID) {

            startInd = j;

            break;

        }

    }

     //3. find new active gal id

    newAGID = arGalleryWidths[0][0];

    for (j=startInd;j>=0;j--){

        iGWidths += arGalleryWidths[j][1];

        if (iGWidths+5 > swidth){

            newAGID = arGalleryWidths[j+1][0]; 

            break;

       }

    }

    if (newAGID) actGalleryID = newAGID;

    //2. scroll to the new 'active' gallery id

    ScrollToActiveGallery(newAGID);

}



function ShowNextGals() {

    var newAGID;

    var tdG;

    var iGWidths = 0;

    var startInd=0;

     

    // 1. find the index of the current active gallery id

    for (j=0; j<arGalleryWidths[0].length; j++) {

        if (arGalleryWidths[j][0] == actGalleryID) {

            startInd = j;

            break;

        }

    }

     //2. find new active gal id       

    for (j=startInd; j<arGalleryWidths[0].length; j++) {

        iGWidths += arGalleryWidths[j][1];

        if (iGWidths+5 > swidth) {

            newAGID = arGalleryWidths[j][0]; 

            break;

         }

   }

    

    if (newAGID) actGalleryID = newAGID;

    //3. scroll to the new 'active' gallery id

    ScrollToActiveGallery(newAGID);

}



function ScrollToActiveItem(item){

    SetItemsNamesWidth(item);

    sum = 0;

    var bStartFindAppActive = false;

    for (var j=arGalleryWidths.length-1;j>=0;j--) {

        sum += arGalleryWidths[j][1];

        if ( arGalleryWidths[j][0] == item ) 

            if ( sum > swidth ) 

                break;

            else {

                bStartFindAppActive = true;

                actGalleryID = arGalleryWidths[0][0];

               }

        

        if (bStartFindAppActive) 

            if( sum > swidth) { 

                actGalleryID = arGalleryWidths[j][0];

                break;

            }

    }

    ScrollToActiveGallery (actGalleryID);

}



function SetItemsNamesWidth(item) {

    var iObj, iObjNode, j=0;

    if (item) {

        iObj = document.getElementById(item);

        if (iObj) {

            for (i=0; i<iObj.parentNode.childNodes.length; i++)  {

                iObjNode = iObj.parentNode.childNodes[i];

                if ( iObjNode.nodeType==1 ) {

                    arGalleryWidths[j] = new Array(iObj.parentNode.childNodes.length);

                    arGalleryWidths[j][0] = iObjNode.getAttribute('id');

                    arGalleryWidths[j][1] = iObjNode.offsetWidth;

                    j++;

                }

            }

        }

    }

}



function ScrollToActiveGallery (agid) {

    var bIsLeftNodeRemoved = false;

    var bIsActFound = false;

    var widthSumAboveActiveGallery = 0;

    var p = 0;

    

    if (agid) { 

        var myG = document.getElementById(agid);

        

        if (myG) {

            var j=0;

            var ncount = myG.parentNode.childNodes.length;

            

            for (i=0; i<myG.parentNode.childNodes.length; i++)  {

                var myGNode = myG.parentNode.childNodes[i];

                

                //// fill the array arGalleryWidths[][] which contains the width of each gallery name

                if (myGNode == myG) {

                    bIsActFound = true;

                    widthSumAboveActiveGallery += arGalleryWidths[p][1];

                    p++;

                }

                else  {

                    if ( myGNode.nodeType == 1 ){   // 1 - Element nodes

                        if (!bIsActFound) {

                            myG.parentNode.removeChild(myGNode);

                            bIsLeftNodeRemoved = true;

                            i--;    // increase counter i only if the current node is not removed, else  after remove the current node 

                                    // its index in the nodes array is occupied by the next node

                                    // this is used for assure that if  myG node is not found the cycle will stop

                        }

                        else {

                            // start calculating the sum of widths after the active gallery is found

                            widthSumAboveActiveGallery += arGalleryWidths[p][1];

                        } 

                        p++;   //counter for the items in arGalleryWidths array

                    }

                }

            }

        }

        

    }



     // hide the Previous 'More galleries' link/arrow because currently shown is the first one

    if (bIsLeftNodeRemoved ) 

     //   document.getElementById ('prevGs').style.display = "";

        document.getElementById ('prevGs').style.visibility = "visible";

     else

     //   document.getElementById ('prevGs').style.display = "none";

        document.getElementById ('prevGs').style.visibility = "hidden";

     // hide the Next 'More galleries' link/arrow because currently shown is the first one

     // if widthSumAboveActiveGallery > swidth means that if from the active gallery to the end there is more width than the visible (swidth) then we show Right arrow

     if (widthSumAboveActiveGallery > swidth ) 

       // document.getElementById ('nextGs').style.display = "";

        document.getElementById ('nextGs').style.visibility = "visible";

     else

      // document.getElementById ('nextGs').style.display = "none";

       document.getElementById ('nextGs').style.visibility = "hidden";

}





function StartGalleryScroll(){

    if(document.getElementById){

        ns6div=document.getElementById('iens6div');

        GalleriesContent = ns6div.innerHTML;    // set an instant copy of the whole gallery list

        ns6div.style.left=0;    //ns6div.style.left=swidth;

        sizeup=ns6div.offsetWidth;

        ns6scroll();

    }

    else 

        if(document.layers){

            ns4layer=document.ns4div.document.ns4div1;

            GalleriesContent = ns4layer.innerHTML;    // set an instant copy of the whole gallery list

            ns4layer.left=0;    //ns4layer.left=swidth;

            ns4layer.document.close();

            sizeup=ns4layer.document.width;

            ns4scroll();

          }

        else 

            if(document.all){

                iediv=iens6div;

                GalleriesContent = iediv.innerHTML;    // set an instant copy of the whole gallery list

                iediv.style.pixelLeft=0;    //iediv.style.pixelLeft=swidth;

                sizeup=iediv.offsetWidth;

                iescroll();

              }

      

      SelectActiveG();

      if(document.getElementById)

        GalleriesContent = ns6div.innerHTML;    

      else 

        if(document.layers)

            GalleriesContent = ns4layer.innerHTML;    

       else 

            if(document.all)

               GalleriesContent = iediv.innerHTML; 

      ScrollToActiveItem(actGalleryID);

      

    }

function iescroll(){

    if(iediv.style.pixelLeft>0&&iediv.style.pixelLeft<=sspeed){

        iediv.style.pixelLeft=0;

        setTimeout("iescroll()",spause);

        }

    else { 

        sizeup=iediv.offsetWidth;

        if(iediv.style.pixelLeft >= swidth-sizeup){

            iediv.style.pixelLeft-=sspeed;

            setTimeout("iescroll()",iScrollInterval);

            }

        else{

            sspeed=0;

            setTimeout('iescroll()',0);

           }

     }

 }

function ns4scroll(){

    if(ns4layer.left>0&&ns4layer.left<=sspeed){

        ns4layer.left=0;

        setTimeout("ns4scroll()",spause);

    }

    else {

        sizeup=ns4layer.document.width;

        if(ns4layer.left >= swidth-sizeup){

            ns4layer.left -= sspeed;

            setTimeout("ns4scroll()",iScrollInterval);

            }

        else{

            sspeed=0;

            setTimeout('ns4scroll()',0);

            }

     }

 }



function ns6scroll(){

    

    if(parseInt(ns6div.style.left)>0&&parseInt(ns6div.style.left)<=sspeed){

        ns6div.style.left=0;

        setTimeout("ns6scroll()",spause);

       }

    else { 

        sizeup=ns6div.offsetWidth;

        if(parseInt(ns6div.style.left)>= swidth-sizeup){    

             ns6div.style.left=parseInt(ns6div.style.left)-sspeed;

             setTimeout("ns6scroll()",iScrollInterval);

             }

         else{

            

              sspeed=0;

              setTimeout('ns6scroll()',0);

             }

      }

  }

   

function StartScroll(){

    ClearHS();

 //   clearInterval(loopReturn);

    delay = setTimeout('sspeed=restart;',1000); 

    

 }

 

 function ReturnAtBeginning() {

    sspeed=0;

    if (ns6div) if (ns6div.style)     ns6div.style.left = 0;

    //loopReturn = setInterval("ret()",0);

 }

 function ret() {

    if (parseInt(ns6div.style.left)<0)

        ns6div.style.left = parseInt(ns6div.style.left)+2;

    else    {

        ns6div.style.left = 0;

        clearInterval(loopReturn);

    }

    

 }

 



function ClearHS() {

	if (toid!=0) {

		clearTimeout(toid);

		toid = 0;

	}

}



function QuitHS() {

	if (toid!=0)

	    ClearHS();

	    

	clearTimeout(delay);

	toid = setTimeout('ReturnAtBeginning()',0); 

    

}



// Change the background color to the active Gallery / or other item (asset)

function SelectActiveG() {

    var sI, eI, cont;

    var old = document.getElementById(actGalleryID);

    if (old)

        for (a=0; a<old.childNodes.length; a++) 

            if (old.childNodes[a].tagName == 'A' )

                old.childNodes[a].className = 'Buttons1m';



    

 }

//-- end Algorithm -->