function SDMenu(id) {
	if (!document.getElementById || !document.getElementsByTagName)
		return false;
	this.menu = document.getElementById(id);
	this.submenus = this.menu.getElementsByTagName("div"); 
	this.speed = 10;
	this.markCurrent = true;
	this.oneSmOnly = true;
}
SDMenu.prototype.init = function() {
	var mainInstance = this;
	for (var i = 0; i < this.submenus.length; i++)
		this.submenus[i].getElementsByTagName("span")[0].onclick = function() {
			mainInstance.toggleMenu(this.parentNode);
		};
	if (this.markCurrent) {
		var links = this.menu.getElementsByTagName("a");
		for (var i = 0; i < links.length; i++)
			if (links[i].href == document.location.href) {
				links[i].className = "current";
				break;
			}
	}
};
SDMenu.prototype.toggleMenu = function(submenu) {
	if (submenu.id) {                                            // start pierce
		if      (submenu.id == "archCementDiv") {showCont('arch', archCementDivImg) }
		else if (submenu.id == "archHouseDiv")  {showCont('arch',archHouseDivImg) } 
		else if (submenu.id == "houseFloorDiv") {showCont('house',houseFloorDivImg,'html') } 
		else if (submenu.id == "houseHouseDiv") {showCont('house',houseHouseDivImg) }
	}                                                            // end pierce
	
	if (submenu.className == "collapsed") 
		this.expandMenu(submenu);
	else
		this.collapseMenu(submenu);
};
SDMenu.prototype.expandMenu = function(submenu) {
	var fullHeight = submenu.getElementsByTagName("span")[0].offsetHeight;
	var links = submenu.getElementsByTagName("a");
	for (var i = 0; i < links.length; i++)
		fullHeight += links[i].offsetHeight;
	var moveBy = Math.round(this.speed * links.length);
	
	var mainInstance = this;
	var intId = setInterval(function() {
		var curHeight = submenu.offsetHeight;
		var newHeight = curHeight + moveBy;
		if (moveBy == 0) {
			clearInterval(intId);
			submenu.style.height = ""; 
			submenu.className = "expanded";     // pierce //
			}
		else {	
		if (newHeight < fullHeight)
			submenu.style.height = newHeight + "px"; 
		else {
			clearInterval(intId);
			submenu.style.height = ""; 
			submenu.className = "expanded";      // pierce //
			}}
	}, 30);
	this.collapseOthers(submenu);
};
SDMenu.prototype.collapseMenu = function(submenu) {
	var minHeight = submenu.getElementsByTagName("span")[0].offsetHeight;
	var moveBy = Math.round(this.speed * submenu.getElementsByTagName("a").length);
	var mainInstance = this;
	var intId = setInterval(function() {
		var curHeight = submenu.offsetHeight;
		var newHeight = curHeight - moveBy;
		if (newHeight > minHeight)
			submenu.style.height = newHeight + "px";
		else {
			clearInterval(intId);
			submenu.style.height = "";
			submenu.className = "collapsed";
			}
	}, 30);
};
SDMenu.prototype.collapseOthers = function(submenu) {
	if (this.oneSmOnly) {
		for (var i = 0; i < this.submenus.length; i++) 
			if (this.submenus[i] != submenu && this.submenus[i].className != "collapsed")
				this.collapseMenu(this.submenus[i]);
	}
};
SDMenu.prototype.expandAll = function() {
	var oldOneSmOnly = this.oneSmOnly;
	this.oneSmOnly = false;
	for (var i = 0; i < this.submenus.length; i++)
		if (this.submenus[i].className == "collapsed")
			this.expandMenu(this.submenus[i]);
	this.oneSmOnly = oldOneSmOnly;
};
SDMenu.prototype.collapseAll = function() {
	for (var i = 0; i < this.submenus.length; i++)
		if (this.submenus[i].className != "collapsed")
			this.collapseMenu(this.submenus[i]);
};



// accordion.js v2.0
// Copyright (c) 2007 stickmanlabs
// Author: Kevin P Miller | http://www.stickmanlabs.com
// Accordion is freely distributable under the terms of an MIT-style license.
if (typeof Effect == 'undefined') 
	throw("accordion.js requires including script.aculo.us' effects.js library!");
