
/*
	The INT3R.workingz
	
	Written by Senior Designer
		- Seth Van Booven [svanbooven@sacbee.com]
	
	Copyright © The Sacramento Bee
	Created: May 21, 2004 (sv)  /  Last update: 05/21/04 (sv)
	
	****************************************************
		IF YOU DON'T KNOW WHAT YOU ARE DOING
		THEN YOU DON'T BELONG HERE.
		.........................CLOSE IMMEDIATELY!
	****************************************************
------------------------------------------------------------*/

/*
	Init Vars
----------------------------------------*/

var baseRef = 'http://www.sacbee.com/static/live/news/projects/pineros/';

var href = location.href;
var loc = href.substring(href.lastIndexOf("/") + 2, href.length);
loc = (loc.indexOf(".html") > -1) ? loc.substring(0, loc.length - 5) : loc;
var sec = (loc == "ndex") ? 0 : (loc > 5) ? 100 : loc.substring(0, 1);
var pge = (loc.indexOf("_") > -1) ? loc.substring(loc.indexOf("_") + 1) : 0;

/*
	Pop Up Window
----------------------------------------*/

function popWin(url, winName, w, h, scroll) {
	var sw = screen.width;
	var sh = screen.height;
	var cx = ( .5 * sw ) - ( w * .5 );
	var cy = ( .5 * sh ) - ( h * .5 );
	var values = 'toolbar=no,status=yes,menubar=no,scrollbars=' + scroll + ',resizable=yes,screenX=' + cx + ',screenY=' + cy + ',left=' + cx + ',top=' + cy + ',width=' + w + ',height=' + h + '';
	child = window.open(url, winName, values);
}

function popGallery(n, s, ss, p) {
	var qs = '';
	if (n != null) qs += "&n=" + n;
	if (s != null) qs += "&s=" + s;
	if (ss != null) qs += "&ss=" + ss;
	if (p != null) qs += "&p=" + p;
	popWin(baseRef + 'gallery.html?' + qs, '', 720, 450, 1);
}

/*
	Misc Functions
----------------------------------------*/

function do_onchange() {
	var o = (document.getElementById) ? document.getElementById('snav') : null;
	if (!o) return;
	var t = o.getElementsByTagName('select');
	t[0].onchange = function() {
		var u = this.options[this.selectedIndex].value;
		if (u != '') {
			var ju = (u.indexOf(baseRef > 0)) ? u : baseRef + u; 
			location.href = ju;
		}
	};
}

function do_onclick() {
	if (!document.getElementsByTagName) return;
	var refs = document.getElementsByTagName('a');
	for (var i = 0; i < refs.length; i++) {
		if (refs[i].className.indexOf('popWin_') > -1) {
			refs[i].onclick = function() {
				var p = this.className.substring(7).split('x');
				popWin(this, 'pop', p[0], p[1], 1);
				return false;
			};
		}
		if (refs[i].className.indexOf('popGallery_') > -1) {
			refs[i].onclick = function() {
				var p = this.className.substring(11).split('_');
				p[0] = (p[0] == 'n') ? null : p[0];
				p[1] = (p[1] == 'n') ? null : p[1];
				p[2] = (p[2] == 'n') ? null : p[2];
				p[3] = (p[3] == 'n') ? null : p[3];
				popGallery(p[0], p[1], p[2], p[3]);
				return false;
			};
		}
		if (refs[i].className == 'bookmark') {
			refs[i].onclick = function() {
				bookmark('http://www.sacbee.com/pineros', 'Sacbee - The Pineros');
				return false;
			};
		}
	}
}

function togAudio() {
	var o = (document.getElementById) ? document.getElementById('a1') : null;
	if (!o) return;
	o.onclick = function() {
		this.innerHTML = (this.innerHTML == 'View transcript') ? 'Close transcript' : 'View transcript';
		var o2 = document.getElementById('a2');
		if (!o2) return;
		o2.style.display = (o2.style.display == 'block') ? 'none' : 'block';
		return false;
	};
}

function getTextVer() {
	var u = location.href;
	var f = u.substring(u.lastIndexOf('/') + 1, u.lastIndexOf('.'));
	location.href = baseRef + 'text.html#' + f;
}

function backToTop() {
	window.scrollTo(0, 0);
}

function bookmark(url, title) {
	if (window.external) {
		window.external.AddFavorite(url, title);
	}
	else {
		alert('To bookmark the ' + title + ' site, press the CTRL (or Command) and D keys.');
	} 
}

function nixErr() { 
	return true; 
}

window.onerror = nixErr;

/*
	Global Initialize
		- Anything that uses an 
			onload event needs to be 
			defined here.
----------------------------------------*/

function gInit() {
	do_onclick();
	do_onchange();
	togAudio();
}

window.onload = gInit; // global onload
