
function initMask() {
  // needed for the mask
  initDHTMLAPI();
}

// this function will see if the mask is currently applied.
// if so, it will do it again, by calling the applyMask function.
// why? one reason could be that the user resized the window.
function checkMask() {
  if (document.getElementById('mask1').style.display == 'block') {
    applyMask(maskNumber);
  }
}

// applying a mask to the whole page.
// two divs are on the page, hidden (one is white transparent, one is black transparent).
// they will be resized to the current website/window size and shown.

// because we might apply the mask again, we are making maskNumber a global variable
var maskNumber = '';
// because we might want to override this value (on the page level), we are making maskNumber a global variable
// this value is the amount of pixels from the top that the box starts in IE6 and lower
var ie6TopValue = '240px';

/* take care when use this function, it's useful to take down the overlay to the bottom of the body so it will show up
	centered in the page, but it's not recommended use this function when you have to send parameters to the server since
	the overlay will be placed outside the form tag*/
function takeDownOverlayBottomDOM(maskNumber){										
	var theOverlay = document.getElementById('above_mask' + maskNumber);
	theOverlay.parentNode.removeChild(theOverlay);
	document.body.appendChild(theOverlay);					  						
}

function applyMask(theMaskNumber) {
  // maskNumber is used when there are multiple possible elements that can be shown above the mask
  if (typeof(theMaskNumber) == 'undefined') theMaskNumber = '';
  maskNumber = theMaskNumber;
  // getting some dimensions of the window, and the page content
  maskH = '0px';
  maskW = '0px';
  bottomH = 0;
  windowH = getInsideWindowHeight();
  windowW = getInsideWindowWidth();
  pageH = (document.getElementById('page')) ? getObjectHeight('page') : getObjectHeight('fl_ibtPage');
  contentW = (document.getElementById('page')) ? getObjectWidth('page') : getObjectWidth('fl_ibtPage');
  if (document.getElementById('footer')){
    footerH = getObjectHeight('footer');
  }else if (document.getElementById('fl_ibtFooter')){
    footerH = getObjectHeight('fl_ibtFooter');
  }else {
    footerH = (document.getElementById('footer-home')) ? getObjectHeight('footer-home') : '';
  }

  if (document.getElementById('fl_ibtPageBottom')) {
    bottomH = getObjectHeight('fl_ibtPageBottom');
  }
    
  contentH = pageH + footerH;
  // alert('windowH = ' + windowH + '\nwindowW = ' + windowW + '\ncontentH = ' + contentH + '\ncontentW = ' + contentW + '\n\nisIE4 = ' + isIE4);
  var extraW = 0;
  var extraH = 0;
  // modifying some dimensions, mostly because of the scrollbar in FF
  if (!isIE4) {	
    if (windowH <= contentH && windowW > contentW) {
      // alert('windowH <= contentH && windowW > contentW');
      extraW = -18;
      // extraH = 22;
    }
    else if (windowH <= contentH && windowW <= contentW) {
      // alert('windowH <= contentH && windowW <= contentW');
      extraW = 0;
      // extraH = 22;
    }
    else if (windowH > contentH && windowW <= contentW) {
      // alert('windowH > contentH && windowW <= contentW');
      extraW = 0;
      extraH = -20;
    }
  }
  
  if (isIE7 || isChrome || isSafari) {
	extraH = extraH + bottomH + 36;
	if(isChrome || isSafari){
		extraW = extraW + 2;
	}
  }else{
	extraH = extraH + bottomH;
  }
  
  // applying the mask dimensions
  if (windowH > contentH) maskH = windowH + extraH + 87;
  else maskH = contentH + extraH + 87;
  if (windowW > contentW) maskW = windowW + extraW;
  else maskW = contentW + extraW;
  document.getElementById('mask1').style.width = maskW + 'px';
  document.getElementById('mask1').style.height = maskH + 'px';
  document.getElementById('mask2').style.width = maskW + 'px';
  document.getElementById('mask2').style.height = maskH + 'px';
  document.getElementById('mask1').style.display = 'block';
  document.getElementById('mask2').style.display = 'block';
  
  // first move the content outside the window 1000px to the left and 1000px to the top
  document.getElementById('above_mask' + theMaskNumber).style.position = "absolute";
  document.getElementById('above_mask' + theMaskNumber).style.top = "-1000px";
  document.getElementById('above_mask' + theMaskNumber).style.left = "-1000px";
  document.getElementById('above_mask' + theMaskNumber).style.margin = "0px 0px 0px 0px";
  // showing the content that needs to appear above the mask
  document.getElementById('above_mask' + theMaskNumber).style.display = 'block';
  // getting dimensions of the shown content
  var aboveMaskH = getObjectHeight('above_mask' + theMaskNumber);
  var aboveMaskW = getObjectWidth('above_mask' + theMaskNumber);
  // if IE6, we will make the content appear at an absolute position in the center, n pixels from the top
  // and we'll hide the pulldowns because they sit on top of the overlay
  // and we'll hide all the embeds (swf files) because they sit on top of the overlay
  if (isIE4 && isIE6CSS && !isIE7) {
    document.getElementById('above_mask' + theMaskNumber).style.position = "absolute";
    document.getElementById('above_mask' + theMaskNumber).style.top = ie6TopValue;
    document.getElementById('above_mask' + theMaskNumber).style.margin = "0px 0px 0px 0px";
	document.getElementById('above_mask' + theMaskNumber).style.left = "20%";
    var allPulldowns = document.getElementsByTagName('select');
    for (i=0;i<allPulldowns.length;i++) {
      if (allPulldowns[i].className.indexOf('overlay-pulldown') == -1) {
        allPulldowns[i].style.visibility = 'hidden';
      }
    }
    var allEmbeds = document.getElementsByTagName('embed');
    for (j=0;j<allEmbeds.length;j++) {
      allEmbeds[j].style.visibility = 'hidden';
    }
    window.location = '#above_mask' + theMaskNumber;
  }
  // if not IE6
  else {
    // when the shown content is taller than the window height, we will make the content appear at an absolute position in the center, n pixels from the top
    if (aboveMaskH > windowH) {
      document.getElementById('above_mask' + theMaskNumber).style.position = "absolute";
      document.getElementById('above_mask' + theMaskNumber).style.top = "20px";
      document.getElementById('above_mask' + theMaskNumber).style.left = "0px";
      document.getElementById('above_mask' + theMaskNumber).style.margin = "0px 0px 0px 0px";
    }
    // for all other scenarios, it will be positioned fixed, in the center and in the middle
    else {
      document.getElementById('above_mask' + theMaskNumber).style.position = "fixed";
      document.getElementById('above_mask' + theMaskNumber).style.top = "50%";
      document.getElementById('above_mask' + theMaskNumber).style.left = "50%";
      document.getElementById('above_mask' + theMaskNumber).style.margin = "0px auto 0px auto";
      
	  if(isIE7){
		document.getElementById('above_mask' + theMaskNumber).style.marginLeft = - maskW/2 + 'px';
	  }else{      
		document.getElementById('above_mask' + theMaskNumber).style.marginLeft = - aboveMaskW/2 + 'px';
	  }
		document.getElementById('above_mask' + theMaskNumber).style.marginTop = - aboveMaskH/2 + 'px';
    }
  }
}

