$(document).ready(function () {
	$(".listing_container .head").click(function() { 
		//$(".listing_container").removeClass("open");
		if( $(this).parent(".listing_container").hasClass("open") ) { 
			$(this).parent(".listing_container").removeClass("open");
		} else { 
			$(this).parent(".listing_container").addClass("open");
		}
	});
	
	$(".tree_icon").hover(
		function() { 
			var tree_id=$(this).attr("id");
			var tree_array = $(this).attr("id").split("-");
			treehover(tree_array[1],tree_array[2],tree_array[3]);
		}, 
		function() { 
			var tree_id=$(this).attr("id");
			var tree_array = $(this).attr("id").split("-");
			treehover(tree_array[1],tree_array[3],tree_array[3]);
		}
	);
	
	$(".tree_icon").click(function() { 
		var tree_id=$(this).attr("id");
		var tree_array = $(this).attr("id").split("-");
		treehovercommit(tree_array[1],tree_array[2],tree_array[3]);
	});
	
	
	
});

function treehover(id,pos,def) { 
	var activetree="0px 0px";
	var inactivetree="-19px 0px";
	for(i=1;i<=5;i++) { 
		if(pos >= i) { document.getElementById('tree-'+id+'-'+i+'-'+def).style.backgroundPosition=activetree; } 
		else  { document.getElementById('tree-'+id+'-'+i+'-'+def).style.backgroundPosition=inactivetree; } 
	}
}
function treehovercommit(id,pos) { 
	var query="e=" + id + "&rating=" + pos;
	$.get("/tools/addrating.cfm",query, function(data){
		response_array=data.split("~");
		$("#trees-"+id).html(response_array[0]);
		$("#rating2-"+id).html(response_array[1]);
	});	
}

function prelaunchMaxCatCheck(form,checkboxid) {
	var total = 0;
	var max = form.ckbox.length;
	for (var idx = 0; idx < max; idx++) {
	if (eval("document.getElementById('add-listing').ckbox[" + idx + "].checked") == true) {
	    total += 1;
	   }
	}
	if (total > 8) {
		alert("You have already selected 8 boxes.");
		checkboxid.checked=false;
		return false;
	}
}
function checkIfAvailable(username) { 
	var query="d=" + username;
	$.get("/tools/check_availability.cfm",query, function(data){
		$("#check_result").html(data);
	});	
}

