/*creates the div*/

function t(e, id) {
	var posx = 0;
	var posy = 0;
	if (!e) var e = window.event;
	if (e.pageX || e.pageY) 	{
		posx = e.pageX;
		posy = e.pageY;
	}
	else if (e.clientX || e.clientY) 	{
		posx = e.clientX + document.body.scrollLeft
			+ document.documentElement.scrollLeft;
		posy = e.clientY + document.body.scrollTop
			+ document.documentElement.scrollTop;
	}

	//alert('hello');

	// posx and posy contain the mouse position relative to the document
	// Do something with this information

	var isLeft;
	var top;
	var left;
	var isIE = $.browser.msie;

	var offsetY = 20; /*originally 23 */
	var bottomRow = 0;

	//var text = $(id).attr("ntitle");
	//var image = $(id).attr("image");
	
	var text = id.getElementsByTagName('a')[0].getAttribute('ndesc');
	if ((text == "") || (text == " ") || (text == "   ") || (text == "     "))
	{	text = "No description available.";
	}
	else if (text.length < 10)
	{	text = "No description available.";
	}
	
	//find the first period
	/*var period = text.indexOf(".");
	if (period > 20)
	{	//look for next period
		var period2 = text.indexOf(".", period + 1);
		if (period2 != -1 && period2 <= 195 && period2 > 0)
		{	text = text.substring(0,period2);
		}
		else{
			text = text.substring(0,period);
		}
	}*/

	//truncate
	text = text.replace(/Reuters - /gi, "");
	text = text.replace(/AP - /gi, "");
	text = text.replace(/(Reuters) - /gi, "");
	text = text.replace(/(AP) - /gi, "");
	text = text.replace(/• /gi,"");
	text = text.replace(/•/gi,"");
	text = text.replace(/<br>/gi, "");

	if (text.length > 197)
	{	text = text.substring(0,197) + "...";
	}
	//text = us.karnivoro.stripHTML(id.getElementsByTagName('a')[0].getAttribute('ndesc'));
	//var image = id.getElementsByTagName('a')[0].getAttribute('nimage');
	/*if (!image)
	{	document.getElementById('popup').innerHTML = "<div class='desc'>" + text + "</div>";
		$('div.desc').css({"width" : "317px"});
	}
	else{
		document.getElementById('popup').innerHTML = "<div class='desc'>" + text + "</div><div class='imageThumb'>" + image + "</div>";
		$('div.desc').css({"width" : "240px"});
	}*/
	document.getElementById('popup').innerHTML = "<div class='desc'>" + text + "</div>";
	/*if (!text)
	{	
	}*/
	//$(id).parent().children('.headline').addClass('lightGray');
	//$(id).removeClass('lightGray');

	
	//alert(text);
	//$('body').append("<div class='popup'>" + text + "</div>");
	
	if (posx < $(window).width()/2)
	{	isLeft = true;
	}
	else{
		isLeft = false;
	}

	//$('#siteUpdate').html(posy);
	var extra = 0;
	var extra2 = 0;
	var extra3 = 0;

	if (isIE)
	{	extra = -9;
		extra2 = -8;
		extra3 = -15;
	}

	if (posy >= 145 + extra && posy <= 166 + extra)
	{	top = 145 + extra;
	}
	else if (posy >= 168 + extra && posy <= 189 + extra)
	{	top = 168 + extra;
	}
	else if (posy >= 191  + extra && posy <= 212 + extra)
	{	top = 191 + extra;
	}
	else if (posy >= 214 + extra && posy <= 235 + extra)
	{	top = 214 + extra;
	}
	else if (posy >= 237 + extra && posy <= 258 + extra)
	{	top = 237 + extra;
	}

	else if (posy >= 352 + extra + extra2 && posy <= 374 + extra + extra2)
	{	top = 353 + extra + extra2;
	}
	else if (posy >= 376 + extra + extra2 && posy <= 397 + extra + extra2)
	{	top = 376 + extra + extra2;
	}
	else if (posy >= 399 + extra + extra2 && posy <= 420 + extra + extra2)
	{	top = 399 + extra + extra2;
	}
	else if (posy >= 422 + extra + extra2 && posy <= 443 + extra + extra2)
	{	top = 422 + extra + extra2;
	}
	else if (posy >= 445 + extra + extra2 && posy <= 466 + extra + extra2)
	{	top = 445 + extra + extra2;
	}

	else if (posy >= 559 + extra + extra3 && posy <= 581 + extra + extra3)
	{	top = 559 + extra + extra3 - bottomRow;
	}
	else if (posy >= 583 + extra + extra3 && posy <= 604 + extra + extra3)
	{	top = 583 + extra + extra3 - bottomRow;
	}
	else if (posy >= 606 + extra + extra3 && posy <= 627 + extra + extra3)
	{	top = 606 + extra + extra3 - bottomRow;
	}
	else if (posy >= 629 + extra + extra3 && posy <= 650 + extra + extra3)
	{	top = 629 + extra + extra3 - bottomRow;
	}
	else if (posy >= 652 + extra + extra3 && posy <= 673 + extra + extra3)
	{	top = 652+ extra + extra3 - bottomRow;
	}
	
	top = top + offsetY;

	if (isLeft)
	{	left = $(window).width()/2 - 353;
	}
	else{
		left = $(window).width()/2 + 133;
	}

	//need to determine where to put the popup

	//top=top+"px";
	//left=left+"px";
	

	
		//$('div.popup').css("top",top + "px").css("left",left + "px");

	if (isIE)
	{	try
		{
			document.getElementById('popup').style.top = top;
			document.getElementById('popup').style.left = left;
		}
		catch (g)
		{
		}
		
	}
	else{
		try
		{
			document.getElementById('popup').style.top = top + "px";
			document.getElementById('popup').style.left = left + "px";
		}
		catch (h)
		{
		}
		
	}
	//$.expose.close(); 
	/*$('div.popup').expose({ 
	 
		// use a custom background color 
		color: '#000000', 
		 
		// when exposing is done change form's background color 
		onLoad: function() { 
			this.getExposed().css({backgroundColor: '#c7f8ff'});
			document.getElementById('popup').style.display = "block";
		}
	});*/
	document.getElementById('popup').style.display = "block";
	//$('div.popup').fadeIn('fast');
	

	//$('div.popup').show();	
	
	
	//alert(text);
}

