

 /* /js/core.js */ 

function addWindowOnLoadEvent(func , domElementId)
{
	// config
	var checkInterval = 250; //ms to check to see if elements have loaded
	
	// see if we have the function array otherwise create it
	if (typeof FUTURE_ONLOAD_FUNCTIONS != 'object')
	{
		//if(window.console)window.console.log('create array and empty timer');
		FUTURE_ONLOAD_FUNCTIONS = new Array();
		FUTURE_DOM_CHECK_TIMER  = false;
	}
	// get  function params
	var func = func;
	var domElementId = (domElementId)?domElementId:false;
	
	// package the function and dom element id
	var functionCall = Array(func , domElementId);
	
	// pack into the global array
	FUTURE_ONLOAD_FUNCTIONS.push(functionCall);
	
	if(!FUTURE_DOM_CHECK_TIMER  && (functionCall[1] != false)) // if we have a call to a dom element
	{
		// create a new timer
		//if(window.console)window.console.log('create a timer - started by ' + functionCall[1]);
		FUTURE_DOM_CHECK_TIMER = setInterval(
			function()
			{
				//if(window.console)window.console.log('timer called');
				//  loop around the FUTURE_ONLOAD_FUNCTIONS and if it has a element_id check to see if its loaded
				var nr = FUTURE_ONLOAD_FUNCTIONS.length -1;
				for(var i = nr; i > -1; i--)
				{
					if ((typeof FUTURE_ONLOAD_FUNCTIONS[i][0] == 'function') && FUTURE_ONLOAD_FUNCTIONS[i][1] && document.getElementById(FUTURE_ONLOAD_FUNCTIONS[i][1]))
					{
						FUTURE_ONLOAD_FUNCTIONS[i][0].call();
						//if(window.console)window.console.log( 'timer called: ' + FUTURE_ONLOAD_FUNCTIONS[i][1] );
						FUTURE_ONLOAD_FUNCTIONS[i] = false;
					}	
				}
				
			} , checkInterval
		);
	}
}

function callWindowOnLoadFunctions()
{
	if(FUTURE_DOM_CHECK_TIMER)clearInterval(FUTURE_DOM_CHECK_TIMER);
	//if(window.console)window.console.log('FUTURE_DOM_CHECK_TIMER killed ');
	var nr = FUTURE_ONLOAD_FUNCTIONS.length -1;
	for(var i = nr; i > -1; i--)
	{
		if (typeof FUTURE_ONLOAD_FUNCTIONS[i][0] == 'function')
		{
			//if(window.console)window.console.log('window onload called: ' + i);
			FUTURE_ONLOAD_FUNCTIONS[i][0].call();
		}	
	}
}

function clearSearchField()
{
	if(!document.getElementById("searchform"))return;
	var inputField = document.getElementById('searchform').getElementsByTagName('input')[0];
	var initalValue = inputField.value;
	inputField.onfocus = function()
	{
		if (this.value == initalValue)
		{
			this.value = "";
		}
	}
	inputField.onblur = function()
	{
		if (this.value == "")
		{
			this.value = initalValue;
		}
	}
}
addWindowOnLoadEvent(clearSearchField);

/*(function attachNewWindowEvent()
{
	var imgs = document.getElementsByTagName('img');
	for(var i = 0; i < imgs.length; i++)
	{
		if(imgs[i].getAttribute('class') && imgs[i].getAttribute('class').indexOf('js_gallery_main_image') > -1)
		{
			imgs[i].onclick = function()
			{
				var galleryPath = this.parentNode.getAttribute("href");
				w = open(galleryPath,'galleryWindow','width=900,height=800,toolbar=no,status=no,scrollbars=auto,resize=no');
				w.focus();
			}
			imgs[i].parentNode.onclick = function()
			{
				return false;
			}		
		}
	}
}
addWindowOnLoadEvent(attachNewWindowEvent);*/

function replaceBrokenImages()
{
	var imgs = document.getElementsByTagName('img');
	var imgNr = imgs.length;
	for (var img = 0; img < imgNr; img++)
	{
		imgs[img].onerror = function()
		{
			var originalScr = this.src;
			var imgSplit = originalScr.split('-');
			var imgCompression = (imgSplit[imgSplit.length-1].split('.')[0]);
			var imgFilename = (imgSplit[imgSplit.length-1].split('.')[1]);
			var imgWidth = (imgSplit[imgSplit.length-2]);
			if (typeof(imgWidth) == "undefined") {
				imgWidth = this.width;
			}
			if (imgWidth == 0) {
				if (this.offsetWidth)
				{
					imgWidth = this.offsetWidth;
				}
			}
			this.setAttribute('brokenurl' , this.src);
			this.setAttribute('width' , imgWidth);
			this.src = 'http://mos.bikeradar.com/images/no-image.jpg'; // just use default.
			this.setAttribute('alt' , 'Broken Image: ' + this.getAttribute('alt'));
			this.onerror = null;
		}
		imgs[img].src = imgs[img].src;
	}
}
addWindowOnLoadEvent(replaceBrokenImages);


