//	hpc.js	Shared JS routines
//
//	(c) Andy Belcher 2005
//
var wwwName		= "www.designercake.co.uk";
var nGal		= 0;
//
function getObjectByAnyMeans(objId) {
	if(document.getElementById) {return document.getElementById(objId);}
	if(document.all)            {return eval("document.all." +objId);}
	if(document.layers)         {return eval("document.layers[" +objId+ "]");}
	return false;
	}
//
function switchClass(lmtId,newClass)
	{document.getElementById(lmtId).className = newClass;}
//
function switchText(lmtId,newText)
	{document.getElementById(lmtId).innerHTML = newText;}
//
function browserUpgradeWarning() {
	document.write("<div id=\"upgrade\"> "
		+ "Sorry, but your browser is either very old or not configured correctly, "
		+ "we shall assume the former! "
		+ "Some of the styling features within this site will not render "
		+ "correctly on your <strong>obsolete</strong> browser. You will still be "
		+ "able to use the site but it won't look as good. "
		+ "In the meantime you are strongly advised to upgrade your browser to "
		+ "at least <strong>Internet Explorer5</strong>, <strong>Netscape6</strong>, "
		+ "or one of the other standards compliant browsers such as FireFox, "
		+ "Mozilla or Opera, these are fully compliant and will work correctly. "
		+ "<br />Try these links for more information: "
		+ "<a href=\"http://webstandards.org/act/campaign/buc/\" target=\"_blank\" "
		+ "title=\"The Browser Upgrade Campaign...\">&raquo;Browser Upgrade Campaign</a> "
		+ "&#8212;<a href=\"http://www.w3.org/QA/\" target=\"_blank\" "
		+ "title=\"Find out more about web standards QA from the W3C...\""
		+ ">&raquo;W3C QA</a></div>");
	}
//
function aSMT(tN,tD,dA,sU) {
	var aS = "{at)";var mT = "ma"+"ilt"+"o:";if(!tD) {tD = domName;}
	var tA = tN+"@"+tD;if(!dA) {dA = tN+aS+tD;}
	if(sU) {sU = "?s"+"ub"+"ject="+sU;} else {sU = "";}
	document.write("<a href=\""+mT+tA+sU+"\" title=\"Ema"
		+ "il to "+dA+"\">"+dA+"</a>");
	}
//
function getSmallImgUrl(imageUrl) {
	var comp		= new Array();comp			= imageUrl.split('.');
	var nComp		= comp.length;var small		= "";var joiner		= "";
	for(i=0;i<nComp-1;i++) {small = small+joiner+comp[i];joiner=".";}
	small = small+imgSmallSuf+"."+comp[nComp-1];
	return small;
	}
//
function imgOwnWindow(imgNo) {
	var orient = "width=\""+imgGalWidth+"\" height=\""+imgGalHgt+"\" ";
	if(iO[imgNo] == "P")
		{orient = "width=\""+imgGalHgt+"\" height=\""+imgGalWidth+"\" ";}
	var galBlrb	 = "";
	var cref = eval((1*imgNo)+1000);
	if((iA[imgNo]) && (iA[imgNo] != "...")) {galBlrb = iA[imgNo]+ "<br />";}
	var pb4 = "";var pft = "<p>";var alg = "";
	if(iO[imgNo] == "P") {pb4 = "<p>";pft = "";alg = "align=\"left\" ";}
	var price = "";
	if(iP[imgNo]) {price = "<br /><strong>Price:</strong> "+iP[imgNo];}
	if(price)
		{price = price+"<br /><small>Cake reference: <code>"
			+ cref+"</code></small>";
		}
	newWindow("","Designer Cake Co."
		, pb4+"<img class=\"gallerymain\" "+alg
			+ "src=\""+imgDir+"/"+iU[imgNo]+"\"\n"
			+ orient+"alt=\""+iA[imgNo]+" (c) "
			+ iC[imgNo]+"\" />\n"+pft
			+ galBlrb
			+ price
			+ "<br /><strong>&copy;</strong> <cite>"+iC[imgNo]+"</cite></p>"
			, 650, 700);
	}
//
function newWindow(name,title,body,hgt,wdt) {
	var winName = window.open("",name,"height=" +hgt+ ",width=" +wdt
		+ ",status=1,resizable=1,scrollbars=1,top=0,left=0");
	winName.document.write("<head><title>" +title+ "</title>\n"
		+ "<style type=\"text/css\">\n"
		+ "body {background:#f7f7f7;font-family:verdana,georgia,arial;"
		+ "font-weight:bold;font-size:smaller;\n"
		+ "background-image:url(\"/images/bgrnd_dal_y2w630_225.jpg\");"
		+ "background-image:url(\"/images/hline_g2w230.jpg\");"
		+ "background-repeat:repeat-y;}\n"
		+ "img {border:4px solid #fffff7;\n"
		+ "border-right:4px solid #d0d0c0;\n"
		+ "border-bottom:4px solid #d0d0c0;}\n"
		+ "span.quote {display:block;border:1px solid #000000;background:#ffffff;"
		+ "padding:2px;margin:0px 5px 0px 5px;font-weight:normal;}\n"
		+ "strong {color:#ff0000;}\ncode {color:#00c000;font-size:larger;}\n"
		+ "</style></head>\n<body>\n" +body
		+ "<a href=\"#\" onclick=\"self.close()\">Remember to close this "
		+ "window...</a></body>\n");
	winName.focus();
	}