// hiding the mask elements and resetting the css values
function hideMask() {
  document.getElementById('mask1').style.display = 'none';
  document.getElementById('mask2').style.display = 'none';
  document.getElementById('above_mask' + maskNumber).style.display = 'none';
  // if IE6, show the pulldowns again
  if (isIE4 && isIE6CSS && !isIE7) {
    var allPulldowns = document.getElementsByTagName('select');
    for (i=0;i<allPulldowns.length;i++) {
      if (allPulldowns[i].className.indexOf('overlay-pulldown') == -1) {
        allPulldowns[i].style.visibility = 'visible';
      }
    }
    var allEmbeds = document.getElementsByTagName('embed');
    for (j=0;j<allEmbeds.length;j++) {
      allEmbeds[j].style.visibility = 'visible';
    }
  }
  
  document.getElementById('above_mask' + maskNumber).style.position = "fixed";
  document.getElementById('above_mask' + maskNumber).style.top = "50%";
  document.getElementById('above_mask' + maskNumber).style.left = "50%";
  document.getElementById('above_mask' + maskNumber).style.margin = "0px auto 0px auto";
}

function setOpacity2(objectId,objectOpacity) {
  var object = document.getElementById(objectId).style; 
  object.opacity = (objectOpacity / 100);
  object.MozOpacity = (objectOpacity / 100);
  object.KhtmlOpacity = (objectOpacity / 100);
  object.filter = "alpha(opacity=" + objectOpacity + ")";
}


