/* Controls the menu system */

$(document).ready(function(){

            originalTabID = $('#mainTabs li:has(a.selected)').attr('id');
            
            $('#topSubNav ul').hide();
            $('#' + originalTabID + 'Subnav').show();

            $('#mainTabs li').mouseover(function(){
                        $('#topSubNav ul').hide();
                        $('#mainTabs a').removeClass('hovered');

                        if ($('a', this).hasClass('selected') == true) {
                                    $('#topSubNav').css('background-color', '#a4a9ac'); //default
                        } else {
                                    $('#topSubNav').css('background-color', '#8d9397');
                                    $('a', this).addClass('hovered');
                        }
                        
                        var thisID = $(this).attr('id') + 'Subnav';
                        $('#' + thisID).show();


            });

            $('#mainTabs li').mouseout(function(){
                        // restore old tab
                        $('a', this).removeClass('hovered');
            });

            $('#globalNavigation').mouseleave(function(){                                   
                        $('#topSubNav ul').hide();
                        $('#mainTabs a').removeClass('hovered');
                        // restore old menu
                        $('#' + originalTabID + 'Subnav').show();
                        //$('#' + originalTabID + ' a').addClass('hovered');
                        $('#topSubNav').css('background-color', '#a4a9ac');
            });


            $('#topSubNav').hover(
                        function(){
                                    var thisTabID = $(this).children('ul:visible').attr('id');
                                    if (thisTabID != null) {
                                                thisTabID = thisTabID.slice(0, thisTabID.length - 6);                                               
            
                                                if ($('#' + thisTabID + ' a').hasClass('selected') != true) {
                                                            $('#' + thisTabID + ' a').addClass('hovered');
                                                }
                                    }
                        },
                        function(){
                        }
            );
            
            
            $('#printPage').click(function(){
                        window.print();
            });
            
            // add a "rel" attrib if Opera 7+  
            if(window.opera) {
                        if ($("#bookmarkPage").attr("rel") != ""){ 
                                    $("#bookmarkPage").attr("rel","sidebar");
                        }
            }
            
            $("#bookmarkPage").click(function(event){
                        event.preventDefault();                                                                                  // prevent the anchor tag from sending the user off to the link  
                        var url = this.href;  
                        var title = this.title;  
                        
                        if (window.sidebar) {                                                                                        // Mozilla Firefox 
                                    window.sidebar.addPanel(title, url,"");  
                        }else if( window.external ) {                                                                // IE Favorite  
                                    window.external.AddFavorite( url, title);  
                        } else if(window.opera) {                                                                                  // Opera 7+  
                                    return false; 
                        } else {                                                                                                                                     // Safari, Konq etc - browsers which do not support bookmarking scripts 
                                    alert('Unfortunately, this browser does not support the requested action,'  
                                    + ' please bookmark this page manually.');  
                        }  
            
            });
            

})
