var domain = 'yoderins';

function setup() {
	// Fixes certain display issues in Opera
	UserAgent = navigator.userAgent;
	if (UserAgent.search(/Opera/) !== -1) {
		document.getElementById('top').style.marginLeft = '2px';
		if (document.body.clientHeight < window.innerHeight) document.body.style.height = window.innerHeight+1+'px';
			foo = (window.innerWidth/2)+'';
			if (foo.charAt(foo.length-2) ==='.') document.getElementById('top').style.marginRight = '2px';
	}
	
	// Makes external links open in new windows
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++) {
		var URL = anchors[i].href;
		URL = URL.substring(0,URL.lastIndexOf('com'));
		if (URL.search(domain)===-1) anchors[i].target = "_blank";
	}
	
	// Sets up all objects affect by the show/hide script
	var els = document.getElementsByTagName('*');
	for (var i=0;i<els.length;i++) {
		if (els[i].className == 'hidden') { toggle(els[i].id,0); }
	}
	setTimeout('opensesame()',20);
}

function swap(foo,bar) {
	swappo = new Array();
	swappo = document.getElementsByTagName('div');
	
	for (i=0 ; i<swappo.length ; i++) {
		if (swappo[i].className === 'swap') {
			swappo[i].style.display = 'none';
			swappo[i].style.position = 'absolute';
		}
	}
	document.getElementById(foo).style.display = 'block';
	document.getElementById(foo).style.position = 'static';
	document.getElementById('content3b').style.background = '#E3EAEA url(../images/bg_content3_' + bar + '.jpg) top left no-repeat';
}

// Form activation script
function activate(brillig) {
	document.getElementById('config').name = "config";
	document.getElementById('config').value = brillig;
}

// Show/hide scripts
function toggle(id,duration,step_duration){
	var el = document.getElementById(id);
	if (!el || !el.style) return;
	if (duration === undefined) duration = 500;
	if (!step_duration) step_duration = 10;
	var steps = Math.max(Math.ceil(duration/step_duration),1);
	if (el.offsetHeight == 0) { //show it
		morph_height(el,0,el.naturalHeight,duration,steps,0);
	} else { //hide it
		el.naturalHeight = el.naturalHeight || el.offsetHeight;
		el.style.overflow = 'hidden';
		morph_height(el,el.offsetHeight,0,duration,steps,0);
	}
}
function morph_height(el,from,to,duration,steps,step) {
	var x = step/steps;
	var y = Math.sin((x-0.5)*Math.PI);
	var z = (y+1)*0.5;
	var h = from + (to-from)*z;
	if (step == steps) h = to;
	el.style.height = h+'px';
	if (h == to) return;
	var t = duration/steps;
	if (el.style.height === '0px') el.style.position = 'static';
	setTimeout(function(){morph_height(el,from,to,duration,steps,step+1)},t);
}
function opensesame() {
	if (document.getElementById('insurance')) toggle('submenu1',0);
}


window.onload = setup;