function styleShift(theElement,propertyName,propertyType,startVal,endVal,steps,thisStep,delay)
{
	var newVal, startValInt, endValInt;
	switch (propertyType)
	{
		case "#":
		{
			var startRed, startGreen, startBlue, endRed, endGreen, endBlue, redInc, greenInc, blueInc;
			startRed = parseInt(startVal.substring(0,2), 16);
			startGreen = parseInt(startVal.substring(2,4), 16);
			startBlue = parseInt(startVal.substring(4,6), 16);
			endRed = parseInt(endVal.substring(0,2), 16);
			endGreen = parseInt(endVal.substring(2,4), 16);
			endBlue = parseInt(endVal.substring(4,6), 16);
			redInc   = parseInt((endRed - startRed) * (thisStep/steps), 10);
			greenInc = parseInt((endGreen - startGreen) * (thisStep/steps), 10);
			blueInc  = parseInt((endBlue - startBlue) * (thisStep/steps), 10);
			newVal = "rgb(" + parseInt(startRed+redInc) +","+parseInt(startGreen+greenInc) + "," + parseInt(startBlue+blueInc) + ")";
			break;
		}
		case "o":
		{
			startValInt = parseInt(startVal, 10);
			endValInt = parseInt(endVal, 10);
			newVal = parseInt(startValInt + (endValInt - startValInt) * (thisStep/steps), 10)/100;
			break;
		}
		case "%":
		{
			startValInt = parseInt(startVal, 10);
			endValInt = parseInt(endVal, 10);
			newVal = parseInt(startValInt + (endValInt - startValInt) * (thisStep/steps), 10).toString()+"%";
			break;
		}
		case "x":
		{
			startValInt = parseInt(startVal, 10);
			endValInt = parseInt(endVal, 10);
			newVal = parseInt(startValInt + (endValInt - startValInt) * (thisStep/steps), 10).toString()+"px";
			break;
		}
		case "t":
		{
			startValInt = parseInt(startVal, 10);
			endValInt = parseInt(endVal, 10);
			newVal = parseInt(startValInt + (endValInt - startValInt) * (thisStep/steps), 10).toString()+"pt";
			break;
		}
		case "m":
		{
			startValInt = parseInt(startVal, 10);
			endValInt = parseInt(endVal, 10);
			newVal = parseInt(startValInt + (endValInt - startValInt) * (thisStep/steps), 10).toString()+"em";
			break;
		}
		default:
		{
			startValInt = parseInt(startVal, 10);
			endValInt = parseInt(endVal, 10);
			newVal = parseInt(startValInt + (endValInt - startValInt) * (thisStep/steps), 10);
		}
	}
	changeStyle(theElement,propertyName, newVal);
	thisStep++;
	if (thisStep <= steps) {setTimeout(function(){styleShift(theElement,propertyName,propertyType,startVal,endVal,steps,thisStep,delay)}, delay);}
}
function changeStyle(div,change_element,change_value)
{
  var x = div.style;
  eval('x.'+change_element+' = "'+change_value+'";');
  if (change_element == "opacity")
  {
  	eval('x.filter = "alpha(opacity='+(parseInt(change_value*100)).toString()+')";');
	}
}

oldOnLoad = function(){func = function(){return};return}; //fix to anoying ad code

function showTakeover() {
	try { 
		enable_takeover();
	} catch (e) {
		setTimeout('showTakeover()',5000);
	}
}

showTakeover();
	

 /* /js/carousel.js */ 

