$(window).load(function(){
	$('div.feat-thumb').bind('mouseenter', function (e) {
		$('div.textHol',this).fadeIn("normal");
	})
	.bind('mouseleave', function (e) {
		$('div.textHol',this).fadeOut("normal");
	});
	
	
	$('div.entry-content').each(function() {
		
	  	$(this).bind('mouseenter', function (e) {
	  		$('div.textHol',this).fadeOut("normal");
	  		$('.featTextBox',this).fadeIn();
	  	})
	  	$(this).bind('mouseleave', function (e) {
	  		$('div.textHol',this).fadeIn("normal");
	  		$('.featTextBox',this).fadeOut();
	  	})
	});

	$('ul.authlist').jScrollPane();
});

$(document).ready(function(){
	var links = $('div a');
	links.hover(function() {
		old_title = $(this).attr('title');
		$(this).attr('title','');
	},
	function(){
		$(this).attr('title', old_title);
	});
	
	$('.featTextBox').hide();
	
	$('#about-dialog').dialog({
		autoOpen: false,
		width: 570,
		modal: true,
		closeOnEscape: true
	});
	
	$('#contact-dialog').dialog({
		autoOpen: false,
		width: 640,
		modal: true,
		closeOnEscape: true
	});

	$('#about-link').click(function(){
		$('#about-dialog').dialog('open');
		$(document).bind('click', dialogBlur);
		return false;
	});
	
	$('#contact-link').click(function(){
		$('#contact-dialog').dialog('open');
		$(document).bind('click', dialogBlur);
		return false;
	});
	
	$('.error').hide();
	$('.send').click(function() {
		
		$('.error').hide();
		var name = $("input#name").val();
		if (name == "") {
			$("label#name-error").show();
			$("input#name").focus();
			return false;
		}
		
		var subject = $("input#subject").val();
		if (subject == "") {
			$("label#subject-error").show();
			$("input#subject").focus();
			return false;
		}
		
		var message = $("textarea#message").val();
		if (message == "") {
			$("label#message-error").show();
			$("textarea#message").focus();
			return false;
		}
		
		var dataString=$("form#contactform").serialize(); 
		//alert (dataString); return false;
		$.ajax({
			type: "POST",
			url: "http://www.thedailystreet.co.uk/wp-content/themes/thedailystreet/scripts/process.php",
			data: dataString,
			success: function() {
				$('#contact-dialog').html("<div id='response'></div>");
				$('#response').html("<p>Contact form submitted!</p>")
				.append("<p>We will be in touch soon.</p>");
			}
		});
		return false;
	});
});

var dialogBlur = function(event){
	var target = $(event.target);
	if (target.is('.ui-dialog') || target.parents('.ui-dialog').length) {
		return;
	};

	$('.ui-dialog:visible').find('.ui-dialog-titlebar-close').trigger('click');

	$(document).unbind('click', dialogBlur);
};
