
/* ====================================================

	GENERAL SITE COMMANDS AND VARIABLES

  Created by John Mounsey, Peaknet Limited.
  john@peaknet.ltd.uk
  © 2OO6 - please do not steal!

==================================================== */

/* ____________________________________________________

Set Overall Variables..
____________________________________________________ */

var siteName		= '_Generic inc.'
var pagelink		= document.location
var pagename		= document.title
var developer		= 'John Mounsey'
var developerurl	= 'http://www.peaknet.co.uk/'
var defaultStatus	= developerurl

/* ____________________________________________________

Date and Time Functions..
____________________________________________________ */

var months=new Array(13);

months[1]	= "January";
months[2]	= "February";
months[3]	= "March";
months[4]	= "April";
months[5]	= "May";
months[6]	= "June";
months[7]	= "July";
months[8]	= "August";
months[9]	= "September";
months[10]	= "October";
months[11]	= "November";
months[12]	= "December";

var time	= new Date();
var lmonth	= months[time.getMonth() + 1];
var date	= time.getDate();
var dateEnd	= "th"
var year	= time.getYear();

if 	(date == 1 || date == 21 || date == 31)	{ dateEnd = 'st'; }
else if (date == 2 || date == 22) 		{ dateEnd = 'nd'; }
else if (date == 3 || date == 23)		{ dateEnd = 'rd'; }

if (year < 2000) year = year + 1900

function today() { document.write(date + dateEnd + " " + lmonth + ", " + year); }



/* ====================================================
Page Greeting
==================================================== */

function greeting()

{
if (hour >= 22)		{ period = 'night'; }
else if (hour >= 17)	{ period = 'evening'; }
else if (hour >= 12) 	{ period = 'afternoon'; }
else if (hour >= 6) 	{ period = 'morning'; }
document.write('Good afternoon');
}


/* ====================================================
Hide "Loading" message
==================================================== */

function hideLoad()

{
// alert('Loading complete!')
document.getElementById('loading')
loading.style.display='none';
}

/* ====================================================
Things to do when page 100% loaded or resized
==================================================== */

function loaded()

{
window.status		= 'Page 100% Loaded.';
hideLoad();
}

/* ====================================================
Show Destination of a url
==================================================== */

function preUrl(destUrl)

{
var destTarg	= destUrl.target;

if (destTarg != '' || destTarg != '_top')
	{
	destUrl.title	= 'Opens: ' + destUrl.href + ' (in a new window)';
	}
}

/* ====================================================
Bookmark / Add to Favorites script
==================================================== */

function bookmark()

{ 
if (window.external)
	{
	external.AddFavorite(pagelink,pagename)
	}
}



/* ====================================================
Recommend a Friend
==================================================== */

function sendPage()
	{
	alert('This opens a blank Email for you to send to friends ..');
	window.location='mailto:?subject=I recommend this site: ' + siteUrl + ' (' + siteName + ')';
	}


/* ====================================================
Previous Pages
==================================================== */

function goBack(dest) { history.go(-1); }
function doubleBack() { history.go(-2); }



/* ====================================================
Change text within an ID'd <P> or <TD> tag
==================================================== */

function change(part,msg)
{
document.getElementById(part).innerText = msg;
}


/* ____________________________________________________

Footer Tools
____________________________________________________ */

function credit()
{
document.write('<P TITLE="copyright message" CLASS="tools">© ' + siteName + ' ' + thisYear + '</P>');
}



/* ____________________________________________________

Generic Change-Class Function
____________________________________________________ */

function rollTo(piece,prefClass)
{
piece.className=prefClass;
}



/* ____________________________________________________

No Class Function
____________________________________________________ */

function deClass(targCell)
{
targCell.className='';
}



/* ____________________________________________________

MM Jump Menu
____________________________________________________ */

function jumpTo(targ,selObj,restore)
{
eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
if (restore) selObj.selectedIndex=0;
}



/* ____________________________________________________

GO to a page
____________________________________________________ */

function go(destPage)
{
top.location=destPage
}



/* ____________________________________________________

Hide all menus
____________________________________________________ */

function m1()
{
document.getElementById('m3').style.display='none';
document.getElementById('m2').style.display='none';
document.getElementById('m1').style.display='inline';
}

function m2()
{
document.getElementById('m1').style.display='none';
document.getElementById('m3').style.display='none';
document.getElementById('m2').style.display='inline';
}

function m3()
{
document.getElementById('m1').style.display='none';
document.getElementById('m2').style.display='none';
document.getElementById('m3').style.display='inline';
}

function hideRecent()
{
document.getElementById('recentGridLo').className='visible';
document.getElementById('recentGrid').className='hidden';
}

function showRecent()
{
document.getElementById('recentGrid').className='visible';
document.getElementById('recentGridLo').className='hidden';
}

