﻿/*  - - - - - - - - - - - - - - - - - - - - - - - -
- - 
- -     TABS FUNCTIONS
- - 
- - - - - - - - - - - - - - - - - - - - - - - - - -*/


var selectedTab = "";

// - - - ACTIONS - - - - -

function mouseActionsForTabs(domElement) {
    var isiPad = navigator.userAgent.match(/iPad/i) != null;
    if (!isiPad) {
        //mouseover
        $(domElement).mouseover(function() {
            if (selectedTab != $(this).attr("id")) {
                $(this).css("top", "42px");
                $(this).css("background-position", "-142px 0px");
            }
        });
        //mouseout
        $(domElement).mouseout(function() {
            if (selectedTab != $(this).attr("id")) {
                $(this).css("top", "40px");
                $(this).css("background-position", "0px 0px");
            }
        });
    }
    //mousedown
    $(domElement).mousedown(function() {
        if (selectedTab != $(this).attr("id")) {
            $(this).css ("background-position", "-284px 0px");
            $(this).css("top", "44px");
        }
    });

    //click
    $(domElement).click(function() {
        /*
        original:
        if (selectedTab != $(this).attr("id")) {
        selectTab($(this).attr("id"));
        }*/
        window.location = "/#/" + $(this).find(':first-child').attr("id").replace("slash","/") + "/";
    });
    
    
    
}

function selectTab(newSelectedTab) {
    if (newSelectedTab != selectedTab) {
        //Vorige deselecteren
        if (selectedTab != "") {
            hideAllTabs();
            $("#" + selectedTab).css("top", "40px");
            $("#" + selectedTab).css("background-position", "0px 0px");
        }
        //nieuwe instellen
        selectedTab = newSelectedTab;
        $("#" + selectedTab).css("background-position", "-284px 0px");
        $("#" + selectedTab).css("top", "44px");
        var fragmentNumber = selectedTab.replace("tabs" + selectedNumber + "_tab", "").replace("_" + selectedType, ""); 
        $("#tabs" + selectedNumber + "_fragment"+fragmentNumber+"_" + selectedType).show();

        //tube verbinden met de inhoud (eerst al de rest gewoon zetten)
        var selectedTabNR = selectedTab.split("_tab")[1].replace("_"+selectedType, "");
        $(".tube_connection").css("background-position", "0px 0px");
        $(".tube_connection" + selectedTabNR).css("background-position", "-20px 0px");
        $(".brown_connection").css("height", "60px");
        $("#brown_connection" + selectedTabNR).css("height", "80px");
        $("#tube_connection").attr("class", "");
        $("#tube_connection").addClass("tube_connection" + selectedTabNR);
    }
}

//Alle tabs hidden maken
function hideAllTabs() {
    $(".tab_content").hide();
}

//Earth close bar
function showEarthCloseBar() {
    
    $("#button_arrowtop_sprite").show();
    $("#button_arrowtop_sprite").css("background-position", "0px 0px");
    var countBGpos = 0;
    var bgPos = ["-130px 0px", "-260px 0px", "-390px 0px", "-520px 0px", "-650px 0px", "-780px 0px", "-650px 0px", "-520px 0px", "-650px 0px", "-780px 0px", "-650px 0px"];
    var showEarthInterval = setInterval(function() {
        countBGpos++;
        if (countBGpos >= 12) {
            $("#button_arrowtop_sprite").hide();
            $("#button_arrowtop_container").show();
            clearInterval(showEarthInterval);
        }
        $("#button_arrowtop_sprite").css("background-position", bgPos[countBGpos]);
    }, 100);
}

function hideEarthCloseBar() {
    $("#button_arrowtop_container").hide();
}


function numberOfTabsCheck(selectedNumber, type) {
    for (var x = 2; x <= 5; x++) {
        if ($("#tabs" + selectedNumber + "_tab" + x + "_" + type).length != 0) {
            $("#tube_connection" + x).attr("class", "tube_connection tube_connection" + x);
            $("#brown_connection" + x).attr("class", "brown_connection tube_connection" + x);
        } else {
            //ALS TAB X NIET INGEVULD IS
            $("#tube_connection" + x).attr("class", "tube_connection_flat tube_connection" + x);
            $("#brown_connection" + x).attr("class", "tube_connection" + x);
        }
    }

    
}

/*
    var countNewMessages = -10;
    var fbNewMsgs = ["0px 0px","-26px 0px","-52px 0px","-78px 0px","-104px 0px","-156px 0px","-104px 0px","-78px 0px","-104px 0px"];
    var refreshIntervalId = setInterval(function() {
        countNewMessages++;
        if(countNewMessages >= 10){
            clearInterval(refreshIntervalId);
        }
        $(".new_messages").css("background-position", fbNewMsgs[countNewMessages]);
    }, 100);
            */
