
// change this next line to modify the home page video
//var HOME_PAGE_VIDEO_URL = 'http://willis.feedroom.com/?skin=oneclip2';
//var HOME_PAGE_VIDEO_URL = 'http://willis.feedroom.com/?skin=oneclip2&fr_story=1527819b49f77b3ec313be7f2b38f39fbbcaa4a8';
var HOME_PAGE_VIDEO_URL = 'http://willis.feedroom.com/?skin=oneclip2&fr_story=a90b57c2479ddea9f3c70e898456ea6a464d5b96';

var arrSlides;
var arrTimeouts;
var numMargin = 0;
var flgAllow = true;

var bioSliders;

var numRandom = Math.floor(Math.random()*5) + 1;  

var IsPublicationSearch = false;

function closeIfStillOpen(a_strTabId, a_numIndex)
{
    if (flgAllow)
    {
	    var objTab = $(a_strTabId);
	    var objSlider = $ES('.SlideDetail', objTab)[0];
    	
	    if (objSlider.getStyle('margin-top') == '0px')
	    {
		    arrSlides[a_numIndex].slideOut();
	    }
	}
}

window.addEvent('domready', function() 
{
  var homeids = $$("body#bodyhome");
  
  if (homeids.length > 0)
  {
    $('SwapPhoto').removeProperty('src');
    $('SwapPhoto').setProperty('src', 'images/img_photo0' + numRandom + '.jpg');
    $('SwapHeader').removeProperty('class');
    $('SwapHeader').addClass('text0' + numRandom);

    var growDiv = new Fx.Style($('VideoContainer'), 'width', 
    {
        duration: 700, 
        onComplete: function()
        {
            $('VideoIntro').setStyle('display', 'none');
            flgAllow = true;
            $('VideoContainer').setStyle('height', '272px');
            
            $('Video').setStyle('margin-top', '3px');
            $('Video').setStyle('margin-left', '3px');
            
            $('Video').setStyle('height', '262px');
            $('Video').setStyle('width', '402px');
            $('VideoClose').setStyle('display', 'block');
            
            var growDiv2 = new Fx.Style($('VideoContainer'), 'width', 
            {
                duration: 700, 
                onComplete: function()
                {
                    $('ShowVideo').setStyle('display', 'block');

                    var elmIframe = new Element('iframe', {
                        'src': HOME_PAGE_VIDEO_URL,
                        'width': '402',
                        'height': '262',
                        'scrolling': 'no',
                        'frameborder': '0',
                        'marginwidth': '0',
                        'marginheight': '0',
                        'id': 'VideoIframe'
                    });
                    
                    $(elmIframe).injectInside('ShowVideo');
                }
            });
            
            growDiv2.start(437);
        }
    });

    var growDiv_back = new Fx.Style($('VideoContainer'), 'width', 
    {
        duration: 700, 
        onComplete: function()
        {
            $('VideoClose').setStyle('display', 'none');
            $('VideoIntro').setStyle('display', 'block');
            flgAllow = true;
            $('VideoContainer').setStyle('height', '262px');
            
            $('Video').setStyle('margin-top', '10px');
            $('Video').setStyle('margin-left', '-5px');
            
            $('Video').setStyle('height', 'auto');
            $('Video').setStyle('width', '240px');
            $('ShowVideo').setStyle('display', 'none');
            
            var growDiv2 = new Fx.Style($('VideoContainer'), 'width', 
            {
                duration: 700, 
                onComplete: function()
                {
                }
            });
            
            growDiv2.start(249);
        }
    });

  }
    
	// initialize variables for 'curtains'
	var arrTabs = $ES('div.ColumnSlider');
	if (arrTabs.length > 0)
    {
	arrSlides = new Array(arrTabs.length);
	arrTimeouts = new Array(arrTabs.length);

	arrTabs.each(function(objAbove, numIndex)
	{
		var objHeader = $ES('div.Intro', objAbove)[0];
		var objSlider = $ES('div.SlideDetail', objAbove)[0];

		if (objSlider.getStyle('height').toInt() > numMargin)
		{
		    numMargin = objSlider.getStyle('height').toInt();
		}

		var objSlideBottom = $ES('div.SlideDetailBottom', objAbove)[0];

		arrSlides[numIndex] = new Fx.Slide(objSlider, 
		    {
		    duration: 200, 
		    onComplete: 
		        function()
		        {
		           if (objSlider.getStyle('margin-top') == '0px')
		           {
		            objSlideBottom.addClass('Closed');

		            if (objAbove.getParent().id != "VideoIntro")
		            {
		                objSlider.setStyle('border-bottom-color', '#6f9dc7');
		            }
		           }
		           else
		           {
		            objSlideBottom.removeClass('Closed');
		            
		            if (objAbove.getParent().id != "VideoIntro")
		            {
		                objSlider.setStyle('border-bottom-color', '#cccccc');
		            }
		           }
		        }
		    }
		);
		
		arrSlides[numIndex].hide();

		objAbove.addEvent('mouseenter', function(e)
		{
		    if (flgAllow)
		    {
		        clearTimeout(arrTimeouts[numIndex]);
		        e = new Event(e);
		        arrSlides[numIndex].slideIn();
		        e.stop();
		    }
		});
		
		objAbove.addEvent('mouseleave', function(e)
		{
		    if (flgAllow)
		    {
		        e = new Event(e);
		        arrSlides[numIndex].slideOut();
		        e.stop();

		        arrTimeouts[numIndex] = setTimeout("closeIfStillOpen('" + objAbove.getParent().id + "'," + numIndex + ")", 1000);
		    }
		});
	});
	
	if (numMargin > 100)
	{
	    numMargin = 100;
	}
	
    $('Columns').setStyle("padding-bottom", numMargin + 'px');
    
    if ($('WatchNow'))
    {
      $('WatchNow').addEvent('click', function(e)
      {
        flgAllow = false;
        growDiv.start(0);
        $('PhotoOverlay').setStyle('display', 'block');
        $('PhotoOverlay').setStyle('opacity', '0');

        var fadeOverlay = new Fx.Style($('PhotoOverlay'), 'opacity', {duration: 700}).start(0.5);
      });
    }
    
    if ($('VideoCloseButton'))
    {
      $('VideoCloseButton').addEvent('click', function(e)
      {
        flgAllow = false;
        $('VideoIframe').remove();
        growDiv_back.start(0);
        var fadeOverlay = new Fx.Style($('PhotoOverlay'), 'opacity', {duration: 700}).start(0);
      });
    }
    
    $('submitbtn').addEvent('click', function()
      {
        $('submitbtn').setProperty('href','/Search/?Q=' + encodeURIComponent($('HeaderSearchField').value));
        return true;
      });
    }
});

