// ============================================================================================================================= //
// ------------------------------------------------------- DROPDOWN MENU ------------------------------------------------------- //
// ============================================================================================================================= //


function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}



function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}


//--------------DROPDOWN MENU FUNCTIONS-------------------//


var submenu_array = ["submenu1"];

function setLyr(obj,lyr)  //controls the positioning of the submenu layer lets you adjust x,y positioning for ie-mac and safari separately
{
	var newX = findPosX(obj);
	var newY = findPosY(obj);
	var x = new getObj(lyr);
//window.alert(newX);
	var fixX //adjasting the diference between ie-mac and other browsers
	var fixY  //adjasting the diference between ie-mac and other browsers
	if ((is_ie5up) && (is_mac)){  // fix for ie-mac
		fixY = 1;
		fixX = -15;
	}	
	else if (is_safari){ // fix for safari
		fixY = 0;
		fixX = 10;
	} 
	else {
		fixY = 0;
		fixX = 0;
	}
	x.style.top = newY + fixY + 18 + 'px';
	x.style.left = newX + fixX -1 + 'px';
}

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;
}

function getObj(name){
 if (document.getElementById)
 {
	   this.obj = document.getElementById(name);
	   this.style = document.getElementById(name).style;
 }
 else if (document.all)
 {
	   this.obj = document.all[name];
	   this.style = document.all[name].style;
 }
 else if (document.layers)
 {
	   if (document.layers[name])
	   {
	   	this.obj = document.layers[name];
	   	this.style = document.layers[name];
	   }
 }
}

function FW_clearTimeout(){
	if (fwHideMenuTimer) clearTimeout(fwHideMenuTimer);
	fwHideMenuTimer = null;
	fwDHFlag = false;
}

function FW_startTimeout(){
	fwStart = new Date();
	fwDHFlag = true;
	fwHideMenuTimer = setTimeout("fwDoHide()", 1000);
}

function fwDoHide(){
	var printstring = '';
	printstring +=fwStart+' fwHideMenuTimer:'+fwHideMenuTimer+' layers: ';
	/*window.status = printstring;*/
	if (!fwDHFlag) return;
	var elapsed = new Date() - fwStart;
	if (elapsed < 40) {
		fwHideMenuTimer = setTimeout("fwDoHide()", 40-elapsed);
		return;
	}
	fwDHFlag = false;
	hideActiveMenus();
	window.ActiveMenuItem = 0;
}

function hideActiveMenus() {  //goes over each of the submenus in the arrays and hide them
	for (i=0; i<(submenu_array.length); i++){
		  var name=submenu_array[i]; 
			var removeLayer = document.getElementById(name);
			removeLayer.style.visibility="hidden";
		}

}

function ShowNav(layerName){  // show named layer and hide All other layers from the submenu_array
	
	for (i=0; i<(submenu_array.length); i++){
		var name=submenu_array[i]; 
		var subname=name.substr(0,7); 
		 if(subname=="submenu"){ 
			   if (layerName==name){
				   MM_showHideLayers(layerName,'','show');
			   } else {
				   var removeLayer = document.getElementById(name);
				   removeLayer.style.visibility="hidden";
				}
			}
	}
}

function mouseoutMenu(){
	fwDHFlag = false;
	return true;
}

// ============================================================================================================================= //
// ------------------------------------------------------ FLASH DETECTION ------------------------------------------------------ //
// ============================================================================================================================= //

/*var hasFlash = '<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="778" height="152">'
		     	 + '<param name="movie" value="swf/banner.swf">'
				 + '<param name="wmode" VALUE="transparent">'
  				 + '<param name="quality" value="high">'
  				 + '<embed src="swf/banner.swf?pgTitle=test" quality="high" wmode="transparent" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="778" height="152"></embed>'
				 + '</object>'*/

var noFlash = '<img src="i/header.gif">';

var requiredVersion = 6;  
var useRedirect = false;   

var flash2Installed = false;    
var flash3Installed = false;    
var flash4Installed = false;    
var flash5Installed = false;   
var flash6Installed = false;    
var flash7Installed = false;    
var flash8Installed = false;    
var flash9Installed = false;    
var maxVersion = 9;             
var actualVersion = 0;         
var hasRightVersion = false;    
var jsVersion = 1.0; 


var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;    
var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false; 

jsVersion = 1.1;

if(isIE && isWin){
  document.write('<SCR' + 'IPT LANGUAGE=VBScript\> \n');
  document.write('on error resume next \n');
  document.write('flash2Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.2"))) \n');
  document.write('flash3Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.3"))) \n');
  document.write('flash4Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.4"))) \n');
  document.write('flash5Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.5"))) \n');  
  document.write('flash6Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.6"))) \n');  
  document.write('flash7Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.7"))) \n');
  document.write('flash8Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.8"))) \n');
  document.write('flash9Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.9"))) \n');
  document.write('<\/SCR' + 'IPT\> \n');
}



function detectFlash() {  
  if (navigator.plugins) {
    if (navigator.plugins["Shockwave Flash 2.0"]
        || navigator.plugins["Shockwave Flash"]) {
      var isVersion2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
      var flashDescription = navigator.plugins["Shockwave Flash" + isVersion2].description;
      var flashVersion = parseInt(flashDescription.substring(16));

      flash2Installed = flashVersion == 2;    
      flash3Installed = flashVersion == 3;
      flash4Installed = flashVersion == 4;
      flash5Installed = flashVersion == 5;
      flash6Installed = flashVersion == 6;
      flash7Installed = flashVersion == 7;
      flash8Installed = flashVersion == 8;
      flash9Installed = flashVersion >= 9;
    }
  }
  
  for (var i = 2; i <= maxVersion; i++) {  
    if (eval("flash" + i + "Installed") == true) actualVersion = i;
  }
  
  if(navigator.userAgent.indexOf("WebTV") != -1) actualVersion = 4;  
  
  if (actualVersion >= requiredVersion) {
    if (useRedirect) {
      if(jsVersion > 1.0) {
        window.location.replace(flashPage);  
      } else {
        window.location = flashPage;
      }
    }
    hasRightVersion = true;                
  } else {  
    if (useRedirect) {
      if(jsVersion > 1.0) {
        window.location.replace((actualVersion >= 2) ? upgradePage : noFlashPage);
      } else {
        window.location = (actualVersion >= 2) ? upgradePage : noFlashPage;
      }
    }
  }
}

detectFlash();

////////////////////
function addEmail(){
var add='<a href="mailto:sales@rwmachines.co.uk">sales@rwmachines.co.uk</a>';
document.write(add);
}
function addEuropeEmail(){
var add='<a href="mailto:sales@rwmachines.co.uk">sales@rwmachines.co.uk</a>';
document.write(add);
}

//////////////////////////////////////////////////// Gallery ///////////////////////
function showPic (whichpic, gohere) {
 if (document.getElementById) {
  document.getElementById(gohere).src = whichpic;
  return false;
 } else {
  return true;
 }
}

function show_hide(strElem,true_false) {
    theElem = document.getElementById(strElem);
    if(!theElem) { return false }

    if(true_false) {
	    theElem.style.display = "";
    } else {
	    theElem.style.display = "none";
    }
}
	    
	    
function show_hide2(strElem,selectedValue) {
    theElem = document.getElementById(strElem);
    if(!theElem) { return false }

    if(selectedValue == "other")
	    theElem.style.display = "";
    else 
	    theElem.style.display = "none";
}
