//
// (c) 2008 primeadd.net
// Service Widget
//
document.write('<style type="text/css">' +
 '#f_896732626_primadd { padding: 0px; margin: 0px; list-style-type: none; }' +
 '#f_896732626_primadd_icons { padding: 0px; margin: 0px; float:left;}' +
 '#f_896732626_primadd_menu { position: absolute; background-color: white; border:1px solid black; font: normal 13px Verdana; z-index: 100; visibility: hidden; padding-bottom: 10px;}' +
 '#f_896732626_primadd_menu ul { list-style-type: none; padding: 0px; margin: 0px; overflow: hidden;}' +
 '#f_896732626_primadd_menu li { padding: 4px; float: left; width: 160px; display: block;}' +
 '#f_896732626_primadd_menu li .tmp { margin-right: 4px; margin-top: 2px; background: url("/icon/services.png") no-repeat; width: 16px; height: 16px; line-height: 16px; display: block; float: left;}' +
 '#f_896732626_primadd_menu li .tmp2 { width: 144px; padding-left: 4px; float: left; line-height: 20px;}' +
 '#f_896732626_primadd_menu li a { font-size: 12px; display: block; text-decoration: none; }' +
 '#f_896732626_primadd_menu li a:hover { background-color: #ffaaaa;}' +
 '#f_896732626_primadd div { width: 16px; height: 16px; background: url("//primadd.net/icon/services.png") no-repeat; padding-right: 10px; }' +
 '#f_896732626_primadd img { border:none; }' +
 '</style>');

document.write('<ul id="f_896732626_primadd"><li id="f_896732626_primadd_icons"></li><li><a href="#" onMouseover="f_896732626_primadd_showmenu(event)" onMouseout="f_896732626_primadd_hidemenu()">PrimAdd</a></li></ul>');

var f_896732626_defaultMenuWidth="336px" //set default menu width.

window.setTimeout("f_896732626_primadd_animImg()", 0);
var f_896732626_primadd_imgCnt = 0;

function f_896732626_primadd_animImg()
{

	if (f_896732626_primadd_imgCnt >= f_896732626_list.length)
		f_896732626_primadd_imgCnt = 0;
		
	document.getElementById('f_896732626_primadd_icons').innerHTML = '<div style="background-position: 0px -'+(f_896732626_list[f_896732626_primadd_imgCnt][2]*16)+'px;">&nbsp;</div>'

	f_896732626_primadd_imgCnt++;
	window.setTimeout("f_896732626_primadd_animImg()", 1000);
}
var f_896732626_list=new Array(
new Array('whatsthis', 'whatsthis', 0, 'http://en.wikipedia.com/', "what's this?"),
new Array('google_bookmarks', 'Google Bookmarks', 3, 'http://www.google.com/', ""),
new Array('delicious', 'del.icio.us', 4, 'http://del.icio.us/', ""),
new Array('slashdot', 'slashdot', 5, 'http://slashdot.org/', ""),
new Array('reddit', 'reddit', 7, 'http://reddit.com/', ""),
new Array('technorati', 'Technorati', 8, 'http://technorati.com/', ""),
new Array('facebook', 'Facebook', 9, 'http://www.facebook.com/', ""),
new Array('mister_wong', 'Mister Wong', 15, 'http://www.mister-wong.de/', ""),
new Array('digg', 'digg', 21, 'http://digg.com/', ""),
new Array('magnolia', 'ma.gnolia', 31, 'http://ma.gnolia.com/', ""),
new Array('more', 'more', 1, 'http://primadd.net/', "for more services"));
function f_896732626_gotoService(service)
{
	subUrl = '//primadd.net/services/' + service + '/';
	if (service == 'more') subUrl = '//primadd.net/bookmark/submit/'
	url = subUrl + '?title='+encodeURIComponent(document.title)+'&url='+encodeURIComponent(window.location.href);
	window.open(url);
  
	if(typeof 'f_896732626_hidemenu' == 'function')
	{
		f_896732626_hidemenu();
	}
}
var ie5 = document.all && !window.opera;
var ns6 = document.getElementById;

if (ie5 || ns6)
{
  document.write('<span id="f_896732626_primadd_menu" onMouseover="f_896732626_clearhidemenu();" onMouseout="f_896732626_dynamichide(event)"></span>');
}

