var delayedObj;
var delayTime = 5000; //in miliseconds

var isRotating = true;
var nextObj

var tabId = new Array();
tabId[0]="tab_corporate";
tabId[1]="tab_sme";
tabId[2]="tab_private";
tabId[3]="tab_mortgage";
tabId[4]="tab_risk";
tabId[5]="tab_worker";

var tabImg = new Array();
tabImg[0]="image/slide1.png";
tabImg[1]="image/slide2.png";
tabImg[2]="image/slide3.png";
tabImg[3]="image/slide4.png";
tabImg[4]="image/slide5.png";
tabImg[5]="image/slide6.png";

var tabDest = new Array();
tabDest[0]="corporate_insurance.cfm";
tabDest[1]="SME_Insurance.cfm";
tabDest[2]="Private_Client_Insurance.cfm";
tabDest[3]="Mortgage_Brokers.cfm";
tabDest[4]="Enterprise_Risk_Manager.cfm";
tabDest[5]="Workers_Compensation.cfm";

function rotateSplash(object){
    
    var bg_img = "";
    var clickDest = "";
    var contentPost = "";
    
    resetSplash(document.getElementById("tab_corporate"));
    resetSplash(document.getElementById("tab_sme"));
    resetSplash(document.getElementById("tab_private"));
    resetSplash(document.getElementById("tab_mortgage"));
    resetSplash(document.getElementById("tab_risk"));
    resetSplash(document.getElementById("tab_worker"));
    
    switch(object.id){//position of background image depends on section
        case tabId[0]: tabIndex = 0;  contentPost="right"; break;
        case tabId[1]: tabIndex = 1; contentPost="right"; break;
        case tabId[2]: tabIndex = 2; contentPost="right"; break;
        case tabId[3]: tabIndex = 3; contentPost="left"; break;
        case tabId[4]: tabIndex = 4; contentPost="right"; break;
        case tabId[5]: tabIndex = 5; contentPost="left"; break;
    }
    
    bg_img = tabImg[tabIndex]; clickDest = tabDest[tabIndex];
    
    var x = document.getElementById("bottomTabsDiv");
    x.style.backgroundImage = "url(" + bg_img + ")";
    x.onclick = function(){window.location=clickDest;};
    
    object.style.background  = "none";
    object.className = object.className + " selTab";
    object.onclick = function(){window.location=clickDest;};
    
    x = document.getElementById("bottomTabsContent");
    x.className = contentPost;
    x.innerHTML = document.getElementById(object.id+"_content").innerHTML;
    
    x = document.getElementById("bottomTabsContent2");
    x.className = contentPost;
}

function resetSplash(object)
{
    object.style.background  = "#eeeeee";
    object.className = (object.className).replace(" selTab", "");
}


function startRotate(objNo)
{
    clearTimeout(delayedObj);   // Stop the timeout

    nextObj = objNo;            // Remember the object we are on (passed in parameter)


    if(isRotating)   // If this is true, then the mouse is NOT over the div
    {  
        var x = document.getElementById(tabId[objNo]);  // Get the the object (tab showing)
        
        rotateSplash(x);    // pass the object into the rotator

        nextObj =  nextObj + 1; // increment the count
        if (nextObj > tabId.length-1)
        {
            nextObj = nextObj - tabId.length;   // make sure not to go past the end
        }

    }
    // Start the timer again. Pass in the id of the tab to show. The id won't have changed
    // if it's not rotating
    delayedObj = setTimeout("startRotate("+nextObj+");",delayTime);

}

// Fires On MouseOver or MouseOut. For MouseOver, grab the id of the div in a global variable. For mouseout, it will be empty string
function setRotation(v)
{
    isRotating = v;
}
