$(window).load(function() {
	
	$.fn.loopedSlider.defaults.addPagination = true;
	$('#loopedSlider').loopedSlider({autoStart: 11000});
	
	$('.menu li').bind("mouseenter", function(e) {
		$(this).addClass('active');
		$(this).find('ul.sub:first').show();
	});
	
	$('.menu li').bind("mouseleave", function(e) {
		$(this).removeClass('active');
		$(this).find('ul.sub:first').hide();
	});
	
});



 
			$(document).ready(function()
			{
				setupRotator();
			});	
			function setupRotator()
			{
				if($('.textItem').length > 1)
				{
					$('.textItem:first').addClass('current').fadeIn(1500);
					setInterval('textRotate()', 6000);
				}
			}
			function textRotate()
			{
				var current = $('#quotes > .current');
				if(current.next().length == 0)
				{
					current.removeClass('current').fadeOut(1000);
					$('.textItem:first').addClass('current').fadeIn(1500);
				}
				else
				{
					current.removeClass('current').fadeOut(1000);
					current.next().addClass('current').fadeIn(1500);
				}
			}

			
function checkForm(id, fields){
	$('#errorMsg').empty();
	var html = "";
	var a = fields.split(',');
	for(var i = 0; i<a.length; i++){
		if($.trim($('#'+a[i]).val()) == ''){
			html = html + "<li>"+upperCaseFirstLetter(a[i]) +" is Required.</li>"
		}
	}
	if(html != ''){
		$('#errorMsg').append(html)
	} else {
		$.ajax({
		   type: "POST",
		   url: "checkAnswer.php",
		   data: {answer: $('#answer').val()},
		   dataType : 'json',
		   success: function(msg){
		     if(msg.success == true){
		    	 $('#errorMsg').empty();
		    	 $('#'+id).submit();
		     } else {
		 		 $('#errorMsg').append("<li>Answer is error.</li>");
		     }
		   }
		});
	}
}


function upperCaseFirstLetter(s){
	return a = s.substr(0, 1).toUpperCase() + s.substring(1);  
}
