
var undefined;


function contactUs() {
	var nextLocation = "mail";
	nextLocation += "to:";
	nextLocation += "enquiries";
	nextLocation += "@";
	nextLocation += "factoryoneracing";
	nextLocation += ".";
	nextLocation += "com";
	document.location = nextLocation;
}

function comingSoon() {
	alert("Coming soon...");
}

var isNS = false;
var isOther = false;
var isSafari = false;
if (navigator.appVersion.indexOf("Safari") != -1) { isSafari = true; }
var bV = navigator.appVersion.charAt(0);
if (navigator.appName == "Netscape" && !isSafari) { isNS = true; }
else if (navigator.appName != "Microsoft Internet Explorer") { isOther = true; }

var isMac = false;
if (navigator.platform == "MacPPC") { isMac = true; }

function simplePreload() {
  var args = simplePreload.arguments;
  document.imageArray = new Array(args.length);
  for(var i=0; i<args.length; i++) {
    document.imageArray[i] = new Image;
    document.imageArray[i].src = args[i];
  }
}

function switchImage(imgName, imgSrc)  {
  if (document.images) {
    if (imgSrc != "none") {
      document.images[imgName].src = imgSrc;
    }
  }
}

function findObj(theObj, theDoc) {
  var p, i, foundObj;
  if(!theDoc) theDoc = document;
  if( (p = theObj.indexOf("?")) > 0 && parent.frames.length) {
    theDoc = parent.frames[theObj.substring(p+1)].document;
    theObj = theObj.substring(0,p);
  }
  if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj];
  for (i=0; !foundObj && i < theDoc.forms.length; i++) 
    foundObj = theDoc.forms[i][theObj];
  for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++) 
    foundObj = findObj(theObj,theDoc.layers[i].document);
  if(!foundObj && document.getElementById) foundObj = document.getElementById(theObj);
  return foundObj;
}

function showHideLayers() {
  var i, visStr, obj, args = showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) {
    if ((obj = findObj(args[i])) != null) {
      visStr = args[i+2];
      if (obj.style) {
        obj = obj.style;
        if(visStr == 'show') visStr = 'visible';
        else if(visStr == 'hide') visStr = 'hidden';
      }
      obj.visibility = visStr;
    }
  }
}


function howToOrder() {
	var h = 370;
	var w = 400;
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	var settings="height=" + h + ",width=" + w + ",top=" + TopPosition + ",left=" + LeftPosition + ",scrollbars=yes,resizable=yes,status=yes,toolbar=no,menubar=no";
	newWindow = window.open( "order.html", "Order_Window", settings);
	setTimeout('newWindow.focus()',0);
}

function photoWin(loc, w, h, urlPrefix) {
	if (!urlPrefix) { urlPrefix = ""; }
	photoWindow = window.open( urlPrefix + "photowin.html?loc=" + loc + "&w=" + w + "&h=" + h, "Photo_Window", "height=300,width=300,top=60,left=60,scrollbars=no,resizable=yes,status=yes,toolbar=no,menubar=no");
	setTimeout('photoWindow.focus()',0);
}

function movieWin(loc,w,h) {
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	var settings="height=" + ((h-0)+135) + ",width=" + ((w-0)+100) + ",top=" + TopPosition + ",left=" + LeftPosition + ",scrollbars=no,resizable=yes,status=no,toolbar=no,menubar=no";
	movieWindow = window.open( "moviewin.html?loc=" + loc + "&w=" + w + "&h=" + h, "Movie_Window", settings);
	setTimeout('movieWindow.focus()',0);
}


// function to move any absolutely positioned object to the mouse coordinates
// theObj = the object to be positioned (usually a DIV)
// modX, modY = optional values by which the coordinate values can be modified if required
function moveToMouseLoc(theObj, modX, modY) {
        var posx = 0;
        var posy = 0;
        var e = window.event;
        if (e.pageX || e.pageY)         {
                posx = e.pageX;
                posy = e.pageY;
        }
        else if (e.clientX || e.clientY)        {
                posx = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
                posy = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
        }
        theObj.style.left = posx + modX;
        theObj.style.top = posy + modY;
        return true;
}


