
var pages = new Array();


pages["home"] = "home.html";
pages["loanProcess"] = "loanProcess.html";
pages["loanApplication"] = "loanApplication.html";
pages["propertyTypes"] = "propertyTypes.html";
pages["loanTypes"] = "loanTypes.html";
pages["mortgageCalculator"] = "mortgageCalculator.html";
pages["glossary"] = "glossary.html";
pages["survey"] = "survey.html";
pages["pricingMatrix"] = "pricingMatrix.html";
pages["contactUs"] = "contactUs.html";
pages["about"] = "about.html";
pages["msg"] = "message.php";


var myMenu =
[
    [null, 'Home', 'javascript:ajaxCall.loadPage("home")', '', 'IRECC Home page'],  // a menu item
    [null, 'Loans', null, '', 'Loans',
		[null, 'Loan Process', 'javascript:ajaxCall.loadPage("loanProcess")', '', 'Loan Process'],  // a menu item
		[null, 'Loan Application', 'javascript:ajaxCall.loadPage("loanApplication")', '', 'Loan Application'],  // a menu item
		[null, 'Property Types', 'javascript:ajaxCall.loadPage("propertyTypes")', '', 'Property Types'],  // a menu item
		[null, 'Loan Types', 'javascript:ajaxCall.loadPage("loanTypes")', '', 'Loan Types']
	],  // a menu item
    [null, 'Tools', null, '', 'description',   // a folder item
        [null, 'Mortgage Calculator', 'javascript:ajaxCall.loadPage("mortgageCalculator")', '', 'Mortgage Calculator'],  // a menu item
        [null, 'Glossary', 'javascript:ajaxCall.loadPage("glossary")', '', 'Glossary']  // a menu item
/*		_cmSplit,
        [null, 'Survey the Market', 'javascript:ajaxCall.loadPage("survey")', '', 'Survey the Market'],  // a menu item
        [null, 'Pricing Matrix', 'javascript:ajaxCall.loadPage("pricingMatrix")', '', 'Pricing Matrix']*/
	],	
    [null, 'Contact Us', 'javascript:ajaxCall.loadPage("contactUs")', '', 'Contact us'],  // a menu item
    [null, 'About IRECC', 'javascript:ajaxCall.loadPage("about")', '', 'About IRECC']
];
function adjustHeight() 
{
	var theWidth = 0, theHeight = 0;
	if (window.innerWidth) 
	{
	theWidth=window.innerWidth;
	}
	else 
	if (document.documentElement && document.documentElement.clientWidth) 
	{
		theWidth=document.documentElement.clientWidth;
	}
	else if (document.body) 
	{
		theWidth=document.body.clientWidth;
	}
	if (window.innerHeight) 
	{
		theHeight=window.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight) 
	{
		theHeight=document.documentElement.clientHeight;
	}
	else if (document.body) 
	{
		theHeight=document.body.clientHeight;
	}
	if (theHeight < 400) theHeight = 400;
	document.getElementById('mainContent').style.height = (theHeight - 215) + "px";
}
function historyChange(newLocation, historyData) {	
	if (newLocation == "") {
		newLocation = "home";
	}
	if (newLocation.length == 1) return;
	ajaxCall.loadPage(newLocation);
}

var ajaxCall = {
	isLoading : false,
	loadPage : function(pageId) {
		if (ajaxCall.isLoading) return;
		ajaxCall.isLoading = true;
		var page = pages[pageId];
		//alert(page);
		if (page == undefined) {
			pageId = "home";
			page = pages[pageId];
		}  // not a page
		
		dhtmlHistory.add(pageId, page);
		
		var loadingIndicator = document.getElementById('loading');
		var mainContentArea = document.getElementById('mainContent');
		mainContentArea.innerHTML = loadingIndicator.innerHTML;
		loadingIndicator.style.visibility="visible";
		
		var handleSuccess = function(o) {
			mainContentArea.innerHTML = o.responseText;
			loadingIndicator.style.visibility="hidden";	
			ajaxCall.isLoading = false;
			
		};
		
		var handleFailure = function(o) {
			alert("Connection failure. Please try again later.");
			loadingIndicator.style.visibility="hidden";	
			ajaxCall.isLoading = false;
		};
		
		var callBack = {success:handleSuccess, failure:handleFailure};
		
		YAHOO.util.Connect.asyncRequest('GET', page +'?nocache=' + Math.random(), callBack);
		
		
	}
};


function init() {
	document.getElementById('loading').style.display="none";
    
    dhtmlHistory.initialize();
    dhtmlHistory.addListener(historyChange);

    var currentLocation = dhtmlHistory.getCurrentLocation();

    if (currentLocation == "") {
       currentLocation = "home";
    }
   	adjustHeight();
    ajaxCall.loadPage(currentLocation);
}

function preloadImages() {

	var d=document,a=arguments; if(!d.FP_imgs) d.FP_imgs=new Array();
	
	for(var i=0; i<a.length; i++) { d.FP_imgs[i]=new Image; d.FP_imgs[i].src=a[i]; }

}
YAHOO.util.Event.on(window, 'load', init);
YAHOO.util.Event.on(window, 'resize', adjustHeight);