window.onload = init;

function init() {
  // needed for the mask
  initDHTMLAPI();
  //pageLevelInit();
}

/* ***********************************************************
Example 4-3 (DHTMLapi.js)
"Dynamic HTML:The Definitive Reference"
2nd Edition
by Danny Goodman
Published by O'Reilly & Associates  ISBN 1-56592-494-0
http://www.oreilly.com
Copyright 2002 Danny Goodman.  All Rights Reserved.
************************************************************ */
// DHTMLapi.js custom API for cross-platform
// object positioning by Danny Goodman (http://www.dannyg.com).
// Release 2.0. Supports NN4, IE, and W3C DOMs.

// Global variables
var isCSS, isW3C, isIE4, isNN4, isIE6CSS, isMac, isIE7,isChrome,isSafari,isIE6;
var pageIsInit = false;
// initialize upon load to let all browsers establish content objects
function initDHTMLAPI() {
    if (document.images) {
        isCSS = (document.body && document.body.style) ? true : false;
        isW3C = (isCSS && document.getElementById) ? true : false;
        isIE4 = (isCSS && document.all) ? true : false;
        isNN4 = (document.layers) ? true : false;
        isIE6CSS = (document.compatMode && document.compatMode.indexOf("CSS1") >= 0) ? true : false;
        isMac = (navigator.userAgent.toLowerCase().indexOf("mac")!=-1) ? true : false;
        var b_version = navigator.appVersion;
		if (b_version.indexOf('MSIE')!=-1 && b_version.indexOf('Opera')==-1) { // test for MSIE but not Opera;
    		var ieversion = b_version.substr(b_version.indexOf('MSIE') + 5, 1); // find MSIE browser version
			isIE6 = (ieversion == 6);
			isIE7 = (ieversion >= 7);
		}		
		isChrome = (navigator.userAgent.toLowerCase().indexOf("chrome")!=-1);
		isSafari = (navigator.userAgent.toLowerCase().indexOf("safari")!=-1);		
    }
//    alert('isCSS = ' + isCSS + '\nisW3C = ' + isW3C + '\nisIE4 = ' + isIE4 + '\nisNN4 = ' + isNN4 + '\nisIE6CSS = ' + isIE6CSS + '\nisMac = ' + isMac + '\nisIE7 = ' + isIE7);
//    alert(navigator.userAgent.toLowerCase());
    pageIsInit = true;
}

// Convert object name string or object reference
// into a valid element object reference
function getRawObject(obj) {
    var theObj;
    if (typeof obj == "string") {
        if (isW3C) {
            theObj = document.getElementById(obj);
        } else if (isIE4) {
            theObj = document.all(obj);
        } else if (isNN4) {
            theObj = seekLayer(document, obj);
        }else{
	     theObj = document.getElementById(obj);
		}
    } else {
        // pass through object reference
        theObj = obj;
    }
    return theObj;
}

