/* 
JavaScript Document for www.fishbol.org
Author: James Nicol, Glossopteris Web Designs, www.glossopteris.com. December 2005
*/

/*----- Behaviour Registers to assign actions to page elements on load -----*/
var fishbol_rules = {
	'#google_search' : function(el) {
		el.onclick = function() { submitGsearch(); return false; }
	},
	'#text_large' : function(el) {
		el.onmouseover = function(){ MM_swapImage('text_large','','images/style_switch_btns/text_size_btn_large_hover.jpg',1); }
		el.onmouseout = function(){ MM_swapImgRestore(); }
		el.onclick = function(){ setActiveStyleSheet('large','text'); return false; }
	},
	'#text_small' : function(el) {
		el.onmouseover = function(){ MM_swapImage('text_small','','images/style_switch_btns/text_size_btn_med_hover.jpg',1); }
		el.onmouseout = function(){ MM_swapImgRestore(); }
		el.onclick = function(){ setActiveStyleSheet('small','text'); return false; }
	},
	'#width_fixed' : function(el) {
		el.onmouseover = function(){ MM_swapImage('width_fixed','','images/style_switch_btns/width_btn_fixed_hover.jpg',1); }
		el.onmouseout = function(){ MM_swapImgRestore(); }
		el.onclick = function(){ setActiveStyleSheet('fixed','width'); return false; }
	},
	'#width_total' : function(el) {
		el.onmouseover = function(){ MM_swapImage('width_total','','images/style_switch_btns/width_btn_total_hover.jpg',1); }
		el.onmouseout = function(){ MM_swapImgRestore(); }
		el.onclick = function(){ setActiveStyleSheet('total','width'); return false; }
	},
	'#icon_contact' : function(el) {
		el.onmouseover = function(){ MM_swapImage('icon_contact','','images/style_switch_btns/contact_icon_hover.jpg',1); }
		el.onmouseout = function(){ MM_swapImgRestore(); }
		el.onclick = function(){ showcontactpage(); return false; }
	},
	'#page_links a' : function(el) {
		el.onmouseover = function(){ page_link_ul_bg (this, 'highlight'); }
		el.onmouseout = function(){ page_link_ul_bg (this, 'off'); }
	},
	'#page_search' : function(el){
		el.onclick = function(){ page_search(); return false; }
	},
	'.st_submit' : function(el){
		el.onclick = function(){ $('st_progress').style.display = 'inline'; }
	}
}
	
/*----- Google Site Search code -----*/
var domainroot="www.fishbol.org"

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();
}

/*----- Page Search functions -----*/
function page_search() {
	document.stream_search.submit();
}

/*------ Image preloader -----*/
function preload_images () {

	MM_preloadImages(	
					 	'images/minus_icon.gif',
						'images/page_links_bullet.gif'					 
					 )

}

/*----- 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(images/page_links_bullet.gif) no-repeat left';
	}else{
		parent_li.style.background = 'none';
	}

}

/*----- 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.register(fishbol_rules);
Behaviour.addLoadEvent(set_page_style);
Behaviour.addLoadEvent(preload_images);

