/* homepages.js - a combination of the scripts: hasJS.js, externalLinks.js, carousel.v3.1.minified.js, bannerRotator4.minified.js, pop-up.v3.noajax.js */
/*
  Updated 14/09/2011 - MJF
    setOpacity function adjusted to remove IE filter upon completion.
    To help combat white spots appearing in black jpgs.
*/
// Simon Willisons - http://simon.incutio.com/archive/2004/05/26/addLoadEvent
function addLoadEvent(f){var o=window.onload;if(typeof window.onload!=='function'){window.onload=f;}else{window.onload=function(){if(o){o();}f();};}}
function $id(id){return(document.getElementById(id)?document.getElementById(id):false);}
//function setOpacity(i,op){var o=$id(i).style;o.filter='alpha(opacity='+op+')';o.opacity=(op/100);}
function setOpacity(id,op){
  var o = $id(id).style,
    isIE = /*@cc_on!@*/false;
  o.filter = "alpha(opacity=" + op + ")";
  if (op >= 100 && isIE) {
    o.filter = "";
  }
  o.opacity = op / 100;
}

// hasJS.js
if(!document.documentElement.className.match("hasJS")){document.documentElement.className+=" hasJS";}

// externalLinks.js
function externalLinks(){if(document.getElementsByTagName){var As=document.getElementsByTagName("a"),i;for(i=As.length-1;i>-1;i--){var A=As[i];if(A.getAttribute("href")&&A.getAttribute("rel")==="external"){A.target="_blank";A.title=(A.title!=="")?A.title+" (launches in a new window)":"Launches in a new window";}}}}
addLoadEvent(externalLinks);

// bannerRotator4.minified.js
var imageRotator=function(){
var dBF=4000,sT=60,hID=250,cCN,llId,ilId,aC,oCR,T=null,R=null,S=null,cO,nO,lL,iL,lA,iA;
function postFade(fromId,toId){$id(fromId).className=$id(fromId).className.replace(cCN,'');$id(toId).style.zIndex='0';clearTimeout(T);T=null;}
function fadeImageIn(fromObj,toObj){if(fromObj.id===toObj.id){return;}if(T===null){setOpacity(toObj.id,0);toObj.style.zIndex="3";toObj.className=toObj.className+" "+cCN;for(var k=0;k<lA.length;k++){if(lA[k].className.match(toObj.id)){if(!lA[k].className.match(' '+cCN)){lA[k].className=lA[k].className+' '+cCN;}}else{lA[k].className=lA[k].className.replace(' '+cCN,'');}}for(var c=1;c<11;c++){T=setTimeout("setOpacity('"+toObj.id+"',0+"+c*10+")",sT*c);}T=setTimeout("imageRotator.postFade('"+fromObj.id+"','"+toObj.id+"')",(sT*c)+5);}}
function stopAuto(){clearInterval(R);R=null;}
function autoRotate(){if(T===null){var lis=iL.getElementsByTagName('li');if(lis){for(var j=0;j<lis.length;j++){if(lis[j].className.match(cCN)){cO=lis[j];break;}}var next=cO.id.replace('h','');if(next>=lis.length-1){next=0;}else{next++;}var nextId="h"+next;var nO=$id(nextId);fadeImageIn(cO,nO);}}}
function resumeAuto(){clearTimeout(S);if(R===null){R=setInterval(autoRotate,dBF);}}
function changeImage(cn){stopAuto();if(T===null){var lis=iL.getElementsByTagName('li');if(lis){for(var j=0;j<lis.length;j++){if(cn.match(lis[j].id)){nO=lis[j];}if(lis[j].className.match(cCN)){cO=lis[j];}}fadeImageIn(cO,nO);}}}
function hoverIntent(){S=setTimeout("imageRotator.changeImage('"+this.className+"')",hID);}
function linkClicked(){return oCR;}
function init(){aC=arguments[0]?arguments[0]:true;oCR=arguments[1]?arguments[1]:false;ilId=arguments[2]?arguments[2]:"imagesList";llId=arguments[3]?arguments[3]:"linksList";cCN=arguments[4]?arguments[4]:"current";addLoadEvent(function(){lL=$id(llId);iL=$id(ilId);if(lL&&iL){iA=iL.getElementsByTagName('a');lA=lL.getElementsByTagName('a');if(lA&&iA){for(var i=0;i<lA.length;i++){lA[i].onmouseover=hoverIntent;lA[i].onfocus=hoverIntent;lA[i].onmouseout=resumeAuto;lA[i].onblur=resumeAuto;lA[i].onclick=linkClicked;}resumeAuto();for(i=0;i<iA.length;i++){iA[i].onmouseover=stopAuto;iA[i].onmouseout=resumeAuto;iA[i].onfocus=stopAuto;iA[i].onblur=resumeAuto;}}}});}
return{init:init,postFade:postFade,changeImage:changeImage};
}();
imageRotator.init(true,false,"imagesList","linksList","current");

