var $j=jQuery.noConflict();



	$j(function() {
		
		//do for each element in the array

		//make_draggable($j("body .componentheading"));
		make_draggable($j("body img"));
		//make_draggable($j("body p"));
		//create_tips($j("body .componentheading"));
		create_tips($j("body img"));
		//create_tips($j("body p"));

		
		
		

		//cache selector

		var  title = $j("title").text() || document.title;
		var a =0;
		

		
		function make_draggable(images1){
		
	    //make images draggable
	    images1.draggable({
		  //create draggable helper
		  helper: function() {
		    return $j("<div>").attr("id", "helper").html("<span>" + title + "</span><img id='thumb' src='" + $j(this).attr("src") + "'>").appendTo("body");
		  },
		  cursor: "pointer",
		  cursorAt: { left: -10, top: 20 },
		  zIndex: 99999,
		  //show overlay and targets
		  start: function() {
            var win_height = $j("body").height() + 50;
		    $j("<div>").attr("id", "overlay").css("opacity", 0.7).css("height", win_height+"px").css("display", "none").appendTo("body");
            $j("#overlay").slideDown();
			$j("#tip").remove();
			$j(this).unbind("mouseenter");
			$j("#targets").css("left", ($j("body").width() / 2) - $j("#targets").width() / 2).slideDown();
		  },
		  //remove targets and overlay
		  stop: function() {
		    $j("#targets").slideUp();
			$j(".share", "#targets").remove();
			$j("#helper").remove();
            $j("#overlay").slideUp();
            setTimeout('$j("#overlay").remove();', 1000);
			$j(this).bind("mouseenter", createTip2);
		  }
		});
		};
		
		var createTip2 = function(e) {
			
		  //create tool tip if it doesn't exist
		  
		  ($j("#tip").length === 0) ? $j("<div>").html("<span>Drag this image to share the page<\/span><span class='arrow'><\/span>").attr("id", "tip").css({ left:e.pageX + 30, top:e.pageY - 16 }).appendTo("body").fadeIn(2000) : null;
		};
		
		//make targets droppable
		$j("#targets li").droppable({
		  tolerance: "pointer",
		  //show info when over target
		  over: function() {
		    $j(".share", "#targets").remove();
		    $j("<span>").addClass("share").text("Share on " + $j(this).attr("id")).addClass("active").appendTo($j(this)).fadeIn();
		  },
		  drop: function() {
		    var id = $j(this).attr("id"),
			  currentUrl = escape(window.location.href),
			  baseUrl = $j(this).find("a").attr("href");

			if (id.indexOf("twitter") != -1) {
			  //window.location.href = baseUrl + "/home?status=" + title + ": " + currentUrl;
              window.open(baseUrl + "/home?status=" + title + ": " + currentUrl,"_blank");
			} else if (id.indexOf("delicious") != -1) {
			  //window.location.href = baseUrl + "/save?url=" + currentUrl + "&title=" + title;
              window.open(baseUrl + "/save?url=" + currentUrl + "&title=" + title,"_blank");
			} else if (id.indexOf("facebook") != -1) {
			  //window.location.href = baseUrl + "/sharer.php?u=" + currentUrl + "&t=" + title;
              window.open(baseUrl + "/sharer.php?u=" + currentUrl + "&t=" + title,"_blank");
			}
		  }
		});

		function create_tips(images1){

	    var createTip = function(e) {
			
		  //create tool tip if it doesn't exist
		  
		  ($j("#tip").length === 0) ? $j("<div>").html("<span>Drag this image to share the page<\/span><span class='arrow'><\/span>").attr("id", "tip").css({ left:e.pageX + 30, top:e.pageY - 16 }).appendTo("body").fadeIn(2000) : null;
		};

		images1.bind("mouseenter", createTip);

		images1.mousemove(function(e) {

		  //move tooltip
          $j("#tip").css({ left:e.pageX + 30, top:e.pageY - 16 });
        });

	    images1.mouseleave(function() {

		  //remove tooltip
		  $j("#tip").remove();
	    });
		};
		
		
	  });
	  
