var check = 0;

// This function shifts the backgrounds behind the site navigation.
function navShift(foo) {
	if (foo === '') {
		if (document.getElementById('newsSection')) navShift('3954');
		else if (document.getElementById('findSection')) navShift('3295');
		else if (document.getElementById('blogSection')) navShift('2636');
		else if (document.getElementById('magazineSection')) navShift('1977');
		else if (document.getElementById('tvSection')) navShift('1318');
		else if (document.getElementById('resellerSection')) navShift('659');
		else navShift('0')
	} else {
		document.getElementById('nav3').style.background = 'url(images/bg_nav3.gif) ' + foo + 'px 0';
	}
}

// These functions open and close the boxes at the top of the page
function toggleTop(foo) {
	closeMe();
	document.getElementById(foo).style.display = 'block';
}

function closeMe(foo) {
	var topBoxes;
	topBoxes = document.getElementsByTagName('div');
	for (i=0 ; i<topBoxes.length ; i++) {
		if (topBoxes[i].className === 'topBox') topBoxes[i].style.display = 'none';
	}
}

// This function compares specific containers and ensures they appear to be the same height.
function setup() {
	var colHeight1
	var colHeight2
	
	if (document.getElementById('compare1-1') && document.getElementById('compare1-2') && document.getElementById('compare1-3')) {
		colHeight1 = document.getElementById('compare1-1').offsetHeight;
		colHeight2 = document.getElementById('compare1-3').offsetHeight;
		if (colHeight1 < colHeight2) {
			document.getElementById('compare1-2').style.height = (document.getElementById('compare1-2').offsetHeight + (colHeight2-colHeight1))-12 + 'px';
		} else if (colHeight1 > colHeight2) {
			document.getElementById('compare1-4').style.height = (document.getElementById('compare1-4').offsetHeight + (colHeight1-colHeight2))-12 + 'px';
		}
	}
	
	if (document.getElementById('compare2-1') && document.getElementById('compare2-2')) {
		colHeight1 = document.getElementById('compare2-1').offsetHeight;
		colHeight2 = document.getElementById('compare2-2').offsetHeight;
		if (colHeight1 < colHeight2) {
			document.getElementById('compare2-1').style.height = (document.getElementById('compare2-1').offsetHeight + (colHeight2-colHeight1))-12 + 'px';
		} else if (colHeight1 > colHeight2) {
			document.getElementById('compare2-2').style.height = (document.getElementById('compare2-2').offsetHeight + (colHeight1-colHeight2))-12 + 'px';
		}
	}
	
	if (document.getElementById('compare3-1') && document.getElementById('compare3-2')) {
		colHeight1 = document.getElementById('compare3-1').offsetHeight;
		colHeight2 = document.getElementById('compare3-2').offsetHeight;
		if (colHeight1 < colHeight2) {
			document.getElementById('compare3-1').style.height = (document.getElementById('compare3-1').offsetHeight + (colHeight2-colHeight1))-14 + 'px';
		} else if (colHeight1 > colHeight2) {
			document.getElementById('compare3-2').style.height = (document.getElementById('compare3-2').offsetHeight + (colHeight1-colHeight2))-14 + 'px';
		}
	}
	
	if (document.getElementById('compare4-1') && document.getElementById('compare4-2') && document.getElementById('compare4-3')) {
		colHeight1 = document.getElementById('compare4-1').offsetHeight + document.getElementById('compare4-2').offsetHeight + document.getElementById('prenav3').offsetHeight;
		colHeight2 = document.getElementById('sidebar').offsetHeight;
		if (colHeight1 < colHeight2) {
			document.getElementById('compare4-3').style.height = (document.getElementById('compare4-3').offsetHeight + (colHeight2-colHeight1))-28 + 'px';
			document.getElementById('content').style.background = 'url(images/bg_content1Bottom.gif) bottom left no-repeat';
			document.getElementById('compare4-3').style.background = 'none';
		} else if (colHeight1 > colHeight2) {
			document.getElementById('sidebar').style.height = (document.getElementById('sidebar').offsetHeight + (colHeight1-colHeight2))-30 + 'px';
			document.getElementById('content').style.background = 'url(images/bg_content1Bottom.gif) bottom left no-repeat';
			document.getElementById('compare4-3').style.background = 'none';
		}
	}
	
	var els = document.getElementsByTagName('*');
	/*
	for (var i=0;i<els.length;i++) {
		if (els[i].className == 'hidden') { toggle(els[i].id,0); }
		if (els[i].className == 'toggle') els[i].style.display = 'block';
	}
	*/
	
	navShift('');
}

function switchBox(foo) {
	if (foo === '1') {
		document.getElementById('switchBox1').style.display = 'block';
		document.getElementById('switchBox2').style.display = 'none';
		document.getElementById('switch1').childNodes[0].className = 'down';
		document.getElementById('switch2').childNodes[0].className = 'up';
	} else {
		document.getElementById('switchBox1').style.display = 'none';
		document.getElementById('switchBox2').style.display = 'block';
		document.getElementById('switch1').childNodes[0].className = 'up';
		document.getElementById('switch2').childNodes[0].className = 'down';
	}
}

// This function allows visitors to swap between video boxes.  It affects #switchBox.
/*
function pretoggle(id,duration,step_duration) {
	toggle(id,duration,step_duration);
}
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
		el.naturalHeight = el.naturalHeight || el.offsetHeight;
		el.style.overflow = 'hidden';
		morph_height(el,el.offsetHeight,0,duration,steps,0);
		check = 0;
	} else { //hide it
		morph_height(el,0,el.naturalHeight,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.offsetHeight == 0 && check == 0) {
		if (el === document.getElementById('switchBox1')) {
			alert('1');
			el.display = 'none';
			trans('switchBox2');
		}
		else if (el === document.getElementById('switchBox2')) {
			alert('2');
			el.display = 'none';
			trans('switchBox1');
		}
	}
	setTimeout(function(){morph_height(el,from,to,duration,steps,step+1)},t);
}

function trans(foo) {
	check = 1;
	toggle(foo,500);
	document.getElementById(foo).style.display = 'block';
}
*/

window.onload=setup;