// JavaScript Document

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}



var TimeToFade = 1000.0;

function fade(eid)
{
  var element = document.getElementById(eid);
  if(element == null)
    return;
   
  if(element.FadeState == null)
  {
    if(element.style.opacity == null 
        || element.style.opacity == '' 
        || element.style.opacity == '1')
    {
      element.FadeState = 2;
    }
    else
    {
      element.FadeState = -2;
    }
  }
    
  if(element.FadeState == 1 || element.FadeState == -1)
  {
    element.FadeState = element.FadeState == 1 ? -1 : 1;
    element.FadeTimeLeft = TimeToFade - element.FadeTimeLeft;
  }
  else
  {
    element.FadeState = element.FadeState == 2 ? -1 : 1;
    element.FadeTimeLeft = TimeToFade;
    setTimeout("animateFade(" + new Date().getTime() + ",'" + eid + "')", 33);
  }  
}
function animateFade(lastTick, eid)
{  
  var curTick = new Date().getTime();
  var elapsedTicks = curTick - lastTick;
  
  var element = document.getElementById(eid);
 
  if(element.FadeTimeLeft <= elapsedTicks)
  {
    element.style.opacity = element.FadeState == 1 ? '1' : '0';
    element.style.filter = 'alpha(opacity = ' 
        + (element.FadeState == 1 ? '100' : '0') + ')';
    element.FadeState = element.FadeState == 1 ? 2 : -2;
    return;
  }
 
  element.FadeTimeLeft -= elapsedTicks;
  var newOpVal = element.FadeTimeLeft/TimeToFade;
  if(element.FadeState == 1)
    newOpVal = 1 - newOpVal;

  element.style.opacity = newOpVal;
  element.style.filter = 'alpha(opacity = ' + (newOpVal*100) + ')';
  
  setTimeout("animateFade(" + curTick + ",'" + eid + "')", 33);
}

function growHeight(id,galleryId,growToHeight,increment,timeout) 
{    
  var element = document.getElementById(id);
	if(element==null){return;}
	var incrementNum=new Number(increment);
	var growToHtNum=new Number(growToHeight);
  var styleHtStr=new String(element.style.height);	
  var htStr=styleHtStr.match(/\d+/)[0];
  var htNum=new Number(htStr);
	htNum+=incrementNum;
	htStr=new String(htNum);
	performgrowHeight(id,galleryId,htNum,growToHeight,increment,timeout);
}

function performgrowHeight(id,galleryId,htNum,growToHeight,increment,timeout)
{
	var element = document.getElementById(id);
	if(element==null){return;}
	
	//document.getElementById('galleryDecription').innerHTML=id;
	var htStr=new String(htNum);
	
	var growToHeightNum=new Number(growToHeight);
	if(htNum<growToHeightNum){
		element.style.height=htStr+"px";
		var newHtNum=new Number(htNum+Number(increment));
		setTimeout("performgrowHeight('" + id + "','" + galleryId + "'," + newHtNum + "," + growToHeight+", "+increment+")", Number(timeout));
	}
	else{
		if(galleryId!=null){
			setInnerHtml('galleryDecription',galleryId);
			embedSwfGallery(galleryId);
		}
		setContainerHeight();
					
	}
}

function growHeight3(galleryId,growToHeight,increment,timeout) 
{    
  var element = document.getElementById('galleryContainer');
	if(element==null){return;}
	var incrementNum=new Number(increment);
	var growToHtNum=new Number(growToHeight);
  var styleHtStr=new String(element.style.height);	
  var htStr=styleHtStr.match(/\d+/)[0];
  var htNum=new Number(htStr);
	htNum+=incrementNum;
	htStr=new String(htNum);
	performGrowHeight(galleryId,htNum,growToHeight,increment, timeout);
}

function performGrowHeight3(galleryId,htNum,growToHeight,increment, timeout)
{
	var element = document.getElementById('galleryContainer');
	if(element==null){return;}
	var htStr=new String(htNum);
	
	var growToHeightNum=new Number(growToHeight);
	if(htNum<growToHeightNum){
		element.style.height=htStr+"px";
		var newHtNum=new Number(htNum+Number(increment));
		setTimeout("performGrowHeight('" + galleryId + "'," + newHtNum + "," + growToHeight+", "+increment+")", Number(timeout));
	}
	else{
		setInnerHtml('galleryDecription',galleryId);
		showGallery(galleryId);
		setContainerHeight();
					
	}
}

