displayTabs = new Object;
displayHeights = new Object;

displayingOverlay = 0;

displayPages = new Object;
displayPages['Sitework']=0;
displayPages['Concrete']=0;
displayPages['Case1']=0;
displayPages['Case2']=0;
displayPages['Contracting']=0;

displayingPages = 0;

defaulttop=144;

var is_ie6 = (
	window.external &&
	typeof window.XMLHttpRequest == "undefined"
);

function showTab(e){
	if(displayPages['Case1'] || displayPages['Case1'] || displayPages['Case2'] || displayPages['Case2']){
		setTimeout("pageQuick('Concrete')",1500);
	}
	navSelection = this.id;
	selection = this.id;
	selection = selection.replace('nav','tab');
	overlaydiv = document.getElementById('overlay');
	//alert(posy);
	hideTabs();
	document.getElementById(this.id).childNodes[0].className = 'here';
	if(!displayingOverlay){
		displayingOverlay = 1;
		document.getElementById('overlayContent').style.display='inline';
		new Effect.Move('overlay', { x: 668, mode:'relative', queue:'end'});
		
		setTimeout('overlaydiv.style.position="absolute"', 1500);
	}
	//alert(selection);
	Effect.Appear(document.getElementById(selection), { duration: 0.5, from: 0, to: 1, queue: 'end'});
	displayTabs[selection] = 1;
	//alert(displayHeights[selection]);
	//alert('offset:' + document.getElementById('wrapper').offsetHeight);
	if(displayHeights[selection] > document.body.clientHeight - 100){
		document.getElementById('overlayContent').style.height = (displayHeights[selection] + 100) +  'px';
	} else {
		//document.getElementById('overlayContent').style.height = (document.body.clientHeight - 50)  + 'px';
		document.getElementById('overlayContent').style.height = 870 +  'px';

	}	
}

function hideTabs(){
	obj = document.getElementById('overlayContent');
	//alert(obj.childNodes.length);
	for ( var count = 0; count < obj.childNodes.length; count++ )
    {
		//alert(count);
		if(obj.childNodes[count].id != undefined){
			currentID=obj.childNodes[count].id;
			tabID = currentID.replace('tab','nav');
			document.getElementById(tabID).childNodes[0].className = '';
			if(displayTabs[currentID] == 1){
				Effect.Fade(document.getElementById(currentID), { duration: 0.5, from: 1, to: 0 });
			} else {
				Effect.Fade(document.getElementById(currentID), { duration: 0, from: 1, to: 0});
			}
			displayTabs[currentID]=0;
		}
    }
	
}

function setHeights(){
	obj = document.getElementById('overlayContent');
	for ( var count = 0; count < obj.childNodes.length; count++ )
    {
		//alert(count);
		if(obj.childNodes[count].id != undefined){
			currentID=obj.childNodes[count].id;
			displayHeights[currentID] = document.getElementById(currentID).clientHeight;
		}
    }
}
function closeTab(){
	if(displayingOverlay==1){
		if(!is_ie6){
			document.getElementById('overlay').style.position='fixed';
		}
		new Effect.Move(document.getElementById('overlay'), { x: -668, queue:'end'});
		displayingOverlay=0;
	}
	hideTabs();
	setTimeout("document.getElementById('overlayContent').style.height = '439px';",1000);
}


function pageFlip(selection){
	closeTab();
	secNav = selection;
	if(selection == 'Case1' || selection == 'Case2'){
		secNav = 'Concrete';
	}
	
	pagedout=0;
	for (var i in displayPages){
		if(displayPages[i] && i != selection){
			displayPages[i]=0;
			new Effect.Fade('page' + i, { duration: 0.25, queue:'end'});
				removeclass=i;
				if(i == 'Case1' || i == 'Case2'){
					removeclass='Concrete';
				}
				document.getElementById('page' + removeclass + 'Link').className = '';
			
			//new Effect.Appear(page, { duration: 0.25,  queue:'end'});		
			pagedout=1;
		} 
	}
	if(!pagedout){
		new Effect.Fade('maincontent', { duration: 0.25, queue:'end'});
	}
		
	new Effect.Appear('page' + selection, { duration: 0.25,  queue:'end'});	
	document.getElementById('page' + secNav + 'Link').className = 'here';
	displayPages[selection]=1;
	
	//Keep top link highlighted
	swapSecondaryNav(secNav);
	
}
function pageQuick(selection){
	secNav = selection;
	if(selection == 'Case1' || selection == 'Case2'){
		secNav = 'Concrete';
	}
	
	for (var i in displayPages){
		if(displayPages[i] && i != selection){
			displayPages[i]=0;
			//new Effect.Fade('page' + i, { duration: 0.25, queue:'end'});
			document.getElementById('page' + i).style.display='none';
				removeclass=i;
				if(i == 'Case1' || i == 'Case2'){
					removeclass='Concrete';
				}
				document.getElementById('page' + removeclass + 'Link').className = '';		
		} 
	}
		
	//new Effect.Appear('page' + selection, { duration: 0.25,  queue:'end'});	
	document.getElementById('page' + selection).style.display='block';
	document.getElementById('page' + secNav + 'Link').className = 'here';
	displayPages[selection]=1;
	
	//Keep top link highlighted
	swapSecondaryNav(secNav);
	
}


