// SWAPS THE HEADER PICTURE AROUND, SETS A NEW LABEL AND HIGHLIGHTS THE CORRECT NUMBER
function swappy(foo) {
	document.getElementById('content4').style.backgroundPosition = '-'+(956*parseFloat(foo-1))+'px 0px';
	document.getElementById('switcher').style.background = 'url(/images/Pic'+foo+'-Title.gif) left top no-repeat';
	var swLinks = document.getElementsByTagName('a');
	for (i=0 ; i<swLinks.length ; i++) {
		if (swLinks[i].className === 'sw') {
			swLinks[i].style.color = '#FFF';
		}
	}
	document.getElementById('sw'+foo).style.color = '#FC0';
	next = parseFloat(foo)+1;
	if (foo == document.getElementById('switcherLinks').childNodes.length) { setTimeout("swappy('1')",6500); }
	else { setTimeout("swappy(next)",6500); }
}

// HANDLES GALLERY PSEUDO-PAGINATION
function page(foo) {
	pages = new Array();
	pages = document.getElementsByTagName('div');
	for (i=0 ; i<pages.length ; i++) {
		if (pages[i].className==='thumbs') pages[i].style.visibility = 'hidden';
	}
	document.getElementById('thumbs'+foo).style.visibility = 'visible';
	document.getElementById('daPage').innerHTML = foo;
}

// FORM ACTIVATION SCRIPT
function activate(brillig) {
	document.getElementById('config').name = "config";
	document.getElementById('config').value = brillig;
}

function setup() {
	// EXTENDS THE LEFT COLUMN TO THE SAME HEIGHT AS THE CONTENT AREA
	if (document.getElementById('compare1').offsetHeight < document.getElementById('compare2').offsetHeight) {
		if (document.getElementById('home')) {
			document.getElementById('compare1').style.height = (document.getElementById('compare2').offsetHeight-228)+'px';
		} else {
			document.getElementById('compare1').style.height = (document.getElementById('compare2').offsetHeight-128)+'px';
		}
	}
	
	// FIXES THE 1 PIXEL JOG PROBLEM IN ALL NON-IE BROWSERS
	UserAgent = navigator.userAgent;
	if (UserAgent.search(/Opera/) !== -1) {
		document.getElementById('content3').style.marginLeft = '2px';
		if (document.body.clientHeight < window.innerHeight) document.body.style.height = window.innerHeight+1+'px';
			foo = (window.innerWidth/2)+'';
			if (foo.charAt(foo.length-2) ==='.') document.getElementById('content3').style.marginRight = '2px';
	}
	if (UserAgent.search(/Firefox/) !== -1) {
		document.getElementById('content3').style.marginRight = '1px';
	}
	
	// MAKES EXTERNAL LINKS OPEN IN NEW WINDOWS
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++) {
		var URL = anchors[i].href;
		if (URL.search('bespoke')===-1 && URL.search('heaven')===-1 && URL.search('http')!==-1) anchors[i].target = "_blank";
	}
	
	//initLightbox();
	URL = window.location+'';
	//if (URL.search('new.bespokekitchensuk')!==-1 ) { swappy('3'); } else { swappy('1'); }
	swappy('1');
}
window.onload = setup; 