
function toggle( targetId ){
  if (document.getElementById){
  		target = document.getElementById( targetId );
  			if (target.style.display == "none"){
  				target.style.display = "";
  			} else {
  				target.style.display = "none";
  			}
  	}
}

function timeAnnounce(){
 newDate = new Date();
 var myWeek = newDate.getDate();
 var myYear = newDate.getFullYear();
 var myMonth = newDate.getMonth();
 var myDay = newDate.getDay();
 var monthName = new Array ('January','February','March','April','May','June','July','August','September','October','November','December')
 var theMonth = monthName[myMonth];
 var daysName = new Array ('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday')
 var theDay = daysName[myDay];
 var allTime =  theDay + ", " + theMonth + " " + myWeek + ", " + myYear;
 var newPara = document.createTextNode(allTime);
 addTimeStamp = document.getElementById("timeStamp");
 addTimeStamp.appendChild(newPara);
}


window.onload = function(){
  bookmark();

  document.getElementById('miUpdate').onclick = function(evt) { minimizeIt('Update')};
  document.getElementById('mxUpdate').onclick = function(evt) { maximizeIt('Update')};
  document.getElementById('xUpdate').onclick = function(evt) { removeIt('Update')};
  document.getElementById('miUpdate').onmouseover = function(evt) { colorit('miUpdate')};
  document.getElementById('mxUpdate').onmouseover = function(evt) { colorit('mxUpdate')};
  document.getElementById('xUpdate').onmouseover = function(evt) { colorit('xUpdate')};
  document.getElementById('miUpdate').onmouseout = function(evt) { decolorit('miUpdate')};
  document.getElementById('mxUpdate').onmouseout = function(evt) { decolorit('mxUpdate')};
  document.getElementById('xUpdate').onmouseout = function(evt) { decolorit('xUpdate')};
  
  document.getElementById('miCareer').onclick = function(evt) { minimizeIt('Career') };
  document.getElementById('mxCareer').onclick = function(evt) { maximizeIt('Career') };
  document.getElementById('xCareer').onclick = function(evt) { removeIt('Career') };
  document.getElementById('miCareer').onmouseover = function(evt) { colorit('miCareer') };
  document.getElementById('mxCareer').onmouseover = function(evt) { colorit('mxCareer') };
  document.getElementById('xCareer').onmouseover = function(evt) { colorit('xCareer') };
  document.getElementById('miCareer').onmouseout = function(evt) { decolorit('miCareer') };
  document.getElementById('mxCareer').onmouseout = function(evt) { decolorit('mxCareer') };
  document.getElementById('xCareer').onmouseout = function(evt) { decolorit('xCareer') };

  document.getElementById('miCode').onclick = function(evt) { minimizeIt('Code')};
  document.getElementById('mxCode').onclick = function(evt) { maximizeIt('Code')};
  document.getElementById('xCode').onclick = function(evt) { removeIt('Code')};
  document.getElementById('miCode').onmouseover = function(evt) { colorit('miCode')};
  document.getElementById('mxCode').onmouseover = function(evt) { colorit('mxCode')};
  document.getElementById('xCode').onmouseover = function(evt) { colorit('xCode')};
  document.getElementById('miCode').onmouseout = function(evt) { decolorit('miCode')};
  document.getElementById('mxCode').onmouseout = function(evt) { decolorit('mxCode')};
  document.getElementById('xCode').onmouseout = function(evt) { decolorit('xCode')};

  document.getElementById('miFeed').onclick = function(evt) { minimizeIt('Feedback')};
  document.getElementById('mxFeed').onclick = function(evt) { maximizeIt('Feedback')};
  document.getElementById('xFeed').onclick = function(evt) { removeIt('Feedback')};
  document.getElementById('miFeed').onmouseover = function(evt) { colorit('miFeed')};
  document.getElementById('mxFeed').onmouseover = function(evt) { colorit('mxFeed')};
  document.getElementById('xFeed').onmouseover = function(evt) { colorit('xFeed')};
  document.getElementById('miFeed').onmouseout = function(evt) { decolorit('miFeed')};
  document.getElementById('mxFeed').onmouseout = function(evt) { decolorit('mxFeed')};
  document.getElementById('xFeed').onmouseout = function(evt) { decolorit('xFeed')};  

  document.getElementById('miBlog').onclick = function(evt) { minimizeIt('Weblog')};
  document.getElementById('mxBlog').onclick = function(evt) { maximizeIt('Weblog')};
  document.getElementById('xBlog').onclick = function(evt) { removeIt('Weblog')};
  document.getElementById('miBlog').onmouseover = function(evt) { colorit('miBlog')};
  document.getElementById('mxBlog').onmouseover = function(evt) { colorit('mxBlog')};
  document.getElementById('xBlog').onmouseover = function(evt) { colorit('xBlog')};
  document.getElementById('miBlog').onmouseout = function(evt) { decolorit('miBlog')};
  document.getElementById('mxBlog').onmouseout = function(evt) { decolorit('mxBlog')};
  document.getElementById('xBlog').onmouseout = function(evt) { decolorit('xBlog')};

  document.getElementById('miSet').onclick = function(evt) { minimizeIt('Setting')};
  document.getElementById('mxSet').onclick = function(evt) { maximizeIt('Setting')};
  document.getElementById('xSet').onclick = function(evt) { removeIt('Setting')};
  document.getElementById('miSet').onmouseover = function(evt) { colorit('miSet')};
  document.getElementById('mxSet').onmouseover = function(evt) { colorit('mxSet')};
  document.getElementById('xSet').onmouseover = function(evt) { colorit('xSet')};
  document.getElementById('miSet').onmouseout = function(evt) { decolorit('miSet')};
  document.getElementById('mxSet').onmouseout = function(evt) { decolorit('mxSet')};
  document.getElementById('xSet').onmouseout = function(evt) { decolorit('xSet')};

  document.getElementById('miBook').onclick = function(evt) { minimizeIt('Bookmarks')};
  document.getElementById('mxBook').onclick = function(evt) { maximizeIt('Bookmarks')};
  document.getElementById('xBook').onclick = function(evt) { removeIt('Bookmarks')};
  document.getElementById('miBook').onmouseover = function(evt) { colorit('miBook')};
  document.getElementById('mxBook').onmouseover = function(evt) { colorit('mxBook')};
  document.getElementById('xBook').onmouseover = function(evt) { colorit('xBook')};
  document.getElementById('miBook').onmouseout = function(evt) { decolorit('miBook')};
  document.getElementById('mxBook').onmouseout = function(evt) { decolorit('mxBook')};
  document.getElementById('xBook').onmouseout = function(evt) { decolorit('xBook')};
 
}

