jQuery(function($){
//
//
// Status bar
if($('table.statusbar td:contains("Logout")').length) $('table.statusbar td:first strong').wrapInner('<a href="/User/Logout.aspx"></a>');
$('table.statusbar td').first().css('text-align', 'center')
$('table.statusbar td:gt(0)').css('display', 'none');
$('table.statusbar strong, table.statusbar b').css({'position': 'relative', 'top': '-2px'});
//
//
// Menu
$('table#m > tbody > tr > td:odd').css('display', 'none');
//$('td.t_horizontal > div.t').css('margin-top', '-7px');
$('table#m > tbody > tr').prepend('<t' + 'd style="padding:0;font-size:0;width:10px;background:url(/Images/Content/1083/287706.png) left top no-repeat"></t' + 'd>');
$('table.menubardiv > tbody > tr').append('<t' + 'd align="right" valign="top" id="searchMenuTd" style="padding:0 20px;background:url(/Images/Content/1083/287707.png) right top no-repeat"></t' + 'd>');
$('td#searchMenuTd').append($('#customSearchForm'));
$('td.t_separator_horizontal').closest('tr').css('display', 'none');
$('table.t > tbody > tr:last-child > td').css('border', 'none');
//
// Replace 'and' with '&'
$('td.t_horizontal > div.t,td.t_horizontal > div.tah > table > tbody > tr:first-child > td > div.t').each(function(){
$(this).html($(this).html().replace(/(\s|&nbsp;)and(\s|&nbsp;)/gi, '&nbsp;&amp;&nbsp;'));
});
//
// Adjust top menu width to reflect titles width
$('td.t_horizontal:even').each(
function(i,el){
$(el).find('div.tah > table.t > tbody > tr > td.t > div.t:eq(1)').css(($.browser.msie ? 'width' : 'min-width'), (this.offsetWidth - ($.browser.msie ? 8 : 36)) + 'px');
});
//
// Add shop to resources dropdown menu
//
function insertNewMenuItem(mNum, mPos, mText, link)
{
   /* mNum = (mNum * 2) + 1;  not needed when finding position on string */
    
    var ln = 0;
    while(document.getElementById('bm_' + mNum + '_' + (++ln))){}
    
    if(mPos > ln) mPos = ln;
    
    var newItem = document.getElementById('bm_' + mNum + '_3').cloneNode(true);
     
    if(window.ActiveXObject)
    {
        newItem.id = 'bm_' + mNum + '_' + ln;
        newItem.onmouseover = (function(n){  return function(){mi('m_' + mNum + '_' + n, event)}})(ln);
        newItem.onmouseout = function(){mo(window.event)};
        newItem.onclick = function(){go_abs(link, event)};
    }
    else
    {
        newItem.setAttribute('id','bm_' + mNum + '_' + ln);
        newItem.setAttribute('onmouseover','mi("m_' + mNum + '_' + ln + '", event)');
        newItem.setAttribute('onmouseout','mo(event)');
        newItem.setAttribute('onclick','go_abs("' + link + '", event)');
    }
    newItem.getElementsByTagName('div')[0].innerHTML = mText.replace(/ /g, '&nbsp;');
    
    var ins = document.getElementById('bm_' + mNum + '_1').parentNode;
    
    if(mPos + 1 < ln)
        ins.insertBefore(newItem, document.getElementById('bm_' + mNum + '_' + (mPos+1))); 
    else
        ins.appendChild(newItem);
};

/* find position of 'Resources' in menu and call insertNewMenuItem with this position */
var menuNum = $('td.t_horizontal > div.t:contains(Resource)').parent().attr("id");

/* Disabled - this is a feature for ElimHQ */
/*
if(menuNum)
{
    mNum = menuNum.split('_')[1];
    insertNewMenuItem(mNum, 1, 'Shop', '/shop');
}
*/

//
// Remove top items from drop-downs
var tr,cn,chk;
// Change 1 to 3 to leave home menu alone
for(var n=1; n < 30; n+=2)
{
if((chk = $('#bm_' + n)).length != 0 && chk.find('div:first').text().toLowerCase() == 'my area') continue;
if((tr = $('#bm_' + n + '_1')).length) tr.css('display', 'none');
$('#bm_' + n + '_2 td.t_separator_horizontal:eq(n == 1 ? 1 : 0)').closest('tr').css('display', 'none'); // Not strictly needed
if(chk.find('tr').length < (n == 1 ? 2 : 3)) chk.find('div:eq(1)').remove();
}
//
$('table.menubardiv').css('visibility', 'visible');
//
// Menu fade in
$('td.t_horizontal:even > div.t, tr.t').each(function(i,el){
var m = el.onmouseover;
//el.onmouseover = '';
el.onmouseover = function(ev){
$(el).find('> td > div.tav > table.t').fadeIn(250);
$(el).next('div').find('> table.t').fadeIn(250);
m(ev);
}
});
//
//
// Other CSS adjustments
$('body > table').css('background', '#FFF url(' + (window.backgroundOverride || '/Images/Content/1799/438316.png') + ') left top repeat-x');
$('table.pagebox > tbody > tr > td, table.PageBox > tbody > tr > td').css('vertical-align', 'top');
});

// Forums fix (empty left column)
if(location.pathname.toLowerCase().indexOf('/forums/threads.aspx') != -1 || location.pathname.toLowerCase().indexOf('/forums/messages.aspx') != -1) document.write('<st' + 'yle type="text/css">td.pageleftcol {display:none}</st' + 'yle>');
