var agt=navigator.userAgent.toLowerCase();

var is_major = parseInt(navigator.appVersion);

var is_minor = parseFloat(navigator.appVersion);

var is_ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));

var is_ie3    = (is_ie && (is_major < 4));

var is_ie4    = (is_ie && (is_major == 4) && (agt.indexOf("msie 4")!=-1) );

var is_ie4up  = (is_ie && (is_major >= 4));

var is_ie5    = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")!=-1) );

var is_ie5_5  = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.5") !=-1));

var is_ie5up  = (is_ie && !is_ie3 && !is_ie4);

var is_ie5_5up =(is_ie && !is_ie3 && !is_ie4 && !is_ie5);

var is_ie6    = (is_ie && (is_major == 4) && (agt.indexOf("msie 6.")!=-1) );

var is_ie6up  = (is_ie && !is_ie3 && !is_ie4 && !is_ie5 && !is_ie5_5);



function MM_preloadImages() { //v3.0

  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();

    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)

    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}

}



function MM_swapImgRestore() { //v3.0

  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;

}



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_swapImage() { //v3.0

  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)

   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}

}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized

  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {

    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}

  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();

}

MM_reloadPage(true);



function P7_Snap()

{ //v2.67 by PVII

	var g,x,y,ox,bx,oy,p,tx,a,b,k,d,da,e,el,tw,q0,xx,yy,w1,pa='px',args=P7_Snap.arguments;

	a=parseInt(a);

	if(document.layers||window.opera)

	{

		pa='';

	}

	for(k=0;k<(args.length);k+=4)

	{

		if((g=MM_findObj(args[k]))!=null)

		{

			if((el=MM_findObj(args[k+1]))!=null)

			{

				a=parseInt(args[k+2]);

				b=parseInt(args[k+3]);

				x=0;
				y=0;
				ox=0;
				oy=0;
				p="";
				tx=1;
				da="document.all['"+args[k]+"']";
				if(document.getElementById)

				{

					d="document.getElementsByName('"+args[k]+"')[0]";
					if(!eval(d))

					{

						d="document.getElementById('"+args[k]+"')";
						if(!eval(d))

						{

							d=da;
						}

					}

				}

				else if(document.all)

				{

					d=da;
				}

				if(document.all||document.getElementById)

				{

					while(tx==1)

					{

						p+=".offsetParent";
						if(eval(d+p))

						{

							x+=parseInt(eval(d+p+".offsetLeft"));
							y+=parseInt(eval(d+p+".offsetTop"));
						}

						else

						{

							tx=0;
						}

					}

					ox=parseInt(g.offsetLeft);
					oy=parseInt(g.offsetTop);
					tw=x+ox+y+oy;
					if(tw==0||(navigator.appVersion.indexOf("MSIE 4")>-1&&navigator.appVersion.indexOf("Mac")>-1))

					{

						ox=0;
						oy=0;
						if(g.style.left)

						{

							x=parseInt(g.style.left);
							y=parseInt(g.style.top);
						}

						else

						{

							w1=parseInt(el.style.width);
							bx=(a<0)?-5-w1:-10;
							a=(Math.abs(a)<1000)?0:a;
							b=(Math.abs(b)<1000)?0:b;
							x=document.body.scrollLeft+event.clientX+bx;
							y=document.body.scrollTop+event.clientY;
						}

					}

				}

				else if(document.layers)

				{

					x=g.x;
					y=g.y;
					q0=document.layers,dd="";
					for(var s=0; s<q0.length; s++)

					{

						dd='document.'+q0[s].name;
						if(eval(dd+'.document.'+args[k]))

						{

							x+=eval(dd+'.left');
							y+=eval(dd+'.top');

							break;
						}

					}

				}

				e=(document.layers)?el:el.style;
				xx=parseInt(x+ox+a), yy=parseInt(y+oy+b);
				if(navigator.appVersion.indexOf("MSIE 5")>-1 && navigator.appVersion.indexOf("Mac")>-1)

				{

					xx+=parseInt(document.body.leftMargin);
					yy+=parseInt(document.body.topMargin);
				}

				e.left=xx+pa;
				e.top=yy+pa;
			}

		}

	}

}



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=='inherit')?'inherit':v; }

    obj.visibility=v; }

}



var shapes = new Array('chamferbox1',13,11,'chamferbox10',81,11,'chamferbox11',147,11,'chamferbox12',215,11,'chamferbox2',282,11,'chamferbox3',350,11,'chamferbox4',418,11,'chamferbox5',486,11,'chamferbox6',13,46,'chamferbox7',80,46,'chamferbox8',147,46,'chamferbox9',216,46,'multimesh1',282,46,'multimesh10',350,46,'multimesh11',418,46,'multimesh2',485,46,'multimesh3',13,82,'multimesh4',80,82,'multimesh5',147,82,'multimesh6',216,82,'multimesh7',282,82,'multimesh8',350,82,'multimesh9',418,82,'tab1',485,82,'tab2',13,118,'tab3',80,118,'tab4',147,118,'tab5',216,118,'tab6',283,118);

