/*	-------------------------------------------------------------
	Bespokes
	- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	Special Mac-Daddy little buggers
	- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
	
function buildAd() {	// build in the 3rd party skyscraper advert
	
	// tests for support
	if (!document.getElementById('skyscraper')) { return false }
	if (!document.createElement) { return false }
	
	// get the 'skyscraper' div
	var targetDiv = document.getElementById('skyscraper');
	
	// create A tag
	var elem = document.createElement('a');
	elem.setAttribute('href', 'http://clkuk.tradedoubler.com/click?p=2554&a=934152&g=30899');
	elem.setAttribute('target', '_blank');
	
	// create IMG tag with link
	var uri = 'http://impgb.tradedoubler.com/imp?type(img)g(30899)a(934152)' + new String (Math.random()).substring (2, 11);
	var imgElem = document.createElement('img');
	imgElem.setAttribute('src', uri);
	
	// append IMG to A
	elem.appendChild(imgElem);
	
	// append A tag to 'skyscraper' div
	targetDiv.appendChild(elem);
	
	
	// create A tag
	var elem = document.createElement('a');
	elem.setAttribute('href', 'http://tracker.tradedoubler.com/click?p=2554&a=934152&g=0&url=http://store.apple.com/Apple/WebObjects/ukBusiness?type=bizukPRO&qprm=67752&family=Certified');
	elem.setAttribute('target', '_blank');
	
	// create IMG tag with link
	var uri = './images/apple/specialdeals.gif' ;
	var imgElem = document.createElement('img');
	imgElem.setAttribute('src', uri);
	
	// append IMG to A
	elem.appendChild(imgElem);
	
	// append A tag to 'skyscraper' div
	targetDiv.appendChild(elem);
}

function buildBtns() {	// attach rounded corners to button links
	
	// tests for support
	if (!document.getElementsByTagName) { return false }
	if (!document.createElement) { return false }
	
	// get the <a> tags
	var pageLinks = document.getElementsByTagName('a');
	
	// loop through and find those with a class of 'btn'
	for (var i=0; i<pageLinks.length; i++) {
		if (pageLinks[i].className.indexOf('btn') != -1) {
			
			// save the text inside the <a>
			var theText = pageLinks[i].firstChild;
			var textValue = document.createTextNode(theText.nodeValue);
			
			// then kill it
			pageLinks[i].removeChild(theText);
			
			// create 4 nested spans - these are 1 for each corner image
			var span1 = document.createElement('span');
			var span2 = document.createElement('span');
			var span3 = document.createElement('span');
			var span4 = document.createElement('span');
			
			// nest spans and the saved text
			span1.appendChild(span2);
			span2.appendChild(span3);
			span3.appendChild(span4);
			span4.appendChild(textValue);
			
			// append to the doc
			pageLinks[i].appendChild(span1);
		}
	}
}



/*	-------------------------------------------------------------
	IE 6 Image replacement flicker fix
	- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	Description:	stops flicker on css image replacement
	- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

		try {
			document.execCommand("BackgroundImageCache", false, true);
		} catch(err) {}



/*	-------------------------------------------------------------
	DOM Ready - Dean Edwards/Matthias Miller/John Resig
	- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	Description:	calls init on DOM Ready, otherwise defaults to onload
	- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

function init() {
	// quit if this function has already been called
	if (arguments.callee.done) return;

	// flag this function so we don't do the same thing twice
	arguments.callee.done = true;

	// kill the timer
	if (_timer) clearInterval(_timer);

	// all page init functions here:
	// do the sifr headers:
	if (typeof sIFR == "function") {
		doSifr();
	};
	// build the rounded corner buttons:
	buildBtns();
	// build the rh col skyscraper:
	buildAd();
};

/* for Mozilla/Opera9 */
if (document.addEventListener) {
	document.addEventListener("DOMContentLoaded", init, false);
}

/* for Internet Explorer */
/*@cc_on @*/
/*@if (@_win32)
	document.write("<script id=__ie_onload defer src=javascript:void(0)><\/script>");
	var script = document.getElementById("__ie_onload");
	script.onreadystatechange = function() {
		if (this.readyState == "complete") {
			init(); // call the onload handler
		}
	};
/*@end @*/

/* for Safari */
if (/WebKit/i.test(navigator.userAgent)) { // sniff
	var _timer = setInterval(function() {
		if (/loaded|complete/.test(document.readyState)) {
			init(); // call the onload handler
		}
	}, 10);
}

/* for other browsers */
window.onload = init;
