document.write("<style type='text/css'> .photo {display:none;} #image-info {display:none;} </style>");

window.onload = function() { 	// wait the full loading of image before the fade effect
$(".photo").fadeIn(1500);

$('.clearField').clearField({
  blurClass: 'clearFieldBlurred',
  activeClass: 'clearFieldActive'
});

};


if (document.images)
{
  preload_image_object = new Image();
  // set image url
  image_url = new Array();
  image_url[0] = "http://intelligentcloud.org/templates/intelligentcloud/images/drag_bg.png";
  image_url[1] = "http://intelligentcloud.org/templates/intelligentcloud/images/iconSprite.png";
  
   var i = 0;
   for(i=0; i<=3; i++) 
     preload_image_object.src = image_url[i];
}
   
  

function validateOnSubmit() {
    var elem;
    var errs=0;
    // execute all element validations in reverse order, so focus gets
    // set to the first one in error.
    if (!validateEmail  (document.forms.post.email, 'inf_email', true)) errs += 1; 
    if (!validatePresent  (document.forms.post.name, 'inf_name', true)) errs += 1; 
 
    if (errs==1) alert('There is a field which needs correction before sending');
    if (errs>1) alert('There is a field which needs correction before sending');
 
    else if (errs==0){document.forms.post.Submit.disabled=false;}
  };


// drag and share!!!
$(function() {
    
	//cache selector
	var images = $("#image-border img"),
	  title = $("title").text() || document.title;	
	
	//make images draggable
    images.draggable({
	  //create draggable helper
	  helper: function() {
	    return $("<div>").attr("id", "helper").html("<img id='thumb' src='" + $(this).attr("src") + "'>").appendTo("body");
	  },
	  cursor: "pointer",
	  cursorAt: { left:-120, top: 10 },
	  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);
	  }
	});
	
	//make targets droppable
	$("#targets li").droppable({
	  tolerance: "pointer",
	  //show info when over target
	  over: function() {
	    $(".share", "#targets").remove();
	    $("<span>").addClass("share").text("share on " + $(this).attr("id")).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("Facebook") != -1) {
		  window.open(baseUrl + "/sharer.php?u=" + currentUrl + "&t=" + title,'mywindow','width=800,height=650,scrollbars=yes');
		} else if (id.indexOf("Twitter") != -1) {
		  window.open(baseUrl + "/home?status=" + title + ": " + currentUrl,'mywindow','width=800,height=650,scrollbars=yes');
		} else if (id.indexOf("Delicious") != -1) {
		  window.open(baseUrl + "/save?url=" + currentUrl + "&title=" + title,'mywindow','width=900,height=650,scrollbars=yes');
		} else if (id.indexOf("StumbleUpon") != -1) {
		  window.open(baseUrl + "/submit?url=" + currentUrl + "&title=" + title,'mywindow','width=800,height=650,scrollbars=yes');
		} else if (id.indexOf("Digg") != -1) {
		  window.open(baseUrl + "/submit?phase=2&url=" + currentUrl + "&title=" + title,'mywindow','width=1000,height=650,scrollbars=yes');
		} else if (id.indexOf("Email") != -1) {
		  window.open("http://intelligentcloud.org/templates/intelligentcloud/mail.php?" + currentUrl, 'mywindow', 'width=460,height=400,scrollbars=no');
		}
	  }		  
	});
	
		  
    var createTip = function(e) {
	  //create tool tip if it doesn't exist
	  ($("#tip").length === 0) ? $("<div>").html("<span>&spades; drag to share &spades;<br \/> click \/ use arrow<br \/>keys to navigate<\/span>").attr("id", "tip").css({ left:e.pageX + 30, top:e.pageY - 16 }).appendTo("body").fadeIn(500) : null;
	};
	
	images.bind("mouseenter", createTip);
	
	images.mousemove(function(e) {
	
	  //move tooltip
      $("#tip").css({ left:e.pageX - 36, top:e.pageY + 40 });
    });
  
    images.mouseleave(function() {
	
	  //remove tooltip
	  $("#tip").remove();
    });
});
