function BrowserCheck() {
	var b = navigator.appName
	if (b=="Netscape") this.b = "ns"
	else if (b=="Microsoft Internet Explorer") this.b = "ie"
	else this.b = b
	this.v = parseInt(navigator.appVersion)
	this.ns = (this.b=="ns" && this.v>=4)
	this.ns4 = (this.b=="ns" && this.v==4)
	this.ns5 = (this.b=="ns" && this.v==5)
	this.ie = (this.b=="ie" && this.v>=4)
	this.ie4 = (navigator.userAgent.indexOf('MSIE 4')>0)
	this.ie5 = (navigator.userAgent.indexOf('MSIE 5')>0)
	if (this.ie5) this.v = 5
	this.min = (this.ns||this.ie)
}

// automatically create the "is" object
is = new BrowserCheck();

function getexpirydate( nodays){
	var UTCstring;
	Today = new Date();
	nomilli=Date.parse(Today);
	Today.setTime(nomilli+nodays*24*60*60*1000);
	UTCstring = Today.toUTCString();
	return UTCstring;
}

function setcookie(name,value,duration){
	cookiestring=name+"="+escape(value)+";EXPIRES="+getexpirydate(duration);
	document.cookie=cookiestring;
}

function getcookie(cookiename) {
	var cookiestring=""+document.cookie;
	var index1=cookiestring.indexOf(cookiename);
	if (index1==-1 || cookiename=="") return ""; 
	var index2=cookiestring.indexOf(';',index1);
	if (index2==-1) index2=cookiestring.length; 
	return unescape(cookiestring.substring(index1+cookiename.length+1,index2));
}


var allClippings = new Array();
var clpArray = new Array();

var global_Id;
var global_Topic;

var state = "visible";

function loadclpArray()
	{
	 if (getcookie("clippings") != "") {
		clpArray = getcookie("clippings").split(";");
	 } else { clpArray = new Array(); }
	}

function createallClippingsArray()
	{
		var i = 0;
		d = document.getElementsByTagName("DIV")
		for (j=0; j < d.length; j++) if (d[j].id.indexOf("clp") > -1) 
			{
			allClippings[allClippings.length] = document.getElementById(d[j].id);
			}
		//for (j=0; j < allClippings.length; j++) {
		//	alert(allClippings[j].id);
		//}
	 }

function clippingsVisibility()
	{
		//loadclpArray();
		for (i = 0; i < allClippings.length; i++) {
			var vis = "visible";
			for (x = 0; x < clpArray.length - 1; x++) {
				if (clpArray[x] == allClippings[i].id) {
					vis = "hidden";
					break;
				} 
			}
			obj = document.getElementById(allClippings[i].id);
			obj.style.visibility = vis;
			obj.onclick = addClipping;
		}
	}

function addClipping(e)
	{
	tempCookie = "";
	obj = document.getElementById(this.id);
	obj.style.visibility = "hidden";
	tempCookie = getcookie("clippings")+this.id+";";
	setcookie("clippings", tempCookie, 30);
	loadclpArray();
	drawClippings();

	originX = (is.ns)? e.pageX : event.x+document.body.scrollLeft;
	originY = (is.ns)? e.pageY : event.y+document.body.scrollTop;

	//event.cancleBubble = true;
	clearInterval(clipTimer);
	clipTimer = setInterval("animateSprite()",10);
	}

function clearAllClippings()
	{
		setcookie("clippings", "", "");
		loadclpArray();
		clippingsVisibility();
		drawClippings();
	}

function clearClipping(newsid)
	{
	tempCookie = "";
		for (i=0; i < clpArray.length - 1; i++)	{
			if (clpArray[i] != newsid) {
				tempCookie += clpArray[i]+";";
			}
		}
		if (tempCookie != "") { time = 30; } else { time = ""; }
		setcookie("clippings", tempCookie, time);
		loadclpArray();
		clippingsVisibility();
		drawClippings();
	}

