/* author: Rob Crowther - 23/08/09 */

function togglePanels(element, panelNum, panel, numOfSections){
    var toggleStatus = getToggleStatus(element, panel);
    switchArrow(panel);
    $(element).removeClass(panel + "rightArrowButton");
    $(element).addClass(panel + "downArrowButton");
    for (var i = 1; i <= numOfSections; i++) {
        if (i == panelNum) {
            if (toggleStatus == "down") {
                switchArrow(panel);
                $("#" + panel + "Contents" + i).slideUp('fast');
            }
            else {
                $("#" + panel + "Contents" + i).slideDown('slow');
            }
        }
        else {
            $("#" + panel + "Contents" + i).slideUp('fast');
        }
    }
}

function togglePagePanels(element, panelNum, panel, numOfSections){
    var toggleStatus = getToggleStatus(element, panel);
    switchArrow(panel);
    $(element).removeClass(panel + "rightArrowButton");
    $(element).addClass(panel + "downArrowButton");
    for (var i = 1; i <= numOfSections; i++) {
        if (i == panelNum) {
            if (toggleStatus == "down") {
                switchArrow(panel);
                $("#" + panel + "Contents" + i).slideUp('fast');
            }
            else {
                if (panelNum === "2") {
                    $("#" + panel + "Contents" + i).slideDown('slow', function() {
                        $("#userSearches").show();
                        $(".myLliButtons").show();
                        $(".personalHeader").show();
                        $(".personalText").show();
                    });
                } else {
                    $("#" + panel + "Contents" + i).slideDown('slow');
                }
            }
        }
        else {
            $("#" + panel + "Contents" + i).slideUp('fast');
        }
    }
}

function getToggleStatus(element, panel){
    var toggleStatus; // get the initial 'up'/'down status of the panel - user can re-close panel if wanted
    if ($(element).attr("class") == panel + "rightArrowButton") {
        toggleStatus = "up";
    } else {
        toggleStatus = "down";
    }
    return toggleStatus;
}

function switchArrow(panel){
    $("." + panel + "downArrowButton").removeClass(panel + "downArrowButton").addClass(panel + "rightArrowButton");
}

function initTankersNav(){
    $("#cO1").mousedown(function(){
        togglePanels(this, "1", "cO", "2");
    });
    $("#cO2").mousedown(function(){
        togglePanels(this, "2", "cO", "2");
    });
}

var gasComboBehaviour = function(){

    $("#cO1").mousedown(function(){
        togglePanels(this, "1", "cO", "4");
    });
    $("#cO2").mousedown(function(){
        togglePanels(this, "2", "cO", "4");
    });
    $("#cO3").mousedown(function(){
        togglePanels(this, "3", "cO", "4");
    });
    $("#cO4").mousedown(function(){
        togglePanels(this, "4", "cO", "4");
    });

};