var accordion = Class.create();
accordion.prototype = {
	//  Setup the Variables
	showAccordion : null,
	currentAccordion : null,
	duration : null,
	effects : [],
	animating : false,
	//  Initialize the accordions
	initialize: function(container, options) {
	  if (!$(container)) {
	    throw(container+" doesn't exist!");
	    return false; }
		this.options = Object.extend({
			resizeSpeed : 8,
			classNames : {
				toggle : 'accordionBar_normal',                     // pierce //
				toggleActive : 'accordionBar_active',               // pierce //                
				content : 'accordion_content' },
			defaultSize : {
				height : null,
				width : null },
			direction : 'horizontal',                             // pierce //
			onEvent : 'click'
		}, options || {});
		this.duration = ((11-this.options.resizeSpeed)*0.15);
		var accordions = $$('#'+container+' .'+this.options.classNames.toggle);  
		accordions.each(function(accordion) {
			Event.observe(accordion, this.options.onEvent, this.activate.bind(this, accordion), false);
			if (this.options.onEvent == 'click') { 
			  accordion.onclick = function() { return false;}; }
			if (this.options.direction == 'horizontal') {
				var options = $H({width: '0px'}); } 
			else { var options = $H({height: '0px'}); }
			options.merge({display: 'none'});			
			this.currentAccordion = $(accordion.next(0)).setStyle(options);	}.bind(this));
	},
	//  Activate an accordion
	activate : function(accordion) {
		if (this.animating) {
			return false; 	}
		this.effects = []; 
		this.currentAccordion = $(accordion.next(0));
		this.currentAccordion.setStyle({
			display: 'block' });
		this.currentAccordion.previous(0).className='accordionBar_normal accordionBar_active';   	//  pierce //
		//	this.currentAccordion.previous(0).addClassName(this.options.classNames.toggleActive); // pierce //
		if (this.options.direction == 'horizontal') {
			this.scaling = $H({
				scaleX: true,
				scaleY: false});  } 
			else {this.scaling = $H({
				scaleX: false,
				scaleY: true }); }
		if (this.currentAccordion == this.showAccordion) {
		  this.deactivate(); } 
		  else { this._handleAccordion(); }
	},
	// Deactivate an active accordion
	deactivate : function() {
		if (!this.showAccordion) { return; } 						// already on home closed state - pierce
		window['objhouse'].slider.setEnabled(); 					//$('house_trk').show(); 
		$('house_hndl').style.top='0'; $('house_main').scrollTop='0';    // pierce //
		$('arch_hndl').style.top='0'; $('arch_main').scrollTop='0';      // pierce //
		$('area_hndl').style.top='0'; $('area_main').scrollTop='0';      // pierce //
		$('contact_hndl').style.top='0'; $('contact_main').scrollTop='0';  //pierce//
		if (navigator.appVersion.indexOf('MSIE')>0) {     // show handle after transtion for Windows anomaly
		    	trk=this.currentAccordion.previous(0).id.substr(0,(this.currentAccordion.previous(0).id.indexOf('_')+1))+'trk';
				if ($(trk)) {$(trk).show;}
		} 	   	// end Pierce	
	   this.currentAccordion = $("house")   								// set up to close = pierce
		
		var options = $H({
		  duration: this.duration,
			scaleContent: false,
			transition: Effect.Transitions.sinoidal,
			queue: {
				position: 'end', 
				scope: 'accordionAnimation' },
			scaleMode: { 
				originalHeight: this.options.defaultSize.height ? this.options.defaultSize.height : this.currentAccordion.scrollHeight,
				originalWidth: this.options.defaultSize.width ? this.options.defaultSize.width : this.currentAccordion.scrollWidth },
			afterFinish: function() { 
				this.showAccordion.setStyle({
                    height: 'auto',
					display: 'none' });				
				this.showAccordion = null; 
				this.animating = false;  }.bind(this) });    
    options.merge(this.scaling); 
    this.showAccordion.previous(0).removeClassName(this.options.classNames.toggleActive); 
   	new Effect.Scale(this.showAccordion, 0, options); },
  // Handle the open/close actions of the accordion
 	_handleAccordion : function() { 
		var options = $H({
			sync: true,
			scaleFrom: 0, 
			scaleContent: false,
			transition: Effect.Transitions.sinoidal,
			scaleMode: { 
				originalHeight: this.options.defaultSize.height ? this.options.defaultSize.height : this.currentAccordion.scrollHeight,
				originalWidth: this.options.defaultSize.width ? this.options.defaultSize.width : this.currentAccordion.scrollWidth }  });
		options.merge(this.scaling);
		this.effects.push(
			new Effect.Scale(this.currentAccordion, 100, options) );
		if (this.showAccordion) {
		    if (navigator.appVersion.indexOf('MSIE')>0) {  // hide handle during transtion for Windows anomaly - Pierce
		    	trk=this.showAccordion.previous(0).id.substr(0,(this.showAccordion.previous(0).id.indexOf('_')+1))+'trk';
			    if ($(trk)) $(trk).hide;                 }  // end Pierce
		 	this.showAccordion.previous(0).removeClassName(this.options.classNames.toggleActive);
			options = $H({
				sync: true,
				scaleContent: false,
				transition: Effect.Transitions.sinoidal });
			options.merge(this.scaling);			
			this.effects.push(
				new Effect.Scale(this.showAccordion, 0, options) );	}
	new Effect.Parallel(this.effects, {
			duration: this.duration, 
			queue: {
				position: 'end', 
				scope: 'accordionAnimation' },
			beforeStart: function() { 
				this.animating = true;  	}.bind(this),
			afterFinish: function() {
				if (this.showAccordion) { 
				   var b=document.getElementById(window["objarch"].main);
					var c=b.childNodes;
					if (c[0].id == "video1") showCont('arch','includes/video1.htm','html');  //stop video from playing
					window['objhouse'].slider.setEnabled(); 									//$('house_trk').show(); 
			  		$('house_hndl').style.top='0'; $('house_main').scrollTop='0';   // pierce //
		      	$('arch_hndl').style.top='0'; $('arch_main').scrollTop='0';     // pierce //
					$('area_hndl').style.top='0'; $('area_main').scrollTop='0';     // pierce //
			  		$('contact_hndl').style.top='0'; $('contact_main').scrollTop='0';     // pierce //
		      	if (navigator.appVersion.indexOf('MSIE')>0) {     						// show handle after transtion for Windows anomaly
						trk=this.currentAccordion.previous(0).id.substr(0,(this.currentAccordion.previous(0).id.indexOf('_')+1))+'trk';
						if ($(trk)) $(trk).show; 
				}    								// end Pierce	
				this.showAccordion.setStyle({
					display: 'none' });	 }
				$(this.currentAccordion).setStyle({ height: 'auto' });
				this.showAccordion = this.currentAccordion; 
				this.animating = false;}.bind(this)}); }
}
