
var loadedobjects=""
var rootdomain="http://"+window.location.hostname
var loadstatustext="<p class=\"loading\"><img src='_js/images/loading.gif' /> Loading Page...</p>"

//this function is for the html links, it needs the return false at the end,  
function ajaxpage(url, containerid){
	
	var page_request = false;
	if (window.XMLHttpRequest) // if Mozilla, Safari etc
			page_request = new XMLHttpRequest()
		
		else if (window.ActiveXObject){ // if IE

		try {
		
		page_request = new ActiveXObject("Msxml2.XMLHTTP")
			} 
		catch (e){

		try{
			page_request = new ActiveXObject("Microsoft.XMLHTTP")
		}
		catch (e){}
		}
	}
else
	return false	
	page_request.onreadystatechange=function(){
	//document.getElementById(containerid).innerHTML=loadstatustext;
	loadpage(page_request, containerid)
}


page_request.open('GET', url, true)
page_request.send(null)  

//this is working on ff nd ie!!!!!!!!!!!!
//loadobjs('secondarylinks.js')
//need this for html links
return false;


}

//this function is for the flash links, it doesnt need the return false at the end,  
function ajaxpageFlash(url, containerid){
switch(url)
	{
	case 'home.html':
		url = 'home.php';
		break;

	case 'news.html':
		url='news.php';
		break;
	
	case "gallery.html":
		url='gallery.php';
		break;
	
	case "biog.html":
		url="biog.php";
		break;

	case "events.html":
		url='events.php';
		break;
	
	case "music.html":
		url="music.php";
		break;

	case "links.html":
		url="links.php";
		break;
	
	default: 
		url = url;
	}
	
	if(url.indexOf('.php?') != -1){
			url = url + "&ajax=1";
		} else {
			url = url + "?ajax=1";
		}
	
	var page_request = false

	if (window.XMLHttpRequest) // if Mozilla, Safari etc
			page_request = new XMLHttpRequest()
		
		else if (window.ActiveXObject){ // if IE

		try {
		
		page_request = new ActiveXObject("Msxml2.XMLHTTP")
			} 
		catch (e){

		try{
			page_request = new ActiveXObject("Microsoft.XMLHTTP")
		}
		catch (e){}
		}
	}
else
	return false
	page_request.onreadystatechange=function(){
	//document.getElementById("content").innerHTML=loadstatustext;
	loadpage(page_request, containerid)

}
page_request.open('GET', url, true)
page_request.send(null)  

//dont need this for flash links
//return false;

}

function loadpage(page_request, containerid){
	if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))
	{
		document.getElementById(containerid).innerHTML=page_request.responseText
		//get all the links ready again
		loadAllLinks();
	}
		
}

function loadobjs(){
if (!document.getElementById)
return
for (i=0; i<arguments.length; i++){
var file=arguments[i]
var fileref=""
if (loadedobjects.indexOf(file)==-1){ //Check to see if this object has not already been added to page before proceeding
if (file.indexOf(".js")!=-1){ //If object is a js file
	fileref=document.createElement('script')
	fileref.setAttribute("type","text/javascript");
	fileref.setAttribute("src", file);
}
else if (file.indexOf(".css")!=-1){ //If object is a css file
		fileref=document.createElement("link")
		fileref.setAttribute("rel", "stylesheet");
		fileref.setAttribute("type", "text/css");
		fileref.setAttribute("href", file);
	}
}
	if (fileref!=""){
		document.getElementsByTagName("head").item(0).appendChild(fileref)
		loadedobjects+=file+" " //Remember this object as being already added to page
		}
		
	}
}



//generic prepare links function
//revised 11/04/07
//now includes a class match, 
//for the links to be ajax'd the <a> needs class , this is set when the function is called
//also appends an ajax variable to the url string, this can be checked for at the front end
function prepareAllLinks(tagID, tagType, loadInTo, linkClass) {
  if (!document.getElementsByTagName) return false;
  if (!document.getElementById) return false;
  if (!document.getElementById(tagID)) return false;
  var ajaxLinks = document.getElementById(tagID);
  var links = ajaxLinks.getElementsByTagName(tagType);
  
  for ( var i=0; i < links.length; i++) {
    if (links[i].className.match(linkClass)) {
		links[i].onclick = function() {
		if(this.getAttribute('href').indexOf('.php?') != -1){
			//return alert(this.getAttribute('href'));
			return ajaxpage(this + "&ajax=1", loadInTo);
		} else {
			//return alert('no');
			return ajaxpage(this + "?ajax=1", loadInTo);
		}
	 //return ajaxpage(this, loadInTo);

	}
    links[i].onkeypress = links[i].onclick;
  } 
  }
}
function showPic(whichpic) {
  if (!document.getElementById("placeholder")) return true;
  var source = whichpic.getAttribute("href");
  var placeholder = document.getElementById("placeholder");
  placeholder.setAttribute("src",source);
  if (!document.getElementById("description")) return false;
  if (whichpic.getAttribute("title")) {
    var text = whichpic.getAttribute("title");
  } else {
    var text = "";
  }
  var description = document.getElementById("description");
  if (description.firstChild.nodeType == 3) {
    description.firstChild.nodeValue = text;
  }
  return false;
}

function prepareGallery() {
  if (!document.getElementsByTagName) return false;
  if (!document.getElementById) return false;
  if (!document.getElementById("imagegallery")) return false;
  var gallery = document.getElementById("imagegallery");
  var links = gallery.getElementsByTagName("a");
  for ( var i=0; i < links.length; i++) {
    links[i].onclick = function() {
      return showPic(this);
	}
    links[i].onkeypress = links[i].onclick;
  }
}

//newWindow function
function externalLinks() {
  if (!document.getElementsByTagName) return false;
  var links=document.getElementsByTagName("a");
  for (var i=0; i < links.length; i++) {
    if (links[i].className.match("ext")) {
      links[i].onclick=function() {
      // Next two lines should be on one line
        window.open(this.href, "","");
        return false;
      }
    }
  }
}


function albumswf()
{
	if(!document.getElementById("feature_album"))
	{
		return false;
	} else 
	{

		var so = new SWFObject("feature_album.swf", "feature_album", "500", "130", "6", "#000000");
		so.addVariable("flashVarText", "this is passed in via FlashVars for example only");
		so.addParam("wmode", "transparent");
		so.write("feature_album");

	}
}


function celticswf()
{
	if(!document.getElementById("feature_celtic"))
	{
		return false;
	} else 
	{

		var so = new SWFObject("feature_celtic.swf", "feature_celtic", "500", "130", "6", "#000000");
		so.addVariable("flashVarText", "this is passed in via FlashVars for example only");
		so.addParam("wmode", "transparent");
		so.write("feature_celtic");

	}
}


function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}


//put all functions in here to prpare different link
//to be called on body load
function loadAllLinks() {

	prepareAllLinks("wrapper","a","container", "int");
	externalLinks();
	prepareGallery();
	albumswf();
	celticswf();
}







//prepares the on window load function
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}




//calls the functions to load on page load

addLoadEvent(loadAllLinks);