
dw_TooltiP.writeStyleRule = function() {
    if ( document.createElement && document.getElementsByTagName &&
        ( document.addEventListener || document.attachEvent ) ) {
        document.write('<style type="text/css" media="screen">.tipContent { display:none; }</style>');
    }
}


addLoadEvent( dw_TooltiP.init );
addLoadEvent( dw_TooltiP.initHandlers );


function dw_initShowTip() {} 


function dw_TooltiPRequest() {}



dw_TooltiP.positionWindowCenter = function() {
    var x = Math.round( (dw_Viewport.width - dw_TooltiP.tip.offsetWidth)/2 ) + dw_Viewport.scrollX;
    var y = Math.round( (dw_Viewport.height - dw_TooltiP.tip.offsetHeight)/2 ) + dw_Viewport.scrollY;
    dw_TooltiP.setPosition(x,y);
}


dw_TooltiP.wrapSticky = function(str, title) {
    title = title || '';
    var src = dw_TooltiP.defaultProps['closeBoxImage'];
    var msg = '<table id="stickyTable" border="0" cellpadding="0" cellspacing="0" width="100%"><tr class="stickyBar">' + 
        '<td><div class="stickyTitle">' + title + '</div></td>' + 
        '<td style="text-align:right"><a href="javascript: void dw_TooltiP.hide()">' + 
        '<img style="float:right" src="' + src + '" border="0" /></a></td></tr>' + 
        '<tr><td colspan="2"><div class="stickyContent">' + str + '</div></td></tr></table>';
    return msg;
}


dw_TooltiP.wrapToWidth = function(obj) {
    if (!obj) return ''; var str = obj['str']; 
    var caption = obj['caption'] || '';
    if ( this.sticky && this.defaultProps['showCloseBox'] ) {
        str = dw_TooltiP.wrapSticky(str, caption );
    } else {
        if (caption) { str = '<div class="caption">' + obj['caption']  + '</div>' + str; }
    }
    if ( obj['w'] ) this.setTipWidth( obj['w'] );
    return str;
}

// w, h in obj are width and height of image
dw_TooltiP.wrapImageToWidth = function(obj) {
    if (!obj) return ''; dw_getImage( obj['img'] );
    var caption = obj['caption'] || ''; var w = obj['w'];
    var str = '<img src="' + obj['img'] + '" width="' +w + '" height="' + obj['h'] + '" alt="">';
    if ( this.sticky && this.defaultProps['showCloseBox'] ) {
        str = dw_TooltiP.wrapSticky(str, caption );
        w += 8; 
    } else {
        if (caption) { str = '<div class="caption">' + obj['caption']  + '</div>' + str; }
    }
    if (w) this.setTipWidth(w);
    return str;
}


dw_TooltiP.wrapTextByImage = function(obj) {
    if (!obj) return ''; dw_getImage( obj['img'] );
    var caption = obj['caption'] || '';
  	var str='<table cellpadding="0" cellspacing="0" border="0"><tr>'+'<td class="txt"><img src="'+obj['img']+'" width="160" height="187" align="left" class="img"/>'+obj['txt']+'</td></tr></table>';

    
    if ( this.sticky && this.defaultProps['showCloseBox'] ) {
        str = dw_TooltiP.wrapSticky(str, caption );
    } else {
        if (caption) { str = '<div class="caption">' + obj['caption']  + '</div>' + str; }
    }
    if ( obj['w'] ) this.setTipWidth( obj['w'] );
    return str;
}

dw_TooltiP.wrapImageOverText = function(obj) {
    if (!obj) return ''; dw_getImage( obj['img'] );
    var caption = obj['caption'] || '';
    var str = '<div class="img"><img src="' + obj['img'] + '" /></div><div class="txt">' + obj['txt'] + '</div>';
    if ( this.sticky && this.defaultProps['showCloseBox'] ) {
        str = dw_TooltiP.wrapSticky(str, caption );
    } else {
        if (caption) { str = '<div class="caption">' + obj['caption']  + '</div>' + str; }
    }
    if ( obj['w'] ) this.setTipWidth( obj['w'] );
    return str;
}

dw_TooltiP.wrapTextOverImage = function(obj) {
    if (!obj) return ''; dw_getImage( obj['img'] );
    var caption = obj['caption'] || '';
    var str = '<div class="txt">' + obj['txt'] + '</div><div class="img"><img src="' + obj['img'] + '" /></div>';
    if ( this.sticky && this.defaultProps['showCloseBox'] ) {
        str = dw_TooltiP.wrapSticky(str, caption );
    } else {
        if (caption) { str = '<div class="caption">' + obj['caption']  + '</div>' + str; }
    }
    if ( obj['w'] ) this.setTipWidth( obj['w'] );
    return str;
}

dw_TooltiP.setTipWidth = function(w) {
    w += dw_backCompatWidth( this.tip ); 
    this.tip.style.width = w + "px";
}


function dw_getImage(src) {
    var img = new Image();
    img.src = src;
}

function dw_backCompatWidth(el) {
    var val = 0;
    if ( el.currentStyle && !window.opera && (document.compatMode == null || document.compatMode == "BackCompat") ) {
        var p = parseInt( dw_getCurrentStyle(el, 'paddingLeft') ) + parseInt( dw_getCurrentStyle(el, 'paddingRight') );
        var b = parseInt( dw_getCurrentStyle(el, 'borderLeftWidth') ) + parseInt( dw_getCurrentStyle(el, 'borderRightWidth') )
        val = p + b;
    }
    return val;
}

function dw_getCurrentStyle(el, prop) {
    var val = '';
    if (document.defaultView && document.defaultView.getComputedStyle) {
        val = document.defaultView.getComputedStyle(el, null)[prop];
    } else if (el.currentStyle) {
        val = el.currentStyle[prop];
         if ( !/^\d+(px)?$/i.test(val) && /^\d/.test(val) ) {
				var style = el.style.left;
				var runtimeStyle = el.runtimeStyle.left;
				el.runtimeStyle.left = el.currentStyle.left;
				el.style.left = val || 0;
				val = el.style.pixelLeft + "px";
				el.style.left = style;
				el.runtimeStyle.left = runtimeStyle;
			}
    }
    return val;
}

