var alp=0;
var coltim=null;
function stepColour() {
	alp+=0.01;
	third=Math.PI*2/3;
	r=Math.round(128+(125*Math.sin(alp)));
	g=Math.round(128+(125*Math.sin(alp+third)));
	b=Math.round(128+(125*Math.sin(alp+(2*third))));
	if (alp>(Math.PI*2)) alp-=(Math.PI*2);
	h=RGBtoHEX(r,g,b);
	objid("logo").style.backgroundColor='#'+h
	coltim=setTimeout("stepColour()",2);
}
function RGBtoHEX(r,g,b) {
	rr=r.toString(16);
	if (rr.length==1) rr="0"+rr;
	gg=g.toString(16);
	if (gg.length==1) gg="0"+gg;
	bb=b.toString(16);
	if (bb.length==1) bb="0"+bb;
	c=rr+gg+bb;
	return c;
}
function showOverlay(srcObj,show) {
	tar=objid(srcObj.id.replace("block","overlay"));
	if (show) {
		revealObject(tar);
	}else{
		hideObjectDelay(tar);
	}
}
var revealObjects=new Array();
var revealTimer=null;
var hideTimer={};
function revealObject(tar) {
	resizeObject(tar,false,true,0,0,null,null,null,10,2,true);
	id=tar.id.replace("block","");
	if (hideTimer[id]) clearTimeout(hideTimer[id]);
}
function hideObjectDelay(tar) {
	id=tar.id.replace("block","");
	if (hideTimer[id]) clearTimeout(hideTimer[id]);
	hideTimer[id]=setTimeout("hideObject('"+tar.id+"')",500);
}
function hideObject(tar) {
	if (typeof(tar)=="string") tar=objid(tar);
	dims=objFreeSize(tar);
	resizeObject(tar,false,true,null,null,null,0,null,2,2,false);
}
function objid(id) {
	return document.getElementById(id);
}
function fadeObjectByClass(cls,alpha) {
	dvs=document.body.getElementsByTagName("DIV");
	for(i=0;i<dvs.length;i++) {
		if (dvs[i].className==cls) fader(dvs[i],alpha);	
	}
}
var selectedFeature=0;
var maxFeature=0;
var selectTimer=null;
var autoselect=true;
function clickFeature(id) {
	autoselect=false;	
	selectTimer=null;
	selectFeature(id);
}
function selectFeature(id) {
	if (selectedFeature!=id) {
		other="feature"+selectedFeature;
		objid("tdlink"+selectedFeature).className="tdlink";
		selectedFeature=id;
		sel=objid("tdlink"+selectedFeature);
		sel.className="tdlinksel";
		toggleExpansion("feature"+selectedFeature,false,true,other);
	}
}
function initFeatures(maxid) {
	maxFeature=maxid;
	selectedFeature=1;
	objid("tdlink"+selectedFeature).className="tdlinksel";
	for(i=1;i<=maxid;i++) {
		objid("feature"+i).style.display=((i==selectedFeature)?'block':'none');
	}
	selectTimer=setTimeout("nextFeature()",4000);
}
function nextFeature() {
	if (autoselect) {
		n=selectedFeature+1;
		if (n>maxFeature) n=1;
		selectFeature(n);
		selectTimer=setTimeout("nextFeature()",4000);
	}
}
function loadMenu() {
	return menus;
}
function gotoURL(url) {
	window.location=url;
}





