function fixPngs()
{
    $('img[src$=.png]').ifixpng();
}

/*
******************************************************
***** BEGIN NAVIGATION *******************************
******************************************************
*/

function initNavigation()
{
    $("#navigation").find("li[id]").hover(navRollover,navRollout);
    $(".nav_drop_down").hover(dropDownRollover,dropDownRollout);
    $(".nav_drop_down").each(function()
        {
            var width = $(this).css('width').replace('px','');
            var lWidth = $(this).find('div.drop_down_bottom .left').css('width').replace('px','');
            var rWidth = $(this).find('div.drop_down_bottom .right').css('width').replace('px','');
            $(this).find('div.drop_down_bottom .middle').css('width', (width - lWidth - rWidth) + 'px');
        });
    $("#navigation").find("li[id]").click(navLinkClick);
    $(".drop_down_content li").hover(function(){ $(this).addClass('hover'); }, function(){ $(this).removeClass('hover'); });
    
    //Hack to get IE to properly calculate the height of the nav drop downs.
    $('.nav_drop_down').each(function()
	{ 
		$(this).css('left', '-10000px'); 
		$(this).show();
	});
	$('.drop_down_content ul').each(function()
	{ 
		$(this).height($(this).height());
	});
    $('.drop_down_content').each(function()
	{ 
		$(this).height($(this).height());
	});
    $('.nav_drop_down').each(function()
	{ 
		$(this).hide();
		$(this).css('left',null);
	});
}
function navLinkClick()
{
    var children = $(this).children("a");
    window.location.href = children.get(0).href;
}
function navRollover()
{
    setNavItemSelected($(this),true);
    setNavDropDownSelected(getNavDropdown($(this)), true);
}
function navRollout()
{
    setNavItemSelected($(this), false);
    setNavDropDownSelected(getNavDropdown($(this)), false);
}
function dropDownRollover()
{
    setNavDropDownSelected($(this), true);
    setNavItemSelected(getNavLink($(this)), true);
}
function dropDownRollout()
{
    setNavDropDownSelected($(this), false);
    setNavItemSelected(getNavLink($(this)), false);
}
function setNavDropDownSelected(item, selected)
{
    if(item)
    {
        if(selected)
        {
            item.show();
        }
        else
        {
            item.hide();
        }
    }
}
function setNavItemSelected(item, selected)
{
    if(item)
    {
        if(selected)
        {
            if(!item.hasClass('nav_selected'))
            {
                item.addClass('nav_selected');
            }
            if(item.hasClass('nav_default'))
            {
                item.removeClass('nav_default');
            }
        }
        else
        {
            if(!item.hasClass('nav_default'))
            {
                item.addClass('nav_default');
            }
            if(item.hasClass('nav_selected'))
            {
                item.removeClass('nav_selected');
            }
        }
        
        var prev = item.prev();
        if(prev)
        {
            var cssClass = prev.hasClass('nav_section_right') ? 'nav_spacer_full' : 'nav_spacer_left';
            if(selected) { prev.addClass(cssClass); } else { prev.removeClass(cssClass); }
        }
        
        var next = item.next();
        if(next)
        {
            var cssClass = next.hasClass('nav_section_left') ? 'nav_spacer_full' : 'nav_spacer_right';
            if(selected) { next.addClass(cssClass); } else { next.removeClass(cssClass); }
        }
    }
}
function getNavLink(dropDownItem)
{
    var tokens = dropDownItem.attr('id').split('_');
    var id = tokens[tokens.length - 1];
    
    var navItem = $('#nav_link_' + id);
    if(navItem && navItem.size() > 0)
    {
        return navItem;
    }
    else
    {
        return null;
    }
}
function getNavDropdown(navItem)
{
    var tokens = navItem.attr('id').split('_');
    var id = tokens[tokens.length - 1];
    
    var dropDown = $('#nav_drop_down_' + id);
    if(dropDown && dropDown.size() > 0)
    {
        return dropDown;
    }
    else
    {
        return null;
    }
}

/*
******************************************************
***** END NAVIGATION *********************************
******************************************************
*/
function getDefaultSearchText()
{
    return 'keyword, catalog #, or molecule';
}

