function init() {
  if (arguments.callee.done) return;
  arguments.callee.done = true;
  if (_timer) clearInterval(_timer);
  
  //if($('section_1'))
   // homepage.setupNewsAndAction();
  if($('container'))
    textSize.init();
  if($('standard_view') && $('high_contrast_view'))
    contrast.init();
}

var contrast = {
  init: function() {
    $('standard_view').onclick = function() { contrast.standard(); }
    $('high_contrast_view').onclick = function() { contrast.high(); }
    
    
    if(readCookie('contrast') == 'high_contrast') {
      document.getElementsByTagName('body')[0].id = 'high_contrast';
      contrast.setActiveStyle('high_contrast_view');
    }
  },
  high: function() {
    document.getElementsByTagName('body')[0].id = 'high_contrast';
    contrast.setActiveStyle('high_contrast_view');
    contrast.saveSelection('high_contrast');
  },
  standard: function() {
    document.getElementsByTagName('body')[0].id = '';
    contrast.setActiveStyle('standard_view');
    contrast.saveSelection('standard');    
  },
  setActiveStyle: function(linkID) {
    var standardView     = $('standard_view');
    var highContrastView = $('high_contrast_view');
    var activeLink       = $(linkID);
    
    standardView.style.fontWeight = 'normal';
    highContrastView.style.fontWeight   = 'normal';
    activeLink.style.fontWeight = 'bold';
  },
  saveSelection: function(style) {
    createCookie('contrast', style, 14);
  }
};

var textSize = {
  small:  '62.5%',
  medium: '75.0%',
  large:  '85.0%',
  
  init: function() {
    var small_text  = $('small_text');
    var medium_text = $('medium_text');
    var large_text  = $('large_text');
    var container   = $('container');
    
    var textSizeCookie     = readCookie('textSize');
    var textSizeCookieName = readCookie('textSizeName');
    if(textSizeCookie && textSizeCookieName) {
      container.style.fontSize = textSizeCookie;
      textSize.resetClassNames();
      eval(textSizeCookieName + '_text').className = 'current';
    }
    
    small_text.onclick = function() {
      textSize.resetClassNames();
      this.className = 'current';
      createCookie('textSize', textSize.small, 14);
      createCookie('textSizeName', 'small', 14);
      container.style.fontSize = textSize.small;
	  $('header').style.fontSize = '11px';
    }
    medium_text.onclick = function() {
      textSize.resetClassNames();
      this.className = 'current';
      createCookie('textSize', textSize.medium, 14);
      createCookie('textSizeName', 'medium', 14);
      container.style.fontSize = textSize.medium;
	  $('header').style.fontSize = '11px';
    }
    large_text.onclick = function() {
      textSize.resetClassNames();
      this.className = 'current';
      createCookie('textSize', textSize.large, 14);
      createCookie('textSizeName', 'large', 14);
      container.style.fontSize = textSize.large;
	  $('header').style.fontSize = '11px';
    }
  },
  
  resetClassNames: function() {
    $('small_text').className  = '';
    $('medium_text').className = '';
    $('large_text').className  = '';
  }
};

var homepage = {
  
  setupNewsAndAction: function() {
    homepage.hideAllSections();
    $('section_1').style.display = 'block';
    $('section_navigation').getElementsByTagName('a')[0].className = 'current';

    var tabs = $('section_navigation').getElementsByTagName('a');
    for(var i=0; i<tabs.length; i++) {
      tabs[i].onclick = function() {
        homepage.resetTabClasses();
        homepage.setToCurrentTab(this);
        homepage.switchSection(this.href);
        return false;
      }
    }    
  },
  
  resetTabClasses: function() {
    var tabs = $('section_navigation').getElementsByTagName('a');
    for(var i=0; i<tabs.length; i++) {
      if(tabs[i].className == 'last' || tabs[i].className == 'current last') {
        tabs[i].className = 'last';
      }
      else {
        tabs[i].className = ''; 
      }
    }
  },
  
  hideAllSections: function() {
    $('section_1').style.display = 'none';
    $('section_2').style.display = 'none';
    $('section_3').style.display = 'none';
  },
  
  setToCurrentTab: function(link) {
    if(link.className == 'last')
      link.className = 'current last';
    else
      link.className = 'current';
  },
  
  switchSection: function(href) {
    homepage.hideAllSections();
    if(href.indexOf('#') > -1) {
      var element = href.substring(href.indexOf('#') + 1);
      $(element).style.display = 'block';
    }
  }
};