// carousel.v3.1.minified.js
var carouselSpace=function(){
var cUL,lis,T1=null,T2=null,T3=null,c=0,m=false;
function hyphenToCamel(s){var x;for(x=/-([a-z])/;x.test(s);s=s.replace(x,RegExp.$1.toUpperCase())){}return s;}
function getStyleProperty(o,p){var v='';if(window.getComputedStyle){v=window.getComputedStyle(o,null).getPropertyValue(p);}else{if(o.currentStyle){v=o.currentStyle[hyphenToCamel(p)];}}return v;}
function stop(){clearInterval(T1);}
function start(){T1=setInterval(startMove,cUL.cD);}
function nextBrand(){if(!m){stop();startMove();start();}}
function previousBrand(){if(!m){stop();startMoveBack();start();}}
function moveIt(){m=true;setOpacity('carouselRight',cUL.oOn);var d=c;d+=cUL.sS;if(d<cUL.sCB){cUL.lP-=cUL.sS;c+=cUL.sS;cUL.style.left=cUL.lP+"px";}else{var diff= d-cUL.sCB;cUL.lP-=diff;c=0;clearInterval(T2);setOpacity('carouselLeft',cUL.oOf);setOpacity('carouselRight',cUL.oOf);m=false;}}
function restart(){m=true;setOpacity('carouselLeft',cUL.oOn);stop();cUL.lP+=cUL.rS;if(cUL.lP<0){cUL.style.left=cUL.lP+"px";}else{cUL.lP=0;cUL.style.left=cUL.lP+"px";c=0;clearInterval(T1);clearInterval(T2);clearInterval(T3);m=false;setOpacity('carouselLeft',cUL.oNo);start();}}
function startMove(){T2=setInterval(moveIt,cUL.sD);if(cUL.lP<=-cUL.mLP){clearInterval(T2);T3=setInterval(restart,cUL.rD);}}
function moveItBackwards(){if(cUL.lP>=0){setOpacity('carouselLeft',cUL.oNo);c=0;cUL.lP=0;clearInterval(T2);}else{m=true;setOpacity('carouselLeft',cUL.oOn);var d=c;d+=cUL.sS;if(d<cUL.sCB){cUL.lP+=cUL.sS;c+=cUL.sS;}else{var diff= d-cUL.sCB;cUL.lP+=diff;c=0;clearInterval(T2);setOpacity('carouselLeft',cUL.oOf);m=false;}}cUL.style.left=cUL.lP+"px";if(cUL.lP===0){setOpacity('carouselLeft',cUL.oNo);}}
function startMoveBack(){if(cUL.lP<0){T2=setInterval(moveItBackwards,cUL.sD);}else{setOpacity('carouselLeft',cUL.oNo);}}
function init(){addLoadEvent(function(){container=$id('carousel');
if(container){
cUL=container.getElementsByTagName("ul")[0];lis=cUL.getElementsByTagName('li');var pN=document.createElement('ul'),li1=document.createElement('li'),li2=document.createElement('li');pN.id="carouselButtons";li1.id="carouselLeft";li2.id="carouselRight";li1.onclick=function(){previousBrand();};li2.onclick=function(){nextBrand();};pN.appendChild(li1);pN.appendChild(li2);container.appendChild(pN);var i;for(i=0;i<lis.length;i++){lis[i].onmouseover=stop;lis[i].onmouseout=start;}cUL.tC=lis.length;cUL.lP=0;cUL.cD=4000;cUL.sD=20;cUL.rD=20;cUL.sS=3;cUL.rS=10;cUL.sCB=getStyleProperty(lis[0],'width').replace("px","");cUL.style.width=cUL.sCB*cUL.tC+"px";cUL.pW=getStyleProperty(lis[0].parentNode.parentNode,'width').replace("px","");cUL.dC=parseInt(cUL.pW/cUL.sCB,10);cUL.mLP=(cUL.tC-cUL.dC)*cUL.sCB;cUL.oOn=100;cUL.oOf=60;cUL.oNo=20;var rLP=(Math.floor(Math.random()*(cUL.tC+1-cUL.dC)))*cUL.sCB;cUL.lP=-rLP;if(cUL.lP===0){setOpacity('carouselLeft',cUL.oNo);}cUL.style.left=cUL.lP+"px";start();
}
});}
return{init:init,startMove:startMove,moveIt:moveIt,moveItBackwards:moveItBackwards,restart:restart};
}();
carouselSpace.init();

