// An object-based cross-browser/platform show/hide/move DHTML toolkit

// Setting IE vs NN constants
// n = Netscape ; ie = Internet Explorer ; 
// w3c = new W3C standard compliant browsers (like Netscape 6)
            
var show='visible';
var hide='hidden';
var left='left';
var top='top';
var none='none';
var block='block';
var bgcolor='backgroundColor';
var n=ie=w3c=op=false;

// detect browser DOM-style
if (document.layers) { // netscape4-esque
    n=true;
    show='show';
    hide='hide';
    bgcolor='bgColor';
} 
if (document.all) { // ie4-5-esque
    ie=true;        
    left='pixelLeft';
    top='pixelTop';
    block='';
} 
if (document.getElementById) { // w3c-compliant-esque
    w3c=true;
}

if (navigator.userAgent.toLowerCase().indexOf("opera 5") != -1 || navigator.userAgent.toLowerCase().indexOf("opera/5") != -1) {
    ie=w3c=n=false;
    op=true;
}

// if(!(n||ie||w3c||op)) alert('No javascript!');


// Open new popup window for greetings
function fPopUp(){
    vW = 400;
    vH = 300;
    vL = (screen.width) ? (screen.width-vW)/2 : 0;
    vT = (screen.height) ? (screen.height-vH)/2 : 0;
    features = "width=" + vW + ",height=" + vH + ",left=" + vL + ",top=" + vT + ",fullscreen=no,toolbar=no,status=no,menubar=no,scrollbars=no,resizable=no,directories=no,location=no";
    newWin = window.open('popup_greeting/popup.html', 'RCG', features);
}


// Create browser-specific menu object
function initDhtmlItem(itemName) {
		
        // create DOM-specific object references for DHTML items
        
        if (w3c) {
			//alert('firefox');
            itemRef = document.getElementById(itemName).style;
        }
		else if (n) { // netscape 4 
			//alert('firefox');		
            WM_layers = new Array();
            with (document) {
              for (i=0; i<layers.length; i++) WM_layers[i]=layers[i]; {
                for (i=0; i<WM_layers.length; i++) {
                  if (WM_layers[i].document && WM_layers[i].document.layers) {
                    for (j=0; j<WM_layers[i].document.layers.length; j++) {
                      WM_layers[WM_layers.length] = WM_layers[i].document.layers[j];
                    }
                    if(WM_layers[i].name == itemName){
                      // So if the code matches the name of the layer, 
                      // return the reference. 
                      itemRef = WM_layers[i];
                    }
                  }
                }
              }
            }
        }
		else if (ie) { 
          itemRef = document.all[itemName].style;
		}
        
        // return reference
        return itemRef;        
}




// make visible or hides the selected item
// note: possible values for showOrHide are 'show' and 'hide'
function showHideItem(itemToShow,showOrHide) {
    
    // initialize item
    theObj = initDhtmlItem(itemToShow);
    
    // insure that showOrHide is valid value
    // default = show (only hides if incoming value is 'hide')
    showOrHide = (showOrHide == 'hide') ? hide : show;

    // do the deed
    theObj.visibility = showOrHide;
    	
}

// moves the selected item to given x,y position
function moveItem(itemToMove,xPos,yPos) {
 
    // initialize item
    theObj = initDhtmlItem(itemToMove);
    
    // do the deed
    theObj.left = parseInt(xPos);
    theObj.top = parseInt(yPos);
    	
}

// changes the contents of the selected item
function putHTML(itemToChange, newHTML) {
	if (ie) { document.all(itemToChange).innerHTML = newHTML; }
    else if (w3c) { document.getElementById(itemToChange).innerHTML = newHTML; }
	else if (n) {
        with (document.layers[itemToChange].document) {
    		write(newHTML);
    		close();
	    }
    } 
}


// changes the background color of the selected item
function changeBGColor(itemToChange, newBGColor) {
    // initialize item
    theObj = initDhtmlItem(itemToChange);
    if (n) theObj.document.bgcolor = newBGColor;
    else theObj.bgcolor = newBGColor;
}


// changes the display mode of the selected layer
// (useful for toggling hierarchical menus)
// note: doesn't work in NS4!
function toggleDisplay(itemToChange) {
    // initialize item
    theObj = initDhtmlItem(itemToChange);
	if (!n) { 
        if (theObj.display == none) {
            theObj.display = block;
        } else {
            theObj.display = none;
        }
    }
}