window.addEvent('domready', function() 
{
	// search box text
	var searchBox = $E('input.HeaderSearchField');
	if (searchBox)
	{
	  var DefaultText = searchBox.value;
	  searchBox.addEvent('focus', function(e)
	  {
	    if (searchBox.value == DefaultText)
	    {
	      searchBox.value = "";
	      searchBox.addClass("selected");
	    }
	  });
	  
	  searchBox.addEvent('blur', function(e)
	  {
	    if (searchBox.value == "")
	    {
	      searchBox.value = DefaultText;
	      searchBox.removeClass("selected");
	    }
	  });
	  
	  searchBox.addEvent("keypress", function(e)
	  {
	    var KeyID = (window.event) ? event.keyCode : e.keyCode;
	    
	    if (KeyID == 13)
	    {
	      document.aspnetForm.submit();
	      return false;
	    }
	  });
	  
	  $("submitbtn").addEvent("click", function()
	    {
	      var url = "/Search/?q=" + encodeURIComponent(searchBox.value);
	      $("submitbtn").setProperty("href",url);
	    });
	    
	  
	}
});

function utxt(elem, value){
    if(value){
        elem.setStyle('text-decoration', 'underline');
    }else{
        elem.setStyle('text-decoration', 'none');
    }
}

function InitializeBios()
{
  var biolinks = $$("ul#biopeoplelist li"); 
  
  biolinks.addEvent('click', function(e)
    {
      var bioidtoopen = parseInt(this.getProperty("bioid"));
      var biotoopen = "bio_" + bioidtoopen;
      
      var openbios = $$("div#bios .selected");
      
      openbios.each(function (openbio)
        {
          var bioidtoclose = parseInt(openbio.id.replace("bio_",""));
          openbio.removeClass("selected");
        });
        
      $(biotoopen).addClass("selected");
        
    }); 

}