function setInnerHtml(id,galleryName)
{
	var txt=new String();
	var contact=new String("<p>Please feel free to <a href='contact.php' target='_self'>contact us</a> for the prices and other information.</p>");
	
	//var customGallId=galleryName.match("galleryCustom");
	//alert(customGallId);
	if(galleryName.match("galleryCustom")=="galleryCustom"){
		txt="<h2>Custom Monument Designs</h2><p>Each of the 5 galleries above represent just a small sample of what we can create.</p>"+contact;
	}else if(galleryName=="galleryFlat"){
		txt="<h2>Bronze &amp; Flat Granite Markers</h2><p>We offer a wide range of bronze and flat granite memorial markers, pet memorial markers, artistic markers and commerical markers.</p>"+contact;
	}else if(galleryName=="galleryPillow"){
		txt="<h2>Pillow Memorial Monuments</h2><p>Our pillow markers have either a 6/3 or 6/4 Pillow, back to front, and may be polished top or polished three sides or all five sides. They are usually placed on a concrete base.</p>"+contact;
	}else if(galleryName=="gallerySloping"){
		txt="<h2>Sloping Upright Memorial Monuments</h2><p>This is a small sampling of sloping upright memorial monuments made from granite.</p>"+contact;
	}else if(galleryName=="galleryVases"){
		txt="<h2>Monument Flower Vases</h2><p>We stock a variety of vases and accessories in Metal, Granite and Marble.</p>"+contact;
	}else if(galleryName=="galleryColum"){
		txt="<h2>Columbariums</h2><p>Talk to us about getting a plaque for a cemetery columbarium or designing a family columbarium.</p>"+contact;
	}else if(galleryName=="galleryUrns"){
		txt="<h2>Beautiful Urns</h2><p>We stock a variety of urns and accessories.</p>"+contact;
	}else if(galleryName=="galleryCremains"){
		txt="<h2>Family Cremains Memorials</h2><p>Although the cremation rate continues to increase, many families are reluctant when it comes to a community columbarium as a tribute to their loved ones or for themselves. Family Cremains Memorials offer a more traditional and personalized memorial and are fast becoming a popular tribute (contact the cemetery for by-laws and for approval). </p><p>These memorials have niches integrated in cubes, benches or upright designs that are practical, aesthetically pleasing, and secure alternatives. The sealed cremains can be placed in a polyurethane pouch and deposited into a round niche drilled into the main portion of conventional cremains memorials. If the cremains of your loved one are already in an urn and now you would like to buy a memorial to commemorate her or his life. Not a problem. The memorial manufactured with a square niche allows you to insert the urn. This concept can be applied on upright memorials, benches, or cube designs. Each niche comes with an aluminum cover to seal permanently and protect the cremains. </p><p>The possibilities in design are endless.</p> "+contact;
	}else if(galleryName=="galleryGolf"){
		txt="<h2>Golf Course Designs</h2><p>We offer a wide range of custom granite products including golf course grounds markers, gateways, benches etc.</p>"+contact;
	}else if(galleryName=="galleryStatues"){
		txt="<h2>Outdoor Furniture &amp; Statues</h2>"+contact;
	}else if(galleryName=="galleryBenches"){
		txt="<h2>Memorial &amp; Civic Benches</h2><p>We offer a full range of memorial benches or granite custom built benches.</p>"+contact;
	}else if(galleryName=="galleryPets"){
		txt="<h2>Pet Memorials</h2><p>Hand etched pet portraits are a distinct way to capture the beauty of your beloved pet. A highly skilled artist makes our pet etchings. Each pet portrait etching is engraved with a hand held power tool. This process works best on black and dark colored granites.</p>"+contact;
	}else if(galleryName=="gallerySamples"){
		txt="<h2>Granite Color Samples</h2><p>Memorials are available in a variety of colors. Prices vary according to Group. Group A granites are the least expensive, and Group F granites are the most expensive.</p>"+contact;
	}else{
		txt="notSet";
	}


	var element = document.getElementById(id);
	if(element==null){return;}
	element.innerHTML=txt;
	
}

function setContainerHeight(){
	var ltBox = document.getElementById('leftContentContainer');
	var rtBox = document.getElementById('rightContentContainer');
	var styleLtHtStr=new String(ltBox.style.height);	
	var ltHtStr=styleLtHtStr.match(/\d+/)[0];
	var ltHtNum=new Number(ltHtStr);
	//alert(ltLtStr+" "+rtBox.offsetHeight);
	
	if(ltHtNum<rtBox.offsetHeight){
		ltBox.style.height=rtBox.offsetHeight+"px";
	}else{
		if(rtBox.offsetHeight>716){
			ltBox.style.height=rtBox.offsetHeight+"px";
		}else{
			ltBox.style.height="716px";
		}
	}
		//alert(ltBox.style.height+" "+rtBox.offsetHeight);
}

function getQueryVariable(variable) {
	var query = window.location.search.substring(1);
	var vars = query.split("&");
	for (var i=0;i<vars.length;i++) {
		var pair = vars[i].split("=");
		if (pair[0].toLowerCase()==variable.toLowerCase()) {
			return pair[1];
		}
	}
	return('not found');
}

var inc=new Number(0.04);
function fadeIn(id) {
	var element = document.getElementById(id);
  if(element == null){return;}
	
  if(inc<1){
		element.style.opacity=inc;
		element.style.MozOpacity=inc;
		element.style.filter="alpha(opacity="+inc*100+")";
		inc+=0.04;
		setTimeout("fadeIn('"+id+"')",10);
  }
		//document.getElementById('galleryDecription').innerHTML=element.style.filter;
}

function controlSubMenu(id,showOrHide){
	var box = document.getElementById(id);
	if(showOrHide.toLowerCase()=="show"){
		box.style.display="block";
		inc=0.04;
		fadeIn(id);
	}else{
		box.style.display="none";
		box.style.opacity=0;
		box.style.MozOpacity=0;
		box.style.filter="alpha(opacity=0)";
	}
}

function showGallery(galleryName){
	// hide submenu
	controlSubMenu('customSubMenu','hide');
	// begin display of the gallery
	growHeight('galleryContainer',galleryName,420,8,1);
}

function showSubGallery(galleryName){
	// hide submenu if applicable
	//controlSubMenu('customSubMenu','hide');
	// begin display of the gallery
	growHeight('galleryContainer',galleryName,420,8,1);
}
function showWaiting() {
	var waitDiv = document.getElementById('waiting');
	if(waitDiv == null)
		return;
	waitDiv.setAttribute("class", "visShow");
	var btnSubmit = document.getElementById('Submit');
	btnSubmit.setAttribute("disabled", "disabled");
	var btnReset = document.getElementById('Reset');
	btnReset.setAttribute("disabled", "disabled");
}