// pop-up.v3.noajax.js + linted and put in closure
var popups=function(){
var pdC="show";
function jsCSS(a,o,c1,c2){switch(a){case'swap':o.className=!jsCSS('check',o,c1)?o.className.replace(c2,c1):o.className.replace(c1,c2);break;case'add':if(!jsCSS('check',o,c1)){o.className+=o.className?' '+c1:c1;}break;case'remove':var rep=o.className.match(' '+c1)?' '+c1:c1;o.className=o.className.replace(rep,'');break;case'check':return new RegExp('\\b'+c1+'\\b').test(o.className);case'toggle':if(jsCSS('check',o,c1)){jsCSS('remove',o,c1);}else{jsCSS('add',o,c1);}break;}return false;}
function idExists(id){return($id(id)?true:false);}
function popOff(i){var o;setOpacity(i,100);for(o=0;o<100;o+=30){setTimeout("setOpacity('"+i+"',"+(100-o)+")",o*2);}setTimeout('popups.jsCSS("remove",$id("'+i+'"),"'+$id(i).dC+'")',o*2);$id(i).removeChild($id(i+"Close"));}
function createCloseLink(i){var o=document.createElement('a');o.href="#"+$id(i).lid;o.id=i+"Close";o.className=$id($id(i).lid).className;o.onclick=function(){popOff(this.parentNode.id);return false;};o.appendChild(document.createTextNode("Return to main content"));$id(i).appendChild(o);return o;}
function popOn(i){var o,op;createCloseLink(i);setOpacity(i,0);for(o=0;o<101;o+=25){op=(o>100)?100:o;setTimeout("setOpacity('"+i+"',"+op+")",o*2);}jsCSS('add',$id(i),$id(i).dC);}
function popup(idN,lid,dC){$id(lid).idN=idN;$id(idN).lid=lid;$id(idN).dC=dC;$id(lid).onclick=function(){var D=$id(this.idN),show=false;if(jsCSS('check',D,D.dC)){show=true;}if(!show){popOn(this.idN);}else{popOff(this.idN);}return false;};}
function init(){var A=document.getElementsByTagName("a"),i;for(i=0;i<A.length;i++){if(A[i].getAttribute("rel")==="appendix"){A[i].idN=A[i].href.substring(A[i].href.lastIndexOf("#")).replace('#','');A[i].id=(A[i].id)?A[i].id:A[i].idN+'Link'+i;popup(A[i].idN,A[i].id,pdC);}}}
return{init:init,jsCSS:jsCSS};
}();
addLoadEvent(popups.init);