/*removes the div*/
function r(){
	//$('div.popup').hide();
	document.getElementById('popup').style.display = "none";
	//$('div.headline').removeClass('lightGray');
	//$(this).parent().children('.headline').removeClass('lightGray');
	//$.expose.close(); 
	//$('div.popup').remove();
}

function imageCompress(){
	for (i=0; i < 6 ;i++ ){
		var width = document.getElementById('top' + i).getElementsByTagName('img')[0].getAttribute('width');
		var height = document.getElementById('top' + i).getElementsByTagName('img')[0].getAttribute('height');

		//alert(width + ' width, ' + height + ' height');
		//first determine which is longer, height or width
		if (height <= width && height >= 80)
		{	//this is a wide image, must scale according to height
			var ratio = height/80;
			height = 80;
			width = width/ratio;
			//assign the new attributes
			document.getElementById('img' + i).getElementsByTagName('img')[0].setAttribute('width', width);
			document.getElementById('img' + i).getElementsByTagName('img')[0].setAttribute('height', height);
		}
		else if (height > width && width >= 80)
		{	var ratio = width/80;
			width = 80;
			height = height/ratio;
			//assign the new attributes
			document.getElementById('img' + i).getElementsByTagName('img')[0].setAttribute('width', width);
			document.getElementById('img' + i).getElementsByTagName('img')[0].setAttribute('height', height);
		}
		if (height < 80 || width < 80)
		{	//then we have a really tiny photo, lets just use stock
			document.getElementById('img' + i).getElementsByTagName('img')[0].setAttribute('src', 'images/camera.png');
			document.getElementById('img' + i).getElementsByTagName('img')[0].setAttribute('width', '80');
			document.getElementById('img' + i).getElementsByTagName('img')[0].setAttribute('height', '80');
		}
		//document.getElementById('img' + i).getElementsByTagName('div')[0].innerHTML = "<img src='images/camera.png' height='80' width='80' border='0' />";
	}


	$('div.imgLoading').hide();
	$('div.imgContainer').hide().fadeIn('fast');

	/*if (height < 80)
	{	//check to see if the width is more than 80
		if (width < 80)
		{	//then we have a really tiny photo, lets just use stock
			document.getElementById('etImg').getElementsByTagName('img')[0].setAttribute('src', 'images/camera.png');
			document.getElementById('etImg').getElementsByTagName('img')[0].setAttribute('width', '80');
			document.getElementById('etImg').getElementsByTagName('img')[0].setAttribute('height', '80');
		}
		else if (width >= 80)
		{	//change the width of the outer element
			//$('div.imgBorder').css({'height' : height});
			document.getElementById('etImg').setAttribute('style', 'height:' + height + 'px');
			//document.getElementById('etImg').setAttribute('style', 'height:' + height + 'px;');
			//document.getElementById('etImg').getElementsByTagName('div')[0].setAttribute('style', 'height:' + (height-2) + 'px;');
		}
		
	}*/

}