// quadHighlight takes an element and 3 colors, 2 to bounce between and the third to settle on, and a duration.
function quadHighlight(elem, col1, col2, col3, d){
	new Effect.Highlight(elem,{startcolor: col1, endcolor: col2, duration: d});
	new Effect.Highlight(elem,{startcolor: col2, endcolor: col1, duration: d, queue: 'end'});
	new Effect.Highlight(elem,{startcolor: col1, endcolor: col2, duration: d, queue: 'end'});
	new Effect.Highlight(elem,{startcolor: col2, endcolor: col1, restorecolor: col3, duration: d, queue: 'end'});
}
// highL takes an element and passes the element and the rest of the arguments to quadHighlight. Highlight colors controlled here. 
function highL(elem){
	quadHighlight(elem, '#FF0000', '#FFFF00', '#009900', 1);
}
// app takes and element and makes that element have an appear effect. 
function app(elem){
	new Effect.Appear(elem, {duration:3});
}

function myMorph(elem,w){
	new Effect.Morph('can\'t morph!', {style:'width:'+w});
	//new Effect.Morph(‘error_message’, {style: {background: ‘#f00’,color: ‘#fff’}, duration: 0.8 });	
	//new Effect.Morph(elem, {style:'background:#f00; color:#fff; border: 20px solid #f88; font-size:2em', duration:0.8});

}

function slidedown(elem){
	new Effect.SlideDown(elem);	
}

function initPage(){
	app('pics');
	slidedown('list');
}

function resetNav(){
	$('projects').style.color = '#666666';
	$('projects').style.backgroundColor = '#FFFFFF';
	$('products').style.color = '#666666';
	$('products').style.backgroundColor = '#FFFFFF';
	$('materials').style.color = '#666666';
	$('materials').style.backgroundColor = '#FFFFFF';
	$('news').style.color = '#666666';
	$('news').style.backgroundColor = '#FFFFFF';
	$('contact').style.color = '#666666';
	$('contact').style.backgroundColor = '#FFFFFF';
	$('about').style.color = '#666666';
	$('about').style.backgroundColor = '#FFFFFF';
	$('links').style.color = '#666666';
	$('links').style.backgroundColor = '#FFFFFF';
	$('login').style.color = '#666666';
	$('login').style.backgroundColor = '#FFFFFF';
	$('home').style.color = '#666666';
	$('home').style.backgroundColor = '#FFFFFF';
}

function setX(){
	var windowWidth = window.innerWidth ? window.innerWidth : document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body.clientWidth;
	var margin = 0;
	if (windowWidth>850) margin = Math.round((windowWidth-850)/2);
	alert(margin);	
	var ss = 850;
	$('cent').style.width=ss+"px";
	$('left').style.width=margin+"px";
	$('left').style.backgroundColor='#FFFFFF';
	$('right').style.width=margin+"px";	
	$('right').style.backgroundColor='#FFFFFF';
}
///////////////////////////////////////////////////// Stuff from projects.php
function scroller(elem,id){
	$(elem).scrollTop = $(id).offsetTop-120;
}
function scroller2(elem,h){
	$(elem).scrollTop = h;
}
function continents(){//takes no arg, retrives all continents from database	
	new Ajax.Updater('continents', 'projgen.php?begin=all', {asynchronous:true, evalScripts:true }); return false;
}

function typesProjGen(t,pid,itemA){
	selectItem(itemA,'tList2');
	new Ajax.Updater('typeProjList', 'projgen.php?tid='+t+'&pid='+pid, {asynchronous:true, evalScripts:true }); return false;
}

function prodProjGen(p,pid,itemA){
	selectItem(itemA,'pList2');
	showProdPic(p);
	new Ajax.Updater('prodProjList', 'projgen.php?prodid='+p+'&pid='+pid, {asynchronous:true, evalScripts:true }); return false;
}

