//initialize urls for print function
var house_url='includes/amenities.htm';
var arch_url='includes/architecture.htm';
var area_url='includes/ranch.htm';
var contact_url='includes/contact.htm';

// secondary pull down menu initial images
var archCementDivImg = 'image/2c_building_two.jpg'
var archHouseDivImg = 'image/2c_northwest.jpg'
var houseFloorDivImg = 'includes/secondfloor.htm' 
var houseHouseDivImg = 'image/1b_eastlawn.jpg'

window.onload = function() { 
	loadAccordion();
	
	var sDiv = document.getElementsByClassName('accordionBar_normal');
	for (var i=0;i<sDiv.length;i++) { 
		sDiv[i].onmouseover = function () {  
			var csN=this.className; 
	 		if (csN=='accordionBar_normal accordionBar_active') {return }
	 		csN+=" accordionBar_over";
	 		this.className=csN;
		}
		sDiv[i].onmouseout  = function () { 
			var csN=this.className; 
	 		if (csN=='accordionBar_normal accordionBar_active') {return }
     		this.className='accordionBar_normal';	
		}
	}	
	
	var aDiv = document.getElementsByClassName('accordion_content');
	for (i=0;i<aDiv.length;i++) {
		var t = document.createElement('div');
		aDiv[i].appendChild(t);
		t.id = aDiv[i].id+'_trk';
		t.style.height = "400px";
		t.className = "track"; 
  
		var h = document.createElement('div');
		t.appendChild(h);  
		h.id = aDiv[i].id+'_hndl';
		h.style.height = "25px";
		h.className = "handle"; 
		
		var m = aDiv[i].id+'_main';
		var o = 'obj'+aDiv[i].id;
		window[o]=new ObjSlide(h.id,t.id,m,o);
	}
	
	var housemenu = new SDMenu("house_menu");housemenu.init();
	var archmenu =  new SDMenu("arch_menu");archmenu.init();
	var areamenu =  new SDMenu("area_menu");areamenu.init();
 
	new Image().src="bars/button_green.jpg";
	new Image().src="bars/button_gray.jpg";
	new Image().src="bars/button_PlantKyle_over.gif";
 
	showCont('contact','includes/contact.htm','text');
}

function ObjSlide(h,t,m,o){
	this.handle = h;
	this.track = t;
	this.main = m;
	this.slider = new Control.Slider(this.handle, this.track, {
	axis: 'vertical',
	onSlide: function(v)		{ scrollVertical(v, $(window[o].main), window[o].slider); },
	onChange: function(v)	{ scrollVertical(v, $(window[o].main), window[o].slider); }
	});
	
	this.slider.setDisabled();
	$(this.track).hide();
}

function scrollVertical(value, element, slider) { 
	element.scrollTop = Math.round(value/slider.maximum*(element.scrollHeight-element.offsetHeight));
};

var gAccordion = {};		
function loadAccordion() { 
   gAccordion = new accordion('accordion_container', {
	defaultSize : { width : 610,height : 400 },
	resizeSpeed : 7
	});
}

function printIt(urlid) {
   loc='printit.html?'+urlid;
   window.open(loc,'_blank','width=750,scrollbars=yes, menubar=yes, toolbar=no,resizable=yes');
}

function showCont(objct,url,txt) { 
	var xmlhttp=null;
	var o='obj'+objct;
	var m = window[o].main;
	var h = window[o].handle;
	var t = window[o].track;
	var obj=$(m);
	
	xmlhttp = HTTP.newRequest(); 	
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
	xmlhttp.onreadystatechange= function() {  
		if (xmlhttp.readyState !=4) { 
			obj.innerHTML= "<div class='ajaxloading'>Loading...</div>";
		} else {	
  		if (xmlhttp.status==200)  { 		
			var u = objct+'_url';
			window[u] = url;
		
			if (txt=="text")  {  				// show html text (only)   
      		obj.style.width='430px';  
				obj.style.margin='20px 40px 10px 30px';
				obj.style.height='370px'; 
				obj.scrollTop='0'; 
				obj.innerHTML=xmlhttp.responseText;  
	 			if ((obj.scrollHeight > obj.offsetHeight) || (objct == "contact")) {   // hack because accordion not yet open 
					window[o].slider.setEnabled();
		  			$(t).show(); 
		 			$(h).style.top='0';
				} else {
					window[o].slider.setDisabled();
		  			$(t).hide(); 
				}
	  		} else if (txt=="html") { 			 // show html (rendering) 	  
					window[o].slider.setDisabled();
					$(t).hide();
					obj.style.height='400px';
					obj.style.width='520px';  
					obj.style.margin='0';
					obj.scrollTop='0';
	    			obj.innerHTML=xmlhttp.responseText; 
	  		} else {   								// show image
	 				window[o].slider.setDisabled();
					$(t).hide();
					obj.style.height='400px';
					obj.style.width='520px';
        			obj.style.margin='0';
					obj.scrollTop='0';
        			obj.innerHTML="<img src='"+url+"'/>"; 
	 		}
  			} else { 
				alert("Problem retrieving data:" + xmlhttp.statusText);
			}  
		}	
	}
}

var HTTP={};
HTTP._factories = [
	function() { return new XMLHttpRequest(); }, 
	function() { return new ActiveXObject("Msxml2.XMLHTTP"); },
	function() { return new ActiveXObject("Microsoft.XMLHTTP"); }
	];
HTTP._factory=null;

HTTP.newRequest = function() {
	if (HTTP._factory != null) return HTTP._factory();
	for (var i = 0; i < HTTP._factories.length; i++) {
		try {
			var factory = HTTP._factories[i];
			var request = factory(); 
			if (request != null) { HTTP._factory = factory; return request; }
		}
		catch(e) { continue; }
	}
	alert("Your browser does not support XMLHTTP, required for this site"); 
}

function endclik() {
	gAccordion.deactivate();
}

function endover(obj) {
	obj.src = "bars/button_PlantKyle_over.gif"; 
}

function endout(obj) {
	obj.src = "bars/button_PlantKyle.gif";  
}
