var network = 'Your NIC needs to run on a 100Base-T, or Fast Ethernet network and have an RJ-45 connector.<br />Wireless network cards should support the 802.11a/g standard. 802.11n should work on the campus wireless network.<br />See the section on <a href="gettingready-three.html#nic">NIC/Ethernet cards</a> for more information.';
var warranty = '3-year on-site service support with accident damage coverage (4-year is highly recommended).';

$(document).ready(function() {
	$('#old_system').hide();
	
	$.ajaxSetup({
		cache: false
	});
	getDepartmentList();
	getDepartment(1);
});

// AJAX Requests
function getDepartmentList() {
	$.getJSON("../php/public_specs.php", { action: 'listDepartments' }, updateDepartmentList);
}

function getDepartment(deptId) {
	$.getJSON("../php/public_specs.php", { action: 'getSpec', id: deptId }, updateSpec);
}

// AJAX Response Handlers
function updateDepartmentList(list, textStatus) {
	columns = [];
	columns[0] = "specs_column1";
	columns[1] = "specs_column2";
	columns[2] = "specs_column3";
	
	columnLength = (list.length / columns.length) | 0;		// Use bitwise OR to cast as integer
	columnRemainder = (list.length % columns.length);
	
	columnLengths = [];
	for (i = 0; i < columns.length; i++) {
		columnLengths[i] = columnLength;
		if (columnRemainder > 0) {
			columnLengths[i]++;
			columnRemainder--;
		}
	}
	
	// Column 1	
	for (i = 0; i < columnLengths[0]; i++) {
		link = "<li><a href=\"#\" onclick=\"javascript: getDepartment(" + 
			list[i].deptId + "); $.scrollTo( '.deptName', 800 ); return false;\">" + list[i].deptName + "</a></li>";
		$("#specs_column1").append(link);
	}
	
	// Column 2
	for (i = columnLengths[0]; i < (columnLengths[1] + columnLengths[0]); i++) {
		link = "<li><a href=\"#\" onclick=\"javascript: getDepartment(" + 
			list[i].deptId + "); $.scrollTo( '.deptName', 800 ); return false;\">" + list[i].deptName + "</a></li>";
		$("#specs_column2").append(link);
	}
	
	// Column 3
	for (i = (columnLengths[1] + columnLengths[0]); i < (columnLengths[2] + columnLengths[1] + columnLengths[0]); i++) {
		link = "<li><a href=\"#\" onclick=\"javascript: getDepartment(" + 
			list[i].deptId + "); $.scrollTo( '.deptName', 800 ); return false; \">" + list[i].deptName + "</a></li>";
		$("#specs_column3").append(link);
	}
}

function updateSpec(spec, textStatus) {		
	// Show appropriate table
	if (spec.platform == 'PC') {
		$('#new_system td.PC').show();
		$('#new_system td.Mac').hide();
	}
	else if (spec.platform == 'Mac') {
		$('#new_system td.PC').hide();
		$('#new_system td.Mac').show();
	}
	else if (spec.platform == 'Either') {
		$('#new_system td.PC').show();
		$('#new_system td.Mac').show();
	}
	else {
		alert('Error: Platform isn\'t set');
	}
	
	if (spec.platform == 'PC')
		spec.platform = 'PC';
	
	spec.network = network;
	spec.warranty = warranty;
	
	// Fill the page with values
	for (key in spec) {
		$('#spec .' + key).html("<span>" + spec[key] + "</span>");
	}
	
	if (spec.platform == 'Either') {
		$('.platform').each(function(index, platform) {
			if ($(platform).hasClass('PC'))
				$(platform).html('PC');
			else if ($(platform).hasClass('Mac'))
				$(platform).html('Mac');
		});
	}
	
	// Show the new screen by default
	// selectTab('newTab');

}