function colorit(obj){
 var color = document.getElementById(obj); 
 color.style.backgroundColor = '#fea98a';
}

function decolorit(obj){
 var color = document.getElementById(obj); 
 color.style.backgroundColor = 'transparent';
}

function removeIt(obj){
 var closeIt = document.getElementById(obj); 
 var tool = document.getElementById('toolBox'); 
 closeIt.style.display = 'none';
 tool.style.display = 'block';
 }

function minimizeIt(obj){
 var mini = document.getElementById(obj); 
 var xPara = mini.getElementsByTagName('p');
  xPara[0].style.display = 'none';
 // while( xPara[0].hasChildNodes() ) { xPara[0].removeChild( xPara[0].lastChild ); }
  mini.style.borderBottom = '0';
  mini.style.height = '17px';
  document.getElementById('toolBox').style.display = 'block';
}

function maximizeIt(obj) {
 var maxi = document.getElementById(obj); 
 var xPara = maxi.getElementsByTagName('p');
  xPara[0].style.display = 'block';
  maxi.style.borderBottom = '1px solid #53779B';
  maxi.style.height = '100%';
}


function showIt(obj){
 openit = document.getElementById(obj);
 openit.style.display = 'block';
 openit.style.height = '100%';
 openit.style.borderBottom = '1px solid #53779B';	 
 openit.getElementsByTagName('p')[0].style.display = 'block';
 openit.getElementsByTagName('p')[0].style.height = '100%';
 openit.getElementsByTagName('p')[0].style.paddingTop = '5px';
 openit.style.position= "relative";
 openit.style.top = "0px";
 openit.style.left = "0px";
}