function initProductSearch()
{
    $("#prod_search_keyword").keypress(function (e) {
      if(e.keyCode == 13) //Enter key pressed.
      {
        e.preventDefault();
        submitProductSearch("#prod_search_keyword");
      }
      else
      {
          if($(this).hasClass('prod_search_textbox_invalid'))
          {
            $(this).removeClass('prod_search_textbox_invalid');
          }
      }
    });
    $("#prod_search_keyword").focus(function (e) {
      if($(this).attr('value') == getDefaultSearchText())
      {
        $(this).attr('value','');
        if($(this).hasClass('prod_search_textbox_invalid'))
        {
            $(this).removeClass('prod_search_textbox_invalid');
        }
      }
    });
}
function submitProductSearch(keywordInputSelector)
{
    var keyword = $(keywordInputSelector).attr('value');
    if(keyword == getDefaultSearchText() || keyword == '')
    {
        $(keywordInputSelector).addClass('prod_search_textbox_invalid');
        $(keywordInputSelector).attr('value',getDefaultSearchText());
    }
    else
    {
        var searchUrl = "/ProductSearchResults.aspx?k=" + keyword;
        window.location = searchUrl;
    }
}

function initContentPage()
{
    var leftNav = $('#left_nav_container');
    var content = $('#content_container');
    
    if(leftNav && content) //If we have both a left nav and a content container, make them both the same height.
    {
        if(leftNav.height() > (content.height()))
        {
            content.height(leftNav.height());
        }
    }
    
    //Handle external links in a compliant way.
    $('a[rel="external"]').click( function() {
        window.open( $(this).attr('href') );
        return false;
    });
}

function showMoreFilters(divID,linkID)
{
    var link = document.getElementById(linkID);
    if(link != null && link.parentNode != null)
    {
        link.parentNode.removeChild(link);
    }
    
    document.getElementById(divID).style.display = "inline";
}

function addLoadEvent(func) 
{
    var oldonload = window.onload;
    if (typeof window.onload != 'function') 
    {
        window.onload = func;
    }
    else 
    {
        window.onload = function() 
        {
            if (oldonload) 
            {
                oldonload();
            }
            func();
        }
    }
} 

function fixSearchTips()
{
    if(typeof(isIE6) !== 'undefined') //IE6 Doesn't handle thickbox properly.
    {
        $('.prod_search_tips_link a.thickbox').each(function(){ $(this).attr("href", "/rnd_page_objectname_searchtips.aspx"); });
        $('.prod_search_tips_link a.thickbox').removeClass('thickbox');
    }
}

var bIsResized = false;

function thickboxResize() {  
 
    var boundHeight = 530; // minimum height  
    var boundWidth = 400; // minimum width  
  
    var viewportWidth = (self.innerWidth || (document.documentElement.clientWidth || (document.body.clientWidth || 0)))  
    var viewportHeight =(self.innerHeight || (document.documentElement.clientHeight || (document.body.clientHeight || 0)))  
  
    if(viewportHeight < boundHeight || bIsResized)
    {
        bIsResized = true;
    
        boundHeight = viewportHeight * 0.6;
    
    //    alert(boundHeight);
    
        $('a.thickbox').each(function(){  
            var text = $(this).attr("href");  
            // constrain the height by defined bounds  
            text = text.replace(/height=[0-9]*/,'height=' + boundHeight);  
            // constrain the width by defined bounds  
            //text = text.replace(/width=[0-9]*/,'width=' + boundWidth);  
            $(this).attr("href", text);  
        });
    } 
} 
function initSplashTabs() {
    $('#tabs').bind('tabsselect', function(event, ui) {
        var element = $('#homepage_splash .homepage_tabcontainer .ui-widget-header')
        element.attr("style","background-image:url('Resources/images/homepage_tabs_tabsel_" + (ui.index + 1) + "_full.png');");
    });
    //Identify the individual tabs for CSS.
    $('#tabs ul li').each(function(index){ $(this).addClass('homepage_tab_' + (index+1)); });
}

function showAnalyzerFilters(){
    if ($('#moreAnalyzerFiltersLink').text() == '> more') {
        $('.liInstrumentHidden').show();
        $('#moreAnalyzerFiltersLink').text('> less');
    }
    else {
        $('.liInstrumentHidden').hide();
        $('#moreAnalyzerFiltersLink').text('> more');
    }
}