if (FUTURE_GLOBAL_PAGEJS == 'home')
{

	function carousel_setup(thumbnailElementName,imgElementName,transImgElementName,useZoomOption)
	{
		var carousel_thumbs = new Array;
		var carousel_pics = new Array;
		// Create arrays of pics and thumbnails using the existing thumbnail sources.
		var thumbPics = document.getElementById(thumbnailElementName).getElementsByTagName("img");
		for (i = 0; i < thumbPics.length; i++)
		{
			carousel_thumbs[i] = thumbPics[i].src;
			var thumbSize = new RegExp("-45-80", "g");
			carousel_pics[i] = carousel_thumbs[i].replace(thumbSize,"-400-85");
		}
		document.getElementById(transImgElementName).src = carousel_pics[1];
		imageObj = new Array;
		for (image=0; image < carousel_pics.length; image++)
		{
			imageObj[image] = new Image();
			imageObj[image].src = carousel_pics[image];
		}

		document.getElementById(thumbnailElementName).getElementsByTagName("li")[0].getElementsByTagName("a")[0].style.color = "rgb(255, 255, 255)";
		if (useZoomOption == "zoom") { styleShift(document.getElementById(thumbnailElementName).getElementsByTagName("li")[0],"fontSize","x","12","16",5,0,25); }
		carousel_timer = setInterval('rotate_carousel("' + thumbnailElementName + '","' + imgElementName + '","' + transImgElementName + '","' + useZoomOption + '")',5000);
		// Time to load the images.
	}

	function carousel_force(clickedImage,thumbnailElementName,imgElementName,transImgElementName,useZoomOption,immediateSwitch)
	{
		if (document.getElementById(imgElementName).src != document.getElementById(transImgElementName).src) {
			if (immediateSwitch == "now") {
				document.getElementById(transImgElementName).src = document.getElementById(imgElementName).src;
			} else { return false; }
		}
		// Prevents image switches happening if there's a transition already in progress,
		// unless we've insisted on an immediate switch.
		var carousel_thumbs = new Array;
		var carousel_pics = new Array;
		var thumbPics = document.getElementById(thumbnailElementName).getElementsByTagName("img");
		for (i = 0; i < thumbPics.length; i++)
		{
			carousel_thumbs[i] = thumbPics[i].src;
			var thumbSize = new RegExp("-45-80", "g");
			carousel_pics[i] = carousel_thumbs[i].replace(thumbSize,"-400-85");
		}
		clearInterval(carousel_timer);
		for (image=0; image < carousel_pics.length; image++)
		{
			var colorString = new RegExp(" ", "g");
			document.getElementById(thumbnailElementName).getElementsByTagName("li")[image].getElementsByTagName("img")[0].className = "";
			document.getElementById(thumbnailElementName).getElementsByTagName("li")[image].getElementsByTagName("a")[0].className = "";
			if (carousel_thumbs[image] == clickedImage.src)
			{
/*			    if (typeof document.getElementById(thumbnailElementName).getElementsByTagName("li")[image].style.backgroundPositionX == "string") {
					styleShift(document.getElementById(thumbnailElementName).getElementsByTagName("li")[image],"backgroundPositionX","x","-324","0",immediateSwitch == "now" ? 1 : 15,0,immediateSwitch == "now" ? 1 : 50);
				} else {
					document.getElementById(thumbnailElementName).getElementsByTagName("li")[image].style.background = "url(../images/chevron-back.png) no-repeat 0px -1px;";
				}*/
				styleShift(document.getElementById(thumbnailElementName).getElementsByTagName("li")[image].getElementsByTagName("img")[0],"borderColor","#","2b2b2e","116EB8",immediateSwitch == "now" ? 1 : 6,0,immediateSwitch == "now" ? 1 : 50);
				styleShift(document.getElementById(thumbnailElementName).getElementsByTagName("li")[image].getElementsByTagName("a")[0],"color","#","666666","ffffff",immediateSwitch == "now" ? 1 : 6,0,immediateSwitch == "now" ?  1 : 50);
				if (useZoomOption == "zoom") { styleShift(document.getElementById(thumbnailElementName).getElementsByTagName("li")[image],"fontSize","x","12","16",immediateSwitch == "now" ? 1 : 5,0,immediateSwitch == "now" ? 1 : 25); }
				document.getElementById(transImgElementName).src = document.getElementById(imgElementName).src;
				document.getElementById(transImgElementName).style.opacity = "1";
				document.getElementById(transImgElementName).style.filter = 'alpha(opacity=100)';
				document.getElementById(imgElementName).src = carousel_pics[image];
			} else 	if ((document.getElementById(thumbnailElementName).getElementsByTagName("li")[image].getElementsByTagName("a")[0].style.color.replace(colorString,"") == "rgb(255,255,255)") ||
				    (document.getElementById(thumbnailElementName).getElementsByTagName("li")[image].getElementsByTagName("a")[0].style.color == "#ffffff")) {
/*			    if (typeof document.getElementById(thumbnailElementName).getElementsByTagName("li")[image].style.backgroundPositionX == "string") {
					styleShift(document.getElementById(thumbnailElementName).getElementsByTagName("li")[image],"backgroundPositionX","x","0","-324",immediateSwitch == "now" ? 1 : 15,0,immediateSwitch == "now" ? 1 : 50);
				} else {
					document.getElementById(thumbnailElementName).getElementsByTagName("li")[image].style.background = "url(../images/chevron-back.png) no-repeat -324px -1px;";
				}*/
				styleShift(document.getElementById(thumbnailElementName).getElementsByTagName("li")[image].getElementsByTagName("img")[0],"borderColor","#","116EB8","2b2b2e",immediateSwitch == "now" ? 1 : 6,0,immediateSwitch == "now" ? 1 : 50);
				styleShift(document.getElementById(thumbnailElementName).getElementsByTagName("li")[image].getElementsByTagName("a")[0],"color","#","ffffff","666666",immediateSwitch == "now" ? 1 : 6,0,immediateSwitch == "now" ? 1 : 50);
				if (useZoomOption == "zoom") { styleShift(document.getElementById(thumbnailElementName).getElementsByTagName("li")[image],"fontSize","x","16","12",immediateSwitch == "now" ? 1 : 5,0,immediateSwitch == "now" ? 1 : 25); }
			}
		}
		setTimeout("fadeThat('" + imgElementName + "','" + transImgElementName + "', 100)", 30);
		carousel_timer = setInterval('rotate_carousel("' + thumbnailElementName + '","' + imgElementName + '","' + transImgElementName + '","' + useZoomOption + '")',5000);
		// Time to load the images.
	}

	function rotate_carousel(thumbnailElementName,imgElementName,transImgElementName,useZoomOption)
	{
		var carousel_pics = new Array;
		var thumbSize = new RegExp("-45-80", "g");
		for (i = 0; i < document.getElementById(thumbnailElementName).getElementsByTagName("li").length; i++)
		{
			carousel_pics[i] = document.getElementById(thumbnailElementName).getElementsByTagName("li")[i].getElementsByTagName("img")[0].src.replace(thumbSize,"-400-85");
		}
		carousel_counter = -1;
		for (image=0; image < carousel_pics.length; image++)
		{
			var colorString = new RegExp(" ", "g");
			if ((document.getElementById(thumbnailElementName).getElementsByTagName("li")[image].getElementsByTagName("a")[0].style.color.replace(colorString,"") == "rgb(255,255,255)") ||
			    (document.getElementById(thumbnailElementName).getElementsByTagName("li")[image].getElementsByTagName("a")[0].style.color == "#ffffff")) {
/*			    if (typeof document.getElementById(thumbnailElementName).getElementsByTagName("li")[image].style.backgroundPositionX == "string") {
					styleShift(document.getElementById(thumbnailElementName).getElementsByTagName("li")[image],"backgroundPositionX","x","0","-324",15,0,50);
				} else {
					document.getElementById(thumbnailElementName).getElementsByTagName("li")[image].style.background = "transparent url(../images/chevron-back.png) no-repeat -324px -1px;";
				}*/
				styleShift(document.getElementById(thumbnailElementName).getElementsByTagName("li")[image].getElementsByTagName("img")[0],"borderColor","#","116EB8","2b2b2e",6,0,50);
				styleShift(document.getElementById(thumbnailElementName).getElementsByTagName("li")[image].getElementsByTagName("a")[0],"color","#","ffffff","666666",6,0,50);
				if (useZoomOption == "zoom") { styleShift(document.getElementById(thumbnailElementName).getElementsByTagName("li")[image],"fontSize","x","16","12",5,0,25); }
			}
			if (carousel_pics[image] == document.getElementById(imgElementName).src)
			{
				carousel_counter = image + 1;
				document.getElementById(transImgElementName).src = document.getElementById(imgElementName).src;
				document.getElementById(transImgElementName).style.opacity = "1";
				document.getElementById(transImgElementName).style.filter = 'alpha(opacity=100)';
			}
		}
		if (carousel_counter < 0)
		{
			document.getElementById(imgElementName).src = carousel_pics[1];
			document.getElementById(transImgElementName).src = carousel_pics[0];
			document.getElementById(transImgElementName).style.opacity = "1";
			document.getElementById(transImgElementName).style.filter = 'alpha(opacity=100)';
			clearInterval(carousel_timer);
			carousel_timer = setInterval('rotate_carousel("' + thumbnailElementName + '","' + imgElementName + '","' + transImgElementName + '","' + useZoomOption + '")',5000);
			return true;
			// If the main background doesn't match any of the thumbs, we'll force the damn thing.
		}
		document.getElementById(transImgElementName).style.zIndex = "110";
		if (carousel_counter > carousel_pics.length - 1) { carousel_counter = 0; }
		fadeThat(imgElementName, transImgElementName, 100);
		setTimeout('document.getElementById("' + imgElementName + '").src = "' + carousel_pics[carousel_counter] + '"',30);
/*	    if (typeof document.getElementById(thumbnailElementName).getElementsByTagName("li")[carousel_counter].style.backgroundPositionX == "string") {
			styleShift(document.getElementById(thumbnailElementName).getElementsByTagName("li")[carousel_counter],"backgroundPositionX","x","-324","0",15,0,50);
		} else {
			document.getElementById(thumbnailElementName).getElementsByTagName("li")[carousel_counter].style.background = "transparent url(../images/chevron-back.png) no-repeat 0px -1px;";
		}*/
		styleShift(document.getElementById(thumbnailElementName).getElementsByTagName("li")[carousel_counter].getElementsByTagName("img")[0],"borderColor","#","2b2b2e","116EB8",6,0,50);
		styleShift(document.getElementById(thumbnailElementName).getElementsByTagName("li")[carousel_counter].getElementsByTagName("a")[0],"color","#","666666","ffffff",6,0,50);
		if (useZoomOption == "zoom") { styleShift(document.getElementById(thumbnailElementName).getElementsByTagName("li")[carousel_counter],"fontSize","x","12","16",5,0,25); }
	}

	function fadeThat(imgElementName,transImgElementName, opacity)
	{
		document.getElementById(transImgElementName).style.opacity = (opacity/100).toString();
		document.getElementById(transImgElementName).style.filter = 'alpha(opacity=' + opacity.toString() + ')';
		opacity-=5;
		if (opacity>=0) {setTimeout("fadeThat('" + imgElementName + "','" + transImgElementName + "', " + opacity + ")", 20);}
		else {document.getElementById(transImgElementName).src = document.getElementById(imgElementName).src;}
	}
}



 /* /js/setup_carousel.js */ 

