// KME javascript functions

// preloading images
function preloadMenuImages() {
		var preload, images, i;
		images = 8;
		preload = new Array(images);
		for (i=0; i<images; i++) {
			preload[i] = new Image();
		}
		preload[0].src = 'Images/MbtnFirst_off.gif';
		preload[1].src = 'Images/MbtnFirst_on.gif';
		preload[2].src = 'Images/MbtnLast_off.gif';
		preload[3].src = 'Images/MbtnLast_on.gif';
		preload[4].src = 'Images/MbtnMiddle_off.gif';
		preload[5].src = 'Images/MbtnMiddle_on.gif';
		preload[6].src = 'Images/Pmenu_off.gif';
		preload[7].src = 'Images/Pmenu_on.gif';
	}

function loadHeader(flashVersion) {
       var elHeader = document.getElementById('Header');
       var html = '';
       if (elHeader!=null) {
               //alert('flashVersion: ' + flashVersion);
               var requiredVersion = 6;
               if (flashVersion >= requiredVersion) { //create the Flash header HTML
                       html+="<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0\" width=\"680\" height=\"180\" id=\"carroussel\" align=\"left\">";
                       html+="<param name=\"allowScriptAccess\" value=\"sameDomain\" />";
                       html+="<param name=\"movie\" value=\"flash/jay.swf\" />";
                       html+="<param name=\"quality\" value=\"high\" />";
                       html+="<param name=\"wmode\" value=\"transparent\" />";
                       html+="<param name=\"bgcolor\" value=\"#ffffff\" />";
                       html+="<embed src=\"flash/jay.swf\" wmode=\"transparent\" quality=\"high\" bgcolor=\"#ffffff\" width=\"680\" height=\"180\" name=\"carroussel\" align=\"left\" allowScriptAccess=\"sameDomain\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" />";
                       html+="</object>";
               }
               else { //create the Image header HTML
                       html+="<div style=\"position:relative; height:180px;\"><img src=\"images/mainlogo.jpg\" width=\"680\" height=\"180\" border=\"0\" alt=\"Viper\">";
                       //html+="<div style=\"bottom: 40px; right:19px; color:#333333;\"></div>";
                       //html+="<div style=\"bottom: 42px;\"></div>";

                       html+="</div>";
               }
               //insert the header HTML
               elHeader.innerHTML = html;
       }
}

// menu
function Left(str, n) {
	if (n <= 0) { return "" }
	else if (n > String(str).length) { return str }
	else { return String(str).substring(0,n) }
}

function Right(str, n) {
    if (n <= 0) { return "" }
    else if (n > String(str).length) { return str }
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}

// product menu
function SubNavHover(reference) {
	reference.style.background = 'url(Images/Pmenu_on.gif) no-repeat';
}

function SubNavRestore(reference) {
	reference.style.background = 'url(Images/Pmenu_off.gif) no-repeat';
}

// product colors
var timerId;

function clearColor(current) {
	if (document.getElementById('PcolorName').innerHTML != current) {
		if (timerId) {clearTimeout(timerId);};
		document.getElementById('PcolorImage').style.width = 0;
	}
}

function setColor(img,name) {
	document.getElementById('PcolorImage').style.backgroundImage = img;
	document.getElementById('PcolorName').innerHTML = name;
}

function showColor() {
	var colorImage = document.getElementById('PcolorImage');
	var i;
	if (colorImage.style.width == '') {
		i = 0;
	}
	else {
		i = parseInt(colorImage.style.width);
	}
	if (i < 280) {
		i += 20;
		colorImage.style.width = i;
		timerId = setTimeout("showColor();", 10);
	}
}

// product features
function getScrollTop(win) {
   var scrollTop = 0;
   if (win.pageYOffset) {
	   scrollTop = win.pageYOffset;
   }
   else if (win.document.documentElement && win.document.documentElement.scrollTop) {
	   scrollTop = win.document.body.scrollTop;
   }
   else if (win.document.body) {
      scrollTop = win.document.body.scrollTop;
   }
   return scrollTop;
}

