$(function(){

		// cufon
		//Cufon.replace('.med', { fontFamily: 'med' });
		$('.orange-bg').each(function() {
			if($(this).height() > 28) { 
				$(this).addClass('large');
			}			
		});


		$('.trigger').click(function () {				
			var showthis = $(this).attr('rel');
			$('.clientfeedback').hide();
			$('#section').html($(this).html());
			$('.'+showthis).show();
		});

		//nav highlighted  for current page			

		$("#nav a").each(function() {
				var hreflink = $(this).attr("href");
 				var subpage = location.href.toLowerCase().split("/").slice(-2,-1);
  				if (hreflink.toLowerCase()==location.href.toLowerCase()) {
  					$(this).addClass("active");
 				}
				//highlight main nav item when subpage is active - console log to see!
 				if (subpage == 'teammember'|| subpage == 'index' ) {
  					$('#nav-team a').addClass("active");
				}				
 				if ( subpage == 'latestnews' ) {
  					$('#nav-news a').addClass("active");
				}				
				
			});	

		//to prevent list showing on team master page but still show up on team details page
 		$('.team-member-about ul').hide();

		//slide to anchor
		$('.top').click(function() {
				$.scrollTo(0,'fast');
			});

		$('#buying-process').click(function() {		   
				$.scrollTo('#buying-process-text','fast');
			});

		$('#service-fees').click(function() {		   
				$.scrollTo('#service-fees-text','fast');
			});
		//position 'read more..' link outside team bio	 	   
		$('div.team-member-about').each(function () {
				var more = $(this).find('a.read-more').remove();
				$(this).find('p:last').append(more);
		});

		$(":text").labelify();
				   
		$("#contact-form").validate({
 				messages: {
 					'name': {
 						required: '*Please enter your name'
 					},				
 					'email': {
 						required: '*Please enter a valid email'
 					}					
 				},
				invalidHandler: function () {$('input').blur();$('.reported').removeClass('reported'); alert('Please enter your Name and Email for this Enquiry');},
				
				errorPlacement: function (error, element) {
					if (element.is('.reported'))
						return true;
					element.addClass('reported');
					element.val(error.text());
					element.bind('focus', function () {
						$(this).val('');
						$(this).unbind('focus');
					});
				}
			});		

		//main contact form response

		$('#contact-form').ajaxForm(function() { 
				$("#response").fadeIn('slow');
				$('#contact-form').show();
				$('input, textarea').val('');
			});		

		$('#buying-process-text h4, #service-fees-text h4').addClass('orange-text');

		$('#buying-process-text ul li, #service-fees-text ul li').addClass('whatwedo-list');

		//subscribe slide down form
    	$("#contactLink").click(function(){
             if ($("#contactForm").is(":hidden")){
                 $("#contactForm").slideDown("slow");
             }
             else{
                 $("#contactForm").slideUp("slow");
             }
         });

		$('#myForm').validate({				
				invalidHandler: function () {$('input').blur();},
				
				errorPlacement: function (error, element) {
					if (element.is('.reported'))
						return true;
					element.addClass('reported');
					element.val(error.text());
					element.bind('focus', function () {
						$(this).val('');
						$(this).unbind('focus');
					});
				}

					})

		$('#myForm').submit(function() {

			$.post($(this).attr('action'), { name: $(this).find('input[name=name]').val(),
					email: $(this).find('input[name=email]').val(),
					newsletter: $(this).find('input[name=newsletter]').val()
					}
			);

			});

		//for archive list slide down

		$('#news-archives a').click(function (event) {
			event.stopPropagation();
			return true;			
		});

		$('#news-archives li').toggle(function(){
				$(this).find('ul').slideDown();
			}, function(){
				$(this).find('ul').slideUp();
			});
		
		$('ul.archive:last-child a' ).click(function() {
				$('#content-left').load($(this).attr('href')+' .content-left-news' );
				return false;
			})
		
	});

