﻿var timeout = 500;
var closetimer = null;
var ddmenuitem = 0;

function selectTab(tabName) {
    if (tabName != '') {
        $('.panel').hide();
        $(tabName).show();

    }
}

$(document).ready(function() {
    if (document.location.hash) {
        selectTab(document.location.hash);
        document.aspnetForm.action = document.location.hash;
        $("#tabs li a img").each(function(i) {
            $(this).attr("style", "cursor:pointer");
            if (document.location.hash != '#laatste') {
                if (i == Right(document.location.hash, 1) - 1) {
                    $(this).attr("style", "cursor:default");
                }
            }
        });

    }
    else {
        selectTab("#page1");
    }

    $('#tabs > li').each(function(i) {
        var tab = this;
        tab.zichtbaarmaken = false;
        tab.timer = null;
    });

    $('#tabs li a').click(function() {
        selectTab(this.hash);
    });

    $('#tabs > li').bind('mouseenter', function() {
        var tab = this;
        tab.zichtbaarmaken = true;
        if (tab.timer) {
            window.clearTimeout(tab.timer);
            tab.timer = null;
        }
        $('#tabs > li').each(
                function(i) {
                    if (this != tab && this.isExpanded == true) {
                        //$(this).find('ul').style.display = 'none';
                        $(this).find('ul').slideUp(0); this.isExpanded = false;
                        
                        window.clearTimeout(tab.timer);
                        this.timer = null;
                    }
                }
            );
        if (!tab.isExpanded) {
            var myElement = this;
            myElement.timer1 = window.setTimeout(
                function() {
                    if (!myElement.isExpanded) {
                        if (myElement.zichtbaarmaken == true) {
                            $(myElement).find('ul').slideDown(300);
                            myElement.isExpanded = true;
                            myElement.timer = null;
                        }
                    }
                },
                10
            );

        }
    });

    $('#tabs > li').bind('mouseleave', function() {
        var myElement = this;
        myElement.zichtbaarmaken = false;
        myElement.timer = window.setTimeout(
                function() {
                    if (myElement.isExpanded) {
                        $(myElement).find('ul').slideUp('Fast');
                        myElement.isExpanded = false;
                        myElement.timer = null;

                    }
                },
                timeout
            );
    });

    $.swapImage(".swapImage");

});

function Left(str, n) {
    if (n <= 0)
        return "";
    else if (n > String(str).length)
        return str;
    else
        return String(str).substring(0, n);
}
function Right(str, n) {
    if (n <= 0)
        return "";
    else if (n > String(str).length)
        return str;
    else {
        var iLen = String(str).length;
        return String(str).substring(iLen, iLen - n);
    }
}