function drawClippings()
	{
		//loadclpArray();
		newHTML = "";
		newHTML += "<table width=100%>";
		if (clpArray.length < 1) {
			newHTML += "<tr><td class=clippings>";
			newHTML += "There are currently no Clippings saved.  To add a Clipping, click on the Clipping icon: ";
			newHTML += "<img src='images/clipping.gif'><br><br>";
			newHTML += "You can access your Clippings through this menu.";
			newHTML += "</td></tr>";
		} else {
			for (i = 0; i < clpArray.length - 1; i++) {
				getIdTopic(clpArray[i]);
				newHTML += "<tr onMouseOver=\"this.style.background='#ffffff'\"; onMouseOut=\"this.style.background='0'\";>";
				newHTML += "<td width=13 valign=\"top\"><a href='javascript:clearClipping(\"clp"+global_Id+"-"+global_Topic+"\")' onmouseover=\"window.status = \'Remove Clipping\'; return true\"><img border=0 src='images/remclipping.gif' alt=\"Remove Clipping\"></a></td>";
				newHTML += "<td onMouseOver=\"this.style.cursor='pointer'\"; onClick=\"window.location.href='?go=viewnews&newsid="+global_Id+"'\";><a class='clippings' href='?go=viewnews&newsid="+global_Id+"'>"+global_Topic+"</a></td></tr>";
			}
		}
		newHTML += "</table>";
		writit(newHTML, "clippingsContainer");
	}

function getIdTopic(string) 
	{
		tA = string.split("-");
		global_Id = tA[0].substring(3, tA[0].length);
		global_Topic = tA[1];
	}
	

function writit(text,id)
{
	if (document.getElementById)
	{
		x = document.getElementById(id);
		x.innerHTML = text;
	}
	else if (document.all)
	{
		x = document.all[id];
		x.innerHTML = text;
	}
	else if (document.layers)
	{
		x = document.layers[id];
		text2 = '<P CLASS="clippings">' + text + '</P>';
		x.document.open();
		x.document.write(text2);
		x.document.close();
	}
}

function showclippingsTable() {
	if (state == "hidden") state = "visible"
	else state = "hidden";
	obj = document.getElementById("clippingsTable");
	obj.style.visibility = state;
}


// Animation parameters
originX = 0;
originY = 0;
endX = 725;
endY = 51;
currentX = 0;
currentY = 0;
clipAnim = 0;
clipTimer = false;
if (document.all) classFix = "className"
else classFix = "class";

function createSprites() {
	for (x=0; x < 4; x++) {
	if (document.getElementById("sprite") == null) {
		sprite = document.createElement("img");
		sprite.src = "images/sprite.gif";
		sprite.setAttribute(classFix,"sprite");
		sprite.setAttribute("id","sprite"+x)
		parentObj = document.getElementById("viewClippings");
		parentObj.appendChild(sprite);

	}
	}
}

function animateSprite() {
	if (clipAnim < 5) {
		for(x = 0; x < 4; x++) {
			obj = document.getElementById("sprite"+x);
			obj.style.visibility = "visible";
			sX  = originX+(clipAnim*((endX-originX)/(7-x)));
			sY  = originY+(clipAnim*((endY-originY)/(7-x)));
			obj.style.left = sX;
			obj.style.top = sY;
		}
		clipAnim++;
	} else {
		for(x = 0; x < 4; x++) {
			obj = document.getElementById("sprite"+x);
			obj.style.visibility = "hidden";
		}
		clipAnim = 0;
		clearInterval(clipTimer);
	}
}

function windowscroll() {
	alert("SCROLLLLLIN");
}

function initClippings()
	{
		createallClippingsArray();
		loadclpArray();
		clippingsVisibility();
		drawClippings();
		createSprites();
		showclippingsTable();

		obj = document.getElementById("viewClippings");
		obj.onclick = showclippingsTable;

		if (is.ns) document.captureEvents(Event.MOUSEDOWN);

		//window.onscroll = windowscroll;
	}