﻿var lastOpenedPane = null;
var lastAnimatedIndex = null;
var collapsedPositions = [0, 56, 112, 168, 224, 280, 336, 392];
var collaspedSize = 56;
var paneOpenTimer = null;
var currentOpeningIndex = 0;
$(document).ready(function () {
    openPane(currentOpeningIndex);
    // Tabs                       

    $("div.pane").mouseenter(function () {
        if ($(lastOpenedPane).attr("id") != $(this).attr("id")) {
            var lastOpenedIndex = parseInt($(lastOpenedPane).attr("id").replace("divPane", ""));
            openPane(parseInt($(this).attr("id").replace("divPane", "")) - 1);
        }
    });

    $("#divPane1").click(function () { document.location.href = "/kat/9/inci-yapi.aspx"; });
    $("#divPane2").click(function () { document.location.href = "/kat/6/hazir-beton.aspx"; });
    $("#divPane3").click(function () { document.location.href = "/kat/7/tas-ocaklari.aspx"; });
    $("#divPane4").click(function () { document.location.href = "/kat/8/beton-yapi-elemanlari.aspx"; });
    $("#divPane5").click(function () { document.location.href = "/kat/10/inci-petrol.aspx"; });
    $("#divPane6").click(function () { document.location.href = "/kat/15/inci-makine.aspx"; });
    $("#divPane7").click(function () { document.location.href = "/kat/11/inci-sigorta.aspx"; });
    $("#divPane8").click(function () { document.location.href = "/kat/12/dis-ticaret.aspx"; });
});


function openPane(paneindex) {

    currentOpeningIndex = paneindex;
    if (paneOpenTimer)
        window.clearTimeout(paneOpenTimer);

    paneOpenTimer = window.setTimeout("openPane(" + ((++paneindex) % 8) + ");", 5000);

    $("div.pane:animated").stop();
    var firstOpenTab = $("div.pane:eq(" + currentOpeningIndex + ")");
    lastOpenedPane = firstOpenTab;
    var lastOpenedIndex = parseInt($(lastOpenedPane).attr("id").replace("divPane", ""));

    //specialEasing: { width: 'linear' },
    $(firstOpenTab).animate(
                           { width: '516px', left: collapsedPositions[currentOpeningIndex] + 'px' },
                           { duration: 1500,
                               complete: function () { }
                           });

    $("div.pane").each(function () {
        var divIndex = parseInt($(this).attr("id").replace("divPane", "")) - 1;
        if (divIndex < currentOpeningIndex) {
            $(this).animate(
                            { width: collaspedSize + 'px', left: collapsedPositions[divIndex] + 'px' },

                            { duration: 1500,
                                complete: function () {
                                    $(this).find("div.collapsedPane").show();
                                    $(this).find("div.expandedPane").hide();
                                }
                            });
        }
        else if (divIndex > currentOpeningIndex) {
            $(this).animate({ width: collaspedSize + 'px', left: (451 + collapsedPositions[divIndex]) + 'px' },
                            {
                                duration: 1500,
                                complete: function () {
                                    $(this).find("div.collapsedPane").show();
                                    $(this).find("div.expandedPane").hide();
                                }
                            });
        }
    });
}
