﻿var buttonFolder = "buttons/";

upSources = new Array("button1.png","button2.png","button3.png","button4.png");
overSources = new Array("button1a.png","button2a.png","button3a.png","button4a.png");

subInfo = new Array();
subInfo[1] = new Array();
subInfo[2] = new Array();
subInfo[3] = new Array();
subInfo[4] = new Array();

subInfo[2][1] = new Array(" Land","http://www.gtamart.com/btr/land.html","");
subInfo[2][2] = new Array(" Commercial","http://www.gtamart.com/btr/commercial.html","");
subInfo[2][3] = new Array(" Residential","http://www.gtamart.com/btr/residential.html","");
subInfo[3][1] = new Array(" Transaction Procedures","http://www.gtamart.com/btr/procedures.html","");
subInfo[3][2] = new Array(" Transaction Support","http://www.gtamart.com/btr/support.html","");
var xSubOffset = 257;
var ySubOffset = 0;

var overSub = false;
var delay = 1000;
totalButtons = upSources.length;

for ( x=0; x<totalButtons; x++) {

if ( subInfo[x+1].length < 1 ) { 
document.write('<div id="submenu' + (x+1) + '">');

} else {
document.write('<div id="submenu' + (x+1) + '" class="dropmenu" ');
document.write('onMouseOver="overSub=true;');
document.write('setOverImg(\'' + (x+1) + '\',\'\');"');
document.write('onMouseOut="overSub=false;');
document.write('setTimeout(\'hideSubMenu(\\\'submenu' + (x+1) + '\\\')\',delay);');
document.write('setOutImg(\'' + (x+1) + '\',\'\');">');
document.write('<ul>');
for ( k=0; k<subInfo[x+1].length-1; k++ ) {
document.write('<li>');
document.write('<a href="' + subInfo[x+1][k+1][1] + '" ');
document.write('target="' + subInfo[x+1][k+1][2] + '">');
document.write( subInfo[x+1][k+1][0] + '</a>');
document.write('</li>');
}
document.write('</ul>');
}
document.write('</div>');
}

function preload() {
for ( x=0; x<totalButtons; x++ ) {
buttonUp = new Image();
buttonUp.src = buttonFolder + upSources[x];
buttonOver = new Image();
buttonOver.src = buttonFolder + overSources[x];
}
}

function setOverImg(But, ID) {
document.getElementById('button' + But + ID).src = buttonFolder + overSources[But-1];
}

function setOutImg(But, ID) {
document.getElementById('button' + But + ID).src = buttonFolder + upSources[But-1];
}

function getElement(id) {
return document.getElementById ? document.getElementById(id) : document.all ? document.all(id) : null; 
}

function getRealLeft(id) { 
var el = getElement(id);
if (el) { 
xPos = el.offsetLeft;
tempEl = el.offsetParent;
while (tempEl != null) {
xPos += tempEl.offsetLeft;
tempEl = tempEl.offsetParent;
} 
return xPos;
} 
} 

function getRealTop(id) {
var el = getElement(id);
if (el) { 
yPos = el.offsetTop;
tempEl = el.offsetParent;
while (tempEl != null) {
yPos += tempEl.offsetTop;
tempEl = tempEl.offsetParent;
}
return yPos;
}
}

function moveObjectTo(objectID,x,y) {
var el = getElement(objectID);
el.style.left = x;
el.style.top = y;
}

function showSubMenu(subID, buttonID) {
hideAllSubMenus();
butX = getRealLeft(buttonID);
butY = getRealTop(buttonID);
moveObjectTo(subID,butX+xSubOffset, butY+ySubOffset);
}

function hideAllSubMenus() {
for ( x=0; x<totalButtons; x++) {
moveObjectTo("submenu" + (x+1) + "",-500, -500 );
}
}

function hideSubMenu(subID) {
if ( overSub == false ) {
moveObjectTo(subID,-500, -500);
}
}
preload();