// Decide browser version
var ns4 = (document.layers)? true:false;
var ns6 = (document.getElementById)? true:false;
var ie4 = (document.all)? true:false;
var ie5 = false;

// Microsoft Stupidity Check(tm).
if (ie4) {
	if (navigator.userAgent.indexOf('MSIE 5')>0) {
		ie5 = true;
	}
	ns6 = false;
}

var CSAg = window.navigator.userAgent; 
var CSBVers = parseInt(CSAg.charAt(CSAg.indexOf("/")+1),10);

function CSFindElement(n,ly) { 
	if (CSBVers < 4) return document[n];
	var curDoc = ly ? ly.document : document; var elem = curDoc[n];
	if (!elem) { for (var i=0;i<curDoc.layers.length;i++) {
		elem = CSFindElement(n,curDoc.layers[i]); if (elem) return elem; }}
	return elem;
}

var isDHTML = 0;
var isID = 0;
var isAll = 0;
var isLayers = 0;
if (document.getElementById) {isID = 1; isDHTML = 1;}
else {
  if (document.all) {isAll = 1; isDHTML = 1;}
  else {
    browserVersion = parseInt(navigator.appVersion);
    if ((navigator.appName.indexOf('Netscape') != -1) && (browserVersion == 4)) {isLayers = 1; isDHTML = 1;}
}}

function findDOM(objectID,withStyle){
  if (withStyle == 1){
    if (isID) {return (document.getElementById(objectID).style);}
    else {
      if (isAll) { return (document.all[objectID].style);}
      else {
        if (isLayers) {return (document.layers[objectID]);}
      };
    }
  }
  else {
    if (isID) {return (document.getElementById(objectID));}
    else {
      if (isAll) { return (document.all[objectID]);}
      else {
        if (isLayers) {return (document.layers[objectID]);}
      };
    }
  }
}

function findDOM2(objectID,objectID2,withStyle){
  if (withStyle == 1){
    if (isID) {return (document.getElementById(objectID2).style);}
    else {
      if (isAll) { return (document.all[objectID2].style);}
      else {
        if (isLayers) {return (document.layers[objectID].layers[objectID2]);}
      };
    }
  }
  else {
    if (isID) {return (document.getElementById(objectID2));}
    else {
      if (isAll) { return (document.all[objectID2]);}
      else {
        if (isLayers) {return (document.layers[objectID].layers[objectID2]);}
      };
    }
  }
}


// object height
function objectHeight(obj) {
    var dom = findDOM(obj,0);
    if (dom.offsetHeight) return dom.offsetHeight;
    if (dom.clip.height) return dom.clip.height;
    return (null);
}

// Hides an object
function hideObject(obj) {
    var dom = findDOM(obj,1);
    dom.visibility = "hidden";
}

// Make an object visible
function showObject(obj) {
    var dom = findDOM(obj,1);
    dom.visibility = "visible";
}

// Colour an object
function setObjectColor(obj,col) {
    var dom = findDOM(obj,1);
    dom.color = col;
}

function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function chg_image(nam, imag) {
	var img = null;
	if (document.images) {
		if (!ie4) img = CSFindElement(nam,0);
		else img = document.images[nam];
		if (img) img.src = 'images/'+imag;
	}
}

var shownObj = null;
var shownNam = '';

function mm_image(nam, imag, txt) {
	var img = null;
	if (document.images) {
		if (!ie4) img = CSFindElement(nam,0);
		else img = document.images[nam];
		if (img) img.src = imag;
	}
 if (txt!=' ') {
   shownObj = null;
   hideObject(txt);
 }
}

function mm_image_o(nam, imag, txt) {
	var img = null;
	if (document.images) {
		if (!ie4) img = CSFindElement(nam,0);
		else img = document.images[nam];
		if (img) img.src = imag;
	}
 if (shownObj) {mm_image(shownNam, '', shownObj)};
 if (txt!=' ') {
   shownObj = txt;
   shownNam = nam;
   showObject(txt);
 }
}

menuImg = new Array()
menuLink = new Array()
menuItm = new Array()
menuTxt = new Array()

function setMenu(mg,lnk,itm,txt){
  var nx = menuImg.length;
  menuImg[nx] = mg;
  menuLink[nx] = lnk;
  menuItm[nx] = itm;
  menuTxt[nx] = txt;
}