function swapSecondaryNav(addclass){
	document.getElementById('secondaryNav').className = 'page' + addclass + 'Active';
	
	if(addclass == ''){
		if(displayPages['Sitework'] == 1){
			addclass="SiteworkActive";
		}
		if(displayPages['Concrete'] == 1 || displayPages['Case1'] == 1 || displayPages['Case2'] == 1){
			addclass="ConcreteActive";
		}
		if(displayPages['Contracting'] == 1){
			addclass="ContractingActive";
		}
		document.getElementById('secondaryNav').className = 'page' + addclass;
	}
	
	
	
	
}
/********* GOOGLE MAPS ******************/
var oldbackground='';
var selectedLoc = '';
var dirFrom = '';
var infoWindowContentStart = "<table id='infowindowcontent' width='400'><tr><td width='50%'><strong>King Enterprise Group</strong>"
var infoWindowContentEnd = "<br><br><a href='javascript:print();'>Print Map</a></td><td valign='top'><form onsubmit='gotoDirections(); return false;'><input id='dirFrom' type='text' value='enter address' onclick='cleardefault();'><p class='example'>(ex. Wichita, KS)</p><input type='submit' value=' Get Directions '></form></td></tr></table>";
var arrLocs =new Array();
var defaultcleared=0;

arrLocs['main']=new Array();
arrLocs['main']['lat'] = 38.350811;
arrLocs['main']['long'] = -97.685537;
arrLocs['main']['address'] = 'Wittig';
arrLocs['main']['address2'] = '';
arrLocs['main']['city'] = 'McPherson';
arrLocs['main']['state'] = 'KS';
arrLocs['main']['zip'] = '67460';
arrLocs['main']['phone'] = '(620) 241-3095';

function openMap(location) {
	selectedLoc = location;
	Lightview.show({
		href: 'map.html',
		rel: 'iframe', 
		title: 'Directions to King Enterprise Group'
	  });
}
function showMap(location) {
	selectedLoc = location;
	defaultcleared = 0;
  if (GBrowserIsCompatible()) {
	var locmap = new GMap2(document.getElementById('mapbox'));
	var currloc = new GLatLng(arrLocs[selectedLoc]['lat'],arrLocs[selectedLoc]['long']);
				
	locmap.setCenter(currloc, 14);
	//locmap.setMapType(G_ROAD_MAP);
	locmap.addOverlay(new GMarker(currloc));
	
	
	/*
	if (geocoder) {
        geocoder.getLatLng(
          buildToAddress(),
          function(point) {
            if (!point) {
              alert(" not found");
            } else {
			alert(point);
              locmap.setCenter(point, 13);
              var marker = new GMarker(point);
			  
				locmap.setMapType(G_HYBRID_MAP);
				locmap.addOverlay(marker);
				locmap.openInfoWindowHtml(locmap.getCenter(),infowindowHTML(selectedLoc));
				locmap.setUIToDefault();
              //locmap.addOverlay(marker);
              //locmap.openInfoWindowHtml(buildToAddress());
            }
          }
        );
      }*/
	
	locmap.openInfoWindowHtml(locmap.getCenter(),infowindowHTML(selectedLoc));
			
	locmap.setUIToDefault();
	/*
	Lightview.show({
		href: 'map.html',
		rel: 'iframe', 
		title: 'Directions to '
	  });
	*/
  }
}

