
/**
 * Ads script library
 */
var oneAdLibraryVersion = '1.0.8';

/**
 * Initialization of the ad.
 */
function setOneAdCallbackParameters(params) {

    document.getElementById(params.adId).callbackParams = params;

    if (typeof params == 'undefined') {
        return;
    }
    
    // handle loading of promotion banner
    if (params.type == 'promotion') {
    	if (oneAdIsSet(params.f) && oneAdIsSet(params.e) && oneAdIsSet(promotionCallback)) {
    	    // call external callback function
    		promotionCallback(params.f, params.e);
    	}
        resizeOneAdPromotion(params);
    }
    
    // handle loading of empty banner
    if (params.type == 'empty') {
        oneAdHide(params);
    }
    
    // handle loading of the sliding banner
    else if (params.type == 'sliding') {
        oneAdSlidingBanner.initialize(params);
    }
    // handle loading of the skyscraper banner
    else if (params.type == 'skyscraper') {
        if (adBrowser && adBrowser.op) {

            // deferred invocation of onAdSkyscraperLoaded() method
            // helps to prevent occasional js hangups in Opera 
            // for some reason
            var command = 'var p = new Object();';
            command +='p.adId = "' + params.adId + '";';
            command +='p.campaignId = "' + params.campaignId + '";';
            command +='p.parentPositionId="' + params.parentPositionId + '";';
            command +='p.childPositionIds = "' + params.childPositionIds + '";';
            command +='oneAdSkyscraperLoaded(p);';
            setTimeout(command, 0);
        } else {
            oneAdSkyscraperLoaded(params);
        }
    }
}

/**
 * Ad event handling.
 */
function oneAdHandleEvent(event) {
    try {
    	// alert("oneAdHandleEvent: " + event);
        if (event == null)
            return;

        var srcElement = event.target || event.srcElement;

        if (srcElement.callbackParams == null) {
            return;
        }
        
        if (srcElement.callbackParams.type == 'dropdown') {
            if (event.type == 'mouseover') {
                showOneAdDropdown(srcElement.callbackParams);
            } else if (event.type == 'mouseout') {
                hideOneAdDropdown(srcElement.callbackParams);
            } else {
                alert('unrecognized event type: ' + event.type);
            }
        }

        else if (srcElement.callbackParams.type == 'sliding') {
            if (event.type == 'mouseover') {
                oneAdSlidingBanner.stop(srcElement.callbackParams);
            } else if (event.type == 'mouseout') {
                oneAdSlidingBanner.start(srcElement.callbackParams);
            } else {
                alert('unrecognized event type: ' + event.type);
            }
        }
    } catch (e) {
        alert(e);
    }
}

function setOneAdSize(oneAdId, width, height) {
	document.getElementById(oneAdId).style.width = width + "px";
	document.getElementById(oneAdId).style.height = height + "px";
}

function oneAdIEPageX(obj)
{
    var tmp = obj.offsetLeft;
    while (obj.offsetParent != null)
    {
        obj = obj.offsetParent;
        tmp += obj.offsetLeft;
        if (obj.tagName == 'BODY') break;
    }
    return tmp;
}

function oneAdIEPageY(obj)
{
    var tmp = obj.offsetTop;
    while (obj.offsetParent != null)
    {
        obj = obj.offsetParent;
        tmp += obj.offsetTop;
        if (obj.tagName == 'BODY') break;
    }
    return tmp;
}

function oneAdGetWindowHeight() {
    if (window.innerHeight)
        return window.innerHeight;

    if (document.compatMode == "BackCompat")
        return document.body.clientHeight;

    return document.documentElement.clientHeight;
}

function oneAdGetWindowWidth() {
    // if (window.innerWidth)
    //    return window.innerWidth - 18;

    if (document.compatMode == "BackCompat")
        return document.body.clientWidth;

    return document.documentElement.clientWidth;
}

/**
 * Creates DIV with display:none with the same size and location as given element. 
 */
