﻿	pic1= new Image(297,215); 
	pic1.src="/images/tipbg.png"; 
	pic2= new Image(12,12); 
	pic2.src="/images/infoicon.gif";
	boxhide_delay = 3000;
		
function gid(id){
	var d=document
	if(d.getElementById){return d.getElementById(id);}
	else if(d.all){return d.all[id];}
	else if(d.layers){return d.layers[id];}
	return null;
}

function cl( s, n ) {
		if( s.length >=n ) return s.substr(0,n-5) + '&hellip;';
		else return s;
}

function GetWindowSize() {
	var x = 0, y = 0;
	if (self.innerHeight) x = self.innerWidth;
	else if (document.documentElement && document.documentElement.clientHeight)
		x = document.documentElement.clientWidth;
	else if (document.body)	x = document.body.clientWidth;

    if (self.innerHeight) y = self.innerHeight;
	else if (document.documentElement && document.documentElement.clientHeight)
		y = document.documentElement.clientHeight;
	else if (document.body)	y = document.body.clientHeight;
    return [x,y];
}

	winddim = GetWindowSize();
	winW = winddim[0];	winH = winddim[1];

	function productInTag( tag, prodnum ) {
		var ret = false;
		if( tag_products[ tag ] ) {
			for( i=0; i<tag_products[ tag ].length; i++ ) {
				if( tag_products[ tag ][i] == prodnum ) {
					ret = true; break;
				}
			}
		}
		return ret;
	}
	
	function parseRelevantData( kw ) {
		p2parse = 10;
		proddescr = []; prodimages = [];
		prodlinks = []; articles = [];
		notusedprods = [];
		if( gid( 'rel_products' )) {
			ccc = 0;
			for( ts=0; ts < p2parse; ts++ ) {
				if( productInTag( kw, ts ) && ccc < 2 ) {
					proddescr.push( gid('descr_'+ts ).innerHTML );
					prodimages.push( gid('repl_image_'+ts ).src );
					prodlinks.push( [ gid('link_'+ts).href, gid('link_'+ts).innerHTML ] );
					ccc++;
				} else {
					if( gid( 'descr_'+ts )) notusedprods.push( ts );
				}
			}
 			if( prodlinks.length == 1 ) {
				rndp = Math.floor(Math.random()* (notusedprods.length) );
				goodtoadd = true;
				descri = gid('descr_'+rndp ).innerHTML;
				for( jj in proddescr ) {
					if( proddescr[jj] == descri ) goodtoadd = false;
				}
				if( goodtoadd ) {
					prodimages.push( gid('repl_image_'+rndp ).src );
					prodlinks.push( [ gid('link_'+rndp).href, gid('link_'+rndp).innerHTML ] );
					proddescr.push( descri );
				}
			}
		}
		if( gid( 'rel_articles' )) {
			el = gid( 'rel_articles' ).getElementsByTagName('ul')[0].getElementsByTagName('LI');
			for( i=0; i<el.length; i++ ) {
				lnk = el[i].getElementsByTagName('A')[0];
				if( articles.length < 2 )
					articles.push( [lnk.href, lnk.innerHTML ] );
			}
		}
		c = '<table>';
		for( i=0; i<prodlinks.length; i++ ) {
			len = 145 - prodlinks[i][1].length;
			olink = "<a style='white-space:auto' href='"+prodlinks[i][0]+"'>";
			c += "<tr><td>"+olink+"<img src='"+ prodimages[i] +"' /></a></td>";
			c += "<td>" + olink +'<strong>'+ prodlinks[i][1] + "</strong></a> ";
			c += "<small>"+ cl( proddescr[i], len )+"</small></td></tr>";
		}
		c += '</table><hr /><ul>';
		for( j=0; j<articles.length; j++ ) {
			c += "<li><a href='"+articles[j][0]+"'>" + cl( articles[j][1], 95 )+ "</a></li>";
		}
		return c + "</ul>";
	}
	