function showContents()
{
document.getElementById('contentsLo').className='hidden';
document.getElementById('contents').className='visible';
}

function hideContents()
{
document.getElementById('contents').className='hidden';
document.getElementById('contentsLo').className='visible';
}

/* ====================================================
Previous Pages
==================================================== */

function windowOpener(page,w,h)
{
window.open(page,'ImageZoom','resizable=yes,location=no,directories=no,toolbar=no,status=no,scrollbars=no,width='+ 800 + ',height='+ 600);
} 

function windowOpenerS(page,w,h)
{
window.open(page,'ImageZoom','resizable=no,location=no,directories=no,toolbar=no,status=no,scrollbars=no,width='+ w + ',height='+ h);
}


function valueCounter(id, opacStart, opacEnd, tFunction, millisec) { 

var speed = Math.round(millisec / 100); 
var timer = 10; 

if(opacStart > opacEnd) { 
 for(i = opacStart; i >= opacEnd; i--) { 
     setTimeout("changeValues(" + i + ",'" + id + "','" + tFunction + "')",(timer * speed)); 
     timer++; 
 } 
} else if(opacStart < opacEnd) { 
 for(i = opacStart; i <= opacEnd; i++) 
 { 
     setTimeout("changeValues(" + i + ",'" + id + "','" + tFunction + "')",(timer * speed)); 
     timer++; 
 } 
} 
} 

function changeValues(nValue, id, tFunction) { 
	
	if(tFunction == "opacity")
	{
		var object = document.getElementById(id).style; 
		object.filter = "alpha(opacity=" + nValue + ")"; 
		object.opacity = (nValue / 100); 
		object.MozOpacity = (nValue / 100); 
		object.KhtmlOpacity = (nValue / 100); 
	}
	else if(tFunction == "top")
	{
		document.getElementById(id).style.top = "-"+nValue+"px";
	}
}


function swapHeaderPhotos(pid){

//Pre Load Images
preimgca = new Image(90,78);
preimgca.src = "/gfx/cooling-photo.png";
preimgcb = new Image(90,78);
preimgcb.src = "/gfx/cooling-photo-2.png";
preimgcc = new Image(90,78);
preimgcc.src = "/gfx/cooling-photo-3.png";
preimgcd = new Image(90,78);
preimgcd.src = "/gfx/cooling-photo-4.png";

preimgha = new Image(90,78);
preimgha.src = "/gfx/heating-photo.png";
preimghb = new Image(90,78);
preimghb.src = "/gfx/heating-photo-2.png";
preimghc = new Image(90,78);
preimghc.src = "/gfx/heating-photo-3.png";
preimghd = new Image(90,78);
preimghd.src = "/gfx/heating-photo-4.png";

preimgda = new Image(90,78);
preimgda.src = "/gfx/drying-photo.png";
preimgdb = new Image(90,78);
preimgdb.src = "/gfx/drying-photo-2.png";
preimgdc = new Image(90,78);
preimgdc.src = "/gfx/drying-photo-3.png";
preimgdd = new Image(90,78);
preimgdd.src = "/gfx/drying-photo-4.png";


	clearTimeout("coolTimer");
	clearTimeout("heatTimer");
	clearTimeout("dryTimer");
	
	clearTimeout("heatOpacStart");
	clearTimeout("dryOpacStart");
	
	clearTimeout("coolOpac");
	clearTimeout("heatOpac");
	clearTimeout("dryOpac");

	clearTimeout("NewImgTimer");

	pnum = pid+1;
	
	if(pnum >= 5){pnum = 1;}
	
	if(document.getElementById("coolingPhoto"))
	{
		valueCounter('coolingPhotoBG', 100, 0, 'opacity', 180);
		
		cpnumtext = "-"+pnum;
		if(pnum == 1){cpnumtext = '';}
		cphototl = "/gfx/cooling-photo"+cpnumtext+".png";
		coolTimer = setTimeout("document.getElementById('coolingPhoto').src='"+cphototl+"'",500);
		coolOpac = setTimeout("valueCounter('coolingPhotoBG', 0, 100, 'opacity', 180)",500);
		
	}
	
	if(document.getElementById("heatingPhoto"))
	{
		heatOpacStart = setTimeout("valueCounter('heatingPhotoBG', 100, 0, 'opacity', 180)",1500);
		
		hpnumtext = "-"+pnum;
		if(pnum == 1){hpnumtext = '';}
		hphototl = "/gfx/heating-photo"+hpnumtext+".png";
		heatTimer = setTimeout("document.getElementById('heatingPhoto').src='"+hphototl+"'",2000);
		heatOpac = setTimeout("valueCounter('heatingPhotoBG', 0, 100, 'opacity', 180)",2000);
	}
	
	if(document.getElementById("dryingPhoto"))
	{
		dryOpacStart = setTimeout("valueCounter('dryingPhotoBG', 100, 0, 'opacity', 180)",3500);
		
		dpnumtext = "-"+pnum;
		if(pnum == 1){dpnumtext = '';}
		dphototl = "/gfx/drying-photo"+dpnumtext+".png";
		dryTimer = setTimeout("document.getElementById('dryingPhoto').src='"+dphototl+"'",4000);
		dryOpac = setTimeout("valueCounter('dryingPhotoBG', 0, 100, 'opacity', 180)",4000);
	}
	
	NewImgTimer = setTimeout("swapHeaderPhotos("+pnum+")",5000);
}