function infowindowHTML(selectedLoc) {
	selectedHTML = infoWindowContentStart + '<br>' + arrLocs[selectedLoc]['address'];
	if(arrLocs[selectedLoc]['address2'].length > 0){
		selectedHTML = selectedHTML + '<br>' + arrLocs[selectedLoc]['address2'];
	}
	selectedHTML = selectedHTML + '<br>' + arrLocs[selectedLoc]['city'] + ', ' + arrLocs[selectedLoc]['state'] + ' ' + arrLocs[selectedLoc]['zip'];
	selectedHTML = selectedHTML + '<br>' + arrLocs[selectedLoc]['phone'];
	selectedHTML = selectedHTML + infoWindowContentEnd;
	
	return selectedHTML;
}


function gotoDirections(){
	//Lightview.hide();
	if(document.getElementById('dirFrom').value.length > 0){
		parent.dirFrom = document.getElementById('dirFrom').value;
		/*Lightview.show({
			href: 'directions.html',
			rel: 'iframe', 
			title: 'Directions to '
		  });*/
		document.location.href='directions.html';
	} else {
		alert('Please enter a From location.');
	}
}
		
function cleardefault(){
	if(!defaultcleared){
		document.getElementById('dirFrom').value = '';
	}
	defaultcleared = 1;
}




/////////////////////////////////////////////////////////////////////
window.onerror = null;
var topMargin = 104;
var slideTime = 1200;
var ns6 = (!document.all && document.getElementById);
var ie4 = (document.all);
var ns4 = (document.layers);
function layerObject(id,left) {
	if (ns6) {
		this.obj = document.getElementById(id).style;
		this.obj.left = left;
		return this.obj;
	}
		else if(ie4) {
		this.obj = document.all[id].style;
		this.obj.left = left;
		return this.obj;
	}
	else if(ns4) {
		this.obj = document.layers[id];
		this.obj.left = left;
	return this.obj;
	}
}
function layerSetup() {
floatLyr = new layerObject('overlay', pageWidth * .5);
window.setInterval("main()", 10)
}
function floatObject() {
if (ns4 || ns6) {
findHt = window.innerHeight;
} else if(ie4) {
findHt = document.body.clientHeight;
   }
} 
function main() {
if (ns4) {
this.currentY = document.layers["overlay"].top;
this.scrollTop = window.pageYOffset;
mainTrigger();
}
else if(ns6) {
this.currentY = parseInt(document.getElementById('overlay').style.top);
this.scrollTop = scrollY;
mainTrigger();
} else if(ie4) {
this.currentY = overlay.style.pixelTop;
this.scrollTop = document.body.scrollTop;
mainTrigger();
   }
}
function mainTrigger() {
var newTargetY = this.scrollTop + this.topMargin;
if ( this.currentY != newTargetY ) {
if ( newTargetY != this.targetY ) {
this.targetY = newTargetY;
floatStart();
}
animator();
   }
}
function floatStart() {
var now = new Date();
this.A = this.targetY - this.currentY;
this.B = Math.PI / ( 2 * this.slideTime );
this.C = now.getTime();
if (Math.abs(this.A) > this.findHt) {
this.D = this.A > 0 ? this.targetY - this.findHt : this.targetY + this.findHt;
this.A = this.A > 0 ? this.findHt : -this.findHt;
}
else {
this.D = this.currentY;
   }
}
function animator() {
var now = new Date();
var newY = this.A * Math.sin( this.B * ( now.getTime() - this.C ) ) + this.D;
newY = Math.round(newY);
if ((( this.A > 0 && newY > this.currentY ) || ( this.A < 0 && newY < this.currentY )) && displayingOverlay == 0) {
if ( ie4 )document.all.overlay.style.pixelTop = newY;
if ( ns4 )document.layers["overlay"].top = newY;
if ( ns6 )document.getElementById('overlay').style.top = newY + "px";
   }
}
function start() {
if(ns6||ns4) {
pageWidth = innerWidth;
pageHeight = innerHeight;
layerSetup();
floatObject();
}
else if(ie4) {
pageWidth = document.body.clientWidth;
pageHeight = document.body.clientHeight;
layerSetup();
floatObject();
   }
}

<!--// open link in new window
function externalLinks() {
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++) {
		var anchor = anchors[i];
		if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external") anchor.target = "_blank";
	}
}
window.onload = externalLinks;
// -->
