/* 
JavaScript Document for BOLI Full Campaign Site
Author: James Nicol, Glossopteris Web Designs, www.glossopteris.com. July 2006
*/

/*----- Behaviour Registers to assign actions to page elements on load -----*/
var campaign_rules = {
	
	'#masthead' : function(el) {
		el.onclick = function() { window.location = baseURL; }	
	}

}

Behaviour.register(campaign_rules);


// ----- 
// Google Site Search code
// -----
function Gsitesearch()
{ 
	document.site_search.q.value="site:"+baseURL+" "+document.site_search.search_text.value; 
}
function submitGsearch() 
{
	document.site_search.q.value="site:"+baseURL+" "+document.site_search.search_text.value; 
	document.site_search.submit();
}
window.onsubmit = function() { Gsitesearch(); }


// ----- 
// Some Scriptaculous effects
// -----
function page_scroll(el)
{
	var ref = el.href.split('#');
	new Effect.ScrollTo(ref[1]);
}


// ----- 
// Stylesheet switcher 
// -----
function set_page_style() 
{
	var cookie = readCookie("style")
	if(cookie||cookie!=null){ setActiveStyleSheet(cookie,'full'); setCookie("style", cookie, 365); }
	else{ setActiveStyleSheet('fixed_small','full'); setCookie("style", 'fixed_small', 365); }
}

function setActiveStyleSheet(title,width) {
	var style_data, style_text;
	if (width!='full'){
		style_data = readCookie("style");
		style_text = style_data.split("_");
		if(width=='text'){ title=style_text[0]+'_'+title; }
		if(width=='width'){ title+='_'+style_text[1]; }
	}
	var i, a, main;
	for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
		if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
		  a.disabled = true;
		  if(a.getAttribute("title") == title){ a.disabled = false; setCookie("style", title, 365); }
		}
	}
}

function getActiveStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
  }
  return null;
}

function getPreferredStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1
       && a.getAttribute("rel").indexOf("alt") == -1
       && a.getAttribute("title")
       ) return a.getAttribute("title");
  }
  return null;
}

//Behaviour.addLoadEvent(set_page_style);