function popUpLinks(){

	links = document.getElementsByTagName("a");
	for(i=0;i<links.length;i++)
	{
		link = links[i];

		linkRel = link.getAttribute("rel");
		linkClass = link.getAttribute("class");
		linkHref = link.getAttribute("href");
		linkChild = link.childNodes[0];
		
		if(linkHref && linkRel == "popupimg")
		{
			nwidth = '800';
			nheight = '600';
				
			if(link.getAttribute("target"))
			{
				link.removeAttribute("target");
			}
		
			if(linkHref && linkChild.nodeName == "IMG")
			{
				linkItemU = link;
				newLinkHref = linkHref;
				imgAttr = new Image();
				imgAttr.onload = function(){
				
					nwidth = imgAttr.width;
					nheight = imgAttr.height;
					linkItemU.href = "javascript:windowOpenerS('"+newLinkHref+"','"+nwidth+"','"+nheight+"')";
				}
				imgAttr.src = linkHref;
			}
			else
			{
				links.item(i).href = "javascript:windowOpenerS('"+linkHref+"','"+nwidth+"','"+nheight+"')";
			}
			
		}
		else if(linkHref && linkRel == "lightbox")
		{
			if(link.getAttribute("target"))
			{
				link.removeAttribute("target");
			}
			
			linkItemU = link;
			newLinkHref = linkHref;
			newLinkClass = linkClass;
			linkItemU.href = "javascript:imageOpener('"+newLinkHref+"','"+newLinkClass+"')";
		}
	}
}

function imageOpener(linkHref,linkClass){		
	
	if(!document.getElementById("zoomphoto"))
	{
		var parentBody = document.getElementsByTagName("body")[0];
		var zoomDiv = document.createElement("div");
		var zoomBG = document.createElement("div");
		var zoomImg = document.createElement("img");
		var zoomClose = document.createElement("a");
		parentBody.appendChild(zoomDiv);
		zoomDiv.appendChild(zoomBG);
		zoomDiv.appendChild(zoomImg);
		zoomDiv.appendChild(zoomClose);
		zoomDiv.setAttribute("id","zoomphoto");
		zoomBG.setAttribute("id","zoomphotobg");
		zoomImg.setAttribute("id","zoomphotoimg");
		zoomImg.setAttribute("alt","Climate Control ImageZoom");
		zoomClose.setAttribute("id","zoomphotoclose");
		zoomClose.setAttribute("href","javascript:imageCloser()");
		zoomClose.setAttribute("title","Close large photo");
	}
	
	document.getElementById("zoomphoto").className = linkClass;
	document.getElementById("zoomphotoimg").src = linkHref;
	document.getElementById("zoomphotoclose").innerHTML = 'X';
	
	loadimg = new Image();
	loadimg.onload = function(){

		nwidth = loadimg.width;
		nheight = loadimg.height;
		mgleft = Math.round(nwidth/2);
		mgtop = Math.round(nheight/2);
		
		document.getElementById("zoomphotoimg").style.width = nwidth+"px";
		document.getElementById("zoomphotoimg").style.height = nheight+"px";
		document.getElementById("zoomphotoimg").style.marginTop = "-"+mgtop+"px";
		document.getElementById("zoomphotoimg").style.marginLeft = "-"+mgleft+"px";
		
		document.getElementById("zoomphotoclose").style.top = "50%";
		document.getElementById("zoomphotoclose").style.left = "50%";
		document.getElementById("zoomphotoclose").style.marginTop = "-"+(mgtop-6)+"px";
		document.getElementById("zoomphotoclose").style.marginLeft = mgleft+"px";
		
		document.getElementById("zoomphotoimg").style.display = "block";
		document.getElementById("zoomphoto").style.display = "block";
		
	}
	loadimg.src = linkHref;
	
}

function imageCloser(){

	document.getElementById("zoomphoto").style.display = 'none';
	document.getElementById("zoomphotoimg").style.display = 'none';
}


window.onload = function(){swapHeaderPhotos(1);popUpLinks();}

