//
//  Orangekid launcher v1.1
//  15 Jul 2006 
//  http://orangekid.sytes.net
//  You are free to use the code below and modify it,
//  Just let me know if you downloaded it and feedback 
//  any suggestions for improvement
//

//  EDIT ICON LABELS
var launchLabel0 = "Main";
var launchLabel1 = "Pictures";
var launchLabel2 = "Writings";
var launchLabel3 = "Professional";
var launchLabel4 = "About";
var launchLabel5 = "Email me";
var launchLabel6 = "Six";
var launchLabel7 = "Seven";
var launchLabel8 = "Eight";
var launchLabel9 = "Nine";
//
//  Set this attribute to the number of icons you have
//
var launcherSize = 5;
//
//  maxWidth and minWidth:
//  The size of the largest and smallest icon in the navigation panel
//  You are recommended not the exceed 120 for maxWidth and 20 for minWidth
//
var launcherCellMaxWidth = 90;
var launcherCellMinWidth = 40;
//
var currentCell = 0;
//
var launcherCellSizeArray = new Array();
//  stores the interval for setInterval function
var launchId;
var focusLaunch = false;
//
//  These flags tell the launcher when to stop refreshing the animation,
//  otherwise, the script will keep polling the resize function
//
var launcherSignalStop = false;
var launcherStopId;
var _called = false;
var launcherIsActive = false;
//
//  set resizeSpeed to a lower value for accelerating resize speeds.
//  The recommended range is between 1.0 (fastest) ~ 5.0 (slowest)
//  (I found that 2 is actually the optimum value for animating smoothly)
//
var resizeSpeed = 2;
//  refresh rate tells the animation engine how many times the
//  resize funtion is called in steps of milliseconds.
//  Range - [10, 100], depending on your scripts. Lower is faster & more responsive
//
var _refreshRate = 10;
//
//  This number defines how much smaller (exponentially) are 
//  the icons directly next to the currently focused one.
//  If the resulting width/height falls below 'launcherMinWidth' it will
//  use the value of minWidth
//
var scaleDownFactor = 0.75;
//
//  **************************************************************
//  UNLESS YOU WISH TO FURTHER MODIFY THE INNER WORKINGS
//  OF LAUNCHER, NEVER MODIFY ANY OF THE CODE BELOW THIS SECTION.
//  INCORRECT MODIFICATION OF CSS AND JAVASCRIPT FILES MAY
//  RENDER YOUR PAGE UN-VIEWABLE OR UN-WORKABLE
//  **************************************************************
//
initLauncher();
function initLauncher(){
    for(var i = 0 ; i < launcherSize ; i++){
        launcherCellSizeArray.push(launcherCellMinWidth);
    }
    stopLauncherEngine();
    launchId = setInterval( resizeLauncher , _refreshRate );
}
function initLauncherCheck(){
    var lli = document.getElementById("listOfIcons").childNodes;
    var lll = document.getElementById("listOfLabels").childNodes;
    if (lli.length != lll.length){
        stopLauncherEngine();
        alert("INCORRECT CONFIGURATION (init check)\r\nThe number of ICONS and LABELS do not match! Please edit the js file again OR check the 'launcherSize' variable!!!");
    }
}
function getArrayOfSizes(ratio){
    var arrayOfSizes = new Array();
    try{
        var mid = Math.floor(launcherSize/2);
        var sizes = new Array();
        var cul = launcherCellMaxWidth;
        for (var i = 0 ; i < mid ; i++){
            if (cul < launcherCellMinWidth)
                cul = launcherCellMinWidth;
            sizes.push(cul);
            //get next size
            cul *= ratio;
        }
        return sizes;
    }catch(e){
        alert("Problem with getArrayOfSizes() - " + e);
        return null;
    }
}
function resizeLauncher(){
    var lc = document.getElementById("launch"+currentCell).childNodes[0].width;
    var diff = Math.abs(lc - launcherCellMaxWidth);
    //
    //  detect whether launcher is carrying a rollover OR rollout action
    //
    if (launcherIsActive){
        var flag = 1;
    }else{
        var flag = launcherCellMaxWidth - launcherCellMinWidth;
    }
    if (diff == flag)
        launcherSignalStop = true;
    if ( !launcherSignalStop && !_called){
        launcherSignalStop = true;
        _called = true;
        //give some time for the resizing to 'settle down'
        launcherStopId = setTimeout(stopLauncherEngine,2000);
    }
    //
    try{
        for(var i = 0 ; i < launcherSize ; i++){
            var w = document.getElementById("launch"+i).childNodes[0].width;
            var h = document.getElementById("launch"+i).childNodes[0].height;
            //
            document.getElementById("launch"+i).childNodes[0].width += (launcherCellSizeArray[i] - w) / resizeSpeed;
            document.getElementById("launch"+i).childNodes[0].height += (launcherCellSizeArray[i] - h) / resizeSpeed;
        }
    }catch(e){
        stopLauncherEngine();
        alert("INCORRECT CONFIGURATION (resizeLauncher)\r\nThe number of ICONS and LABELS do not match! Please edit the js file again OR check the 'launcherSize' variable!!!");
    }
    
}
function updateLauncher(){ 
    initLauncherCheck();
    stopLauncherEngine();
    try{
        var element;
        var arrSize = getArrayOfSizes(scaleDownFactor);
        var index = currentCell;
        //populate left side
        var start = 0;
        while (index >= 0){       
            if (arrSize[start] == undefined) { 
                var dim=launcherCellMinWidth;
            }else{
                var dim=arrSize[start];
            }
            launcherCellSizeArray[index] = dim;
            index--;
            start++;
        }
        //populate right side
        index = currentCell;
        start = 0;
        while (index < launcherSize){
            if (arrSize[start] == undefined) { 
                var dim=launcherCellMinWidth;
            }else{
                var dim=arrSize[start];
            }
            launcherCellSizeArray[index] = dim;
            index++;
            start++;
        }
        launchId = setInterval( resizeLauncher , 70 );
    }catch(e){
        alert("error");
    }
}
function resetLaunchLabels(){
    for(var i=0; i < launcherSize ; i++){
        document.getElementById("launchLabel"+i).innerHTML = "";
    }
}
//
//  Restore launcher to original state
//
function resetLauncher(){
    launcherIsActive = false;
    resetLaunchLabels();
    for (var i=0 ; i<launcherSize ; i++){
        launcherCellSizeArray[i] = launcherCellMinWidth;
    }
}
function doRollOver(cellId){
    clearTimeout(launcherStopId);
    launcherIsActive = true;
    currentCell = cellId;
    resetLaunchLabels();
    document.getElementById("launchLabel"+cellId).innerHTML = eval("launchLabel"+cellId);
    updateLauncher();
}
function doGotoURL(url){
	eval(window.location.href=url)
}
function stopLauncherEngine(){
    //reset values
    launcherSignalStop = false;
    _called = false;
    //
    clearInterval(launchId);
}
//
//  Short & Simple. The key lies in correctly defining the DOM in the CSS file
//