function createOneAdReplacer(elem) {
    var result = document.createElement('div');
    result.id = elem.id + 'Replacer';
    result.style.width = elem.style.width;
    result.style.height = elem.style.height;
    if (elem.callbackParams.type == 'sliding' && adBrowser && adBrowser.op) {
        result.style.visibility = 'hidden';
    } else {
        result.style.display = 'none';
    }
    elem.parentNode.appendChild(result);
    return result;
}

/**
 * Sets elements zIndex. If zIndex is not null, changes style.position to absolute and
 * sets new left/top values so element would appear in the same place.
 * Also puts dynamically created DIV element of the same size to replace the element
 * (As setting position to absolute changes document's layout otherwise). 
 * When zIndex is null, sets everything back (position to static, left/top to null) 
 * and hides dynamic DIV.
 */
function setOneAdZIndex(oneAdId, zIndex) {
    var elem = document.getElementById(oneAdId);
    if (zIndex != null) {
        var elemReplacer = document.getElementById(oneAdId + 'Replacer');
        if (elemReplacer == null)
            elemReplacer = createOneAdReplacer(elem);

        var left = oneAdIEPageX(elem);
        var top = oneAdIEPageY(elem);
        elem.style.position = 'absolute';
        elem.style.zIndex = zIndex;
        elem.style.left = left + 'px';
        elem.style.top = top + 'px';
        elemReplacer.style.display = 'block';
    } else {
        var elemReplacer = document.getElementById(oneAdId + 'Replacer');
        if (elemReplacer != null) {
            elemReplacer.style.display = 'none';
        }

        elem.style.position = 'static';
        elem.style.zIndex = '0';
        elem.style.left = null;
        elem.style.top = null;
    }
}

function oneAdHide(params) {
    if (typeof params.adId != 'undefined') {
	    document.getElementById(params.adId).style.display = "none";
	    setOneAdSize(params.adId, 0, 0);
	}
}

/**
 * Dropdown Banner
 */
function showOneAdDropdown(params) {
    // dropdown banner is not supported in Opera (because of mouseover event bugs with iframe)
    if (adBrowser && adBrowser.op)
        return;

    setOneAdZIndex(params.adId, 9);
    setOneAdSize(params.adId, params.width, params.expandedHeight);
}

function resizeOneAdPromotion(params) {
    if ((typeof params.adId != 'undefined') &&  (typeof params.width != 'undefined') && (typeof params.height != 'undefined')) {
        var promotionFrame = document.getElementById(params.adId);
        setOneAdSize(params.adId,  params.width,  params.height);
    }	
}

function hideOneAdDropdown(params) {
    // dropdown banner is not supported in Opera (because of mouseover event bugs with iframe)
    if (adBrowser && adBrowser.op)
        return;

    setOneAdSize(params.adId, params.width, params.height);
    setOneAdZIndex(params.adId, null);
}

/**
 * Skyscraper Banner.
 */
function oneAdSkyscraperLoaded(params) {
    var loadedFrame = document.getElementById(params.adId);
//    alert('skyscraper loaded - adId: ' + params.adId + '; iframe: ' + loadedFrame);
    if (oneAdIsSet(loadedFrame.getAttribute('childPositionIds'))) {
        var childFrame = document.getElementById(loadedFrame.getAttribute('childPositionIds'));
        if (oneAdIsSet(childFrame.getAttribute('bannerURL'))) {

            childFrame.src = childFrame.getAttribute('bannerURL') +
                    '&ignoreView=true&campaignId=' + params.campaignId;
        }
    } else if (oneAdIsSet(loadedFrame.getAttribute('parentPositionId'))) {
        var parentFrame = document.getElementById(loadedFrame.getAttribute('parentPositionId'));
        parentFrame.style.display = 'block';
        loadedFrame.style.display = 'block';
    }
}

/**
 * Sliding Banner.
 */
function OneAdSlidingBannerHandler() {

    // one pixel per 50 milliseconds
    //this.speed = 1 / 50;
    this.left = 0;
    this.container = null;
    this.height = null;
    this.width = null;
    this.enabled = true;
    this.rollIntervalId = null;
    this.lastRoll = new Date().getTime();
}

window.oneAdAdjustSlidingBannerPosition = function() {
    oneAdSlidingBanner.adjustPosition();
}

