$(function() 
		   {
			   //we want to set up the slider to auto rotate
			   headline_interval = setInterval(rotateImages,5000); //time in milliseconds
   			   
			   //if we hover over one of the slides, we want to pause the animation
			   $('.featured_birds #slides') 
			   .hover(function() 
						{
							clearInterval(headline_interval);
  						}, 
					function() 
						{
							headline_interval = setInterval(rotateImages,5000); //time in milliseconds
						});

		   		//if one of the mini-slides is clicked on, we want to go to the corresponding slide
				$(".featured_birds #controls ul li")
				.click(function()
						{
							var NextSlide = $(".featured_birds #controls ul li").index(this);
							goToSlide(NextSlide, 500);
						});
				
				//if we hover over one of the mini-slides, we want to show the pointer
				$(".featured_birds #controls ul li")
				.hover(function()
						{
							$(".featured_birds #controls ul li").css("cursor","pointer");
						},   
						function()
						{
							$(".featured_birds #controls ul li").css("cursor","auto");
						});
	
				//if we hover over the prev button, lets make it change so the user knows its clickable
				$(".featured_birds #controls div.prev")
				.hover(function()
						{
							$(".featured_birds #controls div.prev")
							.html('<img src="/incs/TechKnow_Slider/images/slider_toolbar_prev_on.gif" width="18" height="25" />')
							.css("cursor","pointer");
						},   
						function()
						{
							$(".featured_birds #controls div.prev")
							.html('<img src="/incs/TechKnow_Slider/images/slider_toolbar_prev.gif" width="18" height="25" />')
							.css("cursor","auto");
						});
	
				//if we hover over the next button, lets make it change so the user knows its clickable
				$(".featured_birds #controls div.next")
				.hover(function()
						{
							$(".featured_birds #controls div.next")
							.html('<img src="/incs/TechKnow_Slider/images/slider_toolbar_next_on.gif" width="18" height="25" />')
							.css("cursor","pointer");
						},   
						function()
						{
							$(".featured_birds #controls div.next")
							.html('<img src="/incs/TechKnow_Slider/images/slider_toolbar_next.gif" width="18" height="25" />')
							.css("cursor","auto");
						});
	
				//if prev is clicked on
				$(".featured_birds #controls div.prev")
				.click(function(){goToSlide("Prev", 500);});
				
				//if next is clicked on
				$(".featured_birds #controls div.next")
				.click(function(){goToSlide("Next", 500);});
		   
$("li.step1").fadeIn("fast");

$(".page-id-12 a.button").click(function() { $("li.step2").hide(); $("li.step3").hide(); $(".page-id-12 a.button").removeClass('selected'); $(this).addClass('selected'); $(".page-id-12 .search_type_box").removeClass('selected'); $(this).parents('section.search_type_box').addClass('selected'); $(".page-id-12 form").each (function(){this.reset();}); step2("search_tag", $(this));});
$(".page-id-10 a.button").click(function() {$("li.step3").hide(); $("li.step2").hide(); $(".page-id-10 a.button").removeClass('selected'); $(this).addClass('selected'); step2("pedigree", $(this));});
$(".page-id-12 select").change(function() {$(".page-id-12 a.button").removeClass('selected'); $(".page-id-12 .search_type_box").removeClass('selected'); $(this).parents('section.search_type_box').addClass('selected'); step2("category", $(this));});
$(".page-id-14 li input:first").focus().parent().addClass("selected");
$(".page-id-14 input").focus(function() {	$(".page-id-14 li").removeClass("selected");$(this).parent().addClass("selected"); }); 	   
$(".page-id-14 textarea").focus(function() {	$(".page-id-14 li").removeClass("selected");$(this).parent().addClass("selected"); }); 	   
$(".page-id-14 form").submit(validate_form);
		   
		   });


//this function changes to the next image in the set
function rotateImages()
{
	var oCurPhoto = $(".featured_birds #slides div.current");
	var oNextPhoto = oCurPhoto.next();
	
	//var oAllPhotos = $(".featured_birds #slides div");
	
	if (oNextPhoto.length == 0)
	{
		oNextPhoto = $(".featured_birds #slides div:first");
	}
	
	//oAllPhotos.css({opacity:0.0});
	
	
	
	oCurPhoto.removeClass('current').addClass('previous');
	
	oNextPhoto.css({opacity:0.0})
	.addClass('current')
	.animate({opacity:1.0}, 500, function() {oCurPhoto.removeClass('previous');});
	
	//oCurPhoto.removeClass('current').addClass('previous').css({opacity:0.0});
	
}

