//this script is called from a javascriptlet

function elementExists(id)
{
	if (document.getElementById(id) != null) {
	return true;
	} 
	else {
	return false;
	}
}


function LoadLinkHarvesterScript (cat)
{

//creates an inline frame in the body of the page that loads a python script link_harvester_get_links.py that scrapes the current page for links, inserts them into the harvesting database, and then displays a message
//window.location.href='http://zzask.com/lh/harvest_links.py?url='+window.location.href + '&cat=' + cat;
//window.location.href='http://google.com?url='+window.location.href + '&cat=' + cat;

var lhscript='http://zzask.com/lh/link_harvester_get_links.py?url='+window.location.href + '&cat=' + cat;
//var lhscript='http://zzask.com/lh/test.php?url='+window.location.href + '&cat=' + cat;
var thisBody=document.body.innerHTML;
/*
var tj_iframe="<div class='test2' id='tj_div_iframe' name='tj_div_iframe' align='center' ><div id='tj2' style='position: absolute; z-index: 99;'><iframe style=\"position: absolute; z-index: 99; background-image: url('http://www.zzask.com/images/1px_white.gif'); \" id='tj_ifrm' name='tj_ifrm' src='" + lhscript + "' scrolling='no'   height='50' frameborder='0'> </iframe></div></div><p><br><br><br><br><a href=\"javascript:opacity('tj_ifrm', 100, 0, 500)\">Hide</a></p>";
*/

var tj_iframe="<div id='tj3' style=\"text-align: center; position: relative; z-index: 99;  \" ><iframe id='tj_ifrm' name='tj_ifrm'  src='" + lhscript + "' scrolling='no'  height='100' frameborder='0'> </iframe></div>";

//style=\"position: absolute; z-index: 99; background-image: url('http://www.zzask.com/images/1px_white.gif'); \"

if (!elementExists ('tj_ifrm'))
{
document.body.innerHTML=tj_iframe + thisBody;
}
/*
works in both browsers:
// this is the scriptlet bookmark that will set the category, and insert this javascipt into the current document. this javascript then creates an inline frame in the body of the document that loads a python script that scrapes the current page for links, inserts them into the harvesting database, and then displays a message.
javascript:var tj_cat='travel'; var script = document.createElement('script');script.src = 'http://zzask.com/lh/lh.js';document.body.appendChild(script);void(0);
*/

//first make an ajax call, then show the message
if (!elementExists ('tj_message'))

{
//document.body.innerHTML="<div id='tj_message' align='center' style='background:blue;color:white'><p><br><br>added links for " + cat + " </p><br><br></div>" + document.body.innerHTML;
//	var thisBody=document.body.innerHTML;
//document.write("<div style='position:absolute;top:300px;left:438px;'><p>hello</p></div>");
//document.write(thisBody);	
}


	}




LoadLinkHarvesterScript(tj_cat);

opacity ('tj_ifrm',350,0,1000);

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 + ")";
}

	