var displayAlbum=new Array();
var displayAlbumTitles=new Array();
function olddisplayPhoto(srcObj) {
	displayAlbum=new Array();
	displayAlbumTitles=new Array();
	imgs=srcObj.parentNode.getElementsByTagName("DIV");
	for(i=0;i<imgs.length;i++) {
		if (imgs[i].className=='img') {
			src=imgs[i].getAttribute("fullimg");
			displayAlbum.push(src);
			displayAlbumTitles.push(src.replace(/-/g," "));
		}
	}
	srcid=srcObj.getAttribute("fullimg");
	currentImg=srcid
	currentTitle=srcid.replace(/-/g," ");
	if (currentTitle=="") currentTitle="Untitled";
	index=displayAlbum.indexOf(currentImg);
	count=displayAlbum.length;
	content='<div id="photoDisplay"><div style="width:50px;height:50px;line-height:50px;text-align:center;margin:0 auto"></div></div>';
	content+="<div id='loadingImg' style='display:none;position:absolute'><img src='/samples/large/"+currentImg+".jpg' onload='showPhoto(this)' /></div>";
	content+="<div id='photoArrows'>"+photoArrows(index,count)+"</div>";
	ins=returnRoundedBox('dialogBox','<span id="photoname">'+currentTitle+'</span>',content,true,5,null,null,true,false);
	startFadeUp();
	pasteRawHTML(ins,document.body);
	centerObject(document.getElementById("dialogBox"));
}
function photoArrows(index,count) {
	w=(count*8);
	reply="";
	if (index>0) {
		reply+="<div class='photoleft' onclick='loadPhoto("+(index-1)+")' title='Previous' ></div>";
		w+=46;
	}
	for(p=0;p<count;p++) {
		if (p==index) {
			reply+="<div class='photoblipon'></div>";
		}else{
			reply+="<div class='photoblip' onclick='loadPhoto("+p+")' title='"+displayAlbumTitles[p]+"'></div>";
		}
	}
	if (index<count-1) {
		reply+="<div class='photoright' onclick='loadPhoto("+(index+1)+")' title='Next' ></div>";
		w+=46;
	}
	reply+="</div>";
	return "<div style='width:"+w+"px;padding:4px;margin:0 auto'>"+reply+"</div>";
}
function loadPhoto(index) {
	li=document.getElementById('photoDisplay');
	img=li.childNodes[0];
	fader(img,40);
	//w=li.offsetWidth;
	//h=li.offsetHeight;
	//li.innerHTML="<div style='width:"+w+"px;height:"+h+"px'></div>";
	document.getElementById('loadingImg').innerHTML="<img src='/samples/large/"+displayAlbum[index]+".jpg' onload='showPhoto(this)' />";
	t=displayAlbumTitles[index];
	if (t=="") t="Untitled";
	document.getElementById("photoname").innerHTML=t;
	document.getElementById("photoArrows").innerHTML=photoArrows(index,displayAlbum.length);
}
function showPhoto(srcObj) {
	li=srcObj.parentNode;
	li.style.visiblity='hidden';
	li.style.display='block';
	w=srcObj.offsetWidth;
	h=srcObj.offsetHeight;
	li.style.display='none';
	setInnerHTMLCentered('photoDisplay',"<img id='displayingPhoto' src='"+srcObj.src.replace('/samples/thumbnails/','/samples/large/')+"' width='"+w+"' height='"+h+"' style='visibility:hidden' onload='fadeObject(this,0,100,5,null)' />",'dialogBox');
	//fadeObject(document.getElementById('displayingPhoto'),0,100,5,null);
	//startFadeIn(document.getElementById('displayingPhoto'));
}
function setInnerHTML(obj,content) {
	if (typeof(obj)=="string") {
    	thisresize=document.getElementById(obj);
	}else{
		thisresize=obj;
	}
    if (thisresize.tagName=="DIV" || thisresize.tagName=="TD") {
        resizeObj.push(thisresize);
        resizeObjContents.push(content);
        if (resizeObj.length==1) startResize();
    }else{
        thisresize.innerHTML=content;
    }
}
function startResize() {
    if (resizeObj.length>0) {
    
        thisresize=resizeObj[0];
        resizeObjCurrentHeight=thisresize.offsetHeight;
        testContent="<div id=\"textContent\">"+resizeObjContents[0]+"</div>";
        thisresize.style.height=resizeObjCurrentHeight+"px";
        thisresize.style.overflow='hidden';
        thisresize.style.display='block';
        if (resizeObjContents[0]=="") {
            resizeObjHeight=1;
        }else{
            thisresize.innerHTML=testContent;
            resizeObjHeight=thisresize.childNodes[0].offsetHeight;
        }
        thisresize.innerHTML=resizeObjContents[0];
        resizeTimer = setTimeout("resizeTheObj()",2);
    }
}
function resizeTheObj(){
    maxMovement=50;
    thisObj=resizeObj[0];
    dh=(resizeObjHeight-resizeObjCurrentHeight)/2;
    if (dh>maxMovement) dh=maxMovement;
    if (dh<-maxMovement) dh=-maxMovement;
    dw=0;
    if (dh<1 && dh>-1 && dw<1 && dw>-1) {
        clearTimeout(resizeTimer);
        resizeTimer=null;
        if (thisObj.innerHTML=="") thisObj.style.display="none";
        thisObj.style.overflow="visible";
        thisObj.style.height="";
        resizeObj.shift();
        resizeObjContents.shift();
        if (resizeObj.length>0) startResize();
    }else{
        resizeObjCurrentHeight+=dh;
        thisObj.style.height=resizeObjCurrentHeight+"px";
        resizeTimer = setTimeout("resizeTheObj()",2);
    }
}
function setInnerHTMLCentered(obj,content,container) {
    thisresize=document.getElementById(obj);
    if (thisresize.tagName=="DIV" || thisresize.tagName=="TD") {
        fullresizeContainer.push(document.getElementById(container));
        fullresizeObj.push(thisresize);
        fullresizeObjContents.push(content);
        if (fullresizeObj.length==1) startResizeCentered();
    }else{
        thisresize.innerHTML=content;
    }
}
function setEmail() {
	at='@';
	dot='.';
	if (o=objid("emailaddy")) o.innerHTML="<a href='mailto:sales"+at+"polyfex"+dot+"com'>sales"+at+"polyfex"+dot+"com</a>";
	if (o=objid("contact")) o.innerHTML="Contact us: <a href='mailto:sales"+at+"polyfex"+dot+"com'>sales"+at+"polyfex"+dot+"com</a>";
	//fadeOverlays();
}
function fadeOverlays() {
	dvs=document.getElementsByTagName("DIV");
	for (d=0;d<dvs.length;d++) {
		if (dvs[d].className=="overlay") fader(dvs[d],70);
	}
}