/* selected state */
function getURLItem(url,number) {    
    var urlparts = url.split('/');
    var item = urlparts[number];
    return item;
}
function UrlMatch(url,matchTxt) { 
     var subStr = url.substring(0,matchTxt.length);               
     if(subStr == matchTxt)
         return true;
     else
        return false;
}

var docUrl = document.location.href;
var URLItem = getURLItem(docUrl,3);
URLItem = URLItem.replace(/#/g, '');

$(document).ready(function () {
    if (UrlMatch(URLItem, 'company')) {
        $(".tTopNav").addClass("tTopNavPosAT");
        $('ul.tSectionsNavList li.mItem:nth-child(5)').addClass("selected");        

    } else if (UrlMatch(URLItem, 'login') || UrlMatch(URLItem, 'search') || UrlMatch(URLItem, 'activate-client')
        || UrlMatch(URLItem, 'registration') || UrlMatch(URLItem, 'account')) {
        // do nothing - this is manipulated from the code-behind	
    } else if (UrlMatch(URLItem, 'automated-testing-tools')) {
        $(".tTopNav").addClass("tTopNavPosST");
        $('ul.tSectionsNavList li.mItem:nth-child(3)').addClass("selected");
        $("#mPurchaseBtn").attr('href', '/automated-testing-tools/purchase.aspx');
        $("#mDownloadBtn").attr('href', '/automated-testing-tools/download.aspx');

    } else if (UrlMatch(URLItem, 'team-productivity-tools')) {
        $(".tTopNav").addClass("tTopNavPosTP");
        $('ul.tSectionsNavList li.mItem:nth-child(2)').addClass("selected");
        $("#mPurchaseBtn").attr('href', '/team-productivity-tools/purchase.aspx');
        $("#mDownloadBtn").attr('href', '/team-productivity-tools/download.aspx');

    } else if (UrlMatch(URLItem, 'developer-tools') || URLItem != "") {
        $(".tTopNav").addClass("tTopNavPosDP");
        $('ul.tSectionsNavList li.mItem:first').addClass("selected");        
    }

});
    
/* dropdowns */
$("ul.tSectionsNavList li.mItem").hover(
  function() {      
      $(this).addClass("hover");      
  },
  function() {  
    
    $(this).removeClass("hover");
  }
);

 $('body').click(function() {
    $(".mSubMenuDisplayed").attr('class', 'mSubMenu');
    $(".mItemSelected").attr('class', 'mItem');
    $(".mArrowSelected").attr('class', 'mArrow');
 });

 $('.tSectionsNavWrap').click(function(event){
     event.stopPropagation();
 });
  
$(".mItem span.mArrow").click(
      function() { 
        if($(this).next().attr('class')=='mSubMenu') {
            $(".mSubMenuDisplayed").attr('class', 'mSubMenu');
            $(".mItemSelected").attr('class', 'mItem');
            $(".mArrowSelected").attr('class', 'mArrow');
            
            $(this).next().attr('class', 'mSubMenu mSubMenuDisplayed');            
            $(this).attr('class', 'mArrow mArrowSelected');
            $(this).parent().attr('class', 'mItem mItemSelected');
        } else {
            $(this).next().attr('class', 'mSubMenu');
            $(this).attr('class', 'mArrow');
            $(this).parent().attr('class', 'mItem');
        }       
      }        
 ); 
