﻿ $(function() {  
        var images = $("#mainimage img"),  
          title = $("title").text() || document.title;  
        images.draggable({  
		  helper: function() {  
			return $("<div>").attr("id", "helper").html("<span>Mit wem m&ouml;chtest du das Bild teilen?</span><img id='thumb' src='" + $(this).attr("src") + "'>").appendTo("body");  
		  },  
		  cursor: "pointer",  
		  cursorAt: { left: -10, top: 20 },  
		  zIndex: 99999,  
		  //show overlay and targets  
		  start: function() {  
			$("<div>").attr("id", "overlay").css("opacity", 0.7).appendTo("body");  
			$("#tip").remove();  
			$(this).unbind("mouseenter");  
			$("#targets").css("left", ($("body").width() / 2) - $("#targets").width() / 2).slideDown();  
		  },  
		  //remove targets and overlay  
		  stop: function() {  
			$("#targets").slideUp();  
			$(".share", "#targets").remove();  
			$("#overlay").remove();  
			$(this).bind("mouseenter", createTip);  
		  }  
		});  
				
		$("#targets li").droppable({  
		  tolerance: "pointer",  
		  //show info when over target  
		  over: function() {  
			$(".share", "#targets").remove();  
			$("<span>").addClass("share").text("Mit " + $(this).attr("id") + " teilen").addClass("active").appendTo($(this)).fadeIn();  
		  },  
		  drop: function() {  
			var id = $(this).attr("id"),  
			  currentUrl = window.location.href,  
			baseUrl = $(this).find("a").attr("href");  
		  
			if (id.indexOf("twitter") != -1) {  
			  window.location.href = baseUrl + "/home?status=" + title + ": " + currentUrl;  
			} else if (id.indexOf("delicious") != -1) {  
			  window.location.href = baseUrl + "/save?url=" + currentUrl + "&title=" + title;  
			} else if (id.indexOf("facebook") != -1) {  
			  window.location.href = baseUrl + "/sharer.php?u=" + currentUrl + "&t=" + title;  
			}  
		  }  
		});  
	
	var createTip = function(e) {  
      ($("#tip").length === 0) ? $("<div>").html("<span>Gef&auml;llt dir das Foto? Zieh es, um es mit anderen zu teilen.<\/span><span class='arrow'><\/span>").attr("id", "tip").css({ left:e.pageX + 30, top:e.pageY - 16 }).appendTo("body").fadeIn(2000) : null;  
    };  
      
    images.bind("mouseenter", createTip);  
    images.mousemove(function(e) { $("#tip").css({ left:e.pageX + 30, top:e.pageY - 16 }); });  
    images.mouseleave(function() { $("#tip").remove(); });  
		
      });  
		$("#white").click(function() { 
			$("#lightroom").fadeOut('slow', function() { }); 
			$("body").css("background-color","#ffffff"); 
		});
		$("#black").click(function() { 
			$("#lightroom").fadeIn('slow', function() { $("body").css("background-color","#ffffff"); }); 
		});
		$(window).bind("resize", function(){$("#lightroom").css("height", $(window).height());});
