// JavaScript Document
function changeClass(obj)
{
      var top = obj.parentNode.parentNode;
      var ob = null;
      var i = 0;
      for ( i = 0; i < top.childNodes.length; i++ )
      {
            ob = top.childNodes[i];
            ob.className= "";
      }
      obj.parentNode.className = "active";
}

function addTodo()
{
	
	
}

function addTask(parent_id)
{
	if ($("#new_task").size()>0)
	{
		saveTask();
	} 
	else 
	{
		$("#ul_tasks").append('<li id="new_li"><input type="text" id="new_task" value="" onblur="saveTask()" ></li>');
		$("#new_task").focus();
	}
}

function saveTask()
{
	if ($("#new_task").val().length>0)
	{
		var project_id = $("#selected_project_id").val();
		var task_name = $("#new_task").val();			
	
	  $.ajax({
			type: 'get',
			url: 'index.php', 
			data: {
				inc: 'todo',
				action: 'add',
				project_id: project_id,
				name: task_name,
				ajax: 1
			},
			
			success: function(data) {
				$("#new_task").remove();
				$("#new_li").text(task_name);
				$("#new_li").attr("id",'task_'+data);
				var id = 'task_'+data;
				$("#"+id).dblclick(
						function()
						{
							editTask(id);
						}
				);
			}
			
	  });	
	} else {
		$("#new_task").remove();
		$("#new_li").remove();
	}
}

function editTask(id)
{
	alert(id);
}

function taskDone(id)
{
	
}

function showDescription(id) 
{
  var obj = document.getElementById('description_'+id);
  var descr_holder = document.getElementById('description');  
  descr_holder.innerHTML = obj.innerHTML;
	$("#selected_task_id").val(id);
  
}

function  showTodo(id) 
{

  $.ajax({
		type: 'get',
		url: 'index.php', 
		data: {
			inc: 'todo',
			action: 'index',
			project_id: id,
			ajax: 1
		},
		success: function(data) {
			$("#content").html(data);
			$("#selected_project_id").val(id);
		}	
			
  });

}

function  DisplayGallery(id) 
{
  $.ajax({
		type: 'get',
		url: 'index.php', 
		data: {
			inc: 'gallery',
			action: 'showGallery',
			id: id,
			ref: 1,
			ajax: 1
		},
		success: function(data) {
			parent.window.$("#gallery_images_"+id).html(data);
		}	
			
  });
}

function  AddToFavorite(id) 
{
  $.ajax({
		type: 'get',
		url: 'index.php', 
		data: {
			inc: 'user',
			action: 'favoriteAdd',
			id: id,
			ajax: 1
		},
		beforeSend: function(data)
		{
			$("#favInfo").html('<img src="img/loader.gif" alt="ok" />');
		},
		success: function(data) {
			$("#favInfo").html('<b>'+data+'</b>');
		}	
			
  });	
}

function AddComment(img_id, type)
{
	if (type==undefined) { type='i'; }
	
  $.ajax({
		type: 'post',
		url: 'index.php', 
		data: {
			inc: 'comment',
			action: 'add',
			body: $("#body").val(),
			img_id: img_id,
			type: type,
			ajax: 1
		},
		beforeSend: function(data)
		{
			$("#new_comment").html('<img src="img/loader.gif" alt="ok" />');
		},
		success: function(data) {
			$("#new_comment").html(data);			
		}	
			
  });
}

function RateImg(img_id, rate)
{
  $.ajax({
		type: 'get',
		url: 'index.php', 
		data: {
			inc: 'gallery',
			action: 'rateImg',
			rate: rate,
			img_id: img_id,
			ajax: 1
		},
		beforeSend: function(data)
		{
			$("#rate_image").html('<img src="img/loader.gif" alt="ok" />');
		},
		success: function(data) {
			$("#rate_image").html('<b>'+data+'</b>');			
		}	
			
  });
}

function  AddToBlocked(id) 
{
  $.ajax({
		type: 'get',
		url: 'index.php', 
		data: {
			inc: 'user',
			action: 'blockedAdd',
			id: id,
			ajax: 1
		},
		beforeSend: function(data)
		{
			$("#blockedInfo").html('<img src="img/loader.gif" alt="ok" />');
		},
		success: function(data) {
			$("#blockedInfo").html('<b>'+data+'</b>');
		}	
			
  });	
}

function  SendKiss(id) 
{
  $.ajax({
		type: 'get',
		url: 'index.php', 
		data: {
			inc: 'user',
			action: 'kissAdd',
			id: id,
			ajax: 1
		},
		beforeSend: function(data)
		{
			$("#kissInfo").html('<img src="img/loader.gif" alt="ok" />');
		},
		success: function(data) {
			$("#kissInfo").html('<b>'+data+'</b>');
		}	
			
  });	
}