/*
	Easy plugin to get element index position
	Author: Peerapong Pulpipatnan
	http://themeforest.net/user/peerapong
*/

$.fn.getIndex = function(){
	var $p=$(this).parent().children();
    return $p.index(this);
}

$.fn.setNav = function(){
	jQuery('#main_menu li ul').css({display: 'none'});

	jQuery('#main_menu li').each(function()
	{	
		
		var $sublist = jQuery(this).find('ul:first');
		
		jQuery(this).hover(function()
		{	
			$sublist.stop().css({overflow:'hidden', height:'auto', display:'none'}).slideDown(200, function()
			{
				jQuery(this).css({overflow:'visible', height:'auto'});
			});	
		},
		function()
		{	
			$sublist.stop().slideUp(200, function()
			{	
				jQuery(this).css({overflow:'hidden', display:'none'});
			});
		});	
		
		jQuery(this).click(function()
		{
			$(this).children('a').click(function(event){
				event.stopPropagation();
			});
		});
		
		if($(this).find('a:first').attr('title').length > 0)
		{
			var iconURL = $(this).find('a:first').attr('title');
			$(this).find('a:first').attr('title', $(this).find('a:first').html());
			$(this).find('a:first').prepend('<img src="'+iconURL+'" class="mid_align" alt=""/>');
		}
		
	});
}

$(document).ready(function(){ 

	$(document).setNav();

	$('.portfolio_image').fancybox({ 
		padding: 0,
		overlayColor: '#000', 
		overlayOpacity: .9
	});
	
	$('.img_frame').fancybox({ 
		padding: 0,
		overlayColor: '#000', 
		overlayOpacity: .9
	});
	
	$('.one_third .gallery_image').hover(function(){  
 			$(this).find('.gallery3_hover').css({ 'top': '-193px', 'visibility': 'visible', 'opacity': 0.8 }).fadeIn(400);
 			
 			$(this).click(function(){
 				$(this).find('a').click();
 			});
 		}  
  		, function(){  
  		
  			$(this).find('.gallery3_hover').fadeOut();
  		}  
  		
	);
	
	$.validator.setDefaults({
		submitHandler: function() { 
		    var actionUrl = $('#contact_form').attr('action');
		    
		    $.ajax({
  		    	type: 'POST',
  		    	url: actionUrl,
  		    	data: $('#contact_form').serialize(),
  		    	success: function(msg){
  		    		$('#contact_form').hide();
  		    		$('#reponse_msg').html(msg);
  		    	}
		    });
		    
		    return false;
		}
	});
		    
		
	$('#contact_form').validate({
		rules: {
		    your_name: "required",
		    email: {
		    	required: true,
		    	email: true
		    },
		    message: "required"
		},
		messages: {
		    your_name: "Please enter your name",
		    email: "Please enter a valid email address",
		    agree: "Please enter some message"
		}
	});
	
	$.validator.setDefaults({
		submitHandler: function() { 
		    var actionUrl = $('#reservation_form').attr('action');
		    
		    $.ajax({
  		    	type: 'POST',
  		    	url: actionUrl,
  		    	data: $('#reservation_form').serialize(),
  		    	success: function(msg){
  		    		$('#reservation_form').hide();
  		    		$('#reponse_msg').html(msg);
  		    	}
		    });
		    
		    return false;
		}
	});
		    
		
	$('#reservation_form').validate({
		rules: {
		    your_name: "required",
		    email: {
		    	required: true,
		    	email: true
		    },
		    phone: "required",
		    when: "required",
		    message: "required"
		},
		messages: {
		    your_name: "Please enter your name",
		    email: "Please enter a valid email address",
		    phone: "Please enter your phone number",
		    when: "Please select the date",
		    message: "Please enter some message"
		}
	});
	
	$(".datepicker").datepicker();

});
