﻿//Get Boss Client
function GetClient() {
    document.downloadForm.submit();
}

//leftNavLinks (BEGIN)
$(document).ready(function() {
    var leftNavLinks = $('#leftNavLinks');
    //Set the behaviour for when user clicks on a category name 
    //If clicks in a link in a category nothing else to do normal link behaviour
    leftNavLinks.find('h5 a').each(function() {
        $(this).click(function() {
            //If category has been selected and click again or has no children no need to show subcategory, only navigate
            if ($(this).parent().parent().hasClass('selected') ||
            $(this).parent().parent().find('div').size() == 0) {
                //    this.url.indexOf('/poker/') == this.url.length + 7) {
                return true;
            }
            else {
                //hiding all rest of selections
                leftNavLinks.find('div').removeClass('selected');
                leftNavLinks.find('div>div').hide();
                //show the section user clicked on
                $(this).parent().parent().addClass('selected');
                $(this).parent().parent().find('div').slideDown('slow');
                return false;
            }
        });
    });
    //Remove all the <br /> generated by the VgmWebContentIndexControl
    leftNavLinks.find('br').remove();
    HighlightSelected(leftNavLinks, '/poker/allgames.aspx');
});

///Execute on page load to pre-select the category depending on page browser is displaying
function HighlightSelected(leftNavLinks, defaultUrl) {
    //If on default page show 'Poker Games' section
    var pathname = window.location.pathname.toLowerCase();
    if (pathname.indexOf('/poker/') == pathname.length - 7 ||
        pathname.indexOf('/poker/default.aspx') >= 0) {
        leftNavLinks.find('a[href="/poker/allgames.aspx"]').parent().parent().addClass('selected').find('div').show();
    }
    else {
        //Search for first Url that matches the actual url on the window (it can be in 'div>h5>a' or 'div>div>a')
        //No 2 links must be the same in different sections or problems (if same add a # character to differenciate them)
        leftNavLinks.find('a:not([href$=/poker/])').each(function(num, domElem) {
            if (window.location.href.toLowerCase().indexOf(this.href.toLowerCase()) >= 0) {
                $(this).parent().parent().addClass('selected').find('div').show();
                return false;
            }
        });
    }
}

// leftNavLinks (END) 