OneAdSlidingBannerHandler.prototype.initialize = function(params) {
    this.height = params.height;
    this.width = params.width;
    var slidingBannerFrame = document.getElementById(params.adId);

    // on browsers other than IE moving of iframe into container element 
    // (using appendChild() method below) triggers invocation of callback mehanism again. 
    // besides that, in Opera current execution thread is terminated immediately after 
    // appendChild() call (who knows why)
    // that's why in non IE browsers initialization is done in two steps: 
    // - at first invocation we wrap iframe within div and return
    // - at second invocation (triggered by first one) we proceed with other tasks 
    if (this.container == null) {

        // step 1
        this.container = createOneAdReplacer(slidingBannerFrame);
        this.container.style.height = this.height + 'px';
        this.container.style.overflow = 'hidden';
        this.container.style.zIndex = 101;

        if (!adBrowser.ie && !adBrowser.op) {
            slidingBannerFrame.src += "&ignoreView=true&campaignId=" + params.campaignId;
        }
        this.container.appendChild(slidingBannerFrame);
        
        if (!adBrowser.ie) {
            return;
        }
    }

    // step 2
    slidingBannerFrame.style.top = 0;
    slidingBannerFrame.style.width = (this.width * 3) + 'px';
    slidingBannerFrame.style.height = '100%';
    slidingBannerFrame.style.position = 'absolute';
    slidingBannerFrame.style.visibility = 'visible';
    this.container.style.visibility = 'visible';
    if (adBrowser && !adBrowser.op) {
        this.container.style.display = 'block';
    }

    if (window.attachEvent) {
        window.attachEvent("onscroll", window.oneAdAdjustSlidingBannerPosition);
        window.attachEvent("onresize", window.oneAdAdjustSlidingBannerPosition);
    } else {
        window.addEventListener("resize", window.oneAdAdjustSlidingBannerPosition, 1);
    }

    this.adjustPosition();
    this.rollIntervalId = setInterval('oneAdSlidingBanner.roll()', 30);
}

OneAdSlidingBannerHandler.prototype.adjustPosition = function() {
    if (document.all) {
        var scrollTop = document.documentElement.scrollTop;
        if (scrollTop == 0 && document.body.scrollTop != 0) {
            scrollTop = document.body.scrollTop;
        }

        this.container.style.top = (scrollTop + oneAdGetWindowHeight() - this.height) + "px";
        this.container.style.position = "absolute";
    } else {
        this.container.style.top = (oneAdGetWindowHeight() - this.height) + "px";
        this.container.style.position = "fixed";
    }

    this.container.style.left = 0;
    this.container.style.width = oneAdGetWindowWidth() + "px";
}

OneAdSlidingBannerHandler.prototype.roll = function() {
    if (!this.enabled)
        return;

    //var currentTime = new Date().getTime();
    //var interval = (currentTime - this.lastRoll);
    //this.lastRoll = currentTime;
    
    // if there was some serious delay, drop the frame
    //if (interval > 150) {
    //    return;
    //}
    
    //this.left -= this.speed * interval;
    this.left -= 1;
    
    while (this.left < -this.width) {
        this.left = new Number(this.left) + new Number(this.width);
    }
    var elementContent = this.container.firstChild;
    elementContent.style.left = Math.round(this.left) + 'px';
}

OneAdSlidingBannerHandler.prototype.stop = function(params) {
    this.enabled = false;
}

OneAdSlidingBannerHandler.prototype.start = function(params) {
    this.enabled = true;
}

var oneAdSlidingBanner = new OneAdSlidingBannerHandler();

/*	BrowserCheck Object
	provides most commonly needed browser checking variables
	19990326
*/
// new browser detection (added by Igor Kapustin) 
// http://www.quirksmode.org/js/detect.html
var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();


// Copyright (C) 1999 Dan Steinman
// Distributed under the terms of the GNU Library General Public License
// Available at http://www.dansteinman.com/dynapi/