var colors = new Array('gray',4,4,'red',4,22,'green',4,40,'blue',4,58,'yellow',4,76,'orange',4,94,'pink',87,4,'teal',87,22,'purple',87,40,'brown',87,58,'cyan',87,76,'olive',87,94);

var materials = new Array('Wood',4,4,'Metal',4,22,'Plastic',4,40,'Glass',4,58,'Stone',4,76,'Marble',4,94);



function clearColor()

{

	document.searchform.elements['colorSelection'].value = "";	

	document.getElementById('colorContainee').style.background = "";

}

function clearShape()

{

	document.searchform.elements['shapeSelection'].value = "";	

	document.getElementById('shapeContainee').style.background = "";

}

function clearTexture()

{

	document.searchform.elements['textureSelection'].value = "";	

	document.getElementById('textureContainee').style.background = "";

}

function clearMaterial()

{

	document.searchform.elements['materialSelection'].value = "";	

	document.getElementById('materialContainee').style.background = "";

}



function setColor(thecolor)

{

	x = y = 4;

	for(i=0; i<colors.length; i+=3)

		if(thecolor == colors[i])

		{

			x = colors[i+1];

			y = colors[i+2];

		}

	document.searchform.elements['colorSelection'].value = thecolor;

	document.getElementById('colorContainee').style.background = "url(/pics/colors.jpg) -"+x+"px -"+y+"px no-repeat";

	MM_showHideLayers('colorPalette','','hide');

}

function setShape(theshape)

{

	x = 13;

	y = 11;

	for(i=0; i<shapes.length; i+=3)

		if(theshape == shapes[i])

		{

			x = shapes[i+1];

			y = shapes[i+2];

		}

	document.searchform.elements['shapeSelection'].value = theshape;

	document.getElementById('shapeContainee').style.background = "url(/pics/shapes.jpg) -"+x+"px -"+y+"px no-repeat";	

	MM_showHideLayers('shapePalette','','hide');

}



function setMaterial(thematerial)

{

	x = y = 4;

	for(i=0; i<materials.length; i+=3)

		if(thematerial == materials[i])

		{

			x = materials[i+1];

			y = materials[i+2];

		}

	document.searchform.elements['materialSelection'].value = thematerial;

	document.getElementById('materialContainee').style.background = "url(/pics/materials.jpg) -"+x+"px -"+y+"px no-repeat";		

	MM_showHideLayers('materialPalette','','hide');

}



var currTexture = 0;

var currPage = 0;

// var texturesArray = new Array("ALTAQUA.jpg", "AMETHYST.jpg", "ASHSEN_2.jpg", "BALMORAL.jpg", "BENEDETI.jpg", "BRKWEA.jpg", "BUBING_2.jpg", "BURLOAK.jpg", "CEDFENCE.jpg", "DRIFTWD.jpg", "DRYMUD1.jpg", "fx3_Rock_2.jpg", "GALVPLAT.jpg", "glassbutton.jpg", "GRASS2.jpg", "GRYDIRT1.jpg", "GRYDIRT2.jpg", "LEAFTEX5.jpg", "LIMESTO1.jpg", "LIMESTO3.jpg", "MEDRUST3.jpg", "METAL7.jpg", "MtlPlat2.jpg", "OAKPLY1.jpg", "OLDMETAL.jpg", "OLDWOOD.jpg", "SAND3.jpg", "SANDSHOR.jpg", "textures_01.jpg", "textures_02.jpg", "textures_03.jpg", "textures_04.jpg", "textures_05.jpg", "textures_06.jpg", "textures_07.jpg", "textures_08.jpg", "textures_09.jpg", "textures_10.jpg", "textures_11.jpg", "textures_12.jpg", "textures_13.jpg", "TILQUR.jpg", "TREEBARK.jpg", "TUTASH.jpg", "WHTGRAN.jpg");

var texturesArray = new Array(45);

for(var i=1; i<=45; i++)

{

	str = i.toString();

	while(str.length < 3)

		str = "0"+str;

	texturesArray[i-1] = "texture"+str;

}



var totalPages = parseInt(texturesArray.length/8);

if (totalPages != parseFloat(texturesArray.length/8))

	totalPages = totalPages + 1;



function check_texture(texture)

{

//	window.status = texture.substring(texture.length - 4, 4);

	if(texture.substring(texture.length - 4, 4) != '.jpg')

		var texture_new = texture + '.jpg';

	return texture_new;

//	return texture;

}



function nextPage()

{

	if(totalPages == currPage + 1)

		currPage = 0;

	else

		currPage = currPage + 1;

	for (var j=1;j<totalPages+1;j++)

	{

		if(j == currPage+1)

			MM_showHideLayers('pager'+j,'','inherit');

		else

			MM_showHideLayers('pager'+j,'','hide');

	}

	var texture;

	for (var i=1;i<9;i++)

	{

		var currThumb = "thumb"+i;

		if(currPage*8 + i - 1 < texturesArray.length)

			document.images[currThumb].src = "/textures/" + check_texture(texturesArray[currPage*8 + i - 1]);

		else

			document.images[currThumb].src = "/pics/spacer.gif";

	}

	document.images.cTexture.src = "/textures/" + check_texture(texturesArray[currPage*8]);

}