function resetAll(){
 showIt('Update'), showIt('Career'), showIt('Code'), showIt('Feedback'), showIt('Weblog'), showIt('Setting'), showIt('Bookmarks');
} 

function bookmark() {
 var ul = document.createElement('ul')
 for (var i=0, post; post = Delicious.posts[i]; i++) {
   var li = document.createElement('li');
   var a = document.createElement('a');
   var img = document.createElement('img');
    a.setAttribute('href', post.u);
    a.setAttribute('target','_blank');
    img.setAttribute('src', 'images/target_blank.gif');
    img.setAttribute('width','9px');
    img.setAttribute('height','9px');
    img.setAttribute('alt','Opens new window');
	img.setAttribute('className','imgTarget'); // IE
    img.setAttribute('class','imgTarget'); // FF
   a.appendChild(document.createTextNode(post.d));
   li.appendChild(a);   
   li.appendChild(img);
   ul.appendChild(li);
  }
 document.getElementById('delicious').appendChild(ul);
}


function tooltip(ids, objs) {
 var oId, oDiv, oText, end, top;
 oId=document.getElementById(ids); //
 myobj=document.getElementById(objs);
 end=calculateOffsetLeft(oId);
 top=calculateOffsetTop(oId);
 vista = ((myobj.style.visibility == 'visible') ? 'hidden' : 'visible');
 myobj.style.visibility = vista;
 myobj.style.left = end +"px";
 myobj.style.top = top+"px";
}
function hideit(objs) {
 myobj=document.getElementById(objs);
 vista = ((myobj.style.visibility == 'hidden') ? 'visible' : 'hidden');
 myobj.style.visibility = vista;
}
function calculateOffsetTop(field) {
 return calculateOffset(field, "offsetTop");
}
function calculateOffset(field, attr) {
 var offset=-40;
 while(field) {
  offset += field[attr]; 
  field = field.offsetParent;
 }
 return offset;
}
function calculateOffsetLeft(field) {
 return calculateOffsetLf(field, "offsetLeft");
}
function calculateOffsetLf(field, attr) {
 var offsetLeftOver=field.offsetWidth;
 var offset=offsetLeftOver;
 while(field) {
   offset += field[attr]; 
   field = field.offsetParent;
 }
 return offset;
} 


// http://developer.yahoo.com/yui/dragdrop/
function DragDropDomCall() {
    var Update, Career, Code, Feedback, Weblog, Setting, Bookmarks;
    YAHOO.util.Event.onDOMReady(function() {
     // Configure one or more child element as a drag handle
     Update = new YAHOO.util.DD("Update");
     Update.setHandleElId("dd-handle-Update");

     Career = new YAHOO.util.DD("Career");
     Career.setHandleElId("dd-handle-Career");

     Code = new YAHOO.util.DD("Code");
     Code.setHandleElId("dd-handle-Code");

     Feedback = new YAHOO.util.DD("Feedback");
     Feedback.setHandleElId("dd-handle-Feedback");

     Weblog = new YAHOO.util.DD("Weblog");
     Weblog.setHandleElId("dd-handle-Weblog");

     Setting = new YAHOO.util.DD("Setting");
     Setting.setHandleElId("dd-handle-Setting");

     Bookmarks = new YAHOO.util.DD("Bookmarks");
     Bookmarks.setHandleElId("dd-handle-Bookmarks");
	 
    });
}
