jQuery(document).ready(function()
{
	initPage();	
	group_dedicate();
	//jQuery("p[class='paginate']").find('a').ajax_paginate({callback: group_dedicate});
	
    $('#treeEditForm').submit(function() { 
		$.blockUI(
		{ 
			message: $('#saveChanges'),
			css: { 
	            border: '2px #666 solid', 
	            padding: '15px', 
	            backgroundColor: '#FFF', 
	            '-webkit-border-radius': '10px', 
	            '-moz-border-radius': '10px', 
	            opacity: '1', 
	            color: '#666' 
	        } 
		});
    });	
});

function group_dedicate()
{
	jQuery('#groupDedicationBlock .dedicationInputTD').hide();
	
	jQuery('#groupDedicationBlock .treeList').hover(function()
	{
		if (!$(this).hasClass('selectedGroup'))
			$(this).animate({ backgroundColor: "#CDCDCD" }, 150);	
	
	},
	function()
	{
		if (!$(this).hasClass('selectedGroup'))
			$(this).animate({ backgroundColor: "#FFF" }, 150);	
	});
	
	jQuery('#groupDedicationBlock .treeList').click(function()
	{	
		if (!$(this).hasClass('selectedGroup'))
		{
			jQuery('#groupDedicationBlock .treeList').removeClass('selectedGroup');
			jQuery('#groupDedicationBlock .treeList').css({ backgroundColor: "#FFF" });
			$(this).find("input[name='group_id']").attr('checked','checked');	
			$(this).css({ backgroundColor: "#DDD" });			
			$(this).addClass('selectedGroup');
		}
	});	
}

function initPage()
{
	$("#benefit_other").hide();
	$("#dedicated_to_other").hide();
	$("#treeCommentBox").hide();
	
	$("#treeWaterComment").click(function()
	{
		$("#treeWaterBox").hide();
		$("#treeCommentBox").show('fast');
	});
	
	$("select[name='benefit']").change(function()
	{
		if( $(this).val() == 'other' )
			$("#benefit_other").show('fast');
		else
			$("#benefit_other").hide('fast');
	}).change();
	
	$("select[name='dedicated_to']").change(function()
	{
		if( $(this).val() == 'other' )
			$("#dedicated_to_other").show('fast');
		else
			$("#dedicated_to_other").hide('fast');
	}).change();		
	
	jQuery('#treeArtSelect li').find("input[name='image']").hide();
	
	jQuery('#treeArtSelect li').hover(function()
	{
		if (!$(this).hasClass('selectedArt'))
			$(this).animate({ backgroundColor: "#84bc2b" }, 150);	
	
	},
	function()
	{
		if (!$(this).hasClass('selectedArt'))
			$(this).animate({ backgroundColor: "#FFF" }, 150);	
	});
	
	jQuery('#treeArtSelect li').click(function()
	{	
		if (!$(this).hasClass('selectedArt'))
		{
			jQuery('#treeArtSelect li').removeClass('selectedArt');
			jQuery('#treeArtSelect li').css({ backgroundColor: "#FFF" });
			$(this).find("input[name='image']").attr('checked','checked');	
			$(this).css({ backgroundColor: "#abd848" });			
			$(this).addClass('selectedArt');
		}
	});
}