function InitializeContactDropDowns(countryddlid,containerprefix,containerclass)
{
  window.addEvent("domready", function(e)
  {
    if ($(countryddlid))
    {

    $(countryddlid).addEvent("change", function(e)
      {
        var divtoshow = "";
        if (this.value != "")
        {
          divtoshow = containerprefix + this.value.replace(/ /g,"_");
          divtoshow = divtoshow.replace(/\//g,"");
        }
        
        var containers = $$("div." + containerclass);
        containers.each(function(container)
          {
            if (divtoshow == "")
            {
              if (container.hasClass("hide"))
              {
                container.removeClass("hide");
              }
            }
            else
            {
              if (container.id == divtoshow)
              {
                if (container.hasClass("hide"))
                {
                  container.removeClass("hide");
                }                
              }
              else
              {
                if (!container.hasClass("hide"))
                {
                  container.addClass("hide");
                }              
              }              
            }
          
          

          });
        
        
        
      });
    }
  });
}

function InitializeSearchBox(txtid,btnid)
{
  window.addEvent("domready", function()
    {
      $(txtid).addEvent("keypress", function(e)
        {
	        var KeyID = (window.event) ? event.keyCode : e.keyCode;
    	    
	        if (KeyID == 13)
	        {
	          document.aspnetForm.submit();
	          return false;
	        }          
        });
    
    
      $(btnid).addEvent('click', function()
        { 
          if (IsPublicationSearch)
          {
            $(btnid).setProperty('href','/What_We_Think/Publications/Search/?q=' + encodeURIComponent($(txtid).value));
          }
          else
          {
            $(btnid).setProperty('href','/Search/?q=' + encodeURIComponent($(txtid).value));
          }
          
          return true;
        });
    });
}

window.addEvent("domready", function()
{
  if (window.ie6)
  {
    var divs_body = $$("div.Fifty_25_50_25");
    var divs_sidebar = $$("div.twentyFiveTwo_25_50_25");
    if ((divs_body.length == 1) && (divs_sidebar.length == 1))
    {
      if (divs_sidebar[0].getSize().size.y > divs_body[0].getSize().size.y)
      {
        divs_body[0].setStyle("height",divs_sidebar[0].getSize().size.y + "px");
      }  
    }
  }
});

function LoadPublicationsFulLViewFilter(lnk, yearddl, secondarytagddl, baseurl)
{
  window.addEvent("domready", function()
  {
    if ($(lnk))
    {
      $(lnk).addEvent("click", function()
      {
        var url = baseurl;
        
        if ($(yearddl) && $(secondarytagddl))
        {
          url += $(yearddl).value;

          if ($(secondarytagddl).value != "")
          {
            url += ($(yearddl).value != "") ? "-" : "";
            url += $(secondarytagddl).value.replace(/ /,"_");          
          }
          
          if (($(yearddl).value != "") || ($(secondarytagddl).value != ""))
          {
            url += ".aspx";
          }
        }
        else if (($(yearddl)) && ($(yearddl).value != ""))
        {
          url += $(yearddl).value + ".aspx";          
        }
        else if (($(secondarytagddl)) && ($(secondarytagddl).value != ""))
        {
          url += $(secondarytagddl).value.replace(/ /,"_") + ".aspx";
        }
                     
       $(lnk).setAttribute("href", url);
      });
    }
  });
}