if (FUTURE_GLOBAL_PAGEJS == 'home')
{

	// setup function to start the homepage carousel

	function setup_homepage_carousel()
	{
		carousel_setup('carousel_thumbnails','carousel_image','carousel_transitional_image','');
		var x = document.getElementById("carousel_thumbnails").getElementsByTagName("li");
		for (var i=0;i<x.length;i++)
		{
			x[i].getElementsByTagName("img")[0].onclick = function () { carousel_force(this,'carousel_thumbnails','carousel_image','carousel_transitional_image','','now'); }
			x[i].onmouseover = function () { carousel_force(this.getElementsByTagName("img")[0],'carousel_thumbnails','carousel_image','carousel_transitional_image','','now'); }
		}
	}
	addWindowOnLoadEvent(setup_homepage_carousel);


}


 /* /js/magazine_blogs.js */ 

function rotateLinkPic(picId)
{
	theLink = document.getElementById("magazine_images");
	theSpan = theLink.getElementsByTagName("span")[0];
	theImg = theLink.getElementsByTagName("img")[0];
	theImg.src = theLink.getElementsByTagName("img")[0].src;
		theLink.href = hrefs[picId];
		theSpan.style.backgroundImage = "url(" + theImg.src + ")";
	//	theSpan.style.zIndex = 90;
		theImg.style.opacity = "0";
		theImg.style.filter = 'alpha(opacity=0)';
		setTimeout(function(){
			theImg.src = mag_imgs[picId];
			theImg.alt = alts[picId];
    		theImg.title = alts[picId];
			styleShift(theImg,"opacity","o",0,100,6,0,60);
		},200);
		setTimeout(function(){theSpan.style.zIndex = 100;}, 2000);

}
function loopLinkPicRotation()
{
	picId++;
	if (picId == mag_imgs.length) {picId = 0;}
	rotateLinkPic(picId);
}


 /* /js/gear_browser.js */ 

