

 $(document).ready(function() {
 
 
		if (!Modernizr.input.placeholder) {
			// adds a placeholder text if the browser doesnt support it
			$("input[placeholder]").each(
			   function () {
					   var term = $(this).attr("placeholder");
					$(this).val(term); 
			   }).focus(
			   function() { 
					$(this).val(""); 
			   }).blur( 
					   function(){ 
						if (this.value == '') { 
							var term = $(this).attr("placeholder");
							$(this).val(term); 
						};     
			   });
		}
 
 
 /*$('#bannerImage .gallery img').unwrap().unwrap().unwrap().unwrap();
	$('#bannerImage br').remove();
 
 
	$('#bannerImage').cycle({ 
		fx:     'scrollRight', 
		timeout: 6000
		
	});*/
	
	/*$(".cat-8-id.single #wp-category-archive-3 h3,.cat-7-id.single #wp-category-archive-4 h3,.cat-8-id.category #wp-category-archive-3 h3,.cat-7-id.category #wp-category-archive-4 h3").addClass("active");
	$(".cat-8-id.single #wp-category-archive-3 ul,.cat-7-id.single #wp-category-archive-4 ul,.cat-8-id.category #wp-category-archive-3 ul,.cat-7-id.category #wp-category-archive-4 ul").slideToggle();
	*/
	
	
	// add the cat id to the archive widget
	$(".widget_wp-category-archive h3").each(function(){
		
		if ($(this).parent('div').children('ul').children('li').length){
		
			var catID = $(this).parent('div').children('ul').children('li').children('a').attr('href').match(/cat=([0-9]+)/)[1];
			var catIDStr = 'cat-'+catID+'-id';
			
			//$(this).addClass('cat-'+catID+'-id');
			if($('body').hasClass(catIDStr) && !$('body').hasClass('blog') )
			{
				$(this).addClass("active");
				$(this).parent('div').children('ul').slideToggle();
			}
		}
		
	});
	
	
	/*$(".widget_wp-category-archive h3").each(function(){
		if($(this).text() == $(".cat-title").text()){
			$(this).addClass("active");
			$(this).parent('div').children('ul').slideToggle();
		}
		
	});*/
	
	
	$("#menu-top-nav li.contact a").click(function(){
		$("#contactForm").slideToggle();
					 
	});	
	
		$( "#tabs" ).tabs();	
	
	$(".home .entry-content ol").each(function(){
       
		$(this).children("li").each(function(i){
			var newno = i + 1;
			$(this).prepend("<span>"+newno+"</span>");
		});
	});
	
	$("#text-11, #text-15, #text-5,#text-16").addClass("moveablewidget");
	
	$(".moveablewidget h3").click(function() {
		$(this).parent().children('.textwidget').slideToggle();
		$(this).toggleClass('on');
	});
	
	$(function() {
		$( "#tabs" ).tabs();
	});
	
	$('.menu-our-services-container li.menu-item-600 ul.sub-menu li.menu-item a').not('.menu-our-services-container li.menu-item ul.sub-menu li.menu-item ul.sub-menu li.menu-item a').click(function() {
		$('a.active').removeClass('active');
		$('.menu-our-services-container li.menu-item-600 ul.sub-menu li.menu-item ul.sub-menu').hide();		
		$(this).addClass("active").parent().children('ul').show();
		return false;
	});
	
	$('.contactWrap:nth-child(odd)').css({marginRight: '20px'});
	
	$('#menu-our-services li#menu-item-646 ul li a,#menu-our-services li#menu-item-650 ul li a').not('#menu-our-services li#menu-item-646 ul li ul li a,#menu-our-services li#menu-item-650 ul li ul li a').click(function() {		
		$('.current').removeClass('current');
		$(this).parent('li').children('ul').addClass('current');
		$('#menu-our-services li#menu-item-646 ul li ul,#menu-our-services li#menu-item-650 ul li ul').not('.current').slideUp();
		$(this).parent().children('ul').slideToggle();
		return false;
	});
	
	$('.widget_wp-category-archive h3').click(function() {
		$(this).toggleClass("active");
		$(this).next().slideToggle();
	});
		
	// autocomplete
	/*$('#autoSearch').autocomplete(function(){
		var terms = $('#autoSearch').val();

		// call ajax
		 
		$.ajax({
					url:"/wp1/wp-admin/admin-ajax.php",
					type:'POST',
					data: {
						action:'my_action',
						s: terms
					},
					beforeSend: function(){
						$("#results").empty();
					},
					success:function(results)
					{
						 alert(results);
						//$("#results").text('ajax return successful');
						$('#results').append(results);
					}
				});
	});*/
	
	$( "#autoSearch" ).autocomplete({
		source: function(request, response){
			$.ajax({
				url: '/wp-admin/admin-ajax.php',
				type:'POST',
				dataType: 'json',
				cache: false,
				data: {
					action:'get_team_member',
					s: request.term
				},
				success: function(data){
					//console.log(data);
					response( $.map( data, function( item ) {
							return {
								label: item.title,
								value: item.title,
								link: item.link
								
							}
					}));
				}
				
			}); 
		},
		minLength: 2,
		select: function( event, ui ) {
			var link = ui.item.link;
			window.location = link;
		}
	});
	
	
	// lightbox
	$('a[href$=".jpg"],a[href$=".png"],a[href$=".gif"]').attr("rel","lightbox[web]").prettyPhoto({
		animationSpeed: 'normal', /* fast/slow/normal */
		padding: 40, /* padding for each side of the picture */
		opacity: 0.50, /* Value between 0 and 1 */
		show_title: false, /* true/false */
		allow_resize: false, /* true/false */
		overlay_gallery: false,
		counter_separator_label: '/', /* The separator for the gallery counter 1 "of" 2 */
		theme: 'light_rounded', /* light_rounded / dark_rounded / light_square / dark_square */
		social_tools: false,
		deeplinking: false
	});
	
	
	// video light box
	$('a[href*="youtube.com/watch?v="],a[href*="embed.buto.tv/"]').each(function(){
		var href = $(this).attr('href');
		href += "?iframe=true&width=500&height=280";
		$(this).attr('href', href);
	});
	

	
	$('a[href*="youtube.com/watch?v="],a[href*="embed.buto.tv/"]').attr("rel","lightbox[iframe]").prettyPhoto({
		animationSpeed: 'normal', /* fast/slow/normal */
		padding: 40, /* padding for each side of the picture */
		opacity: 0.50, /* Value between 0 and 1 */
		show_title: false, /* true/false */
		allow_resize: false, /* true/false */
		overlay_gallery: false,
		counter_separator_label: '/', /* The separator for the gallery counter 1 "of" 2 */
		theme: 'light_rounded', /* light_rounded / dark_rounded / light_square / dark_square */
		social_tools: false,
		deeplinking: false
	});
	
	
	$( "#more").click(function(){
		$("#restoflist").slideToggle();
		return false;
	});
	
	$( ".accordion" ).accordion({
		collapsible: true
	});
	
	$( ".accordion-services" ).accordion({
			header: 'h4',
			autoHeight: false,
			active: false
			
	});
	
	$('.sharing a[style*="share.png"]').addClass('st_sharethis_custom').click(function(){ return false;});
	
	
	$('#VSPForm').submit(function(){
	
		var doSumbit = validatePaymentForm();
	
		return doSumbit;	
	});
	
	
 });
 
 var switchTo5x=true;
 
 function subForm()
 {
	document.forms['displayByForm'].submit();
 }
 
 function validatePaymentForm()
 {
	var isValid = true;
	
	if($('#VSPForm #Reference').val() == '')
	{
		isValid = false;
		$('#VSPForm #Reference').parent('td').parent('tr').children('.errorMsg').children('span').text('Please enter required field.');
	}
	else {
		$('#VSPForm #Reference').parent('td').parent('tr').children('.errorMsg').children('span').text('');
	}
	
	if($('#VSPForm #Amount').val() == '')
	{
		isValid = false;
		$('#VSPForm #Amount').parent('td').parent('tr').children('.errorMsg').children('span').text('Please enter required field.');
	}
	else {
		$('#VSPForm #Amount').parent('td').parent('tr').children('.errorMsg').children('span').text('');
	}
	
	if($('#VSPForm #BillingFirstnames').val() == '')
	{
		isValid = false;
		$('#VSPForm #BillingFirstnames').parent('td').parent('tr').children('.errorMsg').children('span').text('Please enter required field.');
	}
	else {
		$('#VSPForm #BillingFirstnames').parent('td').parent('tr').children('.errorMsg').children('span').text('');
	}
	
	if($('#VSPForm #BillingSurname').val() == '')
	{
		isValid = false;
		$('#VSPForm #BillingSurname').parent('td').parent('tr').children('.errorMsg').children('span').text('Please enter required field.');
	}
	else {
		$('#VSPForm #BillingSurname').parent('td').parent('tr').children('.errorMsg').children('span').text('');
	}
	
	if($('#VSPForm #BillingAddress1').val() == '')
	{
		isValid = false;
		$('#VSPForm #BillingAddress1').parent('td').parent('tr').children('.errorMsg').children('span').text('Please enter required field.');
	}
	else {
		$('#VSPForm #BillingAddress1').parent('td').parent('tr').children('.errorMsg').children('span').text('');
	}
	
	if($('#VSPForm #BillingCity').val() == '')
	{
		isValid = false;
		$('#VSPForm #BillingCity').parent('td').parent('tr').children('.errorMsg').children('span').text('Please enter required field.');
	}
	else {
		$('#VSPForm #BillingCity').parent('td').parent('tr').children('.errorMsg').children('span').text('');
	}
	
	if($('#VSPForm #BillingPostCode').val() == '')
	{
		isValid = false;
		$('#VSPForm #BillingPostCode').parent('td').parent('tr').children('.errorMsg').children('span').text('Please enter required field.');
	}
	else {
		$('#VSPForm #BillingPostCode').parent('td').parent('tr').children('.errorMsg').children('span').text('');
	}
	
	if($('#VSPForm #CustomerEMail').val() == '')
	{
		isValid = false;
		$('#VSPForm #CustomerEMail').parent('td').parent('tr').children('.errorMsg').children('span').text('Please enter required field.');
	}
	else {
		$('#VSPForm #CustomerEMail').parent('td').parent('tr').children('.errorMsg').children('span').text('');
	}
	
	return isValid;
 }
 
