$.fn.placeholdr = function(val) {
	
	$(this).val(val);
	
	$(this).click(function(){
		if($(this).val() == val){	
			$(this).val('');
		}
	});
}

$(document).ready(function(){
	
	$('.clickable').clickable().css('cursor','pointer');
		
	$('.text.placeholder').placeholdr('Enter email address');
	$('.search_placeholder').placeholdr('Search Library Theatre&hellip;');
	
	$('#back-to-top').click(function(){
		$(document).scrollTo( $(this).attr('href'), 800, {easing:'easeOutCubic'} );
		return false;
	});
	
	$("#field-site-search").placeholdr();
	$("#field-subscribe").placeholdr();

	//Social media bookmarks
	$('a.share-button').click(function(){
		if( $('#unit-social-media-bookmarks').css('display') == 'block' ){
			$('#unit-social-media-bookmarks').fadeOut('fast');
		}else{
			$('#unit-social-media-bookmarks').fadeIn('fast');
		}
		return false;
	});
	$('#social-media-close').click(function(){
		$('#unit-social-media-bookmarks').fadeOut('fast');
		return false;
	});
	$('#add-another-email-address').click(function(){
		var newAddr = $('#share-email-list li:first').clone();
		newAddr.children('input').addClass('placeholder').val('Enter email address').placeholdr();
		$('#share-email-list').append(newAddr);
		return false;
	});
	
	$('#btn-share-by-email').click(function(){
		var emailAddress = [];
		$('#share-email-list input').each(function(){
			emailAddress.push($(this).val());
		});
			
		$(this).attr('value', 'Sending...');
			
		var data = {
			"object-type": $('#object-type').val(), 
			"object-id": $('#object-id').val(),
			"email": emailAddress
		}
		$.post('/mmlib/includes/ajax/ajax.sendtofriend.php/', data, function(){
			$('#share-email-list li:gt(0)').remove();
			$('#btn-share-by-email').attr('value', 'Send');
			$('#share-email-list li input').addClass('placeholder').val('Enter email address');
			$('#unit-social-media-bookmarks').fadeOut('fast');
			alert('Your message has been sent');
		});
		return false;
	});
	
});
