
		  
	$(document).ready(function(){ 
	
		// Document ready
		
		// Menu stuff
		
		filename = window.location.pathname.substr(window.location.pathname.lastIndexOf('/')+1);
		$('.top_menu ul li a[href*="'+filename+'"]').parent().addClass('active');
		// Set the current page to active in the menu
		if ($('.top_menu  ul li a[href*="'+filename+'"]').parent().parent().hasClass('sub')) 
		{
			$('.top_menu ul li a[href*="'+filename+'"]').parent().parent().parent().addClass('active');
			// If current page is in sub menu, set parent menu to active also.
		}
		
		$('.footer-menu ul li a[href*="'+filename+'"]').parent().addClass('active');
		// Set the current page to active in the menu
		if ($('.footer-menu  ul li a[href*="'+filename+'"]').parent().parent().hasClass('sub')) 
		{
			$('.footer-menu ul li a[href*="'+filename+'"]').parent().parent().parent().addClass('active');
			// If current page is in sub menu, set parent menu to active also.
		}
		
		
		
		// Call me form
		/*
		$('#header_contact_form').submit(function(event) {
    		event.preventDefault();	// cancel submit

    		$('#header_contact_form #loading').css('display', 'block');
    		$('#header_contact_form #the_form').css('display', 'none');
    		
    		setTimeout(callme, 2000);

		});}
		*/
	    
	    
	    // Popups 
	    
	    $('.popup_trigger').click(function() {
	    
	    	$('#'+$(this).attr('title')).fadeIn(200);
	    
	    });
	    
	    $('a.close').click(function() {
	    
	    	$(this).parent().fadeOut(200);
	    
	    });
	    
	    // Form tips/styling
		
		$('input[type=text], input[type=password], textarea').each(function() 
		{
			if ($(this).attr('title') && !$(this).val()) 
			{
				$(this).val($(this).attr('title'));
			}
		});
		   
		$('input[type=text], input[type=password], textarea').bind('focus', function() 
		{
			$(this).addClass('focused');
			
			if ($(this).val() == $(this).attr('title')) 
			{
				$(this).val('');
			}
		});
		
		$('input[type=text], input[type=password], textarea').bind('blur', function() 
		{	
			if (!$(this).val()) 
			{
				$(this).val($(this).attr('title'));
				$(this).removeClass('focused');
			}
		});
		
		
		/// Validation
		
		jQuery.validator.addMethod("defaultInvalid", function(value, element) 
		{
		    if (element.value == element.getAttribute('title'))
		    {
		        return false;
		    }
		    return true;
		});
		
		$("#header_contact_form").validate({submitHandler: function(form) {
  
  				event.preventDefault();	// cancel submit

    		$('#header_contact_form #loading').css('display', 'block');
    		$('#header_contact_form #the_form').css('display', 'none');
    		
    		setTimeout(callme, 2000);

  				
 		}
		});
		
		$("#contact_form").validate();
		$("#testimonials").validate();
		$("#side_contact_form").validate({
  			rules: {
			    phone: {
			      rangelength: [10, 11]
			    }
  			}
		});
	   	
	    
	}); 
	
	function callme() 
	{
		name = $('#header_contact_form input[name="name"]').val();
		phone = $('#header_contact_form input[name="phone"]').val();
		matter = $('#header_contact_form select[name="matter"]').val();
		callme = $('#header_contact_form select[name="callme"]').val();
		
		$.ajax({
		  type: "POST",
		  url: $('#header_contact_form').attr('action'),
		  data: "name="+name+"&phone="+phone+"&matter="+matter+"&callme="+callme,
		}).done(function( msg ) {
		  msg = jQuery.trim(msg);
		 
		 	$('#header_contact_form #loading').css('display', 'none');
		 	
		  if (msg != 0) 
		  {
		  	$('#header_contact_form #the_form').html(msg);
		  }
		  else
		  {
		  	//
		  }
		  
		  $('#header_contact_form #the_form').css('display', 'block');
		  
		});
		
	}
	