function toggleBottom(status){
	if (status){
		$('thumbs').show();
		$('projdesc').show();
		$('projlink').show();
		projTitle(oldTitle);
		$('bottomspacer').update('');
	}	
	else {
		$('thumbs').hide();
		$('projdesc').hide();
		$('projlink').hide();
		changeProdTitle(0);
		$('bottomspacer').update('<br /><br /><br /><br />');
	}
}
function projTitle(title){
	document.title = title;
}
function changeProdTitle(p) { 
	if (p==1) document.title = "Products Page: Pohl Europanel"; 
	else if (p==2) document.title = "Products Page: Pohl Europlate"; 
	else if (p==3) document.title = "Products Page: Pohl Ecopanel"; 
	else if (p==4) document.title = "Products Page: Custom Panels"; 
	else if (p==5) document.title = "Products Page: Terra Cotta"; 
	else document.title = "Products Page";
}
function highlightNav(nav){
	if (nav=='proj'){
		$('projects').style.color = '#FFFFFF';
		$('projects').style.backgroundColor = '#0000FF';
		$('products').style.color = '#666666';
		$('products').style.backgroundColor = '#FFFFFF';
	}
	else if (nav=='prod'){
		$('products').style.color = '#FFFFFF';
		$('products').style.backgroundColor = '#0000FF';
		$('projects').style.color = '#666666';
		$('projects').style.backgroundColor = '#FFFFFF';
	}
	else alert ("There was an error in the nav!");
}
function showProdPic(prodid){
	changeProdTitle(prodid);
	$('prodPicture').update("<br /><img width=\"400\" src=\"download.php?prodid="+prodid+"\" /><br /><div align=\"left\" id=\"prodDescA\" style=\"width:400px;\">&nbsp;</div><br />");
	new Ajax.Updater('prodDescA', 'projgen.php?proddesc='+prodid, {asynchronous:true, evalScripts:true }); return false;	
}
function scrollLoc(next,writespot,ID){
	var objDiv1 = $("lList");
	objDiv1.scrollTop = objDiv1.scrollHeight;
	new Ajax.Updater(writespot, 'projgen.php?'+next+'='+ID, {asynchronous:true, evalScripts:true }); return false;		
}
function selectItem(itemA,div){
	resetSel(div);
	$(itemA).style.color = '#FFFFFF';
	$(itemA).style.backgroundColor = '#0000FF';
}
function resetSel(elem){
	var elems = $(elem).childElements();
	for(var i=0;i<elems.length;i++){
		var y = elems[i];
		$(y).setStyle({backgroundColor: '#333333'});
	}		
}
function chgPic(pictureid,int){
	if (int) {
		fullPic = "download.php?intpic="+pictureid;
		$('mainpic').setStyle({backgroundImage:"url("+fullPic+")"}); 
	}
	else {
		fullPic = "download.php?npicid="+pictureid;
		$('mainpic').setStyle({backgroundImage:"url("+fullPic+")"});
	}
}
function setNormal(){
	$('type').style.color = '#666666';
	$('type').style.backgroundColor = '#FFFFFF';
	$('name').style.color = '#666666';
	$('name').style.backgroundColor = '#FFFFFF';
	$('product').style.color = '#666666';
	$('product').style.backgroundColor = '#FFFFFF';
	$('location').style.color = '#666666';
	$('location').style.backgroundColor = '#FFFFFF';
	$('inter').style.color = '#666666';
	$('inter').style.backgroundColor = '#FFFFFF';
	$('srch').style.color = '#666666';
	$('srch').style.backgroundColor = '#FFFFFF';
}
function hideAll(){
	$('tOutter').hide();
	$('pOutter').hide();
	$('nList').hide();
	$('lList').hide();
	$('interiors').hide();
	$('sOutter').hide();
}
function showCurr(elem){
	$(elem).show();
}
function byType(tid,h){
	hideAll();
	setNormal();
	$('type').style.color = '#FFFFFF';
	$('type').style.backgroundColor = '#0000FF';
	$('tOutter').show();
	toggleBottom(true);
	$('mainpic').setStyle({backgroundImage:"url("+fullPic+")"}); 
	highlightNav('proj');
	if($('d')) scroller('tList','d');
	if($('b')) scroller('typeProjList','b');
	currElem = 'tOutter';
	curr = 1;
	setMem(curr);
}
function byProd(){
	hideAll();
	setNormal();
	$('product').style.color = '#FFFFFF';
	$('product').style.backgroundColor = '#0000FF';
	$('pOutter').show();
	//$('mainpic').setStyle({backgroundImage:"url(images/prod.jpg)"}); 
	toggleBottom(false);
	highlightNav('prod');
	currElem = 'pOutter';
	curr = 2;
	setMem(curr);
}
function byName(){
	hideAll();
	setNormal();
	$('name').style.color = '#FFFFFF';
	$('name').style.backgroundColor = '#0000FF';
	$('nList').show();
	toggleBottom(true);
	$('mainpic').setStyle({backgroundImage:"url("+fullPic+")"}); 
	highlightNav('proj');
	scroller('nList','a');
	currElem = 'nList';
	curr = 3;
	setMem(curr);
}

function byLoc(){
	hideAll();
	setNormal();
	$('location').style.color = '#FFFFFF';
	$('location').style.backgroundColor = '#0000FF';
	$('lList').show();
	continents();
	toggleBottom(true);
	$('mainpic').setStyle({backgroundImage:"url("+fullPic+")"});  
	highlightNav('proj');
	currElem = 'lList';
	curr = 4;
	setMem(7);
}
function interior(){
	hideAll();
	setNormal();
	$('inter').style.color = '#FFFFFF';
	$('inter').style.backgroundColor = '#0000FF';
	$('interiors').show();
	toggleBottom(true);	
	$('mainpic').setStyle({backgroundImage:"url("+fullPic+")"}); 
	highlightNav('proj');
	scroller('interiors','a');
	currElem = 'interiors';
	curr = 5;
	setMem(curr);
}
function bySearch(){
	hideAll();
	setNormal();
	$('srch').style.color = '#FFFFFF';
	$('srch').style.backgroundColor = '#0000FF';
	$('sOutter').show();
	// drop down the search div 
	toggleBottom(false);	
	$('mainpic').setStyle({backgroundImage:"url("+fullPic+")"}); 
	highlightNav('proj');
	scroller('interiors','a');
	currElem = 'search';
	curr = 6;
	document.forms[0][0].focus();
	setMem(curr);
}

function setMem(i){
	new Ajax.Request('memory.php?last='+i, {asynchronous:true, evalScripts:true });	
}

function updateLowerNav(){
	$('name').addClassName('navtext');
	$('type').addClassName('navtext');
	$('location').addClassName('navtext');
	$('product').addClassName('navtext');
	$('inter').addClassName('navtext');
	$('srch').addClassName('navtext');
}
function cleanupFonts(){
	$('prodPicture').addClassName('desctext');	
	updateLowerNav();
}
function searchProj(){
	var a = document.myform.searchA.value;
	if (a.length>1)	new Ajax.Updater('sugges', 'projgen.php?pname='+a, {asynchronous:true, evalScripts:true }); return false;
}
function clearit(){
	$('sugges').update('<br /><br /><a href=\"http://en.pohlnet.com/facade/references/\" target=\"_blank\" style=\"color:#999999;\">Search in Pohl Group of Companies</a><br /><a href=\"year.php\" style=\"color:#999999;\">View Projects by Completion Year</a><br /><a href=\"size.php\" style=\"color:#999999;\">View Projects by Size (Square Feet)</a>');
	document.myform.searchA.value = '';	
}
