// Written By: Rafiqul Islam on January 29 2008
var sharePickerDivID = "sharepicker";
var iFrameDivID = "sharepickeriframe";

function show(targetName, displayBelowThisObject)
{
  var target = document.getElementsByName (targetName).item(0);
  
  if (!displayBelowThisObject)
    displayBelowThisObject = target;
 
  var x = displayBelowThisObject.offsetLeft;
  var y = displayBelowThisObject.offsetTop + displayBelowThisObject.offsetHeight ;


  var parent = displayBelowThisObject;
  
  while (parent.offsetParent) {
    parent = parent.offsetParent;
    x += parent.offsetLeft;
    y += parent.offsetTop ;
  }

  drawSharePicker(target, x, y );        // 645, 102
}

function close(targetName)
{
   setTimeout("hidemenu(targetName)",0750);
}

function hidemenu(share)
{
  var elem = document.getElementByName(share);
  elem.style.dispaly='none';
  return false;
}


function drawSharePicker(target, x, y)
{ 
  if (!document.getElementById(sharePickerDivID)) {
    
    var newNode = document.createElement("div");
    newNode.setAttribute("id", sharePickerDivID);
    newNode.setAttribute("class", "dpDiv");
    newNode.setAttribute("style", "visibility: hidden;");
    document.body.appendChild(newNode);
  }
   
  var pickerDiv = document.getElementById(sharePickerDivID);
  pickerDiv.style.position = "absolute";
  pickerDiv.style.left = (x-45) + "px";
  pickerDiv.style.top = (y-5) + "px";
  pickerDiv.style.visibility = (pickerDiv.style.visibility == "visible" ? "hidden" : "visible");
  pickerDiv.style.display = (pickerDiv.style.display == "block" ? "none" : "block");
  pickerDiv.style.zIndex = 10000;
  
  refreshSharePicker(target.name);
}


function refreshSharePicker(targetName)
{
  
  var crlf = "\r\n";
  var TABLE = "<table class='dpTable' bgcolor='6e9595' border='0' cellpaadding='5' cellspacing='5'>" ;
  var xTABLE = "</table>" + crlf;
  var TR = "<tr class='dpTR'>";
  var TR_title = "<tr class='dpTitleTR'>";
  
  var xTR = "</tr>" + crlf;

  var TD_buttons = "<td align='left'>";
  var TD_rbuttons = "<td align='right'>";
  var xTD = "</td>" + crlf;

  // start generating the code for the share table
  var html = "";
  //html += '<img border=0 src="/globaloakland/includes/images/share/old/top_round.gif" alt="" width="129" height="11">';
  html += TABLE;


  html += TR_title;
  html += TD_rbuttons + "<span class=\"tinytext\">close " + "<img onClick='updateTargetField(\"" + targetName + "\");' src='/globaloakland/includes/images/share/old/btn_close.gif' alt='' border='0' width='12' height='12' />"  +  xTD;
  html += xTR;
  
  html += TR_title;
  html += TD_buttons + '<a class="share" style="text-decoration:none;border-width:0"  href="http://digg.com/submit?phase=2&url='+encodeURIComponent(location.href)+'" target="_blank">&nbsp;<img border=0 src="/globaloakland/includes/images/share/old/digg_icon.gif" alt="Digg" width="17" height="14">&nbsp; Digg<\/a>' + xTD;
  html += xTR;

  html += TR_title;
  html += TD_buttons + '<a class="share" style="text-decoration:none;border-width:0"  href="http://www.facebook.com/share.php?u='+encodeURIComponent(location.href)+'" target="_blank">&nbsp;<img border=0 src="/globaloakland/includes/images/share/old/facebook_icon.gif" alt="Facebook" width="17" height="14">&nbsp; Facebook<\/a>' + xTD;
  html += xTR;
  
  html += TR_title;
  html += TD_buttons + '<a class="share" style="text-decoration:none;border-width:0"  href="http://del.icio.us/post?v=4&partner=oakgov&noui&jump=close&url='+encodeURIComponent(location.href)+'" target="_blank">&nbsp;<img border=0 src="/globaloakland/includes/images/share/old/delicious_icon.gif" alt="" width="16" height="16">&nbsp; del.icio.us</a>' + xTD;
  html += xTR;
 
  html += TR_title;
  html += TD_buttons + '<a class="share" style="text-decoration:none;border-width:0"  href="http://reddit.com/submit?url='+encodeURIComponent(location.href)+'" target="_blank">&nbsp;<img border=0 src="/globaloakland/includes/images/share/old/reddit_icon.gif" alt="reddit" width="17" height="16">&nbsp; reddit<\/a>' + xTD;
  html += xTR;
  
  html += TR_title;
  html += TD_buttons + '<a class="share" style="text-decoration:none;border-width:0"  href="http://www.stumbleupon.com/submit?url='+encodeURIComponent(location.href)+'" target="_blank">&nbsp;<img border=0 src="/globaloakland/includes/images/share/old/supon_icon.gif" alt="" width="16" height="16">&nbsp; StumbleUpon<\/a>' + xTD;
  html += xTR;


  html += xTABLE;
  //html += '<img border=0 src="/globaloakland/includes/images/share/old/bottom_round.gif" alt="" width="129" height="11">';
  document.getElementById(sharePickerDivID).innerHTML = html;

}


function updateTargetField(targetName)
{
  var targetShareField = document.getElementsByName (targetName).item(0); 
 
  var pickerDiv = document.getElementById(sharePickerDivID);
  pickerDiv.style.visibility = "hidden";
  pickerDiv.style.display = "none";

  if ( (typeof(sharePickerClosed) == "function"))
    sharePickerClosed(targetShareField);
}



