var eImpression_Height = 0;
var eImpression_Width = 0;
var eImpression_Filename = '';
var eImpression_CookieCount = 1;
var eImpression_CookieDays = 1;
var eImpression_MaxWidth = 0;
var eImpression_FadeOut = 'false';
var eImpression_Buffer = 15;
var eImpression_LinkTo = '';
var eImpression_LinkTarget = '_self';
// var eImpression_HostURL = 'videos/';
var eImpression_HostURL = 'http://eimpressionhosting.com/flv/';
var eImpression_BrandLinkID = 1;

var eImpression_Path = 'http://eimpression.myrealtytools.com/';
var eImpression_IsIE = (navigator.appName == 'Microsoft Internet Explorer');
var eImpression_IsVisible = true;
var eImpression_IsSafari = (navigator.appVersion.indexOf('Safari') > -1)

function eImpression_GetLocation(){
  return window.location.href;
}
function eImpression_DetectFFIFrame() {
    if (navigator.userAgent.indexOf("Firefox") > 0) {
        if (document.getElementsByTagName("iframe")) {
            if (document.getElementsByTagName("iframe").length > 0) { return true; }
        }
    }
    return false;
}
function eImpression_DetectFlash() {
    // init
	var bExists = false;
	var plugin;
	var iVersion = 0;
	// does the plugin exist?
	if (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"] ) {
	    // it does exist
		bExists = true;
		// get the version
		plugin = navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin
		if (plugin) { iVersion = parseInt(plugin.description.substring(plugin.description.indexOf(".")-1)) }
		if (iVersion == 0) {
			if (plugin.description.indexOf(' 10.') > -1) {
				iVersion = 10;
			} else {
				if (plugin.description.indexOf(' 11.') > -1) {
					iVersion = 11;
				}
			}
		}
	}
	// return the results
	if (bExists) {
		if (iVersion >= 8) {
			return true;
		} else {
			return false;
		}
	} else {
		return false;
	}
}
function eImpression_GetCookieData(strName) {
    // init
    var arrCookies = document.cookie.split(';')
    var arrCookie = null;
    var strCookieName = '';
    // are there any cookies?
    if (arrCookies.length < 1) { return ''; }
    // loop through each cookie
    for (var intIndex = 0; intIndex < arrCookies.length; intIndex++) {
        // get the cookie parts
        arrCookie = arrCookies[intIndex].split('=');
        // is this valid?
        if (arrCookie.length > 1) {
            // get the cookie name
            strCookieName = arrCookie[0];
            // is this the name we're looking for?
            if ((strCookieName == strName) || (' ' + strCookieName == strName)) { return arrCookie[1]; }
        }
    }
    // not found
    return '';
}
function eImpression_CheckCookies() {
    // init
    var blnShowVideo = false; // don't show video by default
    // should we even bother?
    if (eImpression_CookieCount < 2) { return true };
    // get the existing count
    var intExistingCount = eImpression_GetCookieData('count');
    if (intExistingCount == '') {
        // default
        intExistingCount = 1;
    } else {
        // increment the count
        intExistingCount = parseInt(intExistingCount);
        intExistingCount++;
    }
    // should we reset the count?
    if (intExistingCount > eImpression_CookieCount) { intExistingCount = 1; }
    // should we show the video?
    if (intExistingCount == 1) { blnShowVideo = true; }
    // set the cookie expiration date
    if (eImpression_CookieDays < 1) { eImpression_CookieDays = 0; }
    var intMsPerDay = 24 * 60 * 60 * 1000;
    var dtExpiration = new Date();
    dtExpiration.setTime(dtExpiration.getTime() + (eImpression_CookieDays * intMsPerDay));
    // save the cookie
    // document.cookie = “cookieName=cookieData[; expires=timeInGMTString][; path=pathName][; domain=domainName][; secure]”
    document.cookie = 'count=' + intExistingCount + '; expires=' + dtExpiration.toGMTString();
    // return the result
    return blnShowVideo;
}
function eImpression_ShowVideo() {
    // init
    var strHtml = '';
    eImpression_Filename = eImpression_Filename + '_' + eImpression_Width + 'x' + eImpression_Height;
    // check the cookie
    if (eImpression_CheckCookies()) {
        // is the correct version of flash installed?
        var blnOk = false;
        if (eImpression_IsIE) {
	        blnOk = eImpression_DetectFlash_IE()
        } else {
	        blnOk = eImpression_DetectFlash();
        }
        if (blnOk) {            
            // create the flash object
            var strMovie = eImpression_Path + 'mrtvideo.swf?path_str=' + escape(eImpression_HostURL) + '&fname=' + escape(eImpression_Filename) + '&h=' + eImpression_Height + '&w=' + eImpression_Width + '&fade=' + eImpression_FadeOut + '&buff=' + eImpression_Buffer + '&linkTo=' + escape(eImpression_LinkTo) + '&linkTarget=' + eImpression_LinkTarget + '&brandLinkID=' + eImpression_BrandLinkID;
// temp *****
// alert(strMovie)
// temp *****
			document.write('<div id="eImpression_span" style="z-index: 10000; position: absolute; width: ' + eImpression_Width + 'px; height: ' + eImpression_Height + 'px; top: 0px; left: 0px;">');
            document.write('<obje');
		    document.write('ct classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" ');
		    document.write('codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" ');
		    document.write('width="100%" ');
		    document.write('height="100%" ');
		    document.write('id="mrtvideo" ');
		    document.write('align="middle">');
		    document.write('<param name="allowScriptAccess" value="sameDomain" />');
		    document.write('<param name="allowFullScreen" value="false" />');
		    document.write('<param name="movie" value="' + strMovie + '" />');
		    document.write('<param name="loop" value="false" />');
		    document.write('<param name="menu" value="false" />');
		    document.write('<param name="quality" value="high" />');
			document.write('<param name="wmode" value="transparent" />');
		    document.write('<emb');
		    document.write('ed src="' + strMovie + '" ');
		    document.write('loop="false" ');
		    document.write('menu="false" ');
		    document.write('quality="high" ');
		    document.write('width="100%" ');
		    document.write('height="100%" ');
		    document.write('name="mrtvideo" ');
		    document.write('align="middle" ');
		    document.write('allowScriptAccess="sameDomain" ');
		    document.write('allowFullScreen="false" ');
		    document.write('type="application/x-shockwave-flash" ');
			if (!eImpression_DetectFFIFrame()) { document.write('wmode="transparent" '); }
		    document.write('pluginspage="http://www.macromedia.com/go/getflashplayer" />');
		    document.write('</obje');
		    document.write('ct>');
			document.write('</div>');
        } else {
            // create the message
            document.write('<div id="eImpression_span" style="background-image: url(' + eImpression_Filename + '.gif); z-index: 10000; position: absolute; width: ' + eImpression_Width + 'px; height: ' + eImpression_Height + 'px; top: 0px; left: 0px;">');
            document.write('<table border="0" cellpadding="0" cellspacing="0" width="100%" height="100%">');
            document.write('<tr><td valign="bottom">');
            document.write('<div style="background-color: gainsboro; font-family: verdana; font-size: 12px; border: outset 1px; padding: 5px 5px 5px 5px;">');
            document.write('<div style="text-align: right;"><a href="JavaScript: eImpression_Done();"><img alt="Close" title="Close" src="http://eImpression.myrealtytools.com/x.gif" border="0" /></a></div>');
            document.write('This site contains a personal video message from me. ');
            document.write('To view the video, you will need Macromedia (Adobe) Flash version 8 or higher.<br />&nbsp;');
            document.write('<center><a target="_blank" href="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash&promoid=BIOW"><img src="http://eImpression.myrealtytools.com/get_flash_player.gif" border="0" /></a></center>');
            document.write('</div>');
            document.write('</td></tr>');
            document.write('</table>');
            document.write('</div>');
        }
        // place the video
        setTimeout('eImpression_Place()', 10, 'javascript');
    }
}
function eImpression_Place() {
    // is the video still visible?
    if (eImpression_IsVisible) {
        // init
        var objVideo = document.getElementById('eImpression_span');
        var intX;
        // Because of the vagaries of different browsers supporting different methods of obtaining the info,
        // we have changed the way the video is placed.  We do not test for browsers now, we test for capabilities
        intX = eImpression_GetClientWidth() + eImpression_GetScrollLeft() - eImpression_Width;
        // is the video too far to the right?
        if (eImpression_MaxWidth > 0) {
            if ((intX + eImpression_Width) > eImpression_MaxWidth) { intX = eImpression_MaxWidth - eImpression_Width; }
        }
        objVideo.style.top = eImpression_GetClientHeight() + eImpression_GetScrollTop() - eImpression_Height + 'px';
        objVideo.style.left = intX + 'px';
        /*        
        intX = window.document.body.clientWidth + window.document.body.scrollLeft - eImpression_Width
        // is the video too far to the right?
        if (eImpression_MaxWidth > 0) {
        if ((intX + eImpression_Width) > eImpression_MaxWidth) { intX = eImpression_MaxWidth - eImpression_Width; }
        }
        if (navigator.userAgent.indexOf("Firefox") > 0) { intX = intX - 5; }
        // set the top/left of the video
        if (navigator.userAgent.indexOf("Firefox") > 0) {
        objVideo.style.top = (window.document.body.clientHeight + window.document.body.scrollTop - eImpression_Height - 0) + 'px';
        } else if (eImpression_IsIE){
        objVideo.style.top = (window.document.body.clientHeight + window.document.body.scrollTop - eImpression_Height) + 'px';
        } else if (eImpression_IsSafari) {
        objVideo.style.top = (window.innerHeight+document.body.scrollTop - eImpression_Height) + 'px';
        }else{
        // try something, what the heck
        objVideo.style.top = (window.document.body.clientHeight + window.document.body.scrollTop - eImpression_Height) + 'px';
        }

        objVideo.style.left = intX + 'px';
        */

        // call this again
        setTimeout('eImpression_Place()', 100, 'JavaScript');
    }
}
function eImpression_Done() {
    // hide the video
    var objVideo = document.getElementById('eImpression_span');
    objVideo.style.display = 'none';
    eImpression_IsVisible = false;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function eImpression_GetClientWidth(){
  return eImpression_FilterResults(
    window.innerWidth ? window.innerWidth : 0,
    document.documentElement ? document.documentElement.clientWidth : 0,
    document.body ? document.body.clientWidth : 0
  );
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function eImpression_GetClientHeight(){
  return eImpression_FilterResults(
    window.innerHeight ? window.innerHeight : 0,
    document.documentElement ? document.documentElement.clientHeight : 0,
    document.body ? document.body.clientHeight : 0
  );
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function eImpression_GetScrollLeft(){
  return eImpression_FilterResults(
    window.pageXOffset ? window.pageXOffset : 0,
    document.documentElement ? document.documentElement.scrollLeft : 0,
    document.body ? document.body.scrollLeft : 0
  );
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function eImpression_GetScrollTop(){
  return eImpression_FilterResults(
    window.pageYOffset ? window.pageYOffset : 0,
    document.documentElement ? document.documentElement.scrollTop : 0,
    document.body ? document.body.scrollTop : 0
  );

}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function eImpression_FilterResults(win_num, docEl_num, body_num){
  var result_num = win_num ? win_num : 0;
  if( docEl_num && (!result_num || (result_num > docEl_num))) result_num = docEl_num;
  result_num = body_num && (!result_num || (result_num > body_num)) ? body_num : result_num;
  return result_num;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////