// Convert object name string or object reference
// into a valid style (or NN4 layer) reference
function getObject(obj) {
    var theObj = getRawObject(obj);
    if (theObj && isCSS) {
        theObj = theObj.style;
    }
    return theObj;
}

// Retrieve the rendered width of an element
function getObjectWidth(obj)  {
    var elem = getRawObject(obj);
    var result = 0;
    if (elem.offsetWidth) {
        result = elem.offsetWidth;
    } else if (elem.clip && elem.clip.width) {
        result = elem.clip.width;
    } else if (elem.style && elem.style.pixelWidth) {
        result = elem.style.pixelWidth;
    }
    return parseInt(result);
}

// Retrieve the rendered height of an element
function getObjectHeight(obj)  {
    var elem = getRawObject(obj);
    var result = 0;
    if (elem.offsetHeight) {
        result = elem.offsetHeight;
    } else if (elem.clip && elem.clip.height) {
        result = elem.clip.height;
    } else if (elem.style && elem.style.pixelHeight) {
        result = elem.style.pixelHeight;
    }
    return parseInt(result);
}

// Return the available content width space in browser window
function getInsideWindowWidth() {
    if (window.innerWidth) {
        return window.innerWidth;
    } else if (isIE6CSS) {
        // measure the html element's clientWidth
        return document.body.parentElement.clientWidth
    } else if (document.body && document.body.clientWidth) {
        return document.body.clientWidth;
    }
    return 0;
}
// Return the available content height space in browser window
function getInsideWindowHeight() {
    if (window.innerHeight) {
        return window.innerHeight;
    } else if (isIE6CSS) {
        // measure the html element's clientHeight
        return document.body.parentElement.clientHeight
    } else if (document.body && document.body.clientHeight) {
        return document.body.clientHeight;
    }
    return 0;
}

// from quirksmode
// function to find the position of any element
function findPos(obj) {
  var objt = document.getElementById(obj);
	var curleft = curtop = 0;
	if (objt.offsetParent) {
		curleft = objt.offsetLeft;
		curtop = objt.offsetTop;
		while (objt = objt.offsetParent) {
			curleft += objt.offsetLeft;
			curtop += objt.offsetTop;
		}
	}
	return [curleft,curtop];
}

// Move an object by x and/or y pixels
function shiftBy(obj, deltaX, deltaY) {
    var theObj = getObject(obj);
    if (theObj) {
        if (isCSS) {
            // equalize incorrect numeric value type
            var units = (typeof theObj.left == "string") ? "px" : 0 
            theObj.left = getObjectLeft(obj) + deltaX + units;
            theObj.top = getObjectTop(obj) + deltaY + units;
        } else if (isNN4) {
            theObj.moveBy(deltaX, deltaY);
        }
    }
}

// Retrieve the x coordinate of a positionable object
function getObjectLeft(obj)  {
    var elem = getRawObject(obj);
    var result = 0;
    if (document.defaultView) {
        var style = document.defaultView;
        var cssDecl = style.getComputedStyle(elem, "");
        result = cssDecl.getPropertyValue("left");
    } else if (elem.currentStyle) {
        result = elem.currentStyle.left;
    } else if (elem.style) {
        result = elem.style.left;
    } else if (isNN4) {
        result = elem.left;
    }
    return parseInt(result);
}

// Retrieve the y coordinate of a positionable object
function getObjectTop(obj)  {
    var elem = getRawObject(obj);
    var result = 0;
    if (document.defaultView) {
        var style = document.defaultView;
        var cssDecl = style.getComputedStyle(elem, "");
        result = cssDecl.getPropertyValue("top");
    } else if (elem.currentStyle) {
        result = elem.currentStyle.top;
    } else if (elem.style) {
        result = elem.style.top;
    } else if (isNN4) {
        result = elem.top;
    }
    return parseInt(result);
}


var gotoListing = function (link){	
	self.location =  link;
}