function showBigFeature(src,caption,imgwidth,imgheight) {
	var elPfeatPopup = document.getElementById('PfeatPopup');
	var nScroll = getScrollTop(window);
	var eImage = document.getElementById('PfeatImage');
	var eCaption = document.getElementById('PfeatCaption');
	eImage.src = 'Objects/' + src;
	eImage.width = imgwidth;
	eImage.height = imgheight;
	eCaption.innerHTML = caption;
	if (nScroll > 85) {
		elPfeatPopup.style.top = nScroll;
	}
	else {
		elPfeatPopup.style.top = 85;
	}
	elPfeatPopup.style.display = 'block';
}

function hideBigFeature() {
	document.getElementById('PfeatPopup').style.display = 'none';
	document.getElementById('PfeatImage').src = 'Images/pixel.gif';
}

// product specifications
function specExplain(me, target) {
	me.style.color = '#ff0000';
	document.getElementById(target).style.display = 'block';
}

function specRestore(me, target) {
	me.style.color = '#666666';
	document.getElementById(target).style.display = 'none';
}

// product photos
function imageBorder(element,sclass,color) {
	if (sclass == 'photoThL') {
		element.style.borderColor = color;
	}
	if (sclass == 'photoThL2') {
		element.style.borderColor = color;
		element.previousSibling.previousSibling.previousSibling.previousSibling.previousSibling.style.borderBottomColor = color;
	}
	if (sclass == 'photoTh2') {
		element.style.borderColor = color;
		element.previousSibling.previousSibling.previousSibling.previousSibling.previousSibling.style.borderBottomColor = color;
		element.previousSibling.style.borderRightColor = color;
	}
	if (sclass == 'photoTh') {
		element.style.borderColor = color;
		element.previousSibling.style.borderRightColor = color;
	}
}

//FAQ
function toggle(elementid) {
	element=document.getElementById(elementid);
	if (element.style.display=="block") {
		element.style.display="none";
		}
	else
	{
		element.style.display="block";
	}
}

// Flash Version Detector  v1.2.1
// documentation: http://www.dithered.com/javascript/flash_detect/index.html
// license: http://creativecommons.org/licenses/by/1.0/
// code by Chris Nott (chris[at]dithered[dot]com)
// with VBScript code from Alastair Hamilton (now somewhat modified)

function isDefined(property) {
  return (typeof property != 'undefined');
}

var flashVersion = 0;
function getFlashVersion() {
	var latestFlashVersion = 8;
   var agent = navigator.userAgent.toLowerCase();

   // NS3 needs flashVersion to be a local variable
   if (agent.indexOf("mozilla/3") != -1 && agent.indexOf("msie") == -1) {
      flashVersion = 0;
   }

	// NS3+, Opera3+, IE5+ Mac (support plugin array):  check for Flash plugin in plugin array
	if (navigator.plugins != null && navigator.plugins.length > 0) {
		var flashPlugin = navigator.plugins['Shockwave Flash'];
		if (typeof flashPlugin == 'object') {
			for (var i = latestFlashVersion; i >= 3; i--) {
            if (flashPlugin.description.indexOf(i + '.') != -1) {
               flashVersion = i;
               break;
            }
         }
		}
	}

	// IE4+ Win32:  attempt to create an ActiveX object using VBScript
	else if (agent.indexOf("msie") != -1 && parseInt(navigator.appVersion) >= 4 && agent.indexOf("win")!=-1 && agent.indexOf("16bit")==-1) {
	   var doc = '<scr' + 'ipt language="VBScript"\> \n';
      doc += 'On Error Resume Next \n';
      doc += 'Dim obFlash \n';
      doc += 'For i = ' + latestFlashVersion + ' To 3 Step -1 \n';
      doc += '   Set obFlash = CreateObject("ShockwaveFlash.ShockwaveFlash." & i) \n';
      doc += '   If IsObject(obFlash) Then \n';
      doc += '      flashVersion = i \n';
      doc += '      Exit For \n';
      doc += '   End If \n';
      doc += 'Next \n';
      doc += '</scr' + 'ipt\> \n';
      document.write(doc);
   }

	// WebTV 2.5 supports flash 3
	else if (agent.indexOf("webtv/2.5") != -1) flashVersion = 3;

	// older WebTV supports flash 2
	else if (agent.indexOf("webtv") != -1) flashVersion = 2;

	// Can't detect in all other cases
	else {
		flashVersion = flashVersion_DONTKNOW;
	}

	return flashVersion;
}

flashVersion_DONTKNOW = -1;

function movepic(img_name,img_src) {
	document[img_name].src=img_src;
}

