﻿// Build Search query
function formSubmitSearch(qString) {
  window.location.href = "http://www.biogenidec.com/search_results.html?query=" + qString;
  }

/* Create a namespace */
var Biogen = {};

/* Remove "nojs" class from body tag if Javascript is enabled */
Biogen.enableJavascript = function() {
  $("body").removeClass("nojs");
};

/* Add Mac stylesheet for certain font issues, where appropriate */
Biogen.enableMacStyles = function() {
  var isMac = false;
  var macStyle = '<link rel="stylesheet" type="text/css" src="/files/system/USA2010/styles/mac.css" media="all" />';

  if((navigator.userAgent.indexOf('Mac') != -1) || 
  (navigator.userAgent.indexOf('iPhone') != -1)){
        isMac = true;   
    };
  if (isMac) {
    $("head").append(macStyle);
  };
};
/* This is called before the page loads */
Biogen.enableMacStyles();

Biogen.enablePrint = function() {
  $('a#printpage').click(function() {
    if(window.print) {
      window.print();
    } else {
      alert('Your browser (or its current settings) does not support this print button. You may need to manually print this page.');
    }
    return false;
  });
};

/* Enable Global Websites toggle */
Biogen.enableGlobalWebsites = function() {
  $("a.globaltoggle").click( function() {
    if ($(this).parent("div").hasClass("closed")) {
      $(this).parent("div").removeClass("closed").addClass("opened");
      $(this).children("img").attr("src", "/files/system/USA2010/images/global_sites_down.gif");
    } else {
      $(this).parent("div").removeClass("opened").addClass("closed");
      $(this).children("img").attr("src", "/files/system/USA2010/images/global_sites_up.gif");
    }
    return false;
  });
};

/* Enable Other Resources toggle */
Biogen.enableOtherResources = function() {
  $("a.otherresourcestoggle").click( function() {
    if ($(this).parent("div").hasClass("closed")) {
      $(this).parent("div").removeClass("closed").addClass("opened");
      $(this).children("img").attr("src", "/files/system/USA2010/images/btn_otherresources_down.gif");
    } else {
      $(this).parent("div").removeClass("opened").addClass("closed");
      $(this).children("img").attr("src", "/files/system/USA2010/images/btn_otherresources.gif");
    }
    return false;
  });
};

/* Enable Pipeline */
Biogen.enablePipeline = function() {
  if ($("div.pipelinesection table tr.open").length > 0) {
    $("div.pipelinesection table tr.open").removeClass("open");
  }
  $("div.pipelinesection div.pipehead a").click( function() {
    $(this).parent("div.pipehead").parent("td").parent("tr").addClass("clicked");
    $("div.pipelinesection table tr:not(.clicked)").removeClass("open");
    var tablerow = $(this).parent("div.pipehead").parent("td").parent("tr");
    if (tablerow.hasClass("open")) {
      tablerow.removeClass("open");
    } else {
      tablerow.addClass("open");
    }
    $(this).parent("div.pipehead").parent("td").parent("tr").removeClass("clicked");
    return false;
  });
};

/* Enable no-Flash rotation on homepage */
Biogen.enableHomeRotation = function() {
  if ($("div#homeflash").length > 0) {
    var randomnumber=Math.floor(Math.random()*4);
    var randomnumber = randomnumber + 1;
    $("div.mccue").hide();
    $("div#feature"+randomnumber).show();
  }
}

/* Initialize everything when page is ready */
$(document).ready(function() {
  Biogen.enableJavascript();
  Biogen.enablePrint();
  Biogen.enableGlobalWebsites();
  Biogen.enableOtherResources();
  Biogen.enablePipeline();
  Biogen.enableHomeRotation();
  
  $("input#searchbox").hint();
  
  //fix problem with Firefox not checking radio buttons on load
  if($.browser.mozilla) $("form").attr("autocomplete", "off");    

});

