/* Christmas inspiration pages */

// mike foskett - http://websemantics.co.uk/resources/useful_javascript_functions/
function $id(id){return(document.getElementById(id)?document.getElementById(id):false)}
function isDom(){return (document.getElementById&&document.getElementsByTagName)?true:false}

/* author: 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(){o();f()}}}

// jsCSS(action,object,class1,class2) -  className: swap, add, remove, check or toggle - author: Christian Heilmann - http://www.onlinetools.org/articles/unobtrusivejavascript/cssjsseparation.html
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);break;case'toggle':if(jsCSS('check',o,c1)){jsCSS('remove',o,c1)}else{jsCSS('add',o,c1)};break}return false}


/* Links with rel="external" get launched into new window */
function externalLinks(){
	if (document.getElementsByTagName){
		var as=document.getElementsByTagName("a");
		for (var i=0;i<as.length;i++){
			if (as[i].getAttribute("href") && as[i].getAttribute("rel")=="external"){
				as[i].target="_blank";
				as[i].title="Launches in new window";
		}	}
		var as=document.getElementsByTagName("area")
		for (var i=0;i<as.length;i++){
			if (as[i].getAttribute("href") && as[i].getAttribute("rel")=="external"){
				as[i].target="_blank";
				as[i].title="Launches in new window";
		}	}
	}  
	//return false;
}

function setup(){
	/* rollover image map highlights the link */
	var areaLinks=$id('map1').getElementsByTagName('area');
	for (var i=0; i<areaLinks.length; i++){
		areaLinks[i].onmouseover=function(){
			jsCSS('add',$id(this.className),'highlight')
		}
		areaLinks[i].onmouseout=function(){
			jsCSS('remove',$id(this.className),'highlight')
		}
		areaLinks[i].onfocus=function(){
			jsCSS('add',$id(this.className),'highlight')
		}
		areaLinks[i].onblur=function(){
			jsCSS('remove',$id(this.className),'highlight')
		}
	}
}

if (isDom()){
	addLoadEvent(setup)
	addLoadEvent(externalLinks)
}