// function which returns the mouse's X coordinate value
// modX = optional value by which the returned value can be modified if required
function getMouseX(modX) {
        if (!modX) { modX = 0; }
        var e = window.event;
        if (e.pageX) {
                return ( e.pageX + (modX-0) );
        }
        else if (e.clientX)     {
                return ( e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft + (modX-0) );
        }
        else return modX;
}


// function which returns the mouse's Y coordinate value
// modY = optional value by which the returned value can be modified if required
function getMouseY(modY) {
	if (!modY) { modY = 0; }
	var e = window.event;
	if (e.pageY) {
		return ( e.pageY + (modY-0) );
	}
	else if (e.clientY)     {
		return ( e.clientY + document.body.scrollTop + document.documentElement.scrollTop + (modY-0) );
	}
	else return modY;
}


function getScrollX() {
  var scrOfX = 0;
  if( typeof( window.pageXOffset ) == 'number' ) {
    //Netscape compliant
    scrOfX = window.pageXOffset;
  }
  else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfX = document.body.scrollLeft;
  }
  else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfX = document.documentElement.scrollLeft;
  }
  return scrOfX;
}


function getScrollY() {
  var scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
  }
  return scrOfY;
}


function getWindowX() {
  var myWidth = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
  }
  else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
  }
  else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
  }
  return myWidth;
}


function getWindowY() {
  var myHeight = 0;
  if( typeof( window.innerHeight ) == 'number' ) {
    //Non-IE
    myHeight = window.innerHeight;
  }
  else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myHeight = document.documentElement.clientHeight;
  }
  else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myHeight = document.body.clientHeight;
  }
  return myHeight;
}


// xpos and ypos are optional co-ordinates for controlling the position of the Added To Basket layer
function addToCart(theCode, xpos, ypos) {
	// cookie check
	if(!navigator.cookieEnabled) {
		alert("Your browser does not have Cookies enabled.\n\nOur shopping basket needs Cookies to remember your items.\n\nYou can turn Cookies on in your browser preferences.");
		return;
	}
	var itemIndex;
	for (var i=0; i<shopItems.length; i++) {
		if (shopItems[i].stockCode == theCode) {
			itemIndex = i;
			break;
		}
	}
	// stock check
	if (shopItems[itemIndex].soldout) {
		alert("Sorry, this item is currently out of stock");
		return;
	}
	// add item to cookie
	var cart = getCookie("FactoryOneCart");
	if (cart == null) { cart = ""; }
	if (cart != "") { cart += "+"; }
	cart += theCode;
	setCookie("FactoryOneCart", cart, getExpDate(30,0,0), "/");
	// move choices layer down if necessary
	var scrolledAmount = getScrollY();
	if (scrolledAmount > 0) {
		var newPosX = scrolledAmount + (Math.round(getWindowY()/2));
		document.getElementById("itemAddedLayer").style.top = newPosX+"px";
	}
	// absolutely position choices layer if necessary
	if (xpos != undefined) {
		document.getElementById("itemAddedLayer").style.left = xpos+"px";
	}
	if (ypos != undefined) {
		document.getElementById("itemAddedLayer").style.top = ypos+"px";
	}
	// show choices layer
	showHideLayers("itemAddedLayer","","show");
}



function writeStock(theCode) {
	var itemIndex;
	for (var i=0; i<shopItems.length; i++) {
		if (shopItems[i].stockCode == theCode) {
			itemIndex = i;
			break;
		}
	}
	if (shopItems[itemIndex].soldout) {
		 document.write("<span style='color:red'>Out of stock</span>");
	}
	else {
		document.write("In stock");
	}
}