function BrowserCheck() {
	var b = navigator.appName
	if (b=="Netscape") this.b = "ns"
	else if (b=="Microsoft Internet Explorer") this.b = "ie"
	else if (b=="Opera") this.b = "op"
	else this.b = b
	//new check
	if (BrowserDetect.browser=="Netscape") this.b = "ns"
	else if (BrowserDetect.browser=="Explorer") this.b = "ie"
	else if (BrowserDetect.browser=="Opera") this.b = "op"
	else this.b = b
	
	this.v = parseInt(navigator.appVersion)
	this.ns = (this.b=="ns" && this.v>=4)
	this.ns4 = (this.b=="ns" && this.v==4)
	this.ns5 = (this.b=="ns" && this.v==5)
	this.ie = (this.b=="ie" && this.v>=4)
	this.op = (this.b=="op" && this.v>=7)
	this.ie4 = (navigator.userAgent.indexOf('MSIE 4')>0)
	this.ie5 = (navigator.userAgent.indexOf('MSIE 5')>0)
	this.ie55 = (navigator.userAgent.indexOf('MSIE 5.5')>0)
	if (this.ie55) {
		this.v = 5.5;
		this.ie5 = false;
	}
	this.mac = (navigator.userAgent.indexOf('Mac')>0);
	if (this.ie5) this.v = 5
	this.min = (this.ns||this.ie)
}

// automatically create the "is" object with browser checking parameters
var adBrowser = new BrowserCheck();

function oneAdIsSet(variable) {
    return typeof variable != 'undefined' && variable != null && variable != '' && variable != 'null';
}

/**
 * Ad position script
 */
var oneAdDefaultRendererPath = 'http://ad.one.lv/render';