function $(element_id) {
  var element = document.getElementById(element_id);
  return (element == null) ? (false) : (element);
}


function createCookie(name, value, days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime() + (days*24*60*60*1000));
    var expires = '; expires=' + date.toGMTString();
  }
  else var expires = '';
  document.cookie = name + '=' + value + expires + '; path=/';
}

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}

function eraseCookie(name) {
  createCookie(name, '', -1);
}


if (document.addEventListener) {
  document.addEventListener("DOMContentLoaded", init, false);
}
/* for Internet Explorer */
/*@cc_on @*/
/*@if (@_win32)
  document.write("<script id=__ie_onload defer src=javascript:void(0)><\/script>");
  var script = document.getElementById("__ie_onload");
  script.onreadystatechange = function() {
    if (this.readyState == "complete") {
      init(); // call the onload handler
    }
  };
/*@end @*/
/* for Safari */
if (/WebKit/i.test(navigator.userAgent)) { // sniff
  var _timer = setInterval(function() {
    if (/loaded|complete/.test(document.readyState)) {
      init(); // call the onload handler
    }
  }, 10);
}
/* for other browsers */
window.onload = init;


function showHide(anc, id)
	{
		element = document.getElementById(id);	
		anchorText = anc.innerHTML;
		if(element.style.display=='none' || element.style.display=='')
		{
			document.getElementById(id).style.display = 'block';
			anc.innerHTML = anchorText.replace('Show', 'Hide');
		}
		else
		{
			document.getElementById(id).style.display = 'none';
			anc.innerHTML = anchorText.replace('Hide', 'Show');
		}
		//return false;
	}

function showHideAll(anc, id)
{
	if(document.getElementById(anc[0]).innerHTML == 'Hide all publications')
	{
		if(isArray(id))
		{
				
			
			for(var x=0; x<id.length; x++)
			{
				element = document.getElementById(id[x]);	
				document.getElementById(id[x]).style.display = 'none';
						
			}
		if(isArray(anc))
				{
					for(var y=0; y<anc.length; y++)
					{
						anchorText = document.getElementById(anc[y]).innerHTML;
						document.getElementById(anc[y]).innerHTML = anchorText.replace('Hide', 'Show');
					}
				} 
				else
				{
					anchorText = anc.innerHTML;
					anc.innerHTML = anchorText.replace('Hide', 'Show');
				}	
			
		}
	}
	else
	{
		if(isArray(id))
		{
			for(var x=0; x<id.length; x++)
			{
				//alert('ID is Array and x value is '+x);
				//alert('Lenght of ID array is ' +id.length)
				element = document.getElementById(id[x]);	
				document.getElementById(id[x]).style.display = 'block';
				
			}
		}
		
		if(isArray(anc))
				{
					for(var y=0; y<anc.length; y++)
					{
						//alert('Anc is Array and y value is '+y);
						//alert('Lenght of Anc array is ' +anc.length)
						anchorText = document.getElementById(anc[y]).innerHTML;
						document.getElementById(anc[y]).innerHTML = anchorText.replace('Show', 'Hide');
					}
				} 
				else
				{
					//alert('Anc is not an Array');
					anchorText = anc.innerHTML;
					anc.innerHTML = anchorText.replace('Show', 'Hide');
				}
				//alert('showing');
	}
}


function isArray(obj) {
   if (obj.constructor.toString().indexOf("Array") == -1)
      return false;
   else
      return true;
}

/*
	function showHideAll(anchor, id)
	{
		element = document.getElementById(id);	
		anchorText = anchor.innerHTML;
		
		
		if(element.style.display=='none' || element.style.display=='')
		{
			document.getElementById(id).style.display = 'block';
			anchor.innerHTML = anchorText.replace('Show', 'Hide');
			//alert('showing');
		}
		else
		{
			document.getElementById(id).style.display = 'none';
			anchor.innerHTML = anchorText.replace('Hide', 'Show');
			//alert('hiding');
		}
		//return false;
	}
	*/
