/*
JavaScript Document for Signup America, signup.mittromney.com
Author: James Nicol, www.enilsson.com, April, 2007
 */
 
 var Site = {
	 	 
	 // initialisation function
	 start : function(){
		Site.behaviour();
		Site.preload();
	},
	// preload images
	preload : function() {
		imgs = new Array;
		imgs = [];
		imgs.each(function(b)
		{
			new_img = document.createElement('img');
			new_img.src = baseURL + b;
		});		
		
		//var objMyImg = null;
		//objMyImg = new OpacityObject('boli_logo','images/boli_corner_logo-trans');
		//objMyImg.setBackground();

			
	},
	// apply behaviours to elements via CSS selectors	
	behaviour : function() {
		if ($('sameaddress') != null) {
			$('sameaddress').onchange = function() {
				if (this.checked) {
					$('mail_address').value = $('address').value;						
					$('mail_address2').value = $('address2').value;						
					$('mail_address3').value = $('address3').value;						
					$('mail_city').value = $('city').value;						
					$('mail_state').value = $('state').value;						
					$('mail_country').value = $('country').value;						
					$('mail_postalcode').value = $('postalcode').value;						
				}
			}
		}
		
		if ($('address')) 
		{
			$('address').onkeyup = function() {
				if ($('sameaddress').checked) {
					$('mail_address').value = this.value;
				}
			}
		}
		
		if ($('address2')) 
		{
			$('address2').onkeyup = function() {
				if ($('sameaddress').checked) {
					$('mail_address2').value = this.value;
				}
			}
		}
		
		if ($('address3')) 
		{
			$('address3').onkeyup = function() {
				if ($('sameaddress').checked) {
					$('mail_address3').value = this.value;
				}
			}
		}
		
		if ($('address')) 
		{
			$('city').onkeyup = function() {
				if ($('sameaddress').checked) {
					$('mail_city').value = this.value;
				}
			}
		}
		
		if ($('state')) 
		{
			$('state').onkeyup = function() {
				if ($('sameaddress').checked) {
					$('mail_state').value = this.value;
				}
			}
		}
		
		if ($('country')) 
		{
			$('country').onkeyup = function() {
				if ($('sameaddress').checked) {
					$('mail_country').value = this.value;
				}
			}
		}
		
		if ($('postalcode')) 
		{
			$('postalcode').onkeyup = function() {
				if ($('sameaddress').checked) {
					$('mail_postalcode').value = this.value;
				}
			}
		}
		//  flash the error/success messages	
		$$('p.fail_message','p.success_message').each(function(el) { Effect.Pulsate(el, { duration: 2.0, from:0.2 }); });
		// highlight the active form input
		$$('input.form_input','textarea').each(function(el)
		{
			el.onfocus = function() { new Effect.Highlight(el, {startcolor:'#FFFFFF', endcolor:'#FFFF99', restorecolor:'#FFFF99'}); }
			el.onblur = function() {  new Effect.Highlight(el, {startcolor:'#FFFF99', endcolor:'#FFFFFF', restorecolor:'#FFFFFF'}); }
		});
		// Blind the news feeds
		$$('div#boli_logo').each(function(el,i){
			el.onclick = function() { window.location = ('http://www.dnabarcodes.org'); }
		});
		$$('div.news_item a').each(function(el,i){
			el.onmouseover = function() {
				var top = el.offsetTop;
				var desc = $('desc_' + i);
				if(desc.style.display == 'none'){ 
					desc.style.top = (top + 20) + 'px';
					desc.style.left = '10px';
					new Effect.Appear(desc, { duration: 0.5 });
				}				
			}
		});
		$$('div.news_item', 'div#news_feed').each(function(el,i){
			el.onmouseout = function() { 
				$$('div.news_desc').each(function(el){ el.hide(); }) 
			}
		});
		
		//NK

		$$("a#i_am_a_human").each(function(el,i) {
			el.onclick = function () {
				var form = $("auto_form");
				var action = form.action;
				
				action = action.replace("/inst/", "/institution/");
				action = action.replace("/coll/", "/collection/");
				
				form.action = action;
				
				$("i_am_a_human_container").remove();
				
				return false;
			}
		});
	}
	
		
 }
 
 Event.observe(window, 'load', Site.start ); 
 


/**
 * Scroll Effect for Script.aculo.us
 * Created by Lucas van Dijk
 * http://www.lucasvd.nl
 *
 * Copyright 2007 by Lucas van Dijk
 */
 
Effect.ScrollVertical = Class.create();
Object.extend(Object.extend(Effect.ScrollVertical.prototype, Effect.Base.prototype), 
{
    initialize: function(element){
        if(typeof element == "string") {        
            this.element = $(element);
            if(!this.element){ throw(Effect._elementDoesNotExistError); }
        }
        var options = Object.extend({
            from: this.element.scrollTop || 0,
            to:   this.element.offsetHeight
        }, arguments[1] || {});
        this.start(options);
    },
    update: function(position) {
        this.element.scrollTop = position;
    }
});

Effect.ScrollHorizontal = Class.create();
Object.extend(Object.extend(Effect.ScrollHorizontal.prototype, Effect.Base.prototype), 
{
    initialize: function(element){
        if(typeof element == "string"){        
            this.element = $(element);
            if(!this.element){ throw(Effect._elementDoesNotExistError); }
        }
        var options = Object.extend({
            from: this.element.scrollLeft || 0,
            to:   this.element.offsetWidth
        }, arguments[1] || {});
        this.start(options);
    },
    update: function(position){
        this.element.scrollLeft = position;
    }
});

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


function deleteRecord(url) {
	if (!confirm('Are you sure you want to delete this item?')) 
		return;
	location.href = url;
}

