﻿//function setactive()
//{  
//  var el = this;            
//  var className = el.parentNode.id;  
//  el.parentNode.parentNode.className = className;
//} 
//window.onload = function()
//{  
//  if ($('featured_pub_1_link'))
//  {
//    $('featured_pub_1_link').className = "featuredtitle title1 active";  
//    var titles = document.getElementsByTagName('h2');  
//    for(var i=0;i<titles.length;i++)
//    {
//      titles[i].onclick = setactive;
//    }
//  }            
//} 

window.addEvent('domready', function() 
{
  if ($('featured_pub_1_link'))
  {
    $('featured_pub_1_link').addClass("active");
  }
  if ($('featured_media_1_link'))
  {
    $('featured_media_1_link').addClass("active");
  }  

  var linkids = $$("#featuredpubsbuttons a.featuredtitle");
  
  linkids.addEvent("click", function()
    {
      var linkid = this.id;
      var divtoshow = linkid.substring(0,linkid.length-5);
      var contentdivs = $$("div.featuredpubcontent");
      
      contentdivs.each(function (contentdiv)
        {
          namelink = "featured_pub_" + contentdiv.id.substring(13) + "_link";
          if (contentdiv.id == divtoshow)
          {          
            contentdiv.removeClass("hide");
            $(namelink).addClass("active");
          }
          else
          {
            contentdiv.addClass("hide");
            $(namelink).removeClass("active");
          }
        });
    });
    
    linkids = $$("#featuredmediabuttons a.featuredtitle");
  
    linkids.addEvent("click", function()
    {
      var linkid = this.id;
      var divtoshow = linkid.substring(0,linkid.length-5);
      var contentdivs = $$("div.featuredmediacontent");
      
      contentdivs.each(function (contentdiv)
        {
          namelink = "featured_media_" + contentdiv.id.substring(15) + "_link";
          if (contentdiv.id == divtoshow)
          {          
            contentdiv.removeClass("hide");
            $(namelink).addClass("active");
          }
          else
          {
            contentdiv.addClass("hide");
            $(namelink).removeClass("active");
          }
        });
    });    
});

var ThoughtLeadershipLastClicked = "";
var SearchPublicationsDefaultText = "";


function InitializeThoughtLeadershipLibrary(pubddl,searchbox,gobtn)
{
  window.addEvent("domready", function()
    {
      SearchPublicationsDefaultText = $(searchbox).value;
      $(pubddl).addEvent("change", function()
        {
          $(gobtn).setProperty("href",this.value);
          ThoughtLeadershipLastClicked = "DROPDOWN";
        });
      $(searchbox).addEvent("focus", function(e)
        {
          ThoughtLeadershipLastClicked = "SEARCH";
          
          if (SearchPublicationsDefaultText == this.value)
          {
            this.value = "";
          }
        });
      $(searchbox).addEvent("blur", function(e)
        {
          if (this.value == "")
          {
            this.value = SearchPublicationsDefaultText;
          }
        });
        
	    $(searchbox).addEvent("keypress", function(e)
	    {
	      var KeyID = (window.event) ? event.keyCode : e.keyCode;
  	    
	      if (KeyID == 13)
	      {
	        document.aspnetForm.submit();
	        return false;
	      }
	    });        
        
    
      $(gobtn).addEvent("click", function()
        {
          if (ThoughtLeadershipLastClicked == "")
          {
            var href = "/What_We_Think/Publications/";
            $(gobtn).setProperty("href",href);
          }
          else if (ThoughtLeadershipLastClicked == "DROPDOWN")
          {
            $(gobtn).setProperty("href",$(pubddl).value);
          }
          else
          {
            var href = "/What_We_Think/Publications/Search/?q=" + encodeURIComponent($(searchbox).value);
            $(gobtn).setProperty("href",href);
          }
        });
    
    });  
}
