// JavaScript Document
//jfunctions.js

$(document).ready(function(){

		/**
		* submiting the contact form
		*
		*/
		$("div.formError").hide();
		$("div.formSuccess").hide();
		$("form#contactForm").submit(function(){
				alert("Contact Submitted");
				
				var errorMsg = "";
				
				var name = jQuery.trim($("#name").val());
				var email =  jQuery.trim($("#email").val());
				var comment = jQuery.trim($("#comment").val());
				
				if (name == "") { errorMsg += "- Name is Mandatory<br>"; }
				if (email == "") { errorMsg += "- Email is Mandatory<br>"; }
				if (comment == "") { errorMsg += "- Comment is Mandatory<br>"; }
				
				if (errorMsg)
					{
					$("div.formError").show();	
					$("#err_block").html("Check the following Errors<br>"+errorMsg);	
					return false;			
					} 
								
				var dataStr = $("form#contactForm").serialize();
				
				//send the form as an ajax reques 
				//and get back the result;
				$.ajax({
					type: "POST",
					url: "send_mail.php",
					data: dataStr,
					beforeSend: function(){
						$('div#contactWrapper').html("<div align='center'><img src='images/ajax_loading.gif' border='0' /></div>");	
					},					
					success: function(data){
								alert(data);
								if (data == "success")
									{
									$("div.formSuccess").show().html("Your comments have been sent to the author. He will contact you at the earliest for the same.");	
										
									} else {
										$("div.formError").show().html("Your comments had error, it cannot be sent to the author.");
										}
						}

				});
			return false;
			
		});

		
		/**
		* navigation for 
		* for the book
		* implemented in the book index
		* and also in the side bar
		* both follow the same pattern
		*/
		$("div.partName")
			.hover(
				function(){		
				$(this).css({'backgroundColor':'#F1FCE3'});
				},
				function(){		
					$(this).css({'backgroundColor':'#FFF'});
				}
			)
			.click(
				function(){			
					$(this).next(".partWrapper").toggle('slow');	
				});	


		/**
		* do a random teaser slide show
		* to run after every 5 secons
		*/
		showTeaser();	
			
});


function showTeaser(){

	$("#slider").fadeOut('slow', 
					function(){
						$("#slider").load("teaser_slide.php").fadeIn("slow");
					});
  setTimeout('showTeaser()',10000);
};  
