$(document).ready(function() {
    setupSuperNav();
    youAreHere();
    setupLeftNav();
});
setupSuperNav = function() {
    $('#supernav').children('li').addClass('level1');
    $('#supernav').children('li:first').addClass('first');
    $('#supernav').children('li:last').addClass('last');
    $('.level1').each( 
        function() {
            $(this).children('ul').addClass('level2ul').children('li').addClass('level2');
            $(this).children('ul').children('li:first').addClass('first');
            $(this).children('ul').children('li:last').addClass('last');
        }             
    )
    $('.level2').each( 
        function() {
            $(this).children('ul').addClass('level3ul').children('li').addClass('level3');
            $(this).children('ul').children('li:first').addClass('first');
            $(this).children('ul').children('li:last').addClass('last');
        }             
    )
    var index = 0;
    $('.level3').each( 
        function() {
            $(this).addClass('index' + index).children('ul').addClass('level4ul').children('li').addClass('level4');
            $(this).children('ul').children('li:first').addClass('first');
            $(this).children('ul').children('li:last').addClass('last');
            index++;
        }             
    )
    /*$('#supernav a').each( 
        function() {
            theID = $(this).attr('id');
            if (theID > 0) { $(this).parent().attr('id', 'parentof'+theID) }
        }             
    )*/
    
    $('.level1').hover(function() {
        $(this).addClass('sfhover');
        $(this).find('.level2ul').fadeIn(200);
    }, function() {
        $(this).removeClass('sfhover');
        $(this).find('.level2ul').hide();
    })
    
    // Remove empty ULs
    $('#supernav').children('li').children('ul').each(
        function() {
            if ($(this).children('li').length < 1) {
                $(this).remove();
            }
        }
    )
    
}
youAreHere = function() {
  section = getSiteSection();

  var cDomicile;
  cDomicile = readCookie('DOMICILE');
  if(cDomicile == 'DE' || cDomicile == 'IT'){

    switch (section) {
        case 'About RREEF': highlight = 1; break;
        case 'Investment Strategies': highlight = 2; break;
        case 'Products': highlight = 3; break;
        case 'News & Research': highlight = 4; break;
        case 'Property Transactions': highlight = 5; break;
        case 'Sustainability': highlight = 6; break;
        case 'Our Clients': highlight = 7; break;
        default: highlight = 0;
    }
    $('#supernav').children('li').children('a').removeClass('active');
    if (highlight > 0) {
        $('#supernav').children('li').eq(highlight).children('a').addClass('active');
    } else {
        if ($('#home_wrapper')) {
            $('#supernav').children('li').eq(highlight).children('a').addClass('active');
        }
    }

  }
  else {

    switch (section) {
        case 'About RREEF': highlight = 1; break;
        case 'Investment Strategies': highlight = 2; break;
        case 'News & Research': highlight = 3; break;
        case 'Property Transactions': highlight = 4; break;
        case 'Sustainability': highlight = 5; break;
        case 'Our Clients': highlight = 6; break;
        default: highlight = 0;
    }
    $('#supernav').children('li').children('a').removeClass('active');
    if (highlight > 0) {
        $('#supernav').children('li').eq(highlight).children('a').addClass('active');
    } else {
        if ($('#home_wrapper')) {
            $('#supernav').children('li').eq(highlight).children('a').addClass('active');
        }
    }

  }    
    
}
getSiteSection = function() {
    var pagePath = window.location.pathname;
    var siteSection = 'Home';
    
    if (pagePath.indexOf('/about/')!=-1) { siteSection = 'About RREEF'; }
    else if (pagePath.indexOf('/home/about_rreef.jsp')!=-1) { siteSection = 'About RREEF'; }
    else if (pagePath.indexOf('/strategies/')!=-1) { siteSection = 'Investment Strategies'; }
    else if (pagePath.indexOf('/home/strategies.jsp')!=-1) { siteSection = 'Investment Strategies'; }
    else if (pagePath.indexOf('/insights/')!=-1) { siteSection = 'News & Research'; }
    else if (pagePath.indexOf('/home/insights.jsp')!=-1) { siteSection = 'News & Research'; }
    else if (pagePath.indexOf('/properties/')!=-1) { siteSection = 'Property Transactions'; }
    else if (pagePath.indexOf('/home/properties.jsp')!=-1) { siteSection = 'Property Transactions'; }
    else if (pagePath.indexOf('/sustainability/')!=-1) { siteSection = 'Sustainability'; }
    else if (pagePath.indexOf('/home/sustainability.jsp')!=-1) { siteSection = 'Sustainability'; }
    else if (pagePath.indexOf('/products/')!=-1) { siteSection = 'Products'; }
    else if (pagePath.indexOf('/home/products.jsp')!=-1) { siteSection = 'Products'; }
    
    return siteSection;
}
setupLeftNav = function() {
    // Remove empty ULs
    if ($('#leftNavi .parent.topParent').children('ul').children('li').length < 1){
        $('#leftNavi .parent.topParent').removeClass();
    }
    $('#leftNavi ul ul:empty').hide();

}

function newVideoWindow(fileName) {
    msgWindow=window.open('','altwindow','menubar=no,toolbar=no,location=no,resizable=yes,scrollbars=yes,status=no,width=730,height=720,screenX=10,screenY=10,top=10,left=10');
    msgWindow.close();
    
    msgWindow=window.open(fileName,'altwindow','menubar=no,toolbar=no,location=no,resizable=yes,scrollbars=yes,status=no,width=730,height=720,screenX=10,screenY=10,top=10,left=10');
    msgWindow.focus();
}
