
jQuery(function($) {
    
    var TIME_ANIMATE_OUT         =  500;
    var TIME_ANUMATE_IN          =  500;
    var MOBILE_ANIMATE_OUT       = 500;
    var MOBILE_ANIMATE_IN        = 500;
    var PANEL_POSITION_OFFSET    =  30;
  
    var theAnimateOutTime = TIME_ANIMATE_OUT;
    var theAnimateInTime  = TIME_ANUMATE_IN;
    var panelHeightArray = new Array();
          
    /* Variables used to identify if operating on Mobile or MSIE */
    var bIsMobileClient = false;
    var bIsMSIE = false;
 
    /* Set to True if the browser agent is a mobile device such as iPhone, iPad, etc. */
    bIsMobileClient = navigator.userAgent.toLowerCase().match(/mobile/) == "mobile";
    bIsMSIE         = navigator.userAgent.toLowerCase().match(/msie/) == "msie";
    
    /* Change the animation times if mobile */
    if (bIsMobileClient == true) {
        theAnimateOutTime = MOBILE_ANIMATE_OUT;
        theAnimateInTime  = MOBILE_ANIMATE_IN;
    }

    /* Adjust the wrapper to collapse as the photos are moved into place */
    $('.wrapper_main').css({"overflow" : "hidden"});

    
    /* Stack the panels on top of each other */
    $("#panel_wrapper .panel").panel({PANEL_ANIMATE_OUT: theAnimateOutTime,
                                      PANEL_ANIMATE_IN:  theAnimateInTime,
                                      CALLBACK : TransitionCompete});    
    
    /* panel transistion complete callback function */
    function TransitionCompete() {        
        /* do nothing for now */
    };
            
    
    /* Left NAV MENU */
	$('#left_nav li ul li').click(function() {
        var panel_id = parseInt($(this).attr('id'));                /* get the id as an integer */
        
        $("#panel_wrapper .panel").panel.transition(panel_id);      /* transistion to new panel */
        $('.right_column').animate({"height" : panelHeightArray[panel_id]})  /* adjust the new panel height */
        
        $('#left_nav li ul li').removeClass("highlight");           /* remove highlight class from all li's */
        $(this).addClass("highlight");                              /* add highlight class to selected li */
        			  
	 });
    
    /* Calculate the height of each panel */
    $('#panel_wrapper .panel').each (function(index) {
        var panelHeight = $(this).height();
        panelHeightArray[index] = panelHeight + PANEL_POSITION_OFFSET; 
    });
    
    /* Adjust the panel height for the entry panel */
    $('.right_column').css ({"height" : panelHeightArray[0]});
    
    /* Add the highlight class to the first menu item */
	$('#left_nav li ul li:eq(0)').addClass("highlight");
 
    
    /*----------------------------------------------------------------------------
    ** The following code will add a class to the main Menu when the page loads
    **----------------------------------------------------------------------------
    */
    
    /* Get the www address and extract the last field  */
    var dirs = window.location.pathname.split('/');             // break up the address into an array
    var webPage = dirs[dirs.length - 1];                        // this is the current html page

    /* If the webPage has an underscore in the name, then that part
    ** shall be removed.  For example:
    **    team.html or team_foo.html or team_bar.html
    ** The above three webPage names shall appear as team.html for the
    ** purpose of searching thru the menu items.
    */
    var webPageArray  = webPage.split('_');                     // use "_" as the seperator
    var webPageArray2 = webPage.split('.');                     // use "." as the seperator
    var webPage2 = webPageArray[0];                             // modifly web page for comparasion against menu
    
    /* If an understore was found than the array length will be 2.  Need to add the html or php (file type) back
    ** along with the period
    */
    if (webPageArray.length >= 2) {
        webPage2 = webPage2 + "." + webPageArray2[webPageArray2.length - 1];   
    }
    
    /* Search thru the menu for a match */
    var $hrefObjects = $('#menu').find('a[href!="#"]');         // find all href's != "#"
    
    /* Search thru the href objects for a webPage Match */
    if (webPage2 != "") {
        $hrefObjects.each(function(index) {                     // search thru all menu items
            var hrefString = $(this).attr('href');              // extract the href name
            if (hrefString.indexOf(webPage2) != -1) {            // check for a href match with the webPage
                $(this).addClass("main_highlight");                  // found one - add class
                return false;                                   // and break out of loop
            }
        })
    }
    
    
    /* Compare the web address to the left_nav menu
    ** This compare will use the actual page address for the compare
    */
    var $leftNavObjects = $('#investors_left_nav li').find('a[href!="#"]');
    $leftNavObjects.removeClass("highlight");          // remove any previous attached class
    
    $leftNavObjects.each(function(index) {
            var hrefString = $(this).attr('href');              // extract the href name
            if (hrefString.indexOf(webPage) != -1) {            // check for a href match with the webPage
                $(this).addClass("highlight");         // found one - add class
                return false;                                   // and break out of loop
            }
    })
    
    
    /*-----------------------------------------------------------------------------
    ** The following code is for the technology submenu
    **-----------------------------------------------------------------------------
    */
    
    /* The following code should be implemented in the html file, immediately after the div is defined */
    $('#tech_nav_sub_ourprodrugs').hide();      // hide submenu on page load
    $('#tech_nav_sub_targeting').hide();        // hide submenu on page load
    
    /* Special test to highligh the sub-menus */
    if (webPage == "technology_howItWorks.html") {
        $('#tech_nav_sub_ourprodrugs').show('fast');
        $('#subMenu1').css({"font-weight":"bold"});
    }
    else if (webPage == "technology_howWeMakeIt.html")
    {
        $('#tech_nav_sub_ourprodrugs').show('fast');
        $('#subMenu2').css({"font-weight":"bold"});        
    }
    else if (webPage == "technology_direct.html"){
        $('#tech_nav_sub_targeting').show('fast');
        $('#subMenu3').css({"font-weight":"bold"});        
    }
    else if (webPage == "technology_bloodSupply.html") {
        $('#tech_nav_sub_targeting').show('fast');
        $('#subMenu4').css({"font-weight":"bold"});         
    }
    
    /* Code for mouse enter on a button */
    $('#tech_nav_prodrugs').mouseenter(function() {
        $('#tech_nav_sub_ourprodrugs').show('fast');
        $('#tech_nav_sub_targeting').hide('fast');
        
    })
    
    $('#tech_nav_targeting').mouseenter(function() {
        $('#tech_nav_sub_targeting').show('fast');
        $('#tech_nav_sub_ourprodrugs').hide('fast');
    })

    $('.tech_nav_btn_others').mouseenter(function() {
        $('#tech_nav_sub_ourprodrugs').hide('fast');    
        $('#tech_nav_sub_targeting').hide('fast');                
    })
    

    /*--------------------------------------------------------------------------------------------------------------
    ** The following code applies a class as the mouse hovers over investers_sec.html ul li list for the SEC Filings
    **--------------------------------------------------------------------------------------------------------------
    */
    $('ul.sec_filings_hover > li').hover(function() {
	  $(this).toggleClass('sec_filing_selected').siblings().removeClass('sec_filing_selected'); 
	});

    /* Add pointer as we hover over */
    $('#sec_horiz_form_nav_wrapper div').hover (function() {
       $(this).css({"cursor" : "pointer"});    
    });
    
    $('#sec_horiz_form_nav_wrapper div:eq(0)').addClass('sec_horiz_form_nav_highlight');    // add class to first div
    
    $('#sec_horiz_form_nav_wrapper div').click (function() {
        var panel_id = parseInt($(this).attr('id'));                /* get the id as an integer */
        $("#panel_wrapper .panel").panel.transition(panel_id);      /* transistion to new panel */
        $('.right_column').animate({"height" : panelHeightArray[panel_id]})  /* adjust the new panel height */
        $('#sec_horiz_form_nav_wrapper div').removeClass('sec_horiz_form_nav_highlight');
        $(this).addClass('sec_horiz_form_nav_highlight');
    });
    
    
    /*-----------------------------------------------------------------------------------------------------------------
    ** The following code implements the Investors Press sub-menus
    **-----------------------------------------------------------------------------------------------------------------
    */
    $('#press_links li:eq(0)').addClass('press_links_nav_highlight');    // add class to first div      
    
    $('#press_links').hover (function() {
        $(this).css({"cursor" : "pointer"});
    });
    
    $('#press_links li').click (function() {
        var panel_id = parseInt($(this).attr('id'));
        $("#panel_wrapper .panel").panel.transition(panel_id);      /* transistion to new panel */
        $('#press_links li').removeClass('press_links_nav_highlight');
        $(this).addClass('press_links_nav_highlight');        
    });
    
  
    
});