if (FUTURE_GLOBAL_PAGEJS == 'gear' || FUTURE_GLOBAL_PAGEJS == 'gearlisting' || FUTURE_GLOBAL_PAGEJS == 'geararticle')
{

	// add the css to hide all sub lists without js
	var domain = document.location.toString().split('/')[2]; // get domain
	document.write('<style>@import url(http://'+domain+'/css/js_gear_browser.css);</style>'); //write style

	function setupGearBrowser()
	{
		var gearBrowserElement = document.getElementById('gear_browser');

		gearBrowserElement.onclick = function(e)
		{
			var e = (e)?e:window.event;
			var targetElement = (e.target)?e.target:e.srcElement;

			if(!targetElement.parentNode.hasChildNodes() || targetElement.parentNode.childNodes.length == 1)
			{
				return;
			}

			if (targetElement.nodeName.toLowerCase() == "a" && targetElement.parentNode.childNodes[1].nodeName.toLowerCase() == "ul")
			{
				var ulTags = this.getElementsByTagName("ul");
				ulTagsNr = ulTags.length;

				// if its open just close it
				if(targetElement.parentNode.childNodes[1].className == "open")
				{
					targetElement.parentNode.childNodes[1].className = "";
					return false;
				}
				else
				{
					// otherwise hide everything
					for(var i = 0; i < ulTagsNr; i++)
					{
						ulTags[i].className = "";
					}
					// and then loop up through the uls from target and open them
					var el = targetElement.parentNode.childNodes[1];
					while(el.parentNode.nodeName.toLowerCase() != "div")
					{
						if(el.nodeName.toLowerCase() == "ul")
						{
							el.className = "open";
						}
						el = el.parentNode;
					}
					return false;
				}
				//return false;
			}
		}
	}
	addWindowOnLoadEvent(setupGearBrowser  , 'gear_browser');
}

 /* /js/toggle_specs.js */ 

