// JavaScript document for Barcode of Life:: Case Studies
// Author: James Nicol, Glossopteris Web Design & Development, May 2006

/*----- Behaviour Registers to assign actions to page elements on load -----*/
var case_study_rules = {
	
	'input' : function(el) {
		el.onfocus = function() { new Effect.Highlight(el, {startcolor:'#FFFFFF', endcolor:'#F6FFCB', restorecolor:'#F6FFCB'}); }
		el.onblur = function() { el.style.background = '#FFFFFF'; }
	},
	'#page_links a' : function(el) {
		el.onclick = function() { 
			var ref = el.href.split('#'); new Effect.ScrollTo(ref[1]); return false;
		}
	},
	'.top_link a' : function(el) {
		el.onclick = function() {
			var ref = el.href.split('#'); new Effect.ScrollTo(ref[1]); return false;
		}
	},
	'a.sc_major' :  function(el) {
		el.onclick = function() {
			show_search_categories(el); return false;
		}
	},
	'a.sc_minor' :  function(el) {
		el.onclick = function() {
			show_search_categories(el); return false;
		}
	},
	'#boli_logo' : function(el) {
		el.onclick = function(){ window.location = 'http://www.dnabarcodes.org'; }
	},
	'#explore_campaign a' : function(el) {
		el.onmouseover = function(){ page_link_ul_bg (this, 'highlight'); }
		el.onmouseout = function(){ page_link_ul_bg (this, 'off'); }
	},
	'#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(case_study_rules);

function show_search_categories(element) 
{
	var elmt = element.parentNode.firstChild.nextSibling.nextSibling.id;
	if($(elmt).style.display == 'none') {
		new Effect.BlindDown(elmt, {duration: 0.5});
		element.style.background = 'url(' + domainroot + 'images/li_bullet_down.gif) no-repeat left';
	}else{
		new Effect.BlindUp(elmt, {duration: 0.5});
		element.style.background = 'url(' + domainroot + 'images/li_bullet_side.gif) no-repeat left';
	}
}

function hide_search_categories ()
{
	var nav = document.getElementById("search_categories");
	if(!nav){ return; }
	var links = nav.getElementsByTagName("ul");
	for (var i=0; i<links.length; i++){
		links[i].style.display = 'none';
	}
}

Behaviour.addLoadEvent(hide_search_categories);

/*----- Code for Inserting pngs into IE (sigh.....) -----*/
var objMyImg = null;

function opacity_fix() 
{
	objMyImg = new OpacityObject('boli_logo',domainroot+'images/boli_corner_logo_med');
	objMyImg.setBackground();
}

Behaviour.addLoadEvent(opacity_fix);

/*----- 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_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.addLoadEvent(set_page_style);