//This function responds to the controls 
function goToSlide(oNxtSlide, oAnimInterval)
{
	if (oNxtSlide == "Next")
	{
		var oCurPhoto = $(".featured_birds #slides div.current");
		var oNextPhoto = oCurPhoto.next();
		var oCurSlide = $(".featured_birds #controls ul li.current");
		var oNextSlide = oCurSlide.next();
		
		if (oNextPhoto.length == 0)
		{
			oNextPhoto = $(".featured_birds #slides div:first");
		}
		
		if (oNextSlide.length == 0)
		{
			oNextSlide = $(".featured_birds #controls ul li:first");
		}
	}
	else 
	{
		if (oNxtSlide == "Prev")
		{
			var oCurPhoto = $(".featured_birds #slides div.current");
			var oNextPhoto = oCurPhoto.prev();
			var oCurSlide = $(".featured_birds #controls ul li.current");
			var oNextSlide = oCurSlide.prev();
				
			if (oNextPhoto.length == 0)
			{
				oNextPhoto = $(".featured_birds #slides div:last");
			}
			
			if (oNextSlide.length == 0)
			{
				oNextSlide = $(".featured_birds #controls ul li:last");
			}
		}
			
		else
		{
			//get the next slide based on the index
			var oNextPhoto = $(".featured_birds #slides div").eq(oNxtSlide);
		
			//get the current slide
			var oCurPhoto = $(".featured_birds #slides div.current");
				
			//get the next slide based on the index
			var oNextSlide = $(".featured_birds #controls ul li").eq(oNxtSlide);
				
			//get the current slide
			var oCurSlide = $(".featured_birds #controls ul li.current");
		}
	}
		
	//remove the current class and change it to previous
	oCurPhoto.removeClass('current').addClass('previous');
	oCurSlide.removeClass('current');
	oNextSlide.addClass('current');
		
	//animate the next slide to become the current one and then remove previous class from the old photo
	oNextPhoto.css({opacity:0.0})
	.addClass('current')
	.animate({opacity:1.0}, oAnimInterval, function() {oCurPhoto.removeClass('previous');});
}


function step2(search_type, search_on){
		   var the_search =  '/wp-content/themes/dtl_2011/search/search.php';
		   var the_data = search_type + '=';
		   if (search_type == "category")
		   {
		   	if ($(this).val() != '----')  
              {the_data += search_on.val();
              }
              else
              return null;
           }
		   else
		   the_data += search_on.attr("id"); 	
		   		$.ajax({
		   		type: 'POST',
 				url: the_search,
 				data: the_data,
 				cache: false,
  				success: function(data) {
    			$('li.step2 ul').html(data);
    			$("li.step2").fadeIn("fast");
    			$(".results_img").live('click', function(){step3($(this));});

    			}
});
		   		
	   		
		   		}

function step3(object){
		   	

		  		var the_search =  '/wp-content/themes/dtl_2011/search/get_by_id.php?id=' + object.attr("id");
		   		$.ajax({
 				url: the_search,
 				cache: false,
  				success: function(data) {
  				$(".search_results img").removeClass('selected');
  				object.addClass('selected');
    			$('section.details_box').html(data);
   				}
});
		   		$("li.step3").fadeIn("fast");
		   		return false;
		   		}
		   		
function validate_form(){
	var number_of_errors = 0;
	var error_message = '';
	var email_filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z]{2,4})+$/;

	$("p.error").remove();
	$(".page-id-14 li").removeClass("error");
	
	if ($("input#submitter_name").val().length < 2){
	$("input#submitter_name").parent().addClass("error");
	number_of_errors++;
	error_message += 'Please enter your name.<br />';
	}
	
	if (!email_filter.test($("input#submitter_email").val()))
	{
	$("input#submitter_email").parent().addClass("error");
	number_of_errors++;
	error_message += 'Please enter your valid email address.<br />';
	}
	
	if ($("input#subject").val().length < 4){
	$("input#subject").parent().addClass("error");
	number_of_errors++;
	error_message += 'Please enter a subject.<br />';
	}
	
	if ($("textarea#comments").val().length < 6){
	$("textarea#comments").parent().addClass("error");
	number_of_errors++;
	error_message += 'Please enter your question or comment.<br />';
	}
	
	if (number_of_errors)
	{
		//alert(number_of_errors + ' errors found');
		$(".page-id-14 li").removeClass("selected");
		$('<p class="error">' + error_message + '</p>').insertBefore($("fieldset.contact fieldset ol"));
		return false;
	}
}

		   

