//function to allow more than one window.onload event
function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}


//OpenClose
function OpenClose(id) {
	var element = document.getElementById(id);
	if (element.style.display != 'block') {
		element.style.display = 'block';
	}else{
		element.style.display = 'none';
	}
}


//close
function closeme(id) {
	var element = document.getElementById(id);
	element.style.display = 'none';
}


//open
function openme(id) {
	var element = document.getElementById(id);
	element.style.display = 'block';
}

//SelectRegion
function SelectRegion(id) {

	var List = ['WorkshopsInEngland','WorkshopsInScotland','WorkshopsInWales','WorkshopsInNireland'];//'RegionList',
	

	for(var i=0;i<List.length;i++){
		//alert(List[i]);
		
		var elementValue = document.getElementById(List[i]);
		elementValue.value = '';
		var elementDiv = document.getElementById(String(List[i]));
		elementDiv.style.display = 'none';
	}
	
	var moreOptions = document.getElementById("MoreSearchOptions");
	moreOptions.style.display = 'none';

	var elementValue = document.getElementById(List[id]);
	var elementDiv = document.getElementById(String(List[id]));
	elementDiv.style.display = 'block';
	
}

function MoreSearchOptions(){
	
}


function setSmall()
{	
	addstyle('body', 'font-size:80%', '');
	
	addstyle('#small', 'background:#999999', '');
	addstyle('#small', 'color:#000000', '');
	
	addstyle('#medium', 'background:#000000', '');
	addstyle('#medium', 'color:#999999', '');
	
	addstyle('#large', 'background:#000000', '');
	addstyle('#large', 'color:#999999', '');
	
}

function setMedium()
{	addstyle('body', 'font-size:95%', '');

	addstyle('#small', 'background:#000000', '');
	addstyle('#small', 'color:#999999', '');
	
	addstyle('#medium', 'background:#999999', '');
	addstyle('#medium', 'color:#000000', '');
	
	addstyle('#large', 'background:#000000', '');
	addstyle('#large', 'color:#999999', '');
}


function setLarge()
{	addstyle('body', 'font-size:110%', '');

	addstyle('#small', 'background:#000000', '');
	addstyle('#small', 'color:#999999', '');
	
	addstyle('#medium', 'background:#000000', '');
	addstyle('#medium', 'color:#999999', '');
	
	addstyle('#large', 'background:#999999', '');
	addstyle('#large', 'color:#000000', '');
}

// Prepare Image Gallery
function prepareGallery() {
	if(!document.getElementById("thumbs")) return
	var galleryList = document.getElementById("thumbs")

	var images = galleryList.getElementsByTagName("img");
	
	
	for (i=0;i<images.length;i++) {
		images[i].onmouseover = showPic; //onclick
		images[i].onmouseout = hidePic; //onclick
		images[i].style.cursor = "pointer";
	}
	
	function showPic() {
		var source = this.getAttribute("name");
		//var alt = this.getAttribute("alt");
		//var caption = document.getElementById("caption");
		var placeholder = document.getElementById("placeholder");
		placeholder.setAttribute("src",source);
		//placeholder.setAttribute("alt",alt);
		placeholder.style.display = 'block';
		//caption.innerHTML = alt;
	}
	
	function hidePic() {
		var source = this.getAttribute("name");
		var placeholder = document.getElementById("placeholder");		
		var placeholder_under = document.getElementsByTagName("img");
		for(var i=0; i<placeholder_under.length; i+=1){
			if(placeholder_under[i].className=="Alex"){
				//alert('SET '+source);
				placeholder_under[i].setAttribute("src",source);
			}
		}
		//var placeholder_under2 = document.getElementById("Alex2");
		placeholder.style.display = 'none';		
		//placeholder_under2.setAttribute("src",source);
	}

}

function getElementsByClassName(classname, node) {
	if(!node) node = document.getElementsByTagName("body")[0];
	var a = [];
	var re = new RegExp('\\b' + classname + '\\b');
	var els = node.getElementsByTagName("*");
	for(var i=0,j=els.length; i<j; i++)
	if(re.test(els[i].className))a.push(els[i]);
	return a;
}

function start() {
	prepareGallery();
	initiateMailFriend();
	initiateFavLink();
	initiatePrintLink();
}	 
addLoadEvent(start); 