function pageInit() {
	preloadImages();
	setHovers();
}

function preloadImages() {
	
	var imagedir = 'images/';
	
	// images for hover and active (hot) buttons
	var btnImages = new Array(
		"btn_home_hov.gif",
		"btn_about_hov.gif",
		"btn_services_hov.gif",
		"btn_framing_hov.gif",
		"btn_displays_hov.gif",
		"btn_fineart_hov.gif",
		"btn_contacts_hov.gif",
		"btn_uploads_hov.gif",
		"btn_home_hot.gif",
		"btn_about_hot.gif",
		"btn_services_hot.gif",
		"btn_framing_hot.gif",
		"btn_displays_hot.gif",
		"btn_fineart_hot.gif",
		"btn_contacts_hot.gif",
		"btn_uploads_hot.gif",
		"working_button.gif",
		"tcraft.swf"
		);
		
	var btnHotImages = new Array(
		"btn_home_hot.gif",
		"btn_about_hot.gif",
		"btn_services_hot.gif",
		"btn_framing_hot.gif",
		"btn_displays_hot.gif",
		"btn_fineart_hot.gif",
		"btn_contacts_hot.gif",
		"btn_uploads_hot"
		);
			
	var doc=document; 
	if(doc.images){ 
		if(!doc.imgs) doc.imgs=new Array();
   		var i,j=doc.imgs.length,a=btnImages; 
   		for(i=0; i<a.length; i++)
    	if (a[i].indexOf("#")!=0){ 
    		doc.imgs[j]=new Image; 
    		doc.imgs[j++].src=imagedir+a[i];
    	}
    }
}

function setHovers() {
	
	var theBtn, fnames = new Array;
	var buttons = new Array(
		"btn_home",
		"btn_about",
		"btn_services",
		"btn_framing",
		"btn_displays",
		"btn_fineart",
		"btn_contacts",
		"btn_uploads"
		);
		
	for(var i=0; i<buttons.length; i++) {
		theBtn = document.getElementById(buttons[i]);
		if ( fnames = getSourceAndHover(theBtn) ){		
			theBtn.onmouseout  = function() { setImage(this, 0); }
			theBtn.onmouseover = function() { setImage(this, 1); }
		}
	}
} //end fn

function getSourceAndHover(btn){
	var temp, ext, fbase, source, hover, filenames = new Array;
	// remove _hov to restore original source name
	source = btn.src.replace("_hov", ""); 	
	if (source.indexOf("_hot") <=0 ){
		temp = source.split('/');
		var len = temp.length;
		temp = temp[len-2] + '/' + temp[len-1];
		temp = temp.split('.');
		hover = temp[0] + "_hov." + temp[1];
		filenames[0] = source;
		filenames[1] = hover;
		return filenames;
	} else {
		return false;
	}
}

function setImage(obj, mode) {
	var fnames = getSourceAndHover(obj);
	if (mode < 0 || mode > 1) mode = 0;
	obj.src = fnames[mode];
}


function getHTTPObject() {
  var xhr = false;
  if (window.XMLHttpRequest) {
    xhr = new XMLHttpRequest();
  } else if (window.ActiveXObject) {
    try {
      xhr = new ActiveXObject("Msxml2.XMLHTTP");
    } catch(e) {
      try {
        xhr = new ActiveXObject("Microsoft.XMLHTTP");
      } catch(e) {
        xhr = false;
      }
    }
  }
  return xhr;
}

function grabFile(file) {
  var request = getHTTPObject();
  
  if (request) {
    request.onreadystatechange = function() {
      displayResponse(request);
    };
    request.open("GET", file, true);
    request.send(null);
  }
}

function displayResponse(request) {
  if (request.readyState == 4) {
    if (request.status == 200 || request.status == 304) {
      var dest = document.getElementById('ajaxme');
      dest.innerHTML = request.responseText;
      // alert(request.responseText);
    }
  }
}



// execute initialization function
window.onload=pageInit;