setMenu('Home','index.htm','1','Home');
setMenu('Gallery','gallery1.asp','1','Gallery');
setMenu('Links','links.htm','1','Links');
setMenu('Pattern','patterns.htm','1','Patterns');
setMenu('Beanie1','patbeanie.htm','2','Beanies 1');
setMenu('Beanie2','patbeanie2.htm','2','Beanies 2');
setMenu('Clock','patamy.htm','2','Clock Cable Socks');
setMenu('Knickers','patknickers.htm','2','Dainty Knickers');
setMenu('EasySox','pateasysox.htm','2','Easy Socks');
setMenu('Double','patkathryn.htm','2','Heavy Double Knit Socks');
setMenu('Lace','patamylace.htm','2','Lace Panel Socks');
setMenu('Neck','patneck.htm','2','Neck Warmer');
setMenu('PandV','patpandv.htm','2','Panties and Vest');
setMenu('Pearl','patamypearl.htm','2','Pearl Stitch Socks');
setMenu('Pumpkin','patpumpkin.htm','2','Pumpkin Hat');
setMenu('Twistsox','pattwistsox.htm','2','Twisted Socks');
setMenu('Weaver1','patamyweaver.htm','2','Weaver Lace Socks 1');
setMenu('Weaver2','patwlace.htm','2','Weaver Lace Socks 2');
setMenu('Wisdom','wisdom.htm','1','Knitting Wisdom');
setMenu('Wispoem','wispoem.htm','5','Civil War Poem');
setMenu('Wiswrong','wiswrong.htm','5','Wrong Size Socks');
setMenu('Wool','wool.htm','1','Wool');
setMenu('Mbaby','mbaby.htm','4','Merino Baby');
setMenu('Pdouble','pdouble.htm','4','Perendale Double');
setMenu('Natural','natural.htm','4','Natural');
setMenu('Multi','multi.htm','4','Multi Colours');
setMenu('Perendale','perendale.htm','4','Perendale');
setMenu('Possum','possum.htm','4','Possum/Merino');
setMenu('MHeather','mheather.htm','4','Merino Heather');
setMenu('Spun','spun.htm','4','Spun Sliver');
setMenu('Carded','carded.htm','4','Carded Sliver');
setMenu('Felt','felt.htm','4','Merino Felting');

function buildMenu(pag,itm,xtra){
  document.writeln('<div id="menu">');
  if (pag=="Home") {
    document.writeln('<img src="images/transp.gif" width=1 height=125 border=0><br>');
  }
  document.writeln('<img src="images/transp.gif" width=1 height=10 border=0><br>');
  for (var i=0; i<menuImg.length; i++) {
	if ((menuItm[i] == '1') || (menuItm[i] == itm)) {
		if (menuItm[i] > '1') { 
			if (pag == menuImg[i]) {
				document.writeln('<p class="submenuthis">' + menuTxt[i] + '</p>');
			} else {
				document.writeln('<a href="' + menuLink[i] + '"><p class="submenu">' + menuTxt[i] + '</p></a>');
			}
		} else {								
			if (pag == menuImg[i]) {
      			document.writeln('<img src="images/h' + menuImg[i] + 
	      			'.gif" align=center valign=center width=105 border=0 alt="' + 
         			 menuTxt[i] + '"><br>');
     		} else {
      			document.writeln('<a href="'+menuLink[i]+'">' +
          			'<img src="images/b' + menuImg[i] + 
	    			'.gif" align=center valign=center width=105 border=0 alt="' + 
          			menuTxt[i] + '"></a><br>');
      		}
      	}
      	document.writeln('<img src="images/transp.gif" width=1 height=10 border=0><br>');
    }
  }
  document.writeln('<img src="images/transp.gif" width=1 height=10 border=0><br>');
  document.writeln(xtra);
  document.writeln('</div>');
  document.writeln(' ');
}

var myWin;
function Opn(img,txt) {
//  myWin = this.open("text/html", "Image", 
  myWin = this.open("", "Image", 
    "toolbar=no,menubar=no,location=no,scrollbars=no,resizable=no,width=650,height=580,innerWidth=650,innerHeight=580");
//  myWin.document.open("", "replace");
  myWin.document.write("<HTML><HEAD><TITLE>Jacque's Knitting Gallery</TITLE></HEAD><BODY background='images/bg.gif'><div align='center'><p>&nbsp;</p><table border=1 cellpadding=5 cellspacing=2><tr><td><img src="+img+" border=0></div></td></tr></table><p>"+txt+"</p></BODY></HTML>");
  myWin.document.close();
  myWin.focus();
}

var urlWin;
function OpnURL(url) {
//  urlWin = this.open("text/html", "Image", 
  urlWin = this.open("", "Image", 
    "toolbar=no,menubar=no,location=no,scrollbars=no,resizable=no,width=650,height=580,innerWidth=650,innerHeight=580");
//  urlWin.document.open("", "replace");
  urlWin.document.write('<HTML><HEAD><meta http-equiv="REFRESH" content="0;url='+url+'"></HEAD><BODY> </BODY></HTML>');
  urlWin.document.close();
  urlWin.focus();
}

