// DEFAULT VARS
var ua = navigator.userAgent.toLowerCase();
var isIE = document.all && ua.indexOf("opera") == -1  ? 1:0;
var isOpera = ua.indexOf("opera") != -1  ? 1:0;
var isGecko = ua.indexOf("gecko") != -1  ? 1:0;
var pageOffsetX = 0, pageOffsetY = 0, winWidth = 0;

/**
 *  CREATE LAYER OBJECT
 *  Dynamically creates a layer object. This function support standards browsers with
 *  DOM support and the proprietary IR document.all objects. Netscape 4 or equivilent
 * are not supported.
 */
function createLayerObj(divID) {
    if( document.layers || document[divID]) //Netscape layers and alternate, return null
        return null;
    if( document.getElementById ) //DOM; IE5, NS6, Mozilla, Opera
        return document.getElementById(divID); 
    if( document.all ) //Proprietary DOM; IE4
        return document.all[divID]; 
    return false;
}
/**
 *  CHANGE DIV 
 *  Depending on the arguments passed, this function shows or hides the hotel labels
 *  above the world map. it also dynamically writes the label text and makes it either
 *  visible or invisible.
 *  @param  String  divId       The layer to be manipluated
 *  @param  String  visState    The layers visability state. 
 *  @param  int     target      The property Id number
 *  @return Boolean             TRUE on success, FALSE on failure
 */
function chngDiv(divId,visState,target) {
    //get a reference as above ...
    myReference = createLayerObj(divId);
    if(!myReference) {
        return false;
    }
    if (myReference.style) { //DOM & proprietary DOM
        var top = 0, left = 0;
        // TEMPORARILY PUT THE LAYER IN THE MAIN WINDOW SO IT SIZES CORRECTLY
        myReference.style.top = '0px';
        myReference.style.left = '0px';
        if (visState == 'visible') {
            var coords = getTargetCoordinates(target);
            myReference.style.width = coords[0]+'px';
            myReference.style.minwidth = myReference.style.width;
            innerLayer = createLayerObj("hotellabel");
            innerLayer.innerHTML = coords[3];
            top = coords[1]+"px";
            left = coords[2]+"px";
            myReference.style.display = 'block';
        } else {
            myReference.style.display = 'none';
            top = '-25px';
            left = '-75px';
        }
        myReference.style.top = top;
        myReference.style.left = left;
         myReference.style.visibility = visState;
    } else {
        return false; //don't go any further
    }
    return true;
}
/**
 * GET PAGE OFFSET
 * If the window width is greater than 790px (the page width), this function determines the
 * remaining blank space on the left side of the window, then adds that to the default
 * width of the page nav bar to set a default position at the left edge of the world
 * map. See getTargetCoordinates() for the second half of label positioning.
 * @return  int The page width to the edge of the world map
 */
function getPageOffset() {
    // STANDARDS COMPLIANT BROWSERS
    if (document.documentElement && document.documentElement.clientWidth)
        winWidth = document.documentElement.clientWidth;
    // NON-STANDARDS COMPLIANT BROWSERS AND IE 6 in "QUIRKS" MODE
    else if (document.body && document.body.clientWidth)
        winWidth = document.body.clientWidth;
  
    if (winWidth != 0) {
        // IF THE BROWSER WINDOW IS SMALLER THAN THE WIDTH OF THE PAGE, THE CONTENT
        // WILL BE ALIGNED LEFT, AND THEREFOR THE DEAULT WIDTH OF THE PAGE TO THE MAP,
        // 206px, SHOULD BE RETURNED.
        if (winWidth > defaultWidth) {
            // DETERMINE MAP OFFETS ON PAGE
            var l_offset = parseInt((winWidth - defaultWidth) / 2);
            var map_x = l_offset + navSize;
            return map_x;
        } else {
            return navSize;
        }
    } else {
        return navSize;
    }
}
/**
 * CHECK PAGE DIMESIONS
 * When the browser is resized (in browsers that support BODY.onresize()), this
 * function checks the new browser window against a previously saved page width
 * and if they are different, reloads the page
 *
 */
function checkPageDims() {
    if(document.documentElement && document.documentElement.clientWidth) {
        if (document.documentElement.clientWidth != winWidth)
            document.location.href = document.location.href;
    } else if (document.body && document.body.clientWidth) {
        if (document.body.clientWidth != winWidth)
            document.location.href = document.location.href;
    }
}
