var cookiearray=new Array();

function readClipCookie(name)
{
	var nameEQ=name+"=";
	var ca=document.cookie.split(';');
	for (var i=0;i<ca.length;i++)
	{
		var c=ca[i];
		while (c.charAt(0)==' ') c=c.substring(1,c.length);
		if (c.indexOf(nameEQ)==0) return c.substring(nameEQ.length,c.length);
	}
	return '';
}
function init()
{
	activateAjax();
	if (window==window.top)
		getClips();
}
function addClip(a,url)
{
	add=1;
	for (i=cookiearray.length-1;i>=0;i--)
		if (cookiearray[i]==escape(url)+"^"+escape(a.title))
		{
			for (j=i;j<cookiearray.length-1;j++)
				cookiearray[j]=cookiearray[j+1];
			cookiearray.pop();
			add=0;
		}
	if (add==1)
	{
		cookiearray.push(escape(url)+"^"+escape(a.title));
		a.childNodes[0].src="/images2/clippered.png";
	}
	else
		a.childNodes[0].src="/images2/clipping.png";
	var newcookie=cookiearray.join("|");
	var date=new Date();
	date.setTime(date.getTime()+(8*60*60*1000));
	document.cookie="clips="+newcookie+"; expires="+date.toGMTString()+"; path=/;";
	getClips();
        return false;
}
function getClips()
{
	cookiestring=readClipCookie('clips');
	newcount=0;
	if (cookiestring!='')
	{
		cookiearray=cookiestring.split("|");
		newcount=cookiearray.length;
	}
	var clipcount=document.getElementById("clipcount");
	clipcount.innerHTML="Custom Clipper: <a href='http://www.azstarnet.com/clipper/' target='_new'>"+newcount+" clippings</a>";
	var next1=document.getElementById("nextclip");
	if (next1)
	{
		next="";
		for (i=0;i<cookiearray.length;i++)
		{
			els=cookiearray[i].split("^");
			if (unescape(els[0])==window.location)
			{
				el=(i+1)%cookiearray.length;
				els2=cookiearray[el].split("^");
				next="<a href='"+unescape(els2[0])+"'>Next Clip</a>";
			}
		}
		next1.innerHTML=next;
		next2=document.getElementById("nextclip2");
		next2.innerHTML=next;
	}
}
function clipper()
{
	cl=document.getElementById("clippings");
	if (cl.style.display=="block")
	{
		cl.style.display="none";
		return false;
	}
	if (cookiearray.length==0) return false;
	html="";
	for (i=0;i<cookiearray.length;i++)
	{
		els=cookiearray[i].split("^");
		html+="<a href='"+unescape(els[0])+"'>"+unescape(els[1])+"</a>";
	}
	cl.innerHTML=html;

	var x=0,y=0;
	obj=document.getElementById("clipcount");
	y=obj.scrollHeight;
	while (obj.offsetParent)
	{
		x+=parseInt(obj.offsetLeft);
		y+=parseInt(obj.offsetTop);
		obj=obj.offsetParent;
	}
	x-=50;
	cl.style.left=x+"px";
	cl.style.top=y+"px";
	cl.style.display="block";
	return false;
}

