(function($){	
	
	// -------------------------------------------------------------------------------------------------------
	// Form Validation script - used by the Contact Form script
	// -------------------------------------------------------------------------------------------------------
	
	function validateMyAjaxInputs() {

		$.validity.start();
		// Validator methods go here:
		$("#name").require();
		$("#email").require().match("email");
		$("#subject").require();	

		// End the validation session:
		var result = $.validity.end();
		return result.valid;
	}

	$(document).ready(function(){
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////						   
		
		// -------------------------------------------------------------------------------------------------------
		// Dropdown Menu
		// -------------------------------------------------------------------------------------------------------
		
		$("ul#dropdown-menu li").hover(function () {
												 
			$(this).addClass("hover");
			$('ul:first', this).css({visibility: "visible",display: "none"}).slideDown(200);
		}, function () {
			
			$(this).removeClass("hover");
			$('ul:first', this).css({visibility: "hidden"});
		});
		
		if ( ! ( $.browser.msie && ($.browser.version == 6) ) ){
			$("ul#dropdown-menu li ul li:has(ul)").find("a:first").addClass("arrow");
		}
		
		// -------------------------------------------------------------------------------------------------------
		// Contact Form 
		// -------------------------------------------------------------------------------------------------------
		
		$("#contact-form").submit(function () {
											
			if (validateMyAjaxInputs()) { //  procced only if form has been validated ok with validity
				var str = $(this).serialize();
				$.ajax({
					type: "POST",
					url: "_layout/php/send.php",
					data: str,
					success: function (msg) {
						$("#formstatus").ajaxComplete(function (event, request, settings) {
							if (msg == 'OK') { // Message Sent? Show the 'Thank You' message
								result = '<div class="successmsg">Your message has been sent. Thank you!</div>';
							} else {
								result = msg;
							}
							$(this).html(result);
						});
					}
		
				});
				return false;
			}
			
		});
			
		// -------------------------------------------------------------------------------------------------------
		// Portfolio Fade 
		// -------------------------------------------------------------------------------------------------------
		
		if ($.browser.msie && $.browser.version < 7) return;

			$(".portfolio-item-preview img").fadeTo(1, 1);
			$(".portfolio-item-preview img").hover(
			
			function () {
				$(this).fadeTo("fast", 0.60);
			}, function () {
				$(this).fadeTo("slow", 1);
			});
			
		// -------------------------------------------------------------------------------------------------------
		// ScrollTo - index services overview
		// -------------------------------------------------------------------------------------------------------

		$('#services-menu li a').click(function () {								 
			$("#services-menu li a").removeClass("active");
			$(this).addClass("active");
		});
			
	
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////	
	});

	
	// -------------------------------------------------------------------------------------------------------
	// Form Validation script - used by the Contact Form script
	// -------------------------------------------------------------------------------------------------------
	
	function validateEmp() {

        $.validity.start();
        // Validator methods go here:
        
        $("#emp-form .inp").each(function(){
                if($(this).attr("id")=="email")
                    $(this).require().match("email")
                else $(this).require()
        })
        $("#emp-form #permission").assert( $("#emp-form #permission").is(":checked"), "You must provide us permession for background check");
        // End the validation session:
        var result = $.validity.end();
        return result.valid;
    }
    function validateEvent() {

		$.validity.start();
		// Validator methods go here:
        
        $("#event-form .inp").each(function(){
                if($(this).attr("id")=="email")
                    $(this).require().match("email")
                else $(this).require()
        })
		
		// End the validation session:
		var result = $.validity.end();
		return result.valid;
	}

	$(document).ready(function(){
		

		if($("#date_of_event").length>0) {
			$( "#date_of_event" ).datepicker({
			changeMonth: true,
			changeYear: true,
			minDate: 0
											 });
		}		
		
		$("#emp-form").submit(function () {
            
                                            
            if (validateEmp()) { //  procced only if form has been validated ok with validity
                var str = $(this).serialize();
                $.ajax({
                    type: "POST",
                    url: "_layout/php/emp-send.php",
                    data: str,
                    success: function (msg) {
                        $("#formstatus").ajaxComplete(function (event, request, settings) {
                            if (msg == 'OK') { // Message Sent? Show the 'Thank You' message
                                result = '<div class="successmsg">Your message has been sent. Thank you!</div>';
                            } else {
                                result = msg;
                            }
                            $(this).html(result);
                        });
                    }
        
                });
                return false;
            }

        });
        $("#event-form").submit(function () {
            
											
			if (validateEvent()) { //  procced only if form has been validated ok with validity
				var str = $(this).serialize();
				$.ajax({
					type: "POST",
					url: "_layout/php/event-send.php",
					data: str,
					success: function (msg) {
						$("#formstatus").ajaxComplete(function (event, request, settings) {
							if (msg == 'OK') { // Message Sent? Show the 'Thank You' message
								result = '<div class="successmsg">Your message has been sent. Thank you!</div>';
							} else {
								result = msg;
							}
							$(this).html(result);
						});
					}
		
				});
				return false;
			}

		});
			
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////	
	});
	


})(window.jQuery);	

// non jQuery scripts below
