jQuery(document).ready(function($){
	
	//show / hide profiles
    //hide initially
	$('.profile-content-2').each(function(){
		$(this).css({'display':'none'});
	});
	$('.more-profile').toggle(function(){
		
		$(this).parent().find('.profile-content-2').slideDown('fast');
		
	}, 
	function()
	{
		$(this).parent().find('.profile-content-2').slideUp('fast');
	});
	
	//ajax function to update cart values on page
	$('.add_to_cart, .featured_button2').click(function(){
		var t = setTimeout(function(){
		
			$.ajax({
			
			type:"POST",
				url: site_url + "/get-cart.php",
				dataType: 'json',
				success:function(data)
				{
					$('.item-count').html(data.count);
					$('.cart-total').html(data.total);
					clearTimeout(t);
				},
				error:function()
				{
					alert('error');
				}
		
			});//end ajax
		
		}, 500);
		
		
	});//end add to cart click
	
	//AJAX PROCESSING OF CONTACT FORM
	
	$('#contact-form').submit(function(){
		
		//display a loading message
		$('.required-field').html('Processing, please wait...');
		
		//do the ajax call to process-contact-form.php
		$.ajax({
			
			type:"POST",
			url: site_url + "/wp-content/themes/defaulttheme/process-contact-form.php",
			data: {
				name: $('#name').val(),
				contact_email: $('#contact_email').val(),
				contact_phone: $('#contact_phone').val(),
				inquiry: $('#inquiry').val(),
				vercode: $('#vercode').val()
			},
			success: function(data)
			{
				$('.required-field').html(data);
				if(data == 'Thank you, we will get back to you asap.')
				{
					$('.contact-form').css({'display':'none'});
				}
			},
			error: function()
			{
				$('.required-field').html('There has been a processign error sorry');
			}
		});
		
		//finally dont reload page
		return false;
	
	});//end ajax call
	
	//AJAX PROCESSING OF CONTACT FORM

	//AJAX PROCESSING OF EVENT FORM
	
	$('#register-form').submit(function(){
		
		//display a loading message
		$('.text-information').html('Processing, please wait...');
		
		//do the ajax call to process-register-form.php
		$.ajax({
			
			type:"POST",
			url: site_url + "/wp-content/themes/defaulttheme/process-register-form.php",
			data: {
				eid: $('#eid').val(),
				etitle: $('#etitle').html(),
				fname: $('#fname').val(),
				lname: $('#lname').val(),
				phone: $('#phone').val(),
				email: $('#email').val()
			},
			success: function(data)
			{
				$('.text-information').html(data);
				if(data == 'Thankyou for registering, you will recieve an email shortly.')
				{
					$('#register-form').css({'display':'none'});
					var cur = Number($('.places-'+$('#eid').val()).html());
					$('.places-'+$('#eid').val()).html(cur - 1);
				}
			},
			error: function()
			{
				$('.text-information').html('There has been a processing error sorry');
			}
		});
		
		//finally dont reload page
		return false;
	
	});//end ajax call
	
	//AJAX PROCESSING OF EVENT FORM

	
	//toggle the display of the form
	$('#enews-link, #enews-link-3a, #enews-link-3b').click(function(){
		$("#subscribe").slideDown('fast');
	});
	$('.closebtn').click(function(){
		$("#subscribe").slideUp('fast');
		$('#subscribe .message').html('');//empty the message field
		$('#subscribe > input').css({'display':'block'});//reshow the form fields
	});
	
	//do stuff with the form data
	$("#subscribe").submit(function(){
		
		//set an initial message
		$('#subscribe .message').html('<p>Processing, please wait..</p>');
		
		//do the ajax shit
		$.ajax({
		
			type:"POST",
			url: site_url + "/wp-content/themes/defaulttheme/process-subscribe-form.php",
			data: {
				fname: $('#sfname').val(),
				lname: $('#slname').val(),
				email: $('#semail').val()
			},
			success: function(data)
			{
				if(data == '<p>Thanks! Check you inbox for confirmation.</p>')
				{
					$('#subscribe > input').css({'display':'none'});
				}
				$('#subscribe .message').html(data);
			},
			error: function()
			{
				$('#subscribe .message').html('There has been a processing error sorry');
			}
		
		});//end ajax
		
		//finally dont reload the page
		return false;
	});
	
	//SUBSCRIBE TO NEWSLATTER STUFF
	
	
	//POPUP FORMS
	
	//both forms do the same overlay shit to
	$('.ev').overlay({
		
		  mask: {opacity:0.9, color:'#007AA4'},
		  closeOnClick: false,
		  fixed: false,
		  top:50,
		  onClose: function()
		  {
			  $('#register-form').css({'display':'block'});
		  }
		
	});
	$('.cont').overlay({
		
		  mask: {opacity:0.9, color:'#007AA4'},
		  closeOnClick: false,
		  fixed: false,
		  top:50,
		  onClose: function()
		  {
			  $('.contact-form').css({'display':'none'});
		  }
		
	});
	
	//load the contact form overlay when you click the contact button
	$('.poplight').click(function(){
		$('.cont').data('overlay').load();
	});
	
	//load the event rego form overlay when you click a register button
	$('.popreg').click(function(){
		
		//get the "event and title" attr of the link to pass to the form**********
		var eid = $(this).attr('event');
		$("#eid").val(eid);
		
		var etitle = $(this).attr('title');
		$("#etitle").html(etitle);
		
		$('.ev').data('overlay').load();
	});
	
	//POPUP FORMS
	
});
