/* 	Custom Toppings Site */

function getObj(tagname){var obj=document.getElementById?document.getElementById(tagname):document.all?document.all[tagname]:document.layers[tagname];return obj;}
function createAjaxObject() {var alink;try{alink=new XMLHttpRequest();}catch(e){alink=new ActiveXObject("Microsoft.XMLHTTP");}return alink;}

function showProject(ref) {
	var pref=ref.id,xml=createAjaxObject(),xml2=createAjaxObject(),info='',images,i,tmp1,count;
	
	// Get Project Text
	xml.open('GET','projects/'+pref+'.txt',false);
	xml.send(null);
	info=xml.responseText;
	
	// Get Picture List
	xml.abort();
	xml.open('GET','projects/'+pref+'.images',false);
	xml.send(null);
	
	images=xml.responseText.split("\n");
		
	tmp1='<div id="backlink" onClick="reloadProjects()">&lt; Back to Project List</div><div id="pdesc">'+info+'</div><br>';
	count=images.length;
	if(images[0].substr(0,1)=='-')count=0;
	
	if(count>0) {
		tmp1+='<table width="760" border="0" cellspacing="0" cellpadding="0"><tr><td width="100" valign="top" align="left">';
		for(i=0;i<images.length;i++){
			tmp1+='<div onClick="showPreview(this,'+images.length+')" id="plink'+i+'" file="'+images[i]+'" class="piclink">Picture '+(i+1)+'</div>';
		}	
		tmp1+='</td><td width="660" style="background-color: #f2f2f2; padding: 8px;" align="center" valign="middle"><img id="preview" src=""></td></tr></table><br><br>';
	}
	
	getObj('body').innerHTML=tmp1;	
	
	if(count>0){
		showPreview(getObj('plink0'),images.length);
	}
}

function showPreview(ref,count) {
	var i;
	var file=ref.getAttribute('file');
	getObj('preview').src='art/'+file;
	for(i=0;i<count;i++){
		getObj('plink'+i).style.backgroundColor='#ffffff';
		getObj('plink'+i).style.fontWeight='normal';
	}
	ref.style.backgroundColor='#f2f2f2';
	ref.style.fontWeight='bold';
}	

function reloadProjects(){
	getObj('body').innerHTML='<div id="plist"><div id="p001" onClick="showProject(this)">Granite Countertops</div><div id="p002" onClick="showProject(this)">Slab and Mosaic Surfaces</div><div id="p003" onClick="showProject(this)">Sales of Polished Granite Veneer and Slab Stone</div><div id="p004" onClick="showProject(this)">Concrete Countertops</div><div id="p005" onClick="showProject(this)">Decorative Concrete Coatings</div><div id="p006" onClick="showProject(this)">Stucco Siding and Fencing</div><div id="p007" onClick="showProject(this)">Old World Style Faux and Textured Paint Finishes</div></div><p>Please <a href="contactus.php">contact us</a> and we\'ll be happy to answer any questions or give you a free estimate from your layout.</p><br>';
}
