﻿$(document).ready(function()
{
    $('ul.regions h1').hover(function()
    {
        $('.selected').removeClass('selected');

        var parent = $(this).parent();
        parent.addClass('selected');

        // position the box properly
        var div = parent.children('div');

        var minWidth = 214;
        var padding = 12;
        var width = 0;

        div.children('ul').each(function()
        {
            var thisWidth = $(this).outerWidth();
            width += thisWidth;
        });


        if (width < minWidth)
        {
            width = minWidth;
        }
        else if ($.browser.msie && $.browser.version < 8)
        {
            width += padding * 4;
        }

        div.css('width', width + 'px');

        // if it's too wide, then position right
        if (div.offset().left + width > $('ul.regions').offset().left + $('ul.regions > li:last').outerWidth() * 4)
        {
            div.addClass('right');
        }
    });
});