// JavaScript Document




/* Javascript for tabs */

	/*function to show the hover state of the tab */	
function hoverTab(targetID) {
	
	tab = document.getElementById(targetID);
	if (tab.className != "current_tab")	tab.style.background = "url(/graphics/machines/tabs/background_hover.gif) no-repeat";
}


	/* function to display the tab as a regular tab */
function regTab(targetID) {
	tab = document.getElementById(targetID);
	if (tab.className != "current_tab")	tab.style.background = "url(/graphics/machines/tabs/background.gif) no-repeat";
}


	/* function to display the appropriate tab and hide the rest */	
function goToSection(targetID) {
	//clear video source
	if(document.getElementById('mediaVideo') != null)
	{
		document.getElementById('mediaVideo').innerHTML = '<a href="javascript:;" onclick="document.getElementById(\'videoLink\').click();">Click here to launch video</a>';
	}
	for (var i = 0; i < theSections.length; i++ ) {
		secID = theSections[i];
		
		if (content = document.getElementById(secID)) {
			if ( secID == targetID.substr(4) ) {
				content.style.display = "block";
				if ( tab = document.getElementById("tab_" + secID) ) {
					tab.style.fontWeight = "bold";
					tab.className = "current_tab";
					tab.style.background = "url(/graphics/machines/tabs/background_current.gif) no-repeat";
				} else if ( btn = document.getElementById("btn_" + secID) ) {
					btn.onmouseover = "";
					btn.onmouseout = "";
					btn.src = "/graphics/machines/btn_" + secID + "_sel.gif";
				}

			} else {
				content.style.display = "none";
				if ( tab = document.getElementById("tab_" + secID) ) {			
					tab.style.fontWeight = "normal";
					tab.className = "";
					tab.style.background = "url(/graphics/machines/tabs/background.gif) no-repeat";
				} else if ( btn = document.getElementById("btn_" + secID) ) {
					btn.onmouseover = "this.src='/graphics/machines/btn_" + secID + "_on.gif'";
					btn.onmouseout = "this.src='/graphics/machines/btn_" + secID + ".gif'";
					btn.src = "/graphics/machines/btn_" + secID + ".gif";
				}
			}
		};
	}
	return false;
}



/* Accessory functions */
/*
function updateAccessorySelect(filterID) {
	filterAccessories(this.document.AccessoryForm.accessoryid,allAccessories,filterID,selectedID);
}
*/

function updateAccessoryDisplay(accID) {
	
}

	/* function for automatically updating the dropdown */
function filterAccessories(selectObj,allOptions,filterID,selectedID) {
    var index=0;
    // Clear the select list so nothing is displayed
    selectObj.options.length = 0;
	selectObj.options[index++] = new Option("Select an Accessory", "0");
    for (var loop=0; loop < allOptions.length; loop++) {

		// This is the option that we're currently testing
		var optionInfo = allOptions[loop];

		var id = filterID;
		var inFilter = false;

		//check to see if the option is in the filterList or we if we are not filtering the list.
		if (optionInfo[0] == filterID || filterID == 0) {
		
			// We have a match, so add this option to the select list
			// and increment the index
			var sel = false;
			if  (selectedID == optionInfo[1]) { sel = true; }		
			selectObj.options[index++] =  new Option(optionInfo[1], optionInfo[2], sel);
		}
    }
}

/* Media Functions */

function selectImage(thumbFile,imageFile,opt_video) {
	
	//clearning class of all images
	image = 0;
	for(i in thumbs)
	{
		image++;
		document.getElementById(thumbs[i]).className = '';
		document.getElementById('mediaText' + image).style.display = 'none';
	}
	//if there's a video specified clear it's class
	if(opt_video != null && opt_video != "")
	{
		document.getElementById(opt_video).className = '';
	}
	
	//clear video text if there's a video
	if(document.getElementById('mediaTextVideo') != null)
	{
		document.getElementById('mediaTextVideo').style.display = 'none';
	}
	
	if(imageFile.substr(imageFile.length - 3, imageFile.length) == 'swf'){
		if(DetectFlashVer(8,0,0)) {
			var VideoHTML = AC_FL_RunContent( 'codebase' ,
									  'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0',
									  'name',
									  'machinesVideo',
									  'id',
									  'machinesVideo',
									  'swliveconnect',
									  'true',
									  'width',
									  '293',
									  'height',
									  '220',
									  'src',
									  imageFile,
									  'quality',
									  'high',
									  'pluginspage',
									  'http://www.macromedia.com/go/getflashplayer',
									  'wmode',
									  'transparent',
									  'movie',
									  imageFile,
									  'WriteFlash',
									  'false'
									  );
		} else {
			var VideoHTML = '<div style="margin: 20px;">If you do not see anything, you may need to <a style="color: rgb(190, 54, 70)" href="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=Shockwaveflash">download</a> the latest version of flash.</div>';
		}
		document.getElementById('mediaVideo').innerHTML = VideoHTML;
		document.getElementById('mediaImage').style.display = 'none';
		document.getElementById('mediaVideo').style.display = '';
		//if there's a video selected -- change it's class
		document.getElementById(thumbFile).className = 'current_image';
		//show video text
		document.getElementById('mediaTextVideo').style.display = '';
	}else{			
	/* the thumb highlighting */
		/*if (!document.getElementById) {
			document.location = "";
			return;
		}*/
		
		///assigning selectd image
		image = 0;
		for ( i in thumbs ) {
			image++;
			var thisThumb = thumbs[i];
			var thumbElement = document.getElementById(thisThumb);
			var imageBlurb = document.getElementById('mediaText' + image);
			//alert('mediaText' + image);
			if (thumbFile == thisThumb ) {
				thumbElement.className = "current_image";
				imageBlurb.style.display = "block";
			} else {
				thumbElement.className = "";
				imageBlurb.style.display = "none";
			}
		}
		/*document.getElementById(thumbFile).className = 'current_image';
		document.getElementById('mediaText' + image).style.display = 'block';*/
		
		var imageElement = document.getElementById("theImage");
		imageElement.src = imageFile;
		
		document.getElementById('mediaVideo').innerHTML = '';
		document.getElementById('mediaImage').style.display = '';
		document.getElementById('mediaVideo').style.display = 'none';
	}
	
	function getFlashMovieObject(movieName){
		if(window.document[movieName]){
			return window.document[movieName];
		}
		
		if(navigator.appName.indexOf("Microsoft Internet")==-1){
			if(document.embeds && document.embeds[movieName]){
				return document.embeds[movieName]; 
			}
		}else{
			return document.getElementById(movieName);
		}
	}
 
 


}