
	jQuery(document).ready(function($) {
	
		var email_link = jQuery('a.email_link');
		var email_popup = jQuery('div.email_popup');
		var email_form = jQuery('form#email_link');
		var process_url = email_form.attr('action');
		var process_message = jQuery('div.message');
	
		// shortlist email related functionalities
		var email_shortlist = jQuery('#shortlist a.email_shortlist');
		var email_shortlist_form = jQuery('form#email_shortlink');
		
		var contact_form = jQuery('form#contact_sidebar_form');
	
		email_popup.hide();
		process_message.hide();
		
		email_link.click(function(e) {
			e.preventDefault();
			email_popup.fadeToggle('fast');
			jQuery('input.sender').focus();
		});
		
		contact_form.submit(function() {

			jQuery.ajax({
				type: 'POST',
				url: contact_form.attr('action'),
				data: $(this).serialize(),
				success: function(data) {
					
					if( ! data.sent) {
						alert(data.result);
					} else {
						jQuery('form#contact_sidebar_form .text').val("");
						alert(data.result);
					}				
				},
				dataType: 'json'
			});
		
			return false;
		
		});		

		email_form.submit(function() {

			jQuery.ajax({
				type: 'POST',
				url: process_url,
				data: $(this).serialize(),
				success: function(data) {
					
					if( ! data.sent) {
						alert(data.result);
						email_form.animate({'opacity':1});
					} else {
						email_form.animate({'opacity':0});
						process_message.html(data.result);
						process_message.fadeIn('fast');
					}				
				},
				dataType: 'json'
			});
		
			return false;
		
		});

		email_shortlist_form.submit(function( event ) {

	event.preventDefault();
			$msg_body = "hey check my favourite artist list from Allegro Music Entertainment Booking Agency Melbourne Australia\n";
			$msg_body += "---------------------------------\n";

			$list = jQuery('#shortlist a.short_link');
			
			jQuery.each($list, function(key, value) { 
				$msg_body += jQuery(value).html() + "\n";
				$msg_body += jQuery(value).attr('href') + "\n";
				$msg_body += "---------------------------------\n";
			});
			
			jQuery('#msg_content').val( $msg_body);
			
			jQuery.ajax({
				type: 'POST',
				url: process_url,
				data: $(this).serialize(),
				success: function(data) {
					
					if( ! data.sent) {
						alert(data.result);
					} else {
						jQuery('#shortlist').removeClass('show_form');						
						alert('Short List Sent Successfully');
					}				
				},
				dataType: 'json'
			});
			
			return false;
		
		});


		
		email_popup.find('a.close').click(function(e) {
			e.preventDefault();
			email_popup.fadeToggle('fast');
		});
	

	});