// changes the display mode of the selected layer
// (useful for toggling hierarchical menus)
// note: doesn't work in NS4!
function toggleInline(itemToChange) {
    // initialize item
    theObj = initDhtmlItem(itemToChange);
	if (!n) { 
        if (theObj.display == none) {
            theObj.display = 'inline';
        } else {
            theObj.display = none;
        }
    }
}



// changes the display mode of all selected layers
// to block... useful for expanding menus
// note: doesn't work in NS4!
function expandAll() {
	if (!n) { 
 		for (var i=0; i<expandAll.arguments.length; i++) {
            // initialize item
            theObj = initDhtmlItem(expandAll.arguments[i]);
			theObj.display = block;
		}
    }
}



// changes the display mode of all selected layers
// to none... useful for collapsing expandable menus
// note: doesn't work in NS4!
function collapseAll() {
	if (!n) { 
 		for (var i=0; i<collapseAll.arguments.length; i++) {
            // initialize item
            theObj = initDhtmlItem(collapseAll.arguments[i]);
			theObj.display = none;
		}
    }
}



// toggles back and forth between two selected images.
function toggleImages(itemName,imageOne,imageTwo) {
	if (document.images) {
        if (document[itemName].src.indexOf(imageOne) == -1) changeImages(itemName,imageOne); 
        else changeImages(itemName,imageTwo);
    }
}

// new image object constructor
function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

// swap images function 
function changeImages() {
	if (document.images) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		}
	}
}

//why do we have so many different popup functions? Because the site was built with page-specific ones and its easier to create one generic than to go back and retrofit all the others

// launches popup window -- this is used for Development Portfolio "zoom in" photos. Has fixed width, height, scrollbars

function popUp(path) {
    features = "width=750,height=460,scrollbars=no,fullscreen=no,toolbar=no,status=no,menubar=no,resizable=no,directories=no,location=no";
	window.open(path, 'popup', features);
}

// launches popup window -- for slideshows on residential and commercial listings. Has fixed path to photos directory
	function pWinPop(path,name,width,height,scrollbar) {
		window.open('/photos/'+path+'',''+name+'','target=new,toolbar=0,location=no,directories=0,status=0,menubar=0,scrollbars='+scrollbar+',resizable=1,width='+width+',height='+height+',top=50,left=200');
	}

//pop-up function. Used on Company Cares and can be used anywhere else. All values can be passed. 
	function winPop(path,name,width,height,scrollbar) {
		window.open(path+'',''+name+'','target=new,toolbar=0,location=no,directories=0,status=0,menubar=0,scrollbars='+scrollbar+',resizable=1,width='+width+',height='+height+',top=50,left=200');
	}


// SEARCH RESULT FUNCTIONS

// set search results constants

currentItem = 'item0';
currentPage = 1;

// does the right thing when forwards or backs are clicked
function searchNavigate(clicked) {

	toggleInline("boxOn" + currentPage);
	toggleDisplay("zone" + currentPage);
	toggleInline("boxOff" + currentPage);

	if (clicked == "R" && (parseInt(currentPage) + itemsPerPage <= lastPage))
		pageMove = parseInt(currentPage) + itemsPerPage;
	else if (clicked == "R" && (parseInt(currentPage) + itemsPerPage > lastPage))
		pageMove = parseInt(currentPage);
	else if (clicked == "L" && currentPage != 1)
		pageMove = parseInt(currentPage) - itemsPerPage;
	else if (clicked == "L" && currentPage == 1)
		pageMove = parseInt(currentPage);
	else
		pageMove = parseInt(clicked);

    currentPage = parseInt(pageMove);

	toggleInline("boxOff" + currentPage);
	toggleInline("boxOn" + currentPage);
	toggleDisplay("zone" + currentPage);

}

// does the right thing when forwards or backs are clicked
function jobsNavigate(clicked) {

	toggleDisplay(clicked);
	if (currentItem != 'item0') toggleDisplay(currentItem);
	currentItem = clicked;
	
}


// NEW CONSTRUCTION DETAIL FUNCTIONS

currentDetailImage = 1;

// change detail image and button states
function detailSwitch(newImg) {

	changeImages('detailImg',newImg);
	toggleImages('button1','images/btn1_on.gif','images/btn1_off.gif');
	toggleImages('button2','images/btn2_on.gif','images/btn2_off.gif');
	
	currentDetailImage = (currentDetailImage == 1) ? 2 : 1;

}


