$(document).ready(function() {
/**
 * General scripts
 *
 */

	$('.post img').closest('p').addClass('blog-image-container');
	
	$('.comments .comment:first').addClass('first');
	$('.comments .comment:last').addClass('last');
		
/**
 * Validate contact form
 *
 */

	$("form#contact-form").validate({
		rules:
		{
			name:
			{
				required: true
			},
			email:
			{
				required: true,
				email: true
			},
			phone:
			{
				required: true
			},
			comments:
			{
				required: true
			}
		},
		errorLabelContainer: "#error_display",
		wrapper: "p",
		errorClass: "invalid"
	});
	
/**
 * Calendar event popup
 *
 */

	//select all the a tag with name equal to modal
	$('a.modal').live('click', function(e) {

	// Mask

		// Cancel the link behavior
		e.preventDefault();
		
		// Get the mask height and width
		var maskHeight = $("#mask").height();
		var maskWidth = $("#mask").width();
		
		// Set heigth and width to mask to fill up the whole area
		$('#mask').css({'width':maskWidth,'height':maskHeight});
		
		//transition effect		
		$('#mask').fadeIn(100);	
		$('#mask').fadeTo("slow",0.4);
		
	// Window		
		
		// entry ID clicked from a tag
		var id = $(this).attr('rel');
		var dialogDiv = $("#dialog-"+id);

		//Get the window height and width
		var winH = $(window).height();
		var winW = $(window).width();

		//Set the popup window to center
		//$(".window").css('top',  maskHeight/2-dialogDiv.height()/2);
		//dialogDiv.css('left', maskWidth/2-dialogDiv.width()/2);
	
		//transition effect
		dialogDiv.fadeIn(500);
	
	});
	
	//if close button is clicked
	$('.window .close').live('click', function (e) {
		//Cancel the link behavior
		e.preventDefault();
		
		$('#mask').hide();
		$('.window').hide();
	});		
	
	//if mask is clicked
	$('#mask').live('click', function () {
		$(this).hide();
		$('.window').hide();
	});
	
});
