// services.js
//
var curVisibleId = "default";
function selectTab(td) {
	// Hide any current visible tab
	if(!td) return;
	var curTab = document.getElementById(curVisibleId);
	var curContent = document.getElementById(curVisibleId + "Content");
	if(curTab) curTab.className = "";
	if(curContent) curContent.style.display = "none";
			
	// Show the content related to the specified tab
	curVisibleId = td.id;
	curContent = document.getElementById(curVisibleId + "Content");
	td.className = "sel";
	if(curContent) curContent.style.display = "block";
	
	// Load the image related to the tab
	var img = document.getElementById("serviceImg");
	if(img) {
  	var alt = td.id;
  	var a = td.getElementsByTagName("A");
  	if(a && a.length > 0 && a[0]) {
			alt = a[0].innerHTML;
			alt = alt.replace("&amp;", "&");
		}
  	//var src = "img/services/" + td.id + "/1.jpg";
		var src = "img/services/" + td.id + ".jpg";
		img.alt = alt;
		img.src = src;
	}
}

function showPic(n) {
	// Show the specified picture
	var img = document.getElementById("servicePic");
	if(!img) return false;
	var cur = img.src;
	var slash = cur.lastIndexOf('/');
	img.src = cur.substr(0, slash) + '/' + n + '.jpg';
	return false;
}

function topCorners(img) {
	// Write the top left and right corners
	corners(img, "TL,TR");
}

function bottomCorners(img) {
	// Write the bottom left and right corners
	corners(img, "BL,BR");
}

function corners(img, corners) {
	// Create rounded corners as specified
	var border = parseInt(img.substring(0,3));
	img = "img/corners/" + img.replace(' ', '_');
	var width = 6;
	var height= 6;
	
	// IE is weird with the positioning sometimes...
	var ie = (navigator.appVersion.indexOf('MSIE') > -1);
	if(!border || isNaN(border)) border = 1;
	var ieTL = width - 1;
	var ieTR = width - 1;
	var ieBL = width - 3;
	var ieBR = width - 3;

	// Position each corner
	var r = "";
	if(corners.indexOf("TL") > -1) {
		var style = "float: left; position: relative; left: -2px; top: -2px; ";
		if(ie) style += "left: -" + ieTL + "px; ";
  	r += '<img src="' + img + '_tl.gif" height="' + height + '" width="'+ width + '" style="' + style + '" />';
	}
	if(corners.indexOf("TR") > -1) {
		var style = "float: right; position: relative; left: 2px; top: -2px; ";
		if(ie) style += "left: " + ieTR + "px; ";
  	r += '<img src="' + img + '_tr.gif" height="' + height + '" width="'+ width + '" style="' + style + '" />';
	}	
	if(corners.indexOf("BL") > -1) {
		var style = "float: left; position: relative; left: -2px; top: -" + (height - border) + "px; ";
		if(ie) style += "left: -" + ieBL + "px; top: -" + height + "px";
		r += '<img src="' + img + '_bl.gif" height="' + height + '" width="'+ width + '" style="' + style + '" />';
	}
	if(corners.indexOf("BR") > -1) {
		var style = "float: right; position: relative; left: 2px; top: -" + (height - border) + "px; ";
		if(ie) style += "left: " + ieBR + "px; top: -" + height + "px";
		r += '<img src="' + img + '_br.gif" height="' + height + '" width="'+ width + '" style="' + style + '" />';
	}
	
	document.write(r);
}