if (FUTURE_GLOBAL_PAGEJS == 'geararticle')
{

	// add the css to hide all sub lists without js
	var domain = document.location.toString().split('/')[2]; // get domain
	document.write('<style>@import url(http://'+domain+'/css/js_specs.css);</style>'); //write style

	function setupFullSpec()
	{
		var specsDiv = document.getElementById('specs');

		var dtEls = specsDiv.getElementsByTagName('dt');
		var ddEls = specsDiv.getElementsByTagName('dd');
		var fullSpecHiddenElements = new Array();

		var dtLen = dtEls.length;
		for(var i = 0; i < dtLen; i++)
		{
			if(dtEls[i].className == 'full_spec')
				fullSpecHiddenElements.push(dtEls[i]);
		}
		var ddLen = dtEls.length;
		for(var i = 0; i < ddLen ; i++)
		{
			if(ddEls[i].className == 'full_spec')
				fullSpecHiddenElements.push(ddEls[i]);
		}
		// create link
		var fullSpecP = document.createElement('p');
		var fullSpecA = document.createElement('a');
		var fullSpecT = document.createTextNode('show full Specification');

		fullSpecP.appendChild(fullSpecA);
		fullSpecA.appendChild(fullSpecT);
		fullSpecA.setAttribute('href','#');
		fullSpecA.setAttribute('toggleState','closed')
		fullSpecA.setAttribute('title','Click to display full specification.');
		specsDiv.getElementsByTagName('div')[0].appendChild(fullSpecP);

		fullSpecA.onclick = function()
		{
			var toggleState = this.getAttribute('toggleState');
			if (toggleState == 'closed')
			{
				for(var el in fullSpecHiddenElements)
				{
					if(fullSpecHiddenElements[el].className)
					{
						fullSpecHiddenElements[el].className = 'full_spec_open';
						fullSpecHiddenElements[el].style.display = 'block';
					}
				}
				this.replaceChild(document.createTextNode('hide full specification') , this.firstChild);
				this.setAttribute('toggleState','open');
			}
			else
			{
				for(var el in fullSpecHiddenElements)
				{
					if(fullSpecHiddenElements[el].className)
					{
						fullSpecHiddenElements[el].className = 'full_spec';
						fullSpecHiddenElements[el].style.display = 'none';
					}
				}
				this.replaceChild(document.createTextNode('show full specification') , this.firstChild);
				this.setAttribute('toggleState','closed');
			}
			return false;
		}
	}
	addWindowOnLoadEvent(setupFullSpec);
}

 /* /js/gallery_popup_hook.js */ 

var galleryPopupHook = function(relName,relName2)
{
	// html references and popup window properties
	this.galleryLinkImage = (relName) ? (typeof relName == "object" ? relName : document.getElementById(relName)) : document.getElementById("gallerybox_popup_image");
	this.galleryLinkThumbs = (relName2) ? (typeof relName2 == "object" ? relName2 : document.getElementById(relName2)) : document.getElementById("gallery_thumbs");
  if(this.galleryLinkImage.href)
  {
	  this.galleryHref = this.galleryLinkImage.href; // .split("?")[0];
	  this.windowHeight = 700;
	  this.windowWidth = 1000;
	  this.windowSettings = "height=" + this.windowHeight + ",width=" + this.windowWidth + ",toolbar=0,menubar=0,scrollbars=1,resizable=1,location=0,directories=0,status=0";
	  // Not sure if I'll even end up using relName, but it may come in useful at some unforeseen point.
  } else if(this.galleryLinkThumbs) {
    this.galleryHref = this.galleryLinkThumbs.getElementsByTagName("a")[0].href; // .split("?")[0]; - why did we try to leave the ? out
	  this.windowHeight = 700;
	  this.windowWidth = 1000;
	  this.windowSettings = "height=" + this.windowHeight + ",width=" + this.windowWidth + ",toolbar=0,menubar=0,scrollbars=1,resizable=1,location=0,directories=0,status=0";
  }
}
galleryPopupHook.prototype =
{
	initialise:function()
	{
		var objRef = this;
		if(this.galleryLinkThumbs != null) // check we have a link to hang the popup on.
		{
			galleryThumbs = this.galleryLinkThumbs.getElementsByTagName("a");
			
			for (i=0; i<galleryThumbs.length; i++) {
				galleryThumbs[i].onclick=function()
				{
					objRef.handleClick(this.href); // objRef.galleryHref + "?" + (this.href.split("?")[1]));
					return false; // Cancel the hyperlink.
				}
			}
		} 
		
		if(this.galleryHref != null) {
			this.galleryLinkImage.onclick=function()
			{
				objRef.handleClick2();
				return false; // Cancel the hyperlink.
			}
		}
	},
	handleClick:function(href)
	{
		window.open(href,"gallerybox_popup",this.windowSettings); // Okay, lets load it in a popup instead.
	},
	
	handleClick2:function()
	{
		var popupLocation = this.galleryHref; // Where are we going?
		window.open(popupLocation,"gallerybox_popup",this.windowSettings); // Okay, lets load it in a popup instead.
	}
}


 /* /js/new_gallery.js */ 