function oneAdWritePosition(rendererPath, adId, width, 
        height, site, position, parentPositionId, childPositionIds, nature, type,
        language, callbackURL, tracking, className, hoverStyleName, campaignId, customParameters) {

    // capture site's style for text ads
    var output=document;
    var textStyle = null;
    if ((className != null && className != '') || 
            (hoverStyleName != null && hoverStyleName != '')) {
        textStyle = oneAdExposeTextStyle(adId, className, hoverStyleName);
    }
    
    // check adId
    if (!oneAdIsSet(adId)) {
        if (oneAdIsSet(position)) {
            // replace all dots with underscore
            adId = position.replace(/\./g, '_');
        } else {
            adId = 'oneAd' + new Date().getTime();
        }
    }
    
    // construct referrer from host
    var adHref = document.location.href;
    var adHost = "http://";
    var adDomain = "localhost";
    if (adHref.indexOf("//") != -1) {
        adHost = adHref.split("//")[0];
        adDomain = adHref.split("//")[1];
        adDomain = adDomain.split("/")[0];
    }
    if (!oneAdIsSet(callbackURL)) {
        callbackURL = '';
    } else if (callbackURL.indexOf('http://') != 0) {
        if (callbackURL.indexOf('/') != 0) {
           callbackURL = '/' + callbackURL;
        }
        callbackURL = adHost + "//" + adDomain + callbackURL;
    }
    
    // build rendererPath
    if (oneAdIsSet(rendererPath)) {
        rendererPath = rendererPath + '/render';
    } else {
        rendererPath = oneAdDefaultRendererPath;
    }
    rendererPath += '?adId=';
    rendererPath += adId;

    if (oneAdIsSet(language)) {
        rendererPath += '&language=';
        rendererPath += language;
    }
    if (oneAdIsSet(nature)) {
        rendererPath += '&nature=';
        rendererPath += nature;
    }
    if (oneAdIsSet(position)) {
        rendererPath += '&pos=';
        rendererPath += position;
    }
    if (oneAdIsSet(site)) {
        rendererPath += '&site=';
        rendererPath += site;
    }
    if (oneAdIsSet(type)) {
        rendererPath += '&type=';
        rendererPath += type;
    }
    if (oneAdIsSet(tracking)) {
        rendererPath += '&tracking=';
        rendererPath += tracking;
    }
    if (oneAdIsSet(campaignId)) {
        rendererPath += '&campaignId=';
        rendererPath += campaignId;
    }    
    rendererPath += '&referrer=';
    rendererPath += callbackURL;

    if (oneAdIsSet(customParameters)) {
        rendererPath += customParameters;
    }

    if (textStyle != null) {
        if (oneAdIsSet(textStyle.color)) {
            rendererPath += '&textColor=';
            rendererPath += textStyle.color;
        }
        if (oneAdIsSet(textStyle.fontFamily)) {
            rendererPath += '&textFontFamily=';
            rendererPath += textStyle.fontFamily.replace(/\"/g, "");
        }
        if (oneAdIsSet(textStyle.fontWeight)) {
            rendererPath += '&textFontWeight=';
            rendererPath += textStyle.fontWeight;
        }
        if (oneAdIsSet(textStyle.fontSize)) {
            rendererPath += '&textFontSize=';
            rendererPath += textStyle.fontSize;
        }
        if (oneAdIsSet(textStyle.hoverStyle)) {
            rendererPath += '&textHoverStyle=';
            rendererPath += textStyle.hoverStyle;
        }
    }
    
    // check on browser here
    if (adBrowser && adBrowser.ie) {
        // Internet Explorer
        var container = document.all[document.all.length - 1].parentNode;
        var iFrame = document.createElement('IFRAME');
        iFrame.id = adId;
        iFrame.name = adId;
        if (oneAdIsSet(width)) {
            iFrame.style.width = width;
        } else if (typeof container.width != 'undefined') {
            iFrame.style.width = container.width;
        } else {
            iFrame.style.width = 0;
        }
        if (oneAdIsSet(height)) {
            iFrame.style.height = height;
        } else if (typeof container.height != 'undefined') {
            iFrame.style.height = container.height;
        } else {
            iFrame.style.height = 0;
        }

        if (oneAdIsSet(parentPositionId)) {
            iFrame.src = 'about:blank';
            iFrame.setAttribute('bannerURL', rendererPath);
            iFrame.setAttribute('parentPositionId', parentPositionId);
            iFrame.style.display = 'none';
        } else {
            iFrame.src = rendererPath;
        }

        if (oneAdIsSet(childPositionIds)) {
            iFrame.setAttribute('childPositionIds', childPositionIds);
            iFrame.style.display = 'none';
        }

        iFrame.attachEvent('onmouseover', oneAdHandleEvent);
        iFrame.attachEvent('onmouseout', oneAdHandleEvent);
        iFrame.frameBorder = 0;
        iFrame.marginWidth = 0;
        iFrame.marginHeight = 0;
        iFrame.vspace = 0;
        iFrame.hspace = 0;
        iFrame.allowTransparency = true;
        iFrame.scrolling = 'no';
        iFrame.border = 0;
        container.appendChild(iFrame);
    } else {
        // FireFox, Netscape
        output.write('<iframe id="');
        output.write(adId);
        output.write('" name="');
        output.write(adId);
        output.write('" frameborder="0" ');

        var displayNone = false;
        if (oneAdIsSet(parentPositionId)) {
            output.write('src="about:blank" ');
            output.write('bannerURL="');
            output.write(rendererPath);
            output.write('" ');
            output.write('parentPositionId="');
            output.write(parentPositionId);
            output.write('" ');
            displayNone = true;
        } else {
            output.write('src="');
            output.write(rendererPath);
            output.write('" ');
        }

        if (oneAdIsSet(childPositionIds)) {
            output.write('childPositionIds="');
            output.write(childPositionIds);
            output.write('" ');
            displayNone = true;
        }

        output.write('style="width: ');
        if (oneAdIsSet(width)) {
            output.write(width);
            output.write('px');
        } else {
            output.write('0');
        }
        output.write('; height: ');
        if (oneAdIsSet(height)) {
            output.write(height);
            output.write('px');
        } else {
            output.write('0');
        }
        if (displayNone) {
            output.write('; display:none');
        }
        output.write('" ');
        output.write('onmouseover="oneAdHandleEvent(event)" onmouseout="oneAdHandleEvent(event)" ');
        output.write('marginwidth="0" marginheight="0" vspace="0" hspace="0" allowtransparency="100%" scrolling="no" border="0">');
        output.write('</iframe>');
        
        var el = document.getElementById(adId);
        if (oneAdIsSet(childPositionIds)) {
            el.setAttribute('childPositionIds', childPositionIds);
        }

        if (oneAdIsSet(parentPositionId)) {
            el.setAttribute('parentPositionId', parentPositionId);
            el.setAttribute('bannerURL', rendererPath);
        }
        
        // if dimensions are not specified, try to determine them from container
        if (!oneAdIsSet(width) || !oneAdIsSet(height)) {
            var f = document.getElementById(adId);
            if (typeof f != 'undefined') {
                if (!oneAdIsSet(width) && typeof f.parentNode.style.width != 'undefined') {
                    f.style.width = f.parentNode.style.width;
                }
                if (!oneAdIsSet(height) && typeof f.parentNode.style.height != 'undefined') {
                    f.style.height = f.parentNode.style.height;
                }
            }
        }
    }
}

function oneAdExposeTextStyle(adId, className, hoverStyleName) {
    if (!oneAdIsSet(className)) {
        return null;
    }
    
    var exposeElement = document.createElement('A');
    exposeElement.id = 'exposeStyle' + adId;
    exposeElement.setAttribute('class', className);
    exposeElement.setAttribute('className', className);
    exposeElement.setAttribute('alt', '');
    exposeElement.setAttribute('href', 'about:blank');
    document.body.appendChild(exposeElement);

    var textStyle = new Object();
    if (adBrowser && adBrowser.ie && exposeElement.currentStyle) {
        textStyle.fontWeight = exposeElement.currentStyle['fontWeight'];
        textStyle.fontSize = exposeElement.currentStyle['fontSize'];
        textStyle.fontFamily = exposeElement.currentStyle['fontFamily'];
        textStyle.color = exposeElement.currentStyle['color'];

        try {
            if (hoverStyleName != null && !hoverStyleName == '') {
                var selector=hoverStyleName;
                var rgs=new RegExp('\\s*'+selector+"\\s*","g");
                var css=document.styleSheets;
                var hoverRules;
                for (var k = 0; k < css.length; k++) {
                    var rules=document.styleSheets[k].rules;
                    for (var i = 0; i < rules.length; i++) {
                        if (rgs.test(rules[i].selectorText.toLowerCase())) {
                            textStyle.hoverStyle = rules[i].style.cssText;
                        }
                    }
                }
            }
        } catch (e) {
            // ignore silently
            //alert(e.description);
        }
    } else if (window.getComputedStyle) {

        // in Opera wait while CSS is loaded (which is done asynchronously by other thread) 
        if (adBrowser && adBrowser.op && document.styleSheets.length > 0) {
            var t = new Date().getTime();
            for (;;) {
                if (document.styleSheets[document.styleSheets.length - 1].cssRules.length > 0) {
                    break;
                }
                if (new Date().getTime() - t > 10000) {
                    break;
                }
            }
        }

        var computedStyle = document.defaultView.getComputedStyle(exposeElement,null);
        textStyle.fontWeight = computedStyle.getPropertyValue('font-weight');
        textStyle.fontSize = computedStyle.getPropertyValue('font-size');
        textStyle.fontFamily = computedStyle.getPropertyValue('font-family');
        if (adBrowser && adBrowser.op) {
            textStyle.fontFamily = textStyle.fontFamily.replace(/\"/g, "%22");
        }
        textStyle.color = computedStyle.getPropertyValue('color').replace(/ /gi , "");

        try {        
            if (hoverStyleName != null && !hoverStyleName == '') {
                var selector=hoverStyleName;
                var rgs=new RegExp('\\s*'+selector+"\\s*","g");
                var css=document.styleSheets;
                var hoverRules;
                for (var k = 0; k < css.length; k++) {
                    var rules = document.styleSheets[k].cssRules;
                    for (var i = 0; i < rules.length; i++) {
                        if (rgs.test(rules[i].selectorText.toLowerCase())) {
                            textStyle.hoverStyle = rules[i].style.cssText;
                        }
                    }
                }
            }
        } catch (e) {
            // ignore silently
            //alert(e.description);
        }
    }
    
    document.body.removeChild(exposeElement);
    return textStyle;
}

