// JavaScript Document

	$.noConflict();
	jQuery(document).ready(function($) {
	
		$('.date_has_event').each(function () {
		// options
		var distance = 10;
		var time = 250;
		var hideDelay = 500;

		var hideDelayTimer = null;

		// tracker
		var beingShown = false;
		var shown = false;

		var trigger = $(this);
		var popup = $('.events ul', this).css('opacity', 0);

		// set the mouseover and mouseout on both element
		$([trigger.get(0), popup.get(0)]).mouseover(function () {
			// stops the hide event if we move from the trigger to the popup element
			if (hideDelayTimer) clearTimeout(hideDelayTimer);

			// don't trigger the animation again if we're being shown, or already visible
			if (beingShown || shown) {
				return;
			} else {
				beingShown = true;

				// reset position of popup box
				popup.css({
					bottom: 20,
					left: -76,
					display: 'block' // brings the popup back in to view
				})

				// (we're using chaining on the popup) now animate it's opacity and position
				.animate({
					bottom: '+=' + distance + 'px',
					opacity: 1
				}, time, 'swing', function() {
					// once the animation is complete, set the tracker variables
					beingShown = false;
					shown = true;
				});
			}
		}).mouseout(function () {
			// reset the timer if we get fired again - avoids double animations
			if (hideDelayTimer) clearTimeout(hideDelayTimer);

			// store the timer so that it can be cleared in the mouseover if required
			hideDelayTimer = setTimeout(function () {
				hideDelayTimer = null;
				popup.animate({
					bottom: '-=' + distance + 'px',
					opacity: 0
				}, time, 'swing', function () {
					// once the animate is complete, set the tracker variables
					shown = false;
					// hide the popup entirely after the effect (opacity alone doesn't do the job)
					popup.css('display', 'none');
				});
			}, hideDelay);
		});
	});
	
		var project = $('#banner_image');
		animationTime = 500,  // scroll time in milliseconds
		animationWidth = 776; // image width = 460 + 20px padding between images	
		//leftPadding = parseInt( project.find('ul').css('padding-left'), 10);

		$('#banner_image').cycle({
			fx: 'scrollLeft' // choose your transition type, ex: fade, scrollUp, shuffle, etc...
		});
		
		$('#google_map small a').css("color","#58595b");
		$('#google_map small a').mouseenter(function() {
			$('#google_map small a').css("color","#3b846d");
		});
		$('#google_map small a').mouseleave(function() {
			$('#google_map small a').css("color","#58595b");
		});
		$('#google_map small a').click(function() {
			$('#google_map small a').attr("target", "_blank");
		});
	
		$(':input[name=newsletter_email]').click(function() {
			var whatsintextbox = $(this).val();
			if (whatsintextbox == 'enter email address') {
				$(this).val('');
				$(this).css('color','#58595b');
			}
		});

		$(':input[name=newsletter_email]').blur(function() {
			var whatsintextbox = $(this).val();
			if (whatsintextbox == '') {
				$(this).val('enter email address');
				$(this).css('color','#bcbec0');
			}
		});
		
		$('#newsletter_submit').mouseenter(function() {
			$(this).css('cursor','pointer');
		});

		$("input[name=name]").focus(function() {
			$("input[name=name]").css('background','#e7e8e9');
			$("input[name=name]").css('color','black');
			$("input[name=name]").val('');
		});
	
		$("input[name=email]").focus(function() {
			$("input[name=email]").css('background','#e7e8e9');
			$("input[name=email]").css('color','black');
			$("input[name=email]").val('');
		});
		
		$("#message").focus(function() {
			$("#message").css('background','#e7e8e9');
			$("#message").css('color','black');
			$("#message").val('');
		});	

		$('#contact_form_submit').click(function(e) {
			var sName = $("input[name=name]").val();
			var sEmail = $("input[name=email]").val();
			var sMessage = $("#message").val();
			
			if (sName == '') {
				$("input[name=name]").css('background','red');
				$("input[name=name]").css('color','pink');
				$("input[name=name]").val('cannot be empty');
			}
			if (sEmail == '') {
				$("input[name=email]").css('background','red');
				$("input[name=email]").css('color','pink');
				$("input[name=email]").val('cannot be empty');
			}
			if (sMessage == '') {
				$("#message").css('background','red');
				$("#message").css('color','pink');
				$("#message").val('cannot be empty');
			}
				
			if ((sName != '') && (sEmail != '') && (sMessage != '' )) {
	
				if ((jQuery.trim(sName) != "cannot be empty") && (jQuery.trim(sEmail) != "cannot be empty") && (jQuery.trim(sMessage) != "cannot be empty")) {
				
					$("input[name=name]").css('readonly','true');
				
					$.post("assets/includes/ajax_mail.php", { name : sName, email : sEmail, message : sMessage },
					 function(data){
						$("#response p").html(data);
						$("#response").show();
						$("input[name=name]").val('');
						$("input[name=email]").val('');
						$("#message").val('');
						$("#contact_form").hide();
					 }, "json");
				}
			}
		});
	
		$('#newsletter_submit').click(function() {
			var whatsintextbox = $(':input[name=newsletter_email]').val();
			$('#newsletter_error').css('color','#f84637');
			$('#newsletter_error').fadeIn("fast", function() {});
			if ((whatsintextbox == 'enter email address') || (whatsintextbox == '')) {
				$(':input[name=newsletter_email]').css('border-color','#f84637');
				$('#newsletter_error').css('color','#f84637');
				$('#newsletter_error').html('Please enter a valid email address!');
			}else{
				$(':input[name=newsletter_email]').css('border-color','#e7e8e9');
				$('#newsletter_error').html('');
				var email = $(':input[name=newsletter_email]').val();
				// Do something with the email address
				alert(email);
				var email_success = true;
				// Do something with the result
				if (email_success == true) {
					$('#newsletter_error').css('color','#58595b');
					$('#newsletter_error').html('Email added successfully!');
					$('#newsletter_error').fadeOut(1600, "linear", function() {
						$(':input[name=newsletter_email]').val('');
						$(':input[name=newsletter_email]').val('enter email address');
						$(':input[name=newsletter_email]').css('color','#bcbec0');
					});
					

				}else{
					$('#newsletter_error').css('color','#f84637');
					$('#newsletter_error').html('There was an error with the email address!');
				}
			}
		});
		
		$('#next_image').mouseenter(function() {
			$(this).css('background-Image','url(assets/images/layout/next_image_hover.png)');
			$(this).css('cursor','pointer');
		});

		$('#next_image').mouseleave(function() {
			$(this).css('background-Image','url(assets/images/layout/next_image.png)');
		});
		
		$('#prev_image').mouseenter(function() {
			$(this).css('background-Image','url(assets/images/layout/prev_image_hover.png)');
			$(this).css('cursor','pointer');
		});

		$('#prev_image').mouseleave(function() {
			$(this).css('background-Image','url(assets/images/layout/prev_image.png)');
		});
		
		 // *** Next image ***
		 $('#next_image').click(function() {
		  currentimg = project.find('li.current');
		  nextimg = (currentimg.next().is('li')) ? currentimg.next() : project.find('.images-list li:first');
		  
		  currentimg
		   .removeClass('current')
		   .addClass('animating')
		   .css('left', leftPadding)
		   .animate({
			left: '-=' + animationWidth
		   }, animationTime, function(){
			$(this).removeClass('animating');
		   });
		
		  nextimg
		   .addClass('animating')
		   .css('left', (animationWidth + leftPadding) + 'px')
		   .animate({
			left: 0 + leftPadding
		   }, animationTime, function(){
			$(this).removeClass('animating').addClass('current');
		   })
		
		  return false;
		 });
		
		 // *** Prev image ***
		 $('#prev_image').click(function() {
		  currentimg = project.find('.images-list li.current');
		  previmg = (currentimg.prev().is("li")) ? currentimg.prev() : project.find('.images-list li:last');
		
		  currentimg
		   .addClass('animating')
		   .css('left', leftPadding)
		   .removeClass("current")
		   .animate({
			left: '+=' + animationWidth
		   }, animationTime, function(){
			$(this).removeClass('animating');
		   });
		
		  previmg
		   .addClass('animating')
		   .css('left',  '-' + (animationWidth) + 'px')
		   .animate({
			left: '+=' + (animationWidth + leftPadding)
		   }, animationTime, function(){
			$(this).removeClass('animating').addClass('current');
		   })
		
		  return false;
		 });
	
		//$("#cal-url").calendar({ templateUrl: 'training_services/courses/day-month-year/' });
	
	});

