////////////

var curX;
var rightX;
var leftX;
var CSInit; 
var animLoopIsRunning, CSTimeoutID;
var stepDistA
var stepDistB

CSTimeoutID = null;
animLoopIsRunning = false;

curX = 73; //--starting point
stepDistA = 1; // should be factor of 1628 (2x2x11x37); BIGGER GOES FASTER
stepDistB = 3;


CSAgent = window.navigator.userAgent; 
CSBVers = parseInt(CSAgent.charAt(CSAgent.indexOf("/")+1),10);

CSInit = new Array;

rightX = 73;
leftX = -209;

function killAnim() {
         clearTimeout (CSTimeoutID);
         animLoopIsRunning = false;
         CSTimeoutID = null;
}

function startAnimA( dir ) {
        if (animLoopIsRunning) {
                killAnim() ;
        }
        if (dir == 1) {  // move right
                if (curX < rightX) {
                        stepAnimA( dir );
                }
        } else { // move left
                if (curX > leftX) {
                        stepAnimA( dir );
                }
        }
        animLoopIsRunning = true;
        CSTimeoutID = setTimeout("runAnimA(" + dir+ ")", 1); 
         //-- ready for next loop
}

function startAnimB( dir ) {
        if (animLoopIsRunning) {
                killAnim() ;
        }
        if (dir == 1) {  // move right
                if (curX < rightX) {
                        stepAnimB( dir );
                }
        } else { // move left
                if (curX > leftX) {
                        stepAnimB( dir );
                }
        }
        animLoopIsRunning = true;
        CSTimeoutID = setTimeout("runAnimB(" + dir+ ")", 1); 
         //-- ready for next loop
}
function runAnimA( dir ) {
        if (animLoopIsRunning) {
                if (dir == 1) {  // move right
                        if (curX < rightX) {
                                stepAnimA( dir );
                        }
                } else { // move left
                        if (curX > leftX) {
                                stepAnimA( dir );
                        }
                }
        }
        if (animLoopIsRunning) CSTimeoutID = setTimeout("runAnimA(" + dir+ ")", 1); 
}
function runAnimB( dir ) {
        if (animLoopIsRunning) {
                if (dir == 1) {  // move right
                        if (curX < rightX) {
                                stepAnimB( dir );
                        }
                } else { // move left
                        if (curX > leftX) {
                                stepAnimB( dir );
                        }
                }
        }
        if (animLoopIsRunning) CSTimeoutID = setTimeout("runAnimB(" + dir+ ")", 1); 
}


function stepAnimA( dir ) {
        //-- dir is 1 or -1; -1 means things move left (right-hand btn)
        
        curX = curX + (dir * stepDistA) ;  //-- get new x coordinate
        styleName ='menu' ;  
        CSSetStylePosX( styleName, curX ) ;  //-- set DIV x position
        
        // alert("curX=" + curX);
}
function stepAnimB( dir ) {
        //-- dir is 1 or -1; -1 means things move left (right-hand btn)
        
        curX = curX + (dir * stepDistB) ;  //-- get new x coordinate
        styleName ='menu' ;  
        CSSetStylePosX( styleName, curX ) ;  //-- set DIV x position
        
        // alert("curX=" + curX);
}


function CSSetStylePosX( s, newX ) { 
        if (IsIE()) { 
                CSIEStyl(s).posLeft = newX; 
        } else { 
                CSNSStyl(s).left = newX;
        }
}

function CSGetStylePosX( s ) { 
        if (IsIE()) { 
                return CSIEStyl(s).posLeft;
        } else { 
                return CSNSStyl(s).left;
        }
}

//-------------- IMAGES ------------------

function CSScriptInit() {
	idxArray = new Array;
	for(var i=0;i<CSInit.length;i++)
		idxArray[i] = i;
	CSAction2(CSInit, idxArray);
}

function IsIE() { 
        return CSAgent.indexOf("MSIE") > 0;
}

function CSIEStyl(s) { 
        return document.all.tags("div")[s].style; 
}

function CSNSStyl(s) { 
        return CSFindElement(s,0); 
}

function CSAction2(fct, array) { 
        var result;
        for (var i=0;i<array.length;i++) {
                if(CSStopExecution) return false; 
                var actArray = fct[array[i]];
                var tempArray = new Array;
                for(var j=1;j<actArray.length;j++) {
                        if((actArray[j] != null) && (typeof(actArray[j]) == "object") && (actArray[j].length == 2)) {
                                if(actArray[j][0] == "VAR") {
                                        tempArray[j] = CSStateArray[actArray[j][1]];
                                }
                                else {
                                        if(actArray[j][0] == "ACT") {
                                                tempArray[j] = CSAction(new Array(new String(actArray[j][1])));
                                        }
                                else
                                        tempArray[j] = actArray[j];
                                }
                        }
                        else
                                tempArray[j] = actArray[j];
                }                       
                result = actArray[0](tempArray);
        }
        return result;
}


function CSFindElement(n,ly) { if (CSBVers < 4) return document[n];
        var curDoc = ly ? ly.document : document; var elem = curDoc[n];
        if (!elem) { for (var i=0;i<curDoc.layers.length;i++) {
                elem = CSFindElement(n,curDoc.layers[i]); if (elem) return elem; }}
        return elem;
}

CSIm = new Object();

function CSIShow(n,i) {
        if (document.images) {
                if (CSIm[n]) {
                        var img = (!IsIE()) ? CSFindElement(n,0) : document[n];
                        if (img && typeof(CSIm[n][i].src) != "undefined") {img.src = CSIm[n][i].src;}
                        if(i != 0)
                                self.status = CSIm[n][3];
                        else
                                self.status = " ";
                        return true;
                }
        }
        return false;
}


//------------ OLD ANIMATION HANDLERS --------------

CSStopExecution = false;

////////

