// JavaScript Document
var Preloader = {
  callbacks: [],
  images: [],
  loadedImages: [],
  imagesLoaded: 0,


add: function(image){
    if (typeof image == 'string') this.images.push(image);
    if (typeof image == 'array' || typeof image == 'object'){
      for (var i=0; i< image.length; i++){
        this.images.push(image[i]);
      }
    }
  },
  onFinish: function(func){
    if (typeof func == 'function') this.callbacks.push(func);
    if (typeof func == 'array' || typeof func == 'object'){
      for (var i=0; i< func.length; i++){
        this.callbacks.push(func[i]);
      }
    }
  },
  load: function(){
    for(var i=0; i<this.images.length; i++){
      this.loadedImages[i] = new Image();
      this.loadedImages[i].onload = function(){ Preloader.checkFinished.apply(Preloader) }
      this.loadedImages[i].src = this.images[i];
    }
  },
  checkFinished: function(){
    this.imagesLoaded++;
    if (this.imagesLoaded == this.images.length) this.fireFinish();
  },
  fireFinish: function(){
    for (var i=0; i<this.callbacks.length; i++){
      this.callbacks[i]();
    }
    this.images = [];
    this.loadedImages = [];
    this.imagesLoaded = 0;
    this.callbacks = [];
  }
}

var allImages = new Array('http://musa212.com/happinessishere/images/bg/bottom/bottom.jpg','http://musa212.com/happinessishere/images/bg/sides/sides_01.gif','http://musa212.com/happinessishere/images/bg/sides/sides_03.gif','http://musa212.com/happinessishere/images/bg/top/top_01.gif','http://musa212.com/happinessishere/images/bg/top/top_02.gif','http://musa212.com/happinessishere/images/bg/top/top_03.gif','http://musa212.com/happinessishere/images/bg/top/top_04.gif','http://musa212.com/happinessishere/images/bg/top/top_04_over.gif','http://musa212.com/happinessishere/images/bg/top/top_04_selected.gif','http://musa212.com/happinessishere/images/bg/top/top_05.gif','http://musa212.com/happinessishere/images/bg/top/top_05_over.gif','http://musa212.com/happinessishere/images/bg/top/top_05_selected.gif','http://musa212.com/happinessishere/images/bg/top/top_06.gif','http://musa212.com/happinessishere/images/bg/top/top_06_over.gif','http://musa212.com/happinessishere/images/bg/top/top_06_selected.gif','http://musa212.com/happinessishere/images/bg/top/top_07.gif','http://musa212.com/happinessishere/images/bg/top/top_07_over.gif','http://musa212.com/happinessishere/images/bg/top/top_07_selected.gif','http://musa212.com/happinessishere/images/bg/top/top_08.gif','http://musa212.com/happinessishere/images/bg/top/top_08_over.gif','http://musa212.com/happinessishere/images/bg/top/top_08_selected.gif','http://musa212.com/happinessishere/images/bg/top/top_09.gif','http://musa212.com/happinessishere/images/bg/top/top_09_over.gif','http://musa212.com/happinessishere/images/bg/top/top_09_selected.gif','http://musa212.com/happinessishere/images/bg/top/top_10.gif','http://musa212.com/happinessishere/images/bg/top/top_10_over.gif','http://musa212.com/happinessishere/images/bg/top/top_10_selected.gif','http://musa212.com/happinessishere/images/other/charity.gif');


function navLinkSwitch(imgObj){
	if(imgObj.src.lastIndexOf("_selected.gif")<0){
		oldURL=imgObj.src;
		if(oldURL.indexOf("_over.gif")<0){
			newURL=oldURL.replace(".gif","_over.gif");
		} else {
			newURL=oldURL.replace("_over.gif",".gif");
		}
		imgObj.src=newURL;
	}
}
function TEMPLATE_thispage(thepage){
	var lastchar=thepage.lastIndexOf("/")+1;
	var lastper=thepage.lastIndexOf(".");
	var cuthref=thepage.substring(lastchar,lastper);
	var thesrc=document.getElementById(cuthref).src;
	var newimg1=thesrc.substring(0,thesrc.length-4);
	var newimg2=newimg1+"_selected.gif";
	var cuthrefa = cuthref + "a";
	document.getElementById(cuthref).src=newimg2;
	document.getElementById(cuthrefa).href="#";
}
function dropDown_questions(qnum,thelink){
	var anum="answer"+qnum;
	document.getElementById(anum).style.display="block";
	thelink.style.color="#568EBF";
	thelink.style.cursor="default";
}
function dropDown_answers(qnum){
	var anum="answer"+qnum;
	document.getElementById(anum).style.display="none";
	var question="question"+qnum;
	document.getElementById(question).style.color="#FFBC45";
	document.getElementById(question).style.cursor="pointer";
}
function checkChecked(yn,id){
	//yn = 1 means that the element passed through id will display as block, if it =0 then it will not display;
	if(yn==1){
		document.getElementById(id).style.display='block'
	} else {
		document.getElementById(id).style.display='none'
	}
}
function checkRadio(searchtext){
	if(!document.resorter.search_type[1].checked && !searchtext){
		document.resorter.search_type[0].checked=true;
	}
}
function resetForm(){
	document.getElementById('reverse').checked=false;
	document.getElementById('sort').value='date';
	document.getElementById('search').value='';
	//have to change search_type twice because false only will keep "Any of these words" radio button selected
	document.getElementById('search_type').checked=true;
	document.getElementById('search_type').checked=false;
	document.getElementById('categories_select').value='';
}
function closeForm(){
	document.getElementById('project_sort').style.display='none';
	document.getElementById('refine_search').style.display='block';
}
function filterButton(whattocheckfor,whattoblankout){
	if(document.getElementById(whattocheckfor).value!=''){
		document.getElementById(whattoblankout).value='';
		document.resorter.submit();
	} else {
		if (whattocheckfor=="search"){
			alert('Please fill in text to search for.');
		} else if (whattocheckfor=="categories_select") {
			alert('Please select a category from the drop-down menu.');
		}
		TEMPLATE_setFocus(whattocheckfor);
	}
}
function TEMPLATE_setFocus(elem_id)
{
	document.getElementById(elem_id).focus();
}
function mypu(width,height,filepath) {
	window.open(filepath, "nonuniqueqwindow","scrollbars = no, directories = no, status = no, toolbar = no, menubar = no, height = "+0+", width = "+0+", resizable = no, fullscreen = no");
}