// Written By: Rafiqul Islam on January 29 2008
// Modified By: Mike Hacker for use with Destination Oakland
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+4) + "px";
  pickerDiv.style.top = (y+20) + "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' border='0' cellpadding='0' cellspacing='0'>" ;
  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 += TABLE;


  html += TR;
  html += "<td><img src='/_layouts/images/destinationoakland/sharetop.gif'><td/>";
  html += "</tr>";

  html += TR_title;
  html += TD_rbuttons + "<a style='padding-right:10px;' onClick='updateTargetField(\"" + targetName + "\");'>Close</a>" + xTD;
  html += xTR;
  
  html += TR_title;
  html += TD_buttons + '<a 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="/_layouts/images/DestinationOakland/digg_icon.gif" alt="Digg" width="17" height="14">&nbsp; Digg<\/a>' + xTD;
  html += xTR;

  html += TR_title;
  html += TD_buttons + '<a 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="/_layouts/images/DestinationOakland/facebook_icon.gif" alt="Facebook" width="17" height="14">&nbsp; Facebook<\/a>' + xTD;
  html += xTR;
  
  html += TR_title;
  html += TD_buttons + '<a 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="/_layouts/images/DestinationOakland/delicious_icon.gif" alt="" width="16" height="16">&nbsp; del.icio.us</a>' + xTD;
  html += xTR;
 
  html += TR_title;
  html += TD_buttons + '<a style="text-decoration:none;border-width:0"  href="http://reddit.com/submit?url=' + encodeURIComponent(location.href) + '" target="_blank">&nbsp;<img border=0 src="/_layouts/images/DestinationOakland/reddit_icon.gif" alt="reddit" width="17" height="16">&nbsp; reddit<\/a>' + xTD;
  html += xTR;
  
  html += TR_title;
  html += TD_buttons + '<a style="text-decoration:none;border-width:0"  href="http://www.stumbleupon.com/submit?url=' + encodeURIComponent(location.href) + '" target="_blank">&nbsp;<img border=0 src="/_layouts/images/DestinationOakland/supon_icon.gif" alt="" width="16" height="16">&nbsp; StumbleUpon<\/a>' + xTD;
  html += xTR;
  
  html += TR;
  html += "<td><img src='/_layouts/images/destinationoakland/sharebottom.gif'><td/>";
  html += "</tr>";

  html += xTABLE;
  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);
}
