/* 
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 = {

	'#google_search' : function(el) {
		el.onclick = function() { submitGsearch(); return false; }
	},
	'#explore_campaign a' : function(el) {
		el.onmouseover = function(){ page_link_ul_bg (this, 'highlight'); }
		el.onmouseout = function(){ page_link_ul_bg (this, 'off'); }
	},
	'.page_links' : function(el) {
		el.onclick = function() { page_scroll(el); return false; }
	},
	'#text_large' : function(el) {
		el.onclick = function(){ setActiveStyleSheet('large','text'); return false; }
	},
	'#text_small' : function(el) {
		el.onclick = function(){ setActiveStyleSheet('small','text'); return false; }
	}
}

Behaviour.register(campaign_rules);

/*----- Sons Of Suckerfish Dropdown (applying sfhover class to IE) -----*/
sfHover = function() 
{
	var sfEls = document.getElementById("banner_nav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) 
	{
		sfEls[i].onmouseover=function() { this.className+=" sfhover"; }
		sfEls[i].onmouseout=function() { this.className=this.className.replace(new RegExp(" sfhover\\b"), ""); }
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);


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

/*----- Function to show rollover for right nav bar (cause IE doesnt support li:hover!!!) -----*/
function page_link_ul_bg (element, state)
{
	parent_li = element.parentNode;
	if(state=='highlight'){
		parent_li.style.background = 'url('+domainroot+'images/ul_arrow.gif) no-repeat left';
	}else{
		parent_li.style.background = 'none';
	}
}

/*----- 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);
