/* Glossary Object */
function Glossary() {
	this.glossaryTerms = getGlossaryTerms();
	this.showTerm = showTerm;
	this.hideTerm = hideTerm;

	function showTerm(termID, termObject) {
		if (thisTerm = this.glossaryTerms[termID]) {
			/* Create the tooltip */
			var termBox = document.createElement('div');
			var posX = 0;
			var posY = 0;
			termBox.id = "cekhGlossaryTerm";
			termBox.className = "glossaryDefinition";
			termBox.innerHTML = thisTerm[1];
			termBox.style.position = "absolute";
			document.body.appendChild(termBox);
			posX = (findPosX(termObject) - (termBox.clientWidth + 2));
			posY = (findPosY(termObject) - (termBox.clientHeight + 2));
			if (posX < 0) posX = 0;
			if (posY < 0) posY = 0;
			termBox.style.left = posX + "px";
			termBox.style.top = posY + "px";

			/* Add mouse out event */
			termObject.onmouseout = glossary.hideTerm;
		}
	}

	function hideTerm() {
		if (thisTerm = document.getElementById('cekhGlossaryTerm')) {
			thisTerm.parentNode.removeChild(thisTerm);
		}
	}
}

function getGlossaryTerms() {
	var glossaryTerms = new Array();

	/* Glossary terms */
	glossaryTerms[0]  = glossaryTerms['Digital'] = new Array('Digital', 'Digital describes electronic technology that generates, stores, and processes data in terms of two states: positive (1) and non-positive (0). Data transmitted or stored with digital technology is expressed as a string of 0\'s and 1\'s.');
	glossaryTerms[1]  = glossaryTerms['Digital Television (DTV)'] = new Array('Digital Television (DTV)', 'Television delivered and displayed using radio frequency waves that contain information that is digitally encoded for improved quality and efficiency.');
	glossaryTerms[2]  = glossaryTerms['Analog TV'] = new Array('Analog TV', 'Traditional TV system using radio frequency waves to transmit and display pictures and sound.');
	glossaryTerms[3]  = glossaryTerms['High-Definition Television (HDTV)'] = new Array('High-Definition Television (HDTV)', 'The best quality digital picture, widescreen (16:9) display with at least 720 progressively scanned lines (720p) or 1080 interlaced lines (1080i) and Dolby Digital surround sound.');
	glossaryTerms[4]  = glossaryTerms['Set-Top Box, Set-Top Tuner'] = new Array('Set-Top Box, Set-Top Tuner', 'These components capture and/or convert analog or digital video signals to be played on a display. Outboard DTV tuners are set-top boxes, as are satellite receivers and receiver boxes from a cable TV provider.');
	glossaryTerms[5]  = glossaryTerms['HD-Ready Set'] = new Array('HD-Ready Set', 'Describes a video display that is capable of displaying high-definition resolutions (i.e. minimum 720p) but requires an external tuner or source to receive and decode HDTV signals.');
	glossaryTerms[6]  = glossaryTerms['Digital Cable Ready (DCR)'] = new Array('Digital Cable Ready (DCR)', 'A DTV or other device for digital cable customers that plugs directly into the cable jack and does not require a separate set-top box.  DCR sets require a CableCARD, obtained from the cable provider, in order to view scrambled programming services.');
	glossaryTerms[7]  = glossaryTerms['Widescreen'] = new Array('Widescreen', 'A wide shape, or aspect ratio, for video pictures or displays. Widescreen usually refers to the 16:9 format that is shaped more like a movie screen than a traditional TV.');
	glossaryTerms[8]  = glossaryTerms['Letterbox'] = new Array('Letterbox', 'A method for displaying widescreen pictures on a traditional (4:3 aspect ratio) TV set where the widescreen image has horizontal black bars above and below the picture.');
	glossaryTerms[9]  = glossaryTerms['Resolution'] = new Array('Resolution', 'The sharpness of a video image.  Usually described as a number followed by a letter (e.g. 720p), it describes how many pixels and/or lines are used to create the picture as well as the scanning method, progressive or interlaced.');
	glossaryTerms[10] = glossaryTerms['Dolby Digital Surround Sound (5.1-channel)'] = new Array('Dolby Digital Surround Sound (5.1-channel)', 'A digital audio format found on many DVDs and HDTV broadcasts that provides up to six discrete channels of audio:  left, right, center, left surround, right surround and a low frequency effects (subwoofer) channel.');
	glossaryTerms[11] = glossaryTerms['HD-DVD and BluRay DVD players'] = new Array('HD-DVD and BluRay DVD players', 'These new formats of DVDs offer HDTV-quality video and high-resolution audio on pre-recorded DVD media.');
	glossaryTerms[12] = glossaryTerms['Aspect ratio'] = new Array('Aspect ratio', 'proportion of the screen\'s width as compared to its height');
	glossaryTerms[13] = glossaryTerms['Digital audio input'] = new Array('Digital audio input', 'An audio connection typically found on A/V receivers and home theater systems that accepts a multi-channel, all-digital audio signal from a source component, like a TV or DVD player.  Digital audio connections are typically either optical (also called TOSLINK) coaxial.  The former uses an infrared light to carry the signal over a specially designed cable, the latter uses a standard twisted pair (RCA-style) cable.');	
	glossaryTerms[14] = glossaryTerms['Digital-VHS (D-VHS)'] = new Array('Digital-VHS (D-VHS)', 'A digital video cassette format that can record and playback high-definition video.');	
	glossaryTerms[15] = glossaryTerms['Integrated HDTV, integrated set'] = new Array('Integrated HDTV, integrated set', 'An HDTV that has a digital tuner built into the set.  It does not need a separate set-top box to receive over-the-air DTV broadcasts.');	
	glossaryTerms[16] = glossaryTerms['Interlaced scan'] = new Array('Interlaced scan', 'The traditional way of producing video pictures for analog TV and also some forms of DTV.  Interlaced scanning draws a video picture in two passes, once for all the odd lines of the picture, then a second time for all the even lines.');	
	glossaryTerms[17] = glossaryTerms['Microdisplay'] = new Array('Microdisplay', 'Utilizes some of the technologies found in flat-panel TVs plus newer, more advanced technologies to provide great picture quality in a fairly thin cabinet.');	
	glossaryTerms[18] = glossaryTerms['Multi-channel amplifier'] = new Array('Multi-channel amplifier', 'A component in a home theater audio system that can amplify the audio signal from a source component (like a HDTV set-top box or DVD player) and power five or more speakers.');	
	glossaryTerms[19] = glossaryTerms['Over-The-Air (OTA)'] = new Array('Over-The-Air (OTA)', 'Method of receiving broadcasts from local stations using an antenna.');	
	glossaryTerms[20] = glossaryTerms['Pixel'] = new Array('Pixel', 'Stands for picture element, the smallest bit of data in a video image.');	
	glossaryTerms[21] = glossaryTerms['Progressive scan'] = new Array('Progressive scan', 'When a video display produces images by scanning all of the lines consecutively.  This method produces smooth, film-like images that are free of the flicker associated with interlaced scanning.');	
	glossaryTerms[22] = glossaryTerms['Subwoofer'] = new Array('Subwoofer', 'A speaker designed specifically to reproduce low bass frequencies.  A typical home theater setup would include five full range “surround” speakers plus a subwoofer to handle bass.');	
	glossaryTerms[23] = glossaryTerms['Two-Way Services'] = new Array('Two-Way Services', 'Refers to cable TV services that require the digital cable tuner to both receive and transmit data for features and services such as remote pay-per-view and video-on-demand.');	
	glossaryTerms[24] = glossaryTerms['Video upconversion'] = new Array('Video upconversion', 'A feature of an A/V receiver that takes all incoming source signals and converts them so that they may all be output via a single high-quality output.');
	glossaryTerms[25] = glossaryTerms['Digital Video Recorder'] = new Array('Digital Video Recorder', 'A device that records video without videotape to a hard drive-based digital storage medium.');
	glossaryTerms[26] = glossaryTerms['Five full-range speakers'] = new Array('Five full-range speakers', 'Four “surround” speakers (mounted in the corners of the room) and a "center" speaker that are specifically designed to deliver a wide range of sound. Including: midrange, highs, vocals, etc.');	
	glossaryTerms[27] = glossaryTerms['A/V receiver'] = new Array('A/V receiver', 'Their primary purpose is to amplify sound from a multitude of possible audio sources as well as route video signals to your TV from various sources. ');		
	return glossaryTerms;
}

/* Find position of DOM object */
/* http://www.quirksmode.org/js/findpos.html */
function findPosX(obj) {
	var curleft = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curleft += obj.offsetLeft;
			obj = obj.offsetParent;
		}
	} else {
		if (obj.x) {
			curleft += obj.x;
		}
	}
	return curleft;
}

function findPosY(obj) {
	var curtop = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curtop += obj.offsetTop;
			obj = obj.offsetParent;
		}
	} else {
		if (obj.y) {
			curtop += obj.y;
		}
	}
	return curtop;
}

glossary = new Glossary();
