// JavaScript Document
// initialise plugins


$(document).ready(function() {
	$("#cForm").validate();
	//$("#homeform").validate();
	
	
	//jQuery.validator.addMethod("defaultInvalid", function(value, element) 
//    {
//     switch (element.value) 
//     {
//      case "Name": 
//       if (element.name == "Name")
//          return false;
//	   case "Email": 
//       if (element.name == "Email")
//          return false;
//		   case "Phone": 
//       if (element.name == "Phone Number")
//          return false;
//     }
//    }
////



jQuery.validator.addMethod("notEqual", function(value, element, param) {
  return this.optional(element) || value !== param;
}, "");
	
$("#homeform").validate(
{
	  rules: { 
	name: {
		required:true,
		notEqual:"Name"
	},
	email: {
		required:true,
		notEqual:"Email"
	},
	phone: {
		required:true,
		notEqual:"Phone Number"
	}

	
	
	  }
}
);


		
		
		$("#form-username").focus(function() { 
			var firstname = $("#form-firstname").val(); 
			var lastname = $("#form-lastname").val(); 
			if(firstname && lastname && !this.value) { 
				this.value = firstname + "." + lastname; 
			} 
		});
	//google map 
	if ($('#googleMap').length != 0) {
	//alert('google map');
	initialize();
	}
	//gallery
$('#fancyGallery').fancygallery({thumbHeight:160,width:900,height:700, columns:3, columnOffset:20,thumbOpacity:0.8,imagesPerPage:9,boxOptions: {animationSpeed:'slow',theme:'light_rounded'}});
	//MENU
	 $('ul.sf-menu').superfish();
	 
	 //basic slideshows
    $('.slideshow').cycle({
		fx: 'fade' // choose your transition type, ex: fade, scrollUp, shuffle, etc...
	});
	//home page slideshow
	 $('#slideshow').cycle({
            timeout: 5000,  // milliseconds between slide transitions (0 to disable auto advance)
            fx:      'fade', // choose your transition type, ex: fade, scrollUp, shuffle, etc...            
            pager:   '#pager',  // selector for element to use as pager container
            pause:   0,	  // true to enable "pause on hover"
            pauseOnPagerHover: 0 // true to pause when hovering over pager link
        });
		$('#featured').cycle({
            timeout: 12000,  // milliseconds between slide transitions (0 to disable auto advance)
            fx:      'scrollUp', // choose your transition type, ex: fade, scrollUp, shuffle, etc...                        
            pause:   0,	  // true to enable "pause on hover"
            pauseOnPagerHover: 0 // true to pause when hovering over pager link
        });          
	
	
//for the commenting system
	/* The following code is executed once the DOM is loaded */
	
	/* This flag will prevent multiple comment submits: */
	var working = false;
	
	/* Listening for the submit event of the form: */
	$('#addCommentForm').submit(function(e){

 		e.preventDefault();
		if(working) return false;
		
		working = true;
		$('#submit').val('Working..');
		$('span.error').remove();
		
		/* Sending the form fileds to submit.php: */
		$.post('_cms_submit.php',$(this).serialize(),function(msg){

			working = false;
			$('#submit').val('Submit');
			
			if(msg.status){

				/* 
				/	If the insert was successful, add the comment
				/	below the last one on the page with a slideDown effect
				/*/

				$(msg.html).hide().insertBefore('#addCommentContainer').slideDown();
				$('#body').val('');
			}
			else {

				/*
				/	If there were errors, loop through the
				/	msg.errors object and display them on the page 
				/*/
				
				$.each(msg.errors,function(k,v){
					$('label[for='+k+']').append('<span class="error">'+v+'</span>');
				});
			}
		},'json');

	});

});