if(FUTURE_GLOBAL_PAGEJS == "gallery" ){

	function galleryLoader()
	{
		if (document.getElementById("gallery_items"))
		{
			var selectedIndex = (url.split("mid=")[1])? url.split("mid=")[1]-1 : 0; // We'll need this shortly.
			document.getElementById("arrow_left").onclick = function(){
				initiateMoveGallery("left");
				return false;
			};
			document.getElementById("arrow_right").onclick = function(){
				initiateMoveGallery("right");
				return false;
			};
			var imgThumbs = document.getElementById("gallery_items").getElementsByTagName("img");
			var imgThumbLinks = document.getElementById("gallery_items").getElementsByTagName("a");
			for (i=0; i<imgThumbs.length; i++)
			{
				imgThumbs[i].imgIndex = i;
				imgThumbs[i].onclick = function()
				{
					updateSelectedImage(this.imgIndex);
					return false;
				};
				if (selectedIndex != 0) {
					if (imgThumbLinks[i].href.split("mid=")[1] == selectedIndex) {
						changeGalleryPosition(i);
					}
				}
			}
			if (selectedIndex == 0) {
				changeGalleryPosition(0);
				document.getElementById("arrow_left").style.display = "none";
			}
			if (document.getElementById("closure_link"))
			{
				document.getElementById("closure_link").onclick = function()
				{
					window.close();
				};
			}
		}
	}

	var imgWidth = 62; // This means the scroller functionality only works when the images are the same width. Boo.
	var displayedImgs = 5; // This is the number of images we display in the scroller at once.
	var bigImgWidth = 850;
	
	var speed = 10;
	var alreadyLoaded = false;
	
	var n = 0;
	var position = 0;
	var middleIndex = 2;
	var oldIndex = 0;
	var newIndex = 0;
	var leftmostThumb = 0; // Between 0 and the number of images-1, ie 0-11 for a 12-thumbnail gallery
	var url = window.location.href;
	var selectedIndex = (url.split("img=")[1])? url.split("img=")[1].split("&")[0]-1 : 0; //need to be the index and not the img number

	//Slide gallery from the oldX to the newX position in an animating way
	function slideGallery(divId,newX,oldX){
		timer =  0;				
		do{					
			if(newX >= oldX){oldX++;}else{oldX--;}
			setTimeout("changeX(" + oldX + ",'" + divId + "')",(speed*timer));
			timer++;			
		}while(oldX != newX);
	}

	//Set the margin-left of an element
	function changeX(value,divId){
		document.getElementById(divId).style.margin = "0px -50px 0px "+value+"px ";	
	}


	//Change the gallery position according to the new selectedIndex value
	function changeGalleryPosition(index,arrowShift){
		if (typeof arrowShift == "undefined") arrowShift = 0;
		if (document.getElementById("gallery_items"))
		{
			var imgList = document.getElementById("gallery_items").getElementsByTagName("img");
			if(imgList.length > displayedImgs){
				var maxScroll = imgList.length-displayedImgs;

				
				direction=0;
				if (arrowShift == 0) {
					if (leftmostThumb > 0) {
						if ((index-leftmostThumb) < (displayedImgs/2)) {
							direction=-1;
						}
					}
					if (leftmostThumb < maxScroll) {
						if ((index-leftmostThumb) > (displayedImgs/2)) {
							direction=1;
						}
					}
				} else {
					direction = arrowShift;
				}
				leftmostThumb+=direction;

				//Manage arrows display
				if(leftmostThumb==0){
					document.getElementById("arrow_right").style.display = "block";
					document.getElementById("arrow_left").style.display = "none";   
				}else if(leftmostThumb == maxScroll){
					document.getElementById("arrow_left").style.display = "block";
					document.getElementById("arrow_right").style.display = "none";  
				}else{
					document.getElementById("arrow_right").style.display = "block";
					document.getElementById("arrow_left").style.display = "block";
				}
				imgElList = document.getElementById("gallery_items").getElementsByTagName("img");
				
				if (direction==0) { return false; }
				var newX = - (imgWidth * leftmostThumb);
				slideGallery("gallery_items",newX,position);		
				position = newX;
				oldIndex = index;
				return false;
			}else{
				document.getElementById("arrow_right").style.display = "none";
				document.getElementById("arrow_left").style.display = "none";   
				return false;
			}
		}
	}

	//Generate by an onclick on the arrows link
	//This function initiate (if it is necessary) the gallery move to right direction
	function initiateMoveGallery(direction){
	    if(direction == "left"){
	        newIndex--;
	    }else{
	        newIndex++;
	    }
	     var imgList = document.getElementById("gallery_items").getElementsByTagName("img");
	
	    if (((leftmostThumb > 0) && (direction == "left")) || ((leftmostThumb < imgList.length-displayedImgs) && (direction=="right"))) {
	        changeGalleryPosition(newIndex,(direction=="right" ? 1 : -1));
	        oldIndex = newIndex;
	    }
	}
	
	//Generate by an onclick on a thumbnail
	//This function initiate (if it is necessary) the gallery move to right position
	function updateSelectedImage(index){
	    alreadyLoaded = false;

		newIndex = selectedIndex;
		selectedIndex = middleIndex = index;
		if(middleIndex < 2){middleIndex = 2;}
		if(newIndex != index){
			fadeImageOutIn("image_container",document.getElementById("gallery_items").getElementsByTagName("img")[selectedIndex].src);
		}
	
		var imgList = document.getElementById("gallery_items").getElementsByTagName("img");

		document.getElementById("gallery_items").getElementsByTagName("li")[newIndex].className = "";
		document.getElementById("gallery_items").getElementsByTagName("li")[index].className = "slc";
	
/*		if(document.getElementById("gallery_top")){
			document.getElementById("gallery_top").getElementsByTagName("h2")[0].innerHTML = document.getElementById("gallery_items").getElementsByTagName("a")[selectedIndex].title;
		}*/
		if(document.getElementById("gallery_caption")){
			document.getElementById("gallery_caption").innerHTML = document.getElementById("gallery_items").getElementsByTagName("img")[selectedIndex].alt;
		}
		if(document.getElementById("gallery_pagination")){
			document.getElementById("gallery_pagination").innerHTML = "Showing "+(Number(selectedIndex)+1)+" of "+imgList.length;
		}
		changeGalleryPosition(index);

		if(tempImg == undefined){
			var tempImg = document.createElement("img");					
			tempImg.onload = function(){
				alreadyLoaded = true;
				divId = "image_container";
		 	    setTimeout(function(){changeImageOpacity(0,divId)},(speed*timer));
			    timer++;
				setTimeout(function(){document.getElementById(divId).childNodes[0].src = document.getElementById("gallery_items").getElementsByTagName("img")[index].src.replace(regex , "$1-"+bigImgWidth+"-$2.$3")},(speed*timer));
				timer++;
				for(i=0; i < 100; i++){
					setTimeout("changeImageOpacity(" + i + ",'" + divId + "');",(speed*timer));
					timer++;
				}
				setTimeout(function(){document.getElementById(divId).childNodes[0].style.border = '1px solid #DADADA'},(speed*timer/2));
			}
		}
	    if(newIndex != index){
	    	var regex = /(.*)-[0-9]{1,4}-([0-9]{1,3}).([a-zA-Z]{3}$)/gi;
	        tempImg.src = document.getElementById("gallery_items").getElementsByTagName("img")[selectedIndex].src.replace(regex , "$1-"+bigImgWidth+"-$2.$3");
	        // Soon, we might have an upscaling prevention mechanism on mos. In anticipation of this:
	        //tempImg.src = document.getElementById("gallery_items").getElementsByTagName("img")[selectedIndex].src.replace(regex , "$1-"+bigImgWidth+"-$2-noupscale.$3");
	    }
	    return false;
	}
	
	//Bring the opacity of an element from 0 to 100
	function fadeImageOutIn(divId,newSrc){
		timer =  0;	
		for(i=100; i >= 0; i--){
			setTimeout("changeImageOpacity("+i+",'" + divId + "');",(speed*timer));
			timer++;			
		}
		setTimeout(function(){displayLoader(divId)},(speed*timer));
		timer++;				
	}
	
	//Change the src of the main image to display the loader
	function displayLoader(divId){
		if(alreadyLoaded == false){
			document.getElementById(divId).childNodes[0].style.border = 'none';
			document.getElementById(divId).childNodes[0].src = '/images/gallery-loading.gif';	
			changeImageOpacity(100,divId);
		}			
	}
	//Change the opacity of an image
	function changeImageOpacity(value, divId){		
		if (document.getElementById(divId).style) {
//			if (document.getElementById(divId).style.MozOpacity!=null) {  
				/* Mozilla's pre-CSS3 proprietary rule */
//				document.getElementById(divId).style.MozOpacity = (value/100) - .001;
/*			} else*/ if (document.getElementById(divId).style.opacity!=null) {
				/* CSS3 compatible */
				document.getElementById(divId).style.opacity = (value/100) - .001;
			} else if (document.getElementById(divId).style.filter!=null) {
				/* IE's proprietary filter */
				document.getElementById(divId).style.filter = "alpha(opacity="+value+")";
			}
		}	
	}
	addWindowOnLoadEvent(function(){galleryLoader()});
	addWindowOnLoadEvent(function(){changeGalleryPosition(selectedIndex)}, "wrapper");

}


 /* /js/setup_gallery.js */ 

// set up the Add To/Amend My Gear events
function setupArticleGallery()
{
	if (FUTURE_GLOBAL_PAGEJS == 'geararticle') {
		var articleGalleryHook = new galleryPopupHook(document.getElementById('verdict'), document.getElementById("review_thumbs"));
		articleGalleryHook.initialise();
	} else if (document.getElementById("gallerybox_popup_image")){
		var articleGalleryHook = new galleryPopupHook();
		articleGalleryHook.initialise();
	}
}
addWindowOnLoadEvent(setupArticleGallery);

if (FUTURE_GLOBAL_PAGEJS == 'gallery')
{

	// add the css to hide all sub lists without js
	var domain = document.location.toString().split('/')[2]; // get domain
	document.write('<style>@import url(http://'+domain+'/css/js_gallery.css);</style>'); //write style

}