/*
 *  resume.js - jQuery specific support for my resume
 *  Daniel Smith - javajoint@gmail.com
 *  December 2009 - January 2010
*/

$(document).ready(function(){
	
	var curWhichInfo = "";
	isDragging = 0;
	
	$("#topSection").hover(function() {
		$("#infoResCopyright").css("visibility", "visible");		
	}, function () {
		$("#infoResCopyright").css("visibility", "hidden");
	});
	
	// make external links open in a new window
	$('a[href^="http://"]')
	  .attr("target", "fromDLSResume");

	// would like to stop the shadows
	// from updating underneath a drag...
	// ... don't have it 100% yet..
	$("#draggable").draggable({
		cursor: 'pointer',
		opacity: 0.8,
		start: function(event, ui) {
			isDragging = 1;			
		},
		drag: function(event, ui) {
			isDragging = 1;			
		},
		stop: function(event, ui) {
			isDragging = 0;
		}
	 });
	
	// gather all of the sections that we will be highlighting
	allShadow = $(".useHighlight");

	// ... and all of the ones that will have a popup note...
	allNotes = $(".useNote");

	// handle entering and leaving...
	allShadow.hover(function() {
		$(this).addClass("showShadow");
	}, function() {
		$(this).removeClass("showShadow");
	});


	// we dont want a popup for a link
	$("a").click(function() {
		return true;
	});

	allNotes.click(function(event) {
		var whichInfo = event.currentTarget.id;
		var $target = $(event.target);
		
		// a little offset makes it much easier to
		// quickly toggle the popup on/off...	
		var myX = event.pageX + 10;
		var myY = event.pageY + 10;

		// if we click on a section that has a popup,
		// toggle it off
		// if we happen to be clicking on a link, we need
		// to handle that as well..
		if (whichInfo == curWhichInfo) {
			$("#draggable").css({
					visibility: "hidden"
						});
			curWhichInfo = "";
		
		    if( $target.is("a") ) {
				return true;
		    } else {
				return false;			
			}		  
		} else {
			curWhichInfo = whichInfo;
		}

		// we dont want a popup.. we're just clicking on a link ...
		if( $target.is("a") ) {
			return true;
		}

		$.ajax({
			type: "GET",
			url: "doc.php",
			data: "which=" + whichInfo,			
			
		 	success: function(msg){
				$("#draggable").html(msg);
				$("#draggable").css({visibility: "visible", left: myX, top: myY });
				$("#draggable a")
				  .attr("target", "fromDLSResume");
			}
		});
  });
});