function previousPage(){

	

	if(currPage == 0)

		currPage = totalPages - 1;

	else

		currPage = currPage - 1;



	for (var j=1;j<totalPages+1;j++)

	{

		if(j == currPage+1)

			MM_showHideLayers('pager'+j,'','inherit');

		else

			MM_showHideLayers('pager'+j,'','hide');

	}	



	for (var i=1;i<9;i++)

	{

		var currThumb = "thumb"+i;

		if(currPage*8 + i - 1 < texturesArray.length)

			document.images[currThumb].src = "/textures/" + check_texture(texturesArray[currPage*8 + i - 1]);

		else

			document.images[currThumb].src = "/pics/spacer.gif";	

	}

	document.images.cTexture.src = "/textures/" + check_texture(texturesArray[currPage*8]);

}



function setTexture()

{

	

	if(currTexture >= currPage*8 + 8 || currTexture < currPage*8)

		currTexture = currPage*8;

	document.searchform.elements['textureSelection'].value = texturesArray[currTexture];

	document.getElementById('textureContainee').style.background = "url(/textures/"+check_texture(texturesArray[currTexture])+") 0px 0px no-repeat";		

	MM_showHideLayers('texturePalette','','hide');

}



function setTextureName(strTexture)

{

	document.searchform.elements['textureSelection'].value = strTexture;

	document.getElementById('textureContainee').style.background = "url(/textures/"+check_texture(strTexture)+") 0px 0px no-repeat";

}



function placeTextureThumb(position){

		

	var textureThumbNo = currPage * 8 + position - 1;	

	var textureThumb = "";

		

	if (currPage*8 + position < texturesArray.length-1)

		textureThumb = "<a href=\"javascript:viewThumb("+textureThumbNo+","+position+")\"><img src=\"/textures/"+check_texture(texturesArray[textureThumbNo])+"\" width=\"35\" height=\"35\" border=\"0\" name=\"thumb"+position+"\"></a>";

	else

		textureThumb = "<img src=\"/pics/spacer.gif\" width=\"35\" height=\"35\" border=\"0\" name=\"thumb"+position+"\">";			

	document.write(textureThumb);

}



function viewThumb(tNum,position){

	if (currPage*8 + position - 1 < texturesArray.length)

	{

		document.images.cTexture.src = "/textures/"+check_texture(texturesArray[currPage*8+tNum]);

		currTexture = currPage*8+tNum;

	}

}



function placePager(){

	var	content = "";

	var vis = "";

	for (var j=1;j<totalPages+1;j++)

	{

		if(j == currPage+1)

			content += "<div id=\"pager"+j+"\" style=\"position:absolute; width:65px; height:25px; z-index:101; visibility:inherit; left: 44px; top: 237px;\" class=\"layerPager\">Page " + j + " of " + totalPages + "</div>";

		else

			content += "<div id=\"pager"+j+"\" style=\"position:absolute; width:65px; height:25px; z-index:101; visibility:hidden; left: 44px; top: 237px;\" class=\"layerPager\">Page " + j + " of " + totalPages + "</div>";

	}

	document.write(content);

}



function supersizeme()

{

	if(is_ie)

		P7_Snap('clear1','colorPalette',75,15);

	else

		P7_Snap('clear1','colorPalette',77,15);

	P7_Snap('clear2','shapePalette',0,15);

	if(is_ie)

		P7_Snap('clear3','texturePalette',-62,15);

	else

		P7_Snap('clear3','texturePalette',-60,15);

	if(is_ie)

		P7_Snap('clear4','materialPalette',-35,15);

	else

		P7_Snap('clear4','materialPalette',-33,15);

}



window.onresize = supersizeme;



var clicked = 'no';



function hidePalettes()

{

	if (clicked != 'yes')

	{

		MM_showHideLayers('colorPalette','','hide');

		MM_showHideLayers('shapePalette','','hide');

		MM_showHideLayers('texturePalette','','hide');	

		MM_showHideLayers('materialPalette','','hide');	

	}

}



function grabMD()

{

	document.onmousedown = hidePalettes;

}



function fetch(btnsperpage)

{

	document.location='/buttons' + (btnsperpage != 15 ? '/btns'+btnsperpage : '') + (document.searchform.colorSelection.value != '' ? '/'+document.searchform.colorSelection.value : '') + (document.searchform.shapeSelection.value != '' ? '/'+document.searchform.shapeSelection.value : '') + (document.searchform.textureSelection.value != '' ? '/'+document.searchform.textureSelection.value : '') + (document.searchform.materialSelection.value != '' ? '/'+document.searchform.materialSelection.value : '');

	window.status='';

}



function hide_ie_msg()

{

	var ie_msg = document.getElementById('ie_msg');

	if(ie_msg)

		ie_msg.style.display = 'none';

}
