$(document).ready(function(){
						   
	$('.imageToAction').click(function(){		/* this is done because IE7 cannot pass the value of image inputs the way even */
		$('#action').val($(this).val());		/* IE6, the worst browser ever made, is able to do.  so we have to do this stupid */		
		return true;							/* hack, which puts the value of the clicked image input into a generic hidden input */
	});		
	
	$('form').submit(function(){
		var stopit = 0;
		if($(this).find('.product-option').length>0){
			$(this).find('.product-option').each(function(){
				if($(this).children('option:selected').val()=='0' && stopit == 0){
					alert('All options are required.  Please make your selection and proceed with your order.');
					$(this).focus();
					stopit = 1;
				}
			});
			if(stopit==1){
				return false;
			} else {
				return true;
			}
		} else {
			return true;
		}
	});
					/*				   
		$(".treeOpen").livequery('click',function(){

			$(this).removeClass("treeOpen");
			$(this).addClass("treeClose");
			if($(this).parent().children("ul").length==0){
				getChildrenAndOpen($(this).parent().attr("id"));
			} else {
				$(this).parent().children("ul").slideDown(1000, 'easeOutBounce');
			}
            $(this).addClass('treeClosing'); 
			$(this).removeClass('treeLoading'); 
	
		});
		
		$(".treeClose").livequery('click',function(){

			$(this).removeClass("treeClose");
			$(this).addClass("treeOpen");
			$(this).parent().children("ul").slideUp(1000, 'easeOutBounce');
			$(this).removeClass('treeClosing'); 
			$(this).addClass('treeLoading'); 

		});
		
		$(".treeIcon").livequery(function(){ 
		
			$(this) 
				.hover(function() { 
					if ($(this).hasClass('treeClose')){
						$(this).removeClass('treeLoading');
						$(this).addClass('treeClosing'); 
					} else if ($(this).hasClass('treeOpen')) {
						$(this).removeClass('treeClosing');
						$(this).addClass('treeLoading'); 
					}
				}, function() { 
					$(this).removeClass('treeClosing'); 
					$(this).removeClass('treeLoading'); 
				}); 
			}, function() { 
				$(this) 
					.unbind('mouseover') 
					.unbind('mouseout'); 
				
		});*/
		$(".treeEmpty,.treeIcon,.treeOpen,.treeClose").livequery('click',function(){
			if ($(this).siblings('a').length>0){
				window.location=$(this).siblings('a').attr('href');	
			}
		});
		
});

function getChildrenAndOpen(thisId){
	var parentId = thisId.replace('li','');
	$.ajax({
		type: 'get',
		data: 'parentId='+parentId,
		url: '/smarttree-children.php',
		success: function(results){
			$('#'+thisId).append(results).children("ul").hide();
			$('#'+thisId).children("ul").slideDown(1000, 'easeOutBounce');
		}
	});
}