function f_896732626_addLinks()
{
	var ret = '<ul>';
	for (var i = 0; i < f_896732626_list.length; i++)
	{
		var service = f_896732626_list[i][0];
		var offset_y = f_896732626_list[i][2];
		var currentUrl = escape(window.location.href);
		var currentTitle = escape(document.title);
		ret += '<li><a class="tmp2" href="/services/' + service + '/?title=' + currentTitle + '&url=' + currentUrl +'">' + 
		'<div class="tmp" style="background-position: 0px -'+(offset_y*16)+'px;" href="//primadd.net/services/' + service + '/?title=' + currentTitle + '&url=' + currentUrl +'"></div><span>' + f_896732626_list[i][1] + '</span></a></li>';
	}
	return ret + '</ul>';
}

function iecompattest()
{
  return (document.compatMode && document.compatMode.indexOf('CSS') != -1) ? document.documentElement : document.body;
}

function f_896732626_primadd_showmenu(e, optWidth)
{
	if (!document.all&&!document.getElementById)
	{
		// no dom model
		return;
	}
	
	f_896732626_clearhidemenu();
	
	menuobj = ie5 ? document.all.primadd_menu : document.getElementById('f_896732626_primadd_menu');
	menuobj.innerHTML     = 'Add Article to' + f_896732626_addLinks();
	menuobj.style.width   = (typeof optWidth != 'undefined') ? optWidth : f_896732626_defaultMenuWidth;
	menuobj.contentwidth  = menuobj.offsetWidth;
	menuobj.contentheight = menuobj.offsetHeight;
	var eventX = ie5 ? event.clientX : e.clientX;
	var eventY = ie5 ? event.clientY : e.clientY;

	//Find out how close the mouse is to the corner of the window
	var rightedge  = ie5 ? iecompattest().clientWidth  - eventX : window.innerWidth  - eventX;
	var bottomedge = ie5 ? iecompattest().clientHeight - eventY : window.innerHeight - eventY;
	
	//if the horizontal distance isn't enough to accomodate the width of the context menu
	if (rightedge < menuobj.contentwidth)
	{
	  //move the horizontal position of the menu to the left by it's width
		menuobj.style.left = ie5 ? iecompattest().scrollLeft + eventX - menuobj.contentwidth + 'px'
		  : window.pageXOffset + eventX-menuobj.contentwidth + 'px';
	}
	else
	{
		//position the horizontal position of the menu where the mouse was clicked
		menuobj.style.left = ie5 ? iecompattest().scrollLeft + eventX + 'px' : window.pageXOffset + eventX + 'px';
	}
	
	//same concept with the vertical position
  if (bottomedge<menuobj.contentheight)
  {
    menuobj.style.top = ie5 ? iecompattest().scrollTop + eventY - menuobj.contentheight + 'px'
       : window.pageYOffset + eventY - menuobj.contentheight + 'px';
  }
  else
  {
    menuobj.style.top = ie5 ? iecompattest().scrollTop + event.clientY + 'px'
       : window.pageYOffset + eventY + 'px';
  }
  menuobj.style.visibility = 'visible';
  return false;
}

function f_896732626_contains_ns6(a, b)
{
  // Determines if 1 element in contained in another
  while (b.parentNode)
  {
    if ((b = b.parentNode) == a)
    {
      return true;
    }
  }
  return false;
}

function f_896732626_hidemenu()
{
  if (window.menuobj)
  {
    menuobj.style.visibility = 'hidden';
  }
}

function f_896732626_dynamichide(e)
{
  if (ie5 && !menuobj.contains(e.toElement))
  {
    f_896732626_hidemenu();
  }
  else if (ns6 && e.currentTarget != e.relatedTarget && !f_896732626_contains_ns6(e.currentTarget, e.relatedTarget))
  {
    f_896732626_hidemenu();
  }
}

function f_896732626_primadd_hidemenu()
{
  f_896732626_delayhide = setTimeout('f_896732626_hidemenu()', 500);
}

function f_896732626_clearhidemenu()
{
	if (window.f_896732626_delayhide)
	{
    clearTimeout(f_896732626_delayhide);
  }
}

if (ie5||ns6)
{
  document.onclick = f_896732626_hidemenu;
}

