src = ["img/ext1thumb.jpg", "img/ext2thumb.jpg", "img/ext3thumb.jpg", "img/ext4thumb.jpg", "img/ext5thumb.jpg"]
duration = 3;

ads=[]; ct=0;

function switchAd()
{
    var n=(ct+1)%src.length;
    if (ads[n] && (ads[n].complete || ads[n].complete==null))
    {
        document["slideShow"].src = ads[ct=n].src;
    }
    ads[n=(ct+1)%src.length] = new Image;
    ads[n].src = src[n];

    setTimeout("switchAd()",duration*1000);
}
var height=35;
var Top=95;

function initUnitPositions()
{
    document.getElementById("unit1").style.top=Top;         
    document.getElementById("unit2").style.top=Top+height*1;
    document.getElementById("unit3").style.top=Top+height*2;
    document.getElementById("unit4").style.top=Top+height*3;
    document.getElementById("unit5").style.top=Top+height*4;
    document.getElementById("unit6").style.top=Top+height*5;
    document.getElementById("unit7").style.top=Top+height*6;
    document.getElementById("unit8").style.top=Top+height*7;
    document.getElementById("unit9").style.top=Top+height*8;
    document.getElementById("unit10").style.top=Top+height*9;
}
var i=0;
maxUnitId=10;
shifted=[0,0,0,0,0,0,0,0,0,0];
var collapseAll=0;

function shift(unitId)
{
    if(shifted[unitId-1]==1 && shifted[unitId-2]==0)
    {
        collapseAll=1;
        window.status=collapseAll;
    }
    else{
    
        collapseAll=0;
        window.status=0;
    }
    if(collapseAll)
    {
        
        if(shifted[1]==1)
            document.getElementById("unit2").style.top=Top+height*1+165-33*i+'px';
        if(shifted[2]==1)
            document.getElementById("unit3").style.top=Top+height*2+165-33*i+'px';
        if(shifted[3]==1)
            document.getElementById("unit4").style.top=Top+height*3+165-33*i+'px';
        if(shifted[4]==1)
            document.getElementById("unit5").style.top=Top+height*4+165-33*i+'px';
        if(shifted[5]==1)
            document.getElementById("unit6").style.top=Top+height*5+165-33*i+'px';
        if(shifted[6]==1)
            document.getElementById("unit7").style.top=Top+height*6+165-33*i+'px';
        if(shifted[7]==1)
            document.getElementById("unit8").style.top=Top+height*7+165-33*i+'px';
        if(shifted[8]==1)
            document.getElementById("unit9").style.top=Top+height*8+165-33*i+'px';
        if(shifted[9]==1)
            document.getElementById("unit10").style.top=Top+height*9+165-33*i+'px';
    
    }else{
    
        if(unitId<=2){
            if(shifted[1]==0)
                document.getElementById("unit2").style.top=Top+height*1+33*i+'px';
        }
        if(unitId<=3 || (shifted[1]==1 && unitId>=3)){
            if(shifted[2]==0)
                document.getElementById("unit3").style.top=Top+height*2+33*i+'px';
            if(shifted[1]==1 && unitId>=3)
                document.getElementById("unit2").style.top=Top+height*1+165-33*i+'px';
        }
        if(unitId<=4 || (shifted[2]==1 && unitId>=4)){
            if(shifted[3]==0)
                document.getElementById("unit4").style.top=Top+height*3+33*i+'px';
            if(shifted[2]==1 && unitId>=4)
                document.getElementById("unit3").style.top=Top+height*2+165-33*i+'px';
        }
        if(unitId<=5 || (shifted[3]==1 && unitId>=5)){
            if(shifted[4]==0)
                document.getElementById("unit5").style.top=Top+height*4+33*i+'px';
            if(shifted[3]==1 && unitId>=5)
                document.getElementById("unit4").style.top=Top+height*3+165-33*i+'px';
        }
        if(unitId<=6 || (shifted[4]==1 && unitId>=6)){
            if(shifted[5]==0)
                document.getElementById("unit6").style.top=Top+height*5+33*i+'px';
            if(shifted[4]==1 && unitId>=6)
                document.getElementById("unit5").style.top=Top+height*4+165-33*i+'px';
        }
        if(unitId<=7 || (shifted[5]==1 && unitId>=7)){
            if(shifted[6]==0)
                document.getElementById("unit7").style.top=Top+height*6+33*i+'px';
            if(shifted[5]==1 && unitId>=7){
                document.getElementById("unit6").style.top=Top+height*5+165-33*i+'px';
            }
        }
        if(unitId<=8 || (shifted[6]==1 && unitId>=8)){
            if(shifted[7]==0)
                document.getElementById("unit8").style.top=Top+height*7+33*i+'px';
            if(shifted[6]==1 && unitId>=8)
                document.getElementById("unit7").style.top=Top+height*6+165-33*i+'px';
        }
        if(unitId<=9 || (shifted[7]==1 && unitId>=9)){
            if(shifted[8]==0)
                document.getElementById("unit9").style.top=Top+height*8+33*i+'px';
            if(shifted[7]==1 && unitId>=9)
                document.getElementById("unit8").style.top=Top+height*7+165-33*i+'px';
        }
        if(unitId<=10 || (shifted[8]==1 && unitId>=10)){
            if(shifted[9]==0)
                document.getElementById("unit10").style.top=Top+height*9+33*i+'px';
            if(shifted[8]==1 && unitId>=10)
                document.getElementById("unit9").style.top=Top+height*8+165-33*i+'px';
        }
        if(unitId<=11){
            if(shifted[9]==1 && unitId>=11)
                document.getElementById("unit10").style.top=Top+height*9+165-33*i+'px';
        }

    
    }
          

    
  
    if(collapseAll==1 && i>4){
        collapseAll=0;
        clearTimeout(t);
        i=0;
        shifted=[0,0,0,0,0,0,0,0,0,0];
        return;
    }
    else if(i>4 && collapseAll==0){
        clearTimeout(t);
        i=0;
        // update shifted tracker
        switch(unitId)
        {
            case "2":
                shifted=[0,1,1,1,1,1,1,1,1,1];
                break;
            case "3":
                shifted=[0,0,1,1,1,1,1,1,1,1];
                break;
            case "4":
                shifted=[0,0,0,1,1,1,1,1,1,1];
                break;
            case "5":
                shifted=[0,0,0,0,1,1,1,1,1,1];
                break;
            case "6":
                shifted=[0,0,0,0,0,1,1,1,1,1];
                break;
            case "7":
                shifted=[0,0,0,0,0,0,1,1,1,1];
                break;
            case "8":
                shifted=[0,0,0,0,0,0,0,1,1,1];
                break;
            case "9":
                shifted=[0,0,0,0,0,0,0,0,1,1];
                break;
            case "10":
                shifted=[0,0,0,0,0,0,0,0,0,1];
                break;
            case "11":
                shifted=[0,0,0,0,0,0,0,0,0,0];
                break;
            default:
                alert("ERROR");
        }
      
        return;
    }
    i++;
  
    codeSnippet = "shift(\""+unitId+"\")";
    t=setTimeout(codeSnippet,30);
}



onload = function()
{
    initUnitPositions();
    //if (document.images)
        //switchAd();
}

function imgSwap(oImg)
{
   var strOver  = "_on"
   var strOff = "_off"
   var strImg = oImg.src
   if (strImg.indexOf(strOver) != -1) 
      oImg.src = strImg.replace(strOver,strOff)
   else
      oImg.src = strImg.replace(strOff,strOver)
}


