/* =============================================================================
 * panel.js
 * Code for the panel on the main page
 * Relies on jquery
 * Copyright (c) 2010-2011 Queen's Accounting Association
 * Written by Siyuan Tang, Aug 20, 2010
 * ========================================================================== */

var currentPanel = 0;

if(numPanels == null)
    numPanels = 1;
var qaa_triggers = new Array(numPanels);
var qaa_panel_timeout = null;

function panelSwitch(pid) {
    if(currentPanel != pid) {
        //clear the previous timer if it existed
        if(qaa_panel_timeout != null)
            window.clearTimeout(qaa_panel_timeout);
        //fade away the current panel and switch in new one
        qaa_triggers[currentPanel].qaa_panel.fadeOut(500, (function (){
            qaa_triggers[currentPanel].removeClass("activepanel");
            qaa_triggers[pid].addClass("activepanel");
            currentPanel = pid;
            qaa_triggers[pid].qaa_panel.fadeIn(700, qaa_setPanelTimeout);
        }));
    }
}

(function(){
    for(var i = 0;i < numPanels; i++){
        qaa_triggers[i] = $("#panel_"+(i+1)+"_trigger");
        qaa_triggers[i].qaa_panel = $("#panel_"+(i+1));
        qaa_triggers[i].qaa_panel_id = i;
    }
})();

function qaa_setPanelTimeout() {
    var pid = currentPanel + 1;
    if(pid >= numPanels)
        pid = 0;
    qaa_panel_timeout = window.setTimeout(function(){panelSwitch(pid);}, 7000);
}
qaa_setPanelTimeout();

