var ESCAPED = 1;
var UNESCAPED = 2;

var aggregators = new Array( 
	"AmphetaDesk", "http://127.0.0.1:8888/index.html?add_url=", ESCAPED,
	"Awasu", "http://127.0.0.1:2604/subscribe?url=", ESCAPED,
	"Bloglines", "http://www.bloglines.com/sub/", UNESCAPED,
	"Bot A Blog", "http://www.botablog.com/botthisblog.php?blog=", ESCAPED,
	"BottomFeeder", "http://127.0.0.1:8666/btf?rss=", ESCAPED,
	"FeedDemon", "feed:", UNESCAPED,
	"Google Homepage", "http://fusion.google.com/add?feedurl=", UNESCAPED,
	"Headline Viewer", "http://127.0.0.1:8900/add_provider?url=", ESCAPED,
	"MobileRSS", "http://www.mobilerss.net/fastfeed.php?url=", ESCAPED,
	"My Yahoo!", "http://add.my.yahoo.com/rss?url=", ESCAPED,
	"NetNewsWire", "feed:", UNESCAPED,
	"NewsGator", "http://services.newsgator.com/subscriber/subext.aspx?url=", ESCAPED,
	"NewsMonster", "newsmonster-subscription:", UNESCAPED,
	"NewzCrawler", "feed:", UNESCAPED,
	"nntp//rss", "http://127.0.0.1:7810/?action=addform&URL=", ESCAPED,
	"Python Desktop", "http://127.0.0.1:4334/aggregator/add_redir?url=", ESCAPED,
	"Radio UserLand", "http://127.0.0.1:5335/system/pages/subscriptions?url=", ESCAPED,
	"RSS Bandit", "feed:", UNESCAPED,
	"SharpReader", "http://127.0.0.1:5335/system/pages/subscriptions?url=", ESCAPED,
	"Shrook", "feed:", UNESCAPED,
	"Vox Lite", "feed:", UNESCAPED,
	"Wildgrape", "http://127.0.0.1:8888/NewsDesk.html?add_url=", ESCAPED,
	"WINKsite", "http://winksite.com/site/quick_add_logon_form.cfm?partner_name=&feed_url=", ESCAPED,
	"WinRSS", "rss://addrss/", ESCAPED
);

// Internal vars
var q_frame = self;
var over = null;
var oTimer;

// Determine browser type
var ns4 = (navigator.appName == 'Netscape' && parseInt(navigator.appVersion) == 4);
var ns6 = (document.getElementById)? true:false;
var ie4 = (document.all)? true:false;
if (ie4) {
	var docRoot = 'document.body';
}

if (ie4) {
	if ((navigator.userAgent.indexOf('MSIE 5') > 0) || (navigator.userAgent.indexOf('MSIE 6') > 0)) {
		if(document.compatMode && document.compatMode == 'CSS1Compat') {
			docRoot = 'document.documentElement';
		}
	}
	if (ns6) {
		ns6 = false;
	}
}

// quicksub(url)
// Loads parameters into global runtime variables.
function quicksub(oLink, originalUrl) {

	if (oTimer) {
		clearTimeout(oTimer);
	}

	var url = escape(originalUrl);

	var text = '';
	for(var iCount = 0; iCount < aggregators.length; iCount +=3) {
		text += ('<a target=\'_blank\' title=\'To subscribe to this Journal, select here if you use ' + aggregators[iCount] + '\' class=\'small\' href=\''
			+ aggregators[iCount + 1] 
			+ (aggregators[iCount + 2] == ESCAPED ? url : originalUrl)
			+ '\'>'
			+ aggregators[iCount]
			+ '</a><br><img src=\'img/spacer.gif\' height=4 width=1 border=0><br>');
	}

	if ( (ie4) || (ns6) ) {
		q_frame = self;
		if (ie4) over = q_frame.quickSub.style
		if (ns6) over = q_frame.document.getElementById("quickSub");
	}
	
	if(!ns4) {
		var layerhtml = '' + '<div class=\'qscontent\'><b>Which Feed Reader?</b><hr>' + text + '</div>';
		
		layerWrite(layerhtml);
		placeLayer(oLink);
		showObject(over);
	}	
	return true;
}

function closeqs() {
	if (over != null) hideObject(over);
	return true;
}

function placeLayer(oLink) {
	var placeX, placeY, iOffset, aPosition;
	
	aPosition = findPosition(oLink);
	placeX = eval(aPosition[0]) -124;
	placeY = eval(aPosition[1]) + 16;

	if ( (ie4) ) {
		over.left = (ie4 ? placeX + 'px' : placeX);
		over.top = (ie4 ? placeY + 'px' : placeY);
	} else if (ns6) {
		over.style.left = placeX + "px";
		over.style.top = placeY + "px";
	}
}

function layerWrite(txt) {
	if (ie4) {
		q_frame.document.all["quickSub"].innerHTML = txt
	} else if (ns6) {
		range = q_frame.document.createRange();
		range.setStartBefore(over);
		domfrag = range.createContextualFragment(txt);
		while (over.hasChildNodes()) {
			over.removeChild(over.lastChild);
		}
		over.appendChild(domfrag);
	}
}

function showObject(obj) {
	if (ie4) obj.visibility = "visible";
	else if (ns6) obj.style.visibility = "visible";
}

function hideObject(obj) {
	if (ie4) obj.visibility = "hidden";
	else if (ns6) obj.style.visibility = "hidden";
}

function findPosition (oLink) {
	if (oLink.offsetParent) {
		for (var iPosX = 0, iPosY = 0; oLink.offsetParent; oLink = oLink.offsetParent) {
			iPosX += oLink.offsetLeft;
			iPosY += oLink.offsetTop;
		}
		return [iPosX, iPosY];
	} else {
		return [oLink.x, oLink.y];
	}
}

function timeqs () {
	if(!ns4) {
		var iDelay = 500;

		if (oTimer) {
			clearTimeout(oTimer);
		}

		if ((ie4 && over.visibility != 'hidden') ||
			(ns6 && over.style.visibility != 'hidden')) {
			oTimer = setTimeout(hideqs, iDelay);
		}
	}
}

function hideqs () {
	if (oTimer) {
		clearTimeout(oTimer);
	}

	closeqs();
}

function delayqs () {
	if (oTimer) {
		clearTimeout(oTimer);
	}
}
