
function closeWin(){;
	this.window.close;
}

function showPic(whichpic) {
  if (!document.getElementById("placeholder")) return true;
  var temp_title = document.getElementById("galleryNav");
  var title = temp_title.getAttribute("a");
  var source = whichpic.getAttribute("href");
  if(whichpic.getAttribute("granite_link") == null)
  {
	alert("granite_link is not there");  
  }else{
	var sourceB = whichpic.getAttribute("granite_link");
	//alert("granite_link IS there"); 
	var exampleGranite = document.getElementById("exampleGranite");
  	var sourceC = exampleGranite.getAttribute("href");
  	var graniteAttrib = exampleGranite.getAttribute("graniteColorSample");
  	var graniteAttribB = exampleGranite.getAttribute("a");
  	if (sourceB == "http://www.vancouvergranite.com/gallery.php?granite=null")
	{
	exampleGranite.innerHTML = '&nbsp;<a href="#"><span id="linkText"></span></a>';
	}else{
	exampleGranite.innerHTML = 'Click <a href="gallery.php?granite=72"><span id="linkText">here</span></a> to see this granite color in a memorial';
	exampleGranite.childNodes[1].setAttribute("href", sourceB);
	}
  }
  
  
  //alert(sourceB);
  var placeholder = document.getElementById("placeholder");
 /* if(document.getElementById("exampleGranite"))
  	{ 
  		var exampleGranite = document.getElementById("exampleGranite");
  		var sourceC = exampleGranite.getAttribute("href");
  		var graniteAttrib = exampleGranite.getAttribute("graniteColorSample");
  		var graniteAttribB = exampleGranite.getAttribute("a");
  	}
*/
// alert(exampleGranite.childNodes[1].innerHTML);
	placeholder.setAttribute("src",source);
  //alert(exampleGranite.getAttribute("granite_link"));
  var end = "</a>";
 // alert(graniteAttribB);
 if(document.getElementById("exampleGranite"))
  	{ 
  		
 	}
  //alert(graniteAttrib.value);
  //var temp_title = whichpic.getAttribute("granite_title");
	//alert(temp_title.childNodes.length);
  return false;
}

function showLabel(label) {
  if (document.getElementById("granite_title")) return true;
  
  //var granTitle = label.getAttribute("granite_title");
  //var placeholder = document.getElementById("granite_title");
  //placeholder.appendChild(source);
  	//alert(label.childNodes[0].nodeValue); 
 

  return false;
}


function prepareGallery(myCurrentState){ 
/**********  the ususal tests to make sure methods and ids are in place  ******************/
	if (!document.getElementsByTagName) {
		return false;
	}
	
	if (!document.getElementById) {
		return false;
	}
	if (!document.getElementById("galleryNav")){
		return false;
	}
	//alert(myCurrentState.value);
	
	//**********set up the links by attaching a function literal ***************/
	var gallery = document.getElementById("galleryNav");
	var links = gallery.getElementsByTagName("a");
	
	
	
	for (var i=0; i < links.length; i++){

		links[i].onclick = function() {
		//send an object from prepgallery function(src attribute etc) to the showPic function
		showPic(this);
		showLabel(this);
		replaceParagraph();
		//stop the default a link behavior 
		return false;	
		}
	}
}
	
function replaceParagraph(){
	//alert("IE SUCKSSSS!!!!!!!!!");
	//grab the colorAttribute from the gallery nav links...
	var gallery = document.getElementById("galleryNav");
	var graniteColorSample = gallery.getElementsByTagName("a");
	
	
	var mainPic = document.getElementById("placeholder");
		//process the file "src" file name to make it more friendly to read for uses
		var picSrc = mainPic.getAttribute("src");
		var getFullName = picSrc.split("/");//use the "/" character to mark the split point into an array
		//var getTempName = getFullName.split(".");
		var getName = getFullName[4];
		//var getNewName = getName.substr(0, 4);
		//extract all characters and cut off the end ".jpg" which is four characters
		var getNameA = getName.slice(0, -4);
		
		//split the rest of the word into an array of two elements by useing the "_" for the separation point
		var getNameB = getNameA.split("_");
		//check if the array string has only one element in it, if so, only set the first element, otherwise set both
		if(getNameB[1] == null)
		{
			//extract the first letter of the element
			var getUpper = getNameB[0].charAt(0);
			
			/*alert(getUpper);*/
			//concatonate the two results together and capitalize the first letter
			var getNameC = getUpper.toUpperCase() + getNameB[0].slice(1);
		}else{
			//extract the first letter of the element
			var getUpper = getNameB[0].charAt(0);
			
			//extract the second letter of the element
			var getUpperB = getNameB[1].charAt(0);
			//concatonate the four results together and capitalize the first letters
			var getNameC = getUpper.toUpperCase() + getNameB[0].slice(1)+ " "+ getUpperB.toUpperCase() + getNameB[1].slice(1);
		}
		
		
	//alert(getNameC);
	/*	var newName = document.createTextNode(getName[0]);*/
		
	var container = document.getElementById("divContainer");
	var paras = document.getElementById("replaceMe");	
	//alert(container.hasAttribute("class"));
	//alert(container.childNodes[1].getAttribute("granite_title"));
	var newPara = document.createElement("p"); 

	newPara.setAttribute("id","replaceMe");
	var text = document.createTextNode(getNameC);
	newPara.appendChild(text);
	container.replaceChild(newPara, paras);

	return false;
}



function addLoadEvent(func){
var oldOnLoad = window.onload;
if (typeof window.onload != 'function'){
	window.onload = func;
}else{
	window.onload = function(){
		oldOnLoad();
		func();
		}
	}
}

var myCurrentState = "1";
addLoadEvent(prepareGallery, myCurrentState);