/* 	for( el in gid('entry').childNodes) {
		nd = gid('entry').childNodes[el]; 
		if( nd.nodeName == 'P' ) {
			curlinks = nd.getElementsByTagName("A");
			for( j=0;j<curlinks.length; j++ ) {
				if( curlinks[j].href != '' ) PrepareLink( curlinks[j] );
			}
		}
	} */

	
	
	
	function showTip( el ) {
//		if( gid('tipcontent').style.display != 'block' ) {
			dat = parseRelevantData( el.innerHTML );
			gid('tipkeyword').innerHTML = cl( el.innerHTML, 33 );
			gid( 'tiptext' ).innerHTML = dat;
//		}
		if( -1==dat.indexOf( '<a' )) {
			TipVisible( false );
			return false;
		}
		tpos = CalcTipPosition( findPos( el ) ); 
		TipPosition( tpos );
		TipVisible( true );
		el.onmousemove = function(){ClearHideInterval()};
		el.onmouseout = function(){tbtimeout = setTimeout( 'TipVisible(false)', boxhide_delay )};
	}

	function findPos(obj) {
		var curleft = curtop = 0;
		if (obj.offsetParent) {
			curleft = obj.offsetLeft
			curtop = obj.offsetTop
			while (obj = obj.offsetParent) {
				curleft += obj.offsetLeft
				curtop += obj.offsetTop
			}
		}
		return [curleft,curtop];
	}
	
	function CalcTipPosition( posxy ) {
		posxy[0] -= 20;
		if( posxy[0]+300 > winW ) posxy[0] -= 250;
		if( posxy[1]+200 > winH ) posxy[1] -= 233;
		return posxy;
	}
	function TipVisible( ifshow ) {
		el = gid( 'tipcontent' );
		if( ifshow ) {
			if( el.style.display = 'block' )
				el.style.display = 'none';
			opacity( 'tipcontent', 0, 100, 300 );		
			setTimeout( "el.style.display = 'block'", 20 );
			ClearHideInterval();
			tbtimeout = setTimeout( 'TipVisible(false)', boxhide_delay+2000 );
		} else {
			setTimeout( "el.style.display = 'none'", 280 );
			opacity( 'tipcontent', 100, 0, 250 )
		}
		clearTimeout( tbtimeout );
	}
	function TipPosition( posxy ) {
		gid( 'tipcontent' ).style.left = posxy[0]+'px';
		gid( 'tipcontent' ).style.top = posxy[1]+'px';
	}
		
	function opacity(id, opacStart, opacEnd, millisec) {
	    //speed for each frame
	    var speed = Math.round(millisec / 100);
	    var timer = 0;

	    //determine the direction for the blending, if start and end are the same nothing happens
	    if(opacStart > opacEnd) {
	        for(i = opacStart; i >= opacEnd; i--) {
	            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
	            timer++;
	        }
	    } else if(opacStart < opacEnd) {
	        for(i = opacStart; i <= opacEnd; i++)
	            {
	            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
	            timer++;
	        }
	    }
	}

//change the opacity for different browsers
	function changeOpac(opacity, id) {
	    var object = document.getElementById(id).style;
	    object.opacity = (opacity / 100);
	    object.MozOpacity = (opacity / 100);
	    object.KhtmlOpacity = (opacity / 100);
	    object.filter = "alpha(opacity=" + opacity + ")";
	} 
	
		function PrepareLink( lnk ) {
		lnk.onmouseover=function() { showTip( this ); }
		lnk.style.borderBottom ='3px double #0066a7';
		lnk.style.background = "url(/images/infoicon.gif) no-repeat right center";
		lnk.style.paddingRight = "15px";
		lnk.style.textDecoration = 'none';
	}

	function ClearHideInterval() {
		if( typeof( tbtimeout )!= 'undefined')
			clearTimeout( tbtimeout );
	}
			