function showSpecificThumbNail(imgNo,imgAlign) {
	timgNo = eval(nImg - 1);
	while((imgNo == "last") && (timgNo >= 0)) {imgNo = timgNo;}
	var classStr = "thumbnail";var alignStr = "";
	if((imgAlign) && ((imgAlign == "left") || (imgAlign == "right")))
		{classStr = "intext"+imgAlign;alignStr = imgAlign;}
	document.write(makeImgHtmlStr(imgNo,classStr,alignStr));
	}
//
function doDandyThumbnail(noShow,align) {
	var rndNo	= noShow;
	while(rndNo == noShow) {rndNo = Math.round(Math.random()*(nImg-1));}
	showSpecificThumbNail(rndNo,align);
	}
//
function doSideBarThumbs(nThm,align,ori,noShow) {
	var rndNo	= noShow;
	while(rndNo == noShow) {rndNo = Math.round(Math.random(3.5688)*(nImg-1));}
	document.write('<div id="rightbar">');
	plotSBarThumbs(rndNo,nThm,ori,align);
	document.write('</div><!--rightbar-->');
	}
//
function plotSBarThumbs(rndNo,nThm,ori,align) {
	if(ori != "P") {ori = "L";}
	for(ii=1;ii<=nThm;ii++)
		{var flg = 1;while(flg)
			{if(rndNo >= nImg) {rndNo = 0;}
			if(iO[rndNo] == ori) {showSpecificThumbNail(rndNo,align);flg = 0;}
			rndNo++;
			}
		}
	}
//
function linkThumbs(imgNo,txt,tit) {
	if(!tit) {tit="View picture...";}
	document.write("<a href=\"#\" "
		+ "title=\""+tit+"\" "
		+ "onclick=\"imgOwnWindow("+imgNo+");\">");
	if(txt) {document.write(txt+"</a>");}
	else {document.write("picture</a>");}
	}
//
function makeImgHtmlStr(imgNo,imgClass,imgAlign) {
	var classStr	= "";if(imgClass) {classStr = "class=\""+imgClass+"\" ";}
	var alignStr	= "";if(imgAlign) {alignStr = "align=\""+imgAlign+"\" ";}
	var widthStr	= "width=\""+imgWidth+"\" ";
	var heightStr	= "height=\""+imgHeight+"\" ";
	if(iO[imgNo] == "P")
		{heightStr	= "height=\""+imgWidth+"\" ";
		widthStr	= "width=\""+imgHeight+"\" ";
		}
	var smallUrl	= getSmallImgUrl(iU[imgNo]);
	return "<img src=\""+imgDir+"/"+smallUrl+"\" "
		+ classStr + alignStr + widthStr + heightStr
		+ "onclick=\"imgOwnWindow("+imgNo+");\" "
		+ "alt=\""+iA[imgNo]+" (c) "+iC[imgNo]
		+ " Click for larger image...\" />";
	}
//
function showGalThumb(imgNo) {
	if(imgNo >= nImg) {return "";}
	var smallUrl	= getSmallImgUrl(iU[imgNo]);
	var iSrc		= imgDir+"/"+smallUrl;
	var iCls		= "gil";
	var iWdt		= "160";
	var iHgt		= "120";
	if(iO[imgNo] == "P") {iCls = "gip";iWdt = "120";iHgt = "160";}
	return "<div class=\"galimg\""
		+ "><img src=\""+iSrc+"\" "
		+ "onclick=\"imgOwnWindow("+imgNo+");\" "
		+ "class=\""+iCls+"\" width=\""+iWdt+"\" height=\""+iHgt+"\" "
		+ "alt=\""+iA[imgNo]+"\" /></div><!--galimg-->";
	}
//
function plotCakeGallery(galNo)	{
	if(!galNo) {galNo = 0;}
//	var galListStr = "1,3,5,7,9,11,2,4,6,8,10,12";
	var galListStr = loadGallery(galNo);
	var noteStr	= "<form style=\"float:right;\">"	
		+ makeButton(0,galNo)+"</form>"
		+ "<p>Click on any thumbnailed picture (here or anywhere else "
		+"in this website) and a larger version of the picture will open in "
		+ "a separate window together with any details...";
	var outStr = noteStr+"</p>";
	outStr += "<p class=\"galindex\">"+setGalleryButtons(galNo);
	outStr += "<br />"+galInfo[galNo]+"</p>";
	var galList = galListStr.split(",");
	for(var jj=0;jj<galList.length;jj++)
		{outStr += showGalThumb(galList[jj]);}
	outStr += "<p style=\"clear:left;\"><br />"
		+ "<a href=\"#\" "
		+ "class=\"top\" title=\"To the top of the page...\">Top</a></p>";
	switchText("gallerypane",outStr);
	}
//
function setGalleryButtons(galNo) {
	var retStr = "";
	for(var g=1;g<nGal;g++) {retStr += makeButton(g,galNo);}
	return retStr;
	}
//
function makeButton(galNo,thisGal) {
	var gCls = "orbut";if(galNo == thisGal) {gCls = "hibut";}
	return "<input type=\"button\" class=\""+gCls+"\" id=\"but"+galNo+"\" "
		+ "onclick=\"plotCakeGallery("+galNo+")\" "
		+ "onmouseover=\"switchClass('but"+galNo+"','hibut');\" "
		+ "onmouseout=\"switchClass('but"+galNo+"','"+gCls+"');\" "
		+ "value=\""+galTit[galNo]+"\" />";
	}
function noPrice() {
	alert('Designer Cake Co.\nSorry, our pricelists are being updated and are temporarily unavailble...');
	return false;
	}
//	EOF
