String.prototype.trim = function () {
	return this.replace(/^\s+|\s+$/g,"");
}

function QS() {
    this.qs = {};
    var s = location.search.replace( /^\?|#.*$/g, '' );
    if(s) {
        var qsParts = s.split('&');
        var i, nv;
        for (i = 0; i < qsParts.length; i++) {
            nv = qsParts[i].split('=');
            this.qs[nv[0]] = nv[1];
        }
    }
}

QS.prototype.add = function (name, value) {
    if( arguments.length == 1 && arguments[0].constructor == Object ) {
        this.addMany( arguments[0] );
        return;
    }
    this.qs[name] = value;
}

QS.prototype.addMany = function (newValues) {
    for( nv in newValues ) {
        this.qs[nv] = newValues[nv];
    }
}

QS.prototype.remove = function (name) {
    if( arguments.length == 1 && arguments[0].constructor == Array ) {
        this.removeMany( arguments[0] );
        return;
    }
    delete this.qs[name];
}

QS.prototype.removeMany = function (deleteNames) {
    var i;
    for( i = 0; i < deleteNames.length; i++ ) {
        delete this.qs[deleteNames[i]];
    }
}

QS.prototype.getQueryString = function () {
    var nv, q = [];
    for( nv in this.qs ) {
        q[q.length] = nv+'='+this.qs[nv];
    }
    return q.join( '&' );
}

QS.prototype.toString = QS.prototype.getQueryString;
var qs = new QS;

//Document Ready
jQuery(function ($){  

	//Adding classes where necessary
	$('.top-nav li:last').addClass('last');
	$('#content .post:last').addClass('post-last');
	$('#footer .links span:last').remove();
	$('#searchform #s').wrap('<div class="field-container"></div>');
	$(".seo-tabs .links li:eq(0) a").addClass('active');
	$(".seo-tabs .tab:eq(0)").addClass('active');
	$('#navigation .sub-menu').each(function () {
		$(this).find('li:first').addClass('first');
	});
	
	//Subnav DD
	$(".subnav li a").click(function (){ 
		if($(this).parent().find('.dd').length > 0 ){
			$(this).parent().find('.dd').slideToggle();
			$(this).parent().toggleClass('active');
			return false; 
		}
	});
	
	//Blink Fields
	$('.blink, .blink-cnt input, .blink-cnt textarea').live('focus', function () {
		if(this.title==this.value) {
		    this.value = '';
		}
	}).live('blur', function (){
		if(this.value=='') {
		    this.value = this.title;
		}
	});
	
	$('.keypress-blink, .keypress-blink-cnt input, .keypress-blink-cnt textarea').live('keypress', function () {
		if(this.title==this.value) {
		    this.value = '';
		}
	}).live('blur', function (){
		if(this.value=='') {
		    this.value = this.title;
		}
	});
	
	//Main Navigation Dropdown
	$('#navigation ul:eq(0) > li').hover(function () {
		$(this).addClass('hover');
	}, function () {
		$(this).removeClass('hover');
	});
	
	function change_fader_slide(idx) {
		var current = $('#fader .nav li').index($('#fader .nav li.active'));
		if (current == idx) {
			return false;
		}
		$('#fader .nav li.active').removeClass('active');
		$('#fader .nav li:eq(' + idx + ')').addClass('active');
		$('#fader > #fader-cnt > .content > ul > li:visible').stop(true, true).fadeOut();
		$('#fader > #fader-cnt > .content > ul > li:eq(' + idx + ')').stop(true, true).fadeIn();	
	}
	
	//Custom Select
	$(".custom_select select").selectbox({
		replaceInvisible: true
	});

	
	//Ads Slider
	$('#fader .boxes .ads > ul').jcarousel({
		auto: 0,
		visible: 1,
		scroll: 1,
		wrap: 'circular',
		initCallback: adscarousel_initCallback
	});
	
	//News Slider
	$('#fader .blog-ticker .slider > ul').jcarousel({
		auto: 5,
		visible: 1,
		scroll: 1,
		wrap: 'circular',
		initCallback: newscarousel_initCallback
	});
	
	$('.ads li.linked').click(function () {
		var url = $(this).find('.actual-link a:eq(0)').attr('href');
		var title = $(this).find('.actual-link a:eq(0)').attr('title');
		if ($(this).hasClass('lightbox-enabled')) {
			$.colorbox({
				href:url,
				title: title,
				width: '750',
				height: '650',
				iframe: true,
				opacity: 0.6,
				onComplete: function () {
					$('#cboxLoadedContent').addClass('cboxLoadedContent');
				},
				fastIframe: false
			}); 	
		} else {
			window.location = url;
		}
	});
	
	$('a.custom-lightbox').colorbox({
		opacity: 0.6,
		onComplete: function () {
			$('#cboxLoadedContent').addClass('cboxLoadedContent');
		},
		fastIframe: false
	});
	
	$('a.custom-lightbox-iframe').colorbox({
		width: '750',
		height: '650',
		iframe: true,
		opacity: 0.6,
		onComplete: function () {
			$('#cboxLoadedContent').addClass('cboxLoadedContent');
		},
		fastIframe: false
	});
	$('a.custom-lightbox-iframe2').colorbox({
		width: '450',
		height: '580',
		initialWidth: '450',
		initialHeight: '580',
		overflow: 'hidden',
		iframe: true,
		opacity: 0.6,
		onComplete: function () {
			$('#cboxLoadedContent').addClass('cboxLoadedContent2');
		},
		fastIframe: false
	});
	
	var stop_fader = false, trigger = false;
	jQuery("#fader .nav li").hover(
		function (){
			var idx = $('#fader .nav li').index($(this));
			if (!trigger) {
				stop_fader = true;
			}
			change_fader_slide(idx);
	    },
	    function () {
	    	stop_fader = false;
	    	scroll_throughout_tabs();
	    }
	);
	
	var scroll = 1;
	function scroll_throughout_tabs() {
		trigger = false;
		if (scroll > 2 || stop_fader) {
			return false;
		}
		setTimeout(function () {
			if (stop_fader) {
				return false;
			}
			trigger = true;
			$('#fader .nav li:eq(' + scroll + ')').trigger('mouseenter');
			scroll++;
			scroll_throughout_tabs();
		}, 5000);
	}
	
	scroll_throughout_tabs();
	
	//Home SEO Tabs
	
	var max_h = 0;
	$('.seo-tabs .tab').each(function () {
		var h = $(this).height();
		if (h > max_h) {
			max_h = h;
		};
	});
	$('.seo-tabs .tab').css('height', max_h);
	
	$('.seo-tabs .links li a').click(function (){ 
		$('.seo-tabs .links li a').removeClass('active');
		var a_idx = $(this).parent().index();
		$(this).addClass('active');
		$(".seo-tabs .tab").removeClass('active');
		$(".seo-tabs .tab").eq(a_idx).addClass('active');
		return false;
	 });
	 
	//Testimonials tab
	$("#testimonials .links li:eq(0) a").addClass('active');
	$("#testimonials .tab:eq(0)").addClass('active');
	
	$('#testimonials .links li a').click(function (){ 
		$('#testimonials .links li a').removeClass('active');
		var a_idx = $(this).parent().index();
		$(this).addClass('active');
		$("#testimonials .tab").removeClass('active');
		$("#testimonials .tab").eq(a_idx).addClass('active');
		
		fix_testimonials_separators();
		cut_testimonials_paging();
		
		window.location.hash = $(this).parents('li:eq(0)').attr('id').replace('testimonials-', '');
		return false;
	 });
	 
	//Handling current testimonial category
	if ($('#testimonials').length && window.location.hash.length > 1) {
		var item = $('#testimonials-' + window.location.hash.replace('#', ''));
		if (item.length) {
			item.find('a:eq(0)').trigger('click');
		}
	}
	
	//Custom Radios
	$(".radio_buttons input[type=radio]").prettyCheckboxes({
		checkboxWidth: 16,
		checkboxHeight: 16,
		className : 'prettyCheckbox',
		display: 'list'
	});
	
	//Jobs Table
	$(".jobs-table tr:even").addClass('even');
	
	//Popups
	$('.get-started-btn').colorbox({
		inline: true,
		onComplete: function (){ 
			$('#get-started-popup .overlay').show();
		},
		opacity: 0.6
	});
	$('.share .send-to-friend').colorbox({
		inline: true,
		onComplete: function (){ 
			$('#send-to-friend-popup .overlay').show();
		},
		opacity: 0.6
	});
	
	
	//Popup Form Overlay
	$(".prettyCheckbox .holder").live('click',function (){ 
		$('.popup .overlay').fadeOut();
	 });
	 
	//PNG Fix
	if($.browser.msie && $.browser.version == 6 ){
		DD_belatedPNG.fix('#navigation, .live-chat-btn, .get-started-btn, #fader .content ul li .text .btn, #fader .content ul li .text ul li, #fader .boxes, #fader .boxes .ads .prev, #fader .boxes .ads .next, #fader .blog-ticker, #fader .blog-ticker .slider .prev, #fader .blog-ticker .slider .next, .subnav ul li a, #fader .nav li a, .popup .overlay, .popup-t, .popup-b, .faq-question .box-top, .faq-question .box-middle, .faq-question .box-bottom');
	}
	
	function cut_testimonials_paging() {
		var total = $('#testimonials .tab.active .paging:eq(0) .pagination-item').length;
		var current = $('#testimonials .tab.active .paging:eq(0) li:gt(0):lt(' + total + ')').index($('#testimonials .tab.active .paging:eq(0) li.current-parent'));
		$('#testimonials .tab.active .paging .pagination-item').parent().hide();
		if (current == 0 || current == 1 || current == 2) {
			$('#testimonials .tab.active .paging').each(function () {
				$(this).find('.pagination-item:lt(5)').parent().show();
			});
		} else if(current == total - 1 || current == total - 2 || current == total - 3) {
			$('#testimonials .tab.active .paging').each(function () {
				$(this).find('.pagination-item:lt(' + total + '):gt(' + (total-6) + ')').parent().show();
			});
		} else {
			$('#testimonials .tab.active .paging').each(function () {
				$(this).find('.pagination-item:lt(' + (current+3) + '):gt(' + (current-3) + ')').parent().show();
			});
		}
	}
	cut_testimonials_paging();
	
	//Testimonials pagination
	$('#testimonials ul.paging a').click(function () {
		var current = $('#testimonials .tab.active .item').index($('#testimonials .tab.active .item:visible'));
		var total = $('#testimonials .tab.active .item').length;
		var next;
		if ($(this).hasClass('prev') && current > 0) {
			next = current - 1;
		} else if($(this).hasClass('next') && current < total - 1) {
			next = current + 1;
		} else {
			var paging = $(this).parents('.paging:eq(0)');
			next = paging.find('a.pagination-item').index($(this));
		}
		
		$('#testimonials .tab.active .item:visible').hide();
		$('#testimonials .tab.active .item:eq(' + next + ')').show();
		
		if (next > 0) {
			$('#testimonials .tab.active a.prev').show();
		} else {
			$('#testimonials .tab.active a.prev').hide();
		}
		if (next < total - 1) {
			$('#testimonials .tab.active a.next').show();
		} else {
			$('#testimonials .tab.active a.next').hide();
		}
		
		$('#testimonials .tab.active .paging .current').removeClass('current').parent().removeClass('current-parent');
		$('#testimonials .tab.active .paging').each(function () {
			$(this).find('.pagination-item:eq(' + next + ')').addClass('current').parent().addClass('current-parent');
		});
		
		cut_testimonials_paging();
		
		return false;
	});
	
	//application request submission handling
	$('.application-request-form').live('submit', function () {
		var th = $(this);
		var email_regex = "[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?";
		var has_error = false;
		
		var required = th.find('input[name="provider_type"], input[name="first_name"], input[name="last_name"], input[name="email_address"], input[name="phone_number"]');
		
		required.each(function () {
			if ($(this).attr('name') == 'email_address') {
				if (!$(this).val().match(email_regex)) {
					alert('Please input your correct email address.');
					$(this).focus();
					has_error = true;
					return false;
				}
			} else if($(this).attr('name') == 'provider_type') {
				if (!th.find('input[name="provider_type"]:checked').length) {
					alert('Please choose your provider type.');
					has_error = true;
					return false;
				}
			} else {
				if (!$(this).val() || $(this).val() == '' || $(this).val() == $(this).attr('title')) {
					alert('Please input your correct ' + $(this).attr('title').toLowerCase().replace('*', ''));
					$(this).focus();
					has_error = true;
					return false;
				}
			}
			
		});
		
		if (has_error) {
			return false;
		}
		
		$.ajax({  
			type: "POST",  
			url: $(this).attr('action'),
			data: "sent_form=yes&provider_type=" + $(this).find('input[name="provider_type"]:checked').val() + 
				"&first_name=" + $(this).find('input[name="first_name"]').val() + 
				"&last_name=" + $(this).find('input[name="last_name"]').val() + 
				"&email_address=" + $(this).find('input[name="email_address"]').val() + 
				'&phone_number=' + $(this).find('input[name="phone_number"]').val() + 
				'&practice_areas=' + $(this).find('input[name="practice_areas"]').val() + 
				'&states_licensed=' + $(this).find('input[name="states_licensed"]').val() + 
				'&business_name=' + $(this).find('input[name="business_name"]').val() + 
				'&time_to_reach=' + $(this).find('select[name="time_to_reach"] option:selected').val() + 
				'&comments=' + $(this).find('textarea[name="comments"]').val(),
			success: function (response) { 
				if (response.indexOf('error') > -1) {
					th.append(response);
				} else {
					th.html(response);
					if (th.parents('.popup').length) {
						setTimeout(function () {
							$.colorbox.close();
						}, 2000);
					}
				}
			}
		});
		return false;
	});
	
	//changing fields depending on the provider type
	$('.change-form input[name="provider_type"]').live('change', function () {
		if ($(this).val().trim() == 'Facility or Practice') {
			$('input[name="Submitted_State_Licenses__c"]').attr('name', 'company').attr('title', 'Business Name');
			if ($(this).parents('.popup').length) {
				$('input[name="company"]').parents('.gfield:eq(0)').find('label').text('Business Name');
			} else {
				$('input[name="company"]').val('Business Name');
			}
		} else {
			$('input[name="company"]').attr('name', 'Submitted_State_Licenses__c').attr('title', 'State(s) Licensed');
			if ($(this).parents('.popup').length) {
				$('input[name="Submitted_State_Licenses__c"]').parents('.gfield:eq(0)').find('label').text('State(s) Licensed');
			} else {
				$('input[name="Submitted_State_Licenses__c"]').val('State(s) Licensed');
			}
		}
	});
	
	//correct html for hacked plugin form
	$('.job-apply-table tr').each(function () {
		if ($(this).find('input[type="text"], textarea').length) {
			var title = $(this).find('th').text();
			$(this).find('input[type="text"], textarea').wrap('<div class="ginput_container"></div>').addClass('keypress-blink').attr('title', title).val(title);
			$(this).find('textarea').parent().wrap('<div class="custom_textarea"></div>');
		} else if($(this).find('select').length) {
			$(this).find('select').selectbox({
				replaceInvisible: true
			});
		} else if($(this).find('input[type="submit"]')) {
			$(this).find('input[type="submit"]').addClass('button').val('Submit');
		}
	});
	
	//correct html for default template sidebar menu
	$('.landing-subnav ul').each(function () {
		$(this).addClass('dd');
	});
	
	function cut_jobs_paging() {
		var total = $('.jobs-pagination:eq(0) a').length;
		if (total < 11) {
			return false;
		}
		var current = $('.jobs-pagination:eq(0) a').index($('.jobs-pagination:eq(0) a.active'));
		$('.jobs-pagination a, .jobs-pagination span').hide();
		if (current < 6) {
			$('.jobs-pagination').each(function () {
				$(this).find('a:lt(10)').show();
			});
		} else if(current > total - 6) {
			$('.jobs-pagination').each(function () {
				$(this).find('a:lt(' + total + '):gt(' + (total-11) + ')').show();
			});
		} else {
			$('.jobs-pagination').each(function () {
				$(this).find('a:lt(' + (current+5) + '):gt(' + (current-6) + ')').show();
			});
		}
		if (total > 1) {
			$('.jobs-pagination .nextpage, .jobs-pagination .prevpage').show();
			if (current == 0) {
				$('.jobs-pagination .prevpage').hide();
			} else if(current == total - 1) {
				$('.jobs-pagination .nextpage').hide();
			}
		}
	}
	
	//adds even classes to even indexed table rows
	function fix_table_tr_classes() {
		$('.jobs-table tr:not(:first)').each(function () {
			$(this).removeClass('even');
			if ($('.jobs-table tr:not(:first)').index($(this)) % 2 == 0) {
				$(this).addClass('even');
			}
		});
	}
	$('.jobs-table tr:not(:eq(0))').addClass('show-me');
	
	//adds ads between jobs
	function add_ads_between_jobs() {
		if (!$('#job-ads').length) {
			return false;
		}
		$('.jobs-table tr:not(:first)').each(function () {
			var idx = $('.jobs-table tr:not(:first):visible').index($(this));
			if ((idx+1) % 3 == 0 && idx > 0) {
				var ad = $('#job-ads tr:eq(' + ((idx+1)/3-1) + ')');
				if (ad.length) {
					ad.clone().insertAfter($(this));
				}
			}
		});
	}
	
	//custom table sort function
	function sort_table_data(selector, descending) {
		qs.add('sort', selector);
		qs.add('desc', descending);
		
		$('.jobs-table').html('<div class="loading"></div>');

		$.ajax({
			type: "GET",
			url: window.location.href,
			data: qs.toString(),
			success: function (res) {
				var html = $(res).find('.jobs-table').html();
				$('.jobs-table').html(html);

				var active = '';
				if (selector == 'span.date') {
					active = '.sorter-date';
				} else if(selector == 'h3') {
					active = '.sorter-title';
				} else if(selector == 'td:eq(1)') {
					active = '.sorter-speciality';
				} else if(selector == 'td:eq(2)') {
					active = '.sorter-state';
				}

				$('.sorter').parent().removeClass('sorted-by');
				$('.jobs-table').find(active).parent().addClass('sorted-by');

				if (descending) {
					$('.jobs-table').find(active).addClass('desc-sorting');
				}

				paginate_jobs();
				display_jobs_page(1);
			}
		});

	}
	
	//custom table caller event
	$('a.sorter').live('click', function () {
		var descending = false;
		if (!$(this).hasClass('desc-sorting')) {
			descending = true;
			$(this).addClass('desc-sorting');
		} else {
			$('a.sorter').removeClass('desc-sorting');
		}
		if ($(this).hasClass('sorter-title')) {
			sort_table_data('h3', descending);
		} else if ($(this).hasClass('sorter-date')) {
			sort_table_data('span.date', descending);
		} else if ($(this).hasClass('sorter-speciality')) {
			sort_table_data('td:eq(1)', descending);
		} else if ($(this).hasClass('sorter-state')) {
			sort_table_data('td:eq(2)', descending);
		}
		$('.sorter').parent().removeClass('sorted-by');
		$(this).parent().addClass('sorted-by');
		return false;
	});
	
	$('.jobs-map-area').live('click', function (e) {
		var x = e.pageX - this.offsetLeft;
        var y = e.pageY - this.offsetTop;
		
		var param = '';

		if (x <= 192) {
			if ($(this).hasClass('jobs-west')) {
				$(this).removeClass('jobs-west').removeAttr('id');
			} else {
				param = 'West';
				$(this).removeClass('jobs-central jobs-east').addClass('jobs-west').attr('id', 'Jobs-West');
			}
		} else if(x <= 339) {
			if ($(this).hasClass('jobs-central')) {
				$(this).removeClass('jobs-central').removeAttr('id');
			} else {
				param = 'Central';
				$(this).removeClass('jobs-west jobs-east').addClass('jobs-central').attr('id', 'Jobs-Central');
			}
		} else {
			if ($(this).hasClass('jobs-east')) {
				$(this).removeClass('jobs-east').removeAttr('id');
			} else {
				param = 'East';
				$(this).removeClass('jobs-west jobs-central').addClass('jobs-east').attr('id', 'Jobs-East');
			}
		}

		if (param.length) {
			qs.add('filter', param);
		} else {
			qs.remove('filter');
		}
		
		$('.jobs-table').html('<div class="loading"></div>');

		$.ajax({
			type: "GET",
			url: window.location.href,
			data: qs.toString(),
			success: function (res) {
				var html = $(res).find('.jobs-table').html();
				$('.jobs-table').html(html);
				paginate_jobs();
			}
		});

	});
	
	$('.jobs-map-area').mousemove(function (e) {
		var x = e.pageX - this.offsetLeft;
        var y = e.pageY - this.offsetTop;
		if (x <= 192) {
			$(this).addClass('jobs-west-hover').removeClass('jobs-central-hover jobs-east-hover');
		} else if(x <= 339) {
			$(this).addClass('jobs-central-hover').removeClass('jobs-west-hover jobs-east-hover');
		} else {
			$(this).addClass('jobs-east-hover').removeClass('jobs-west-hover jobs-central-hover');
		}
	});
	
	$('.jobs-map-area').mouseout(function () {
		$(this).removeClass('jobs-west-hover jobs-central-hover jobs-east-hover');
	});
	
	//show all jobs
	$('.show-all-jobs').click(function () {
		$('.jobs-map-area').removeClass('jobs-west').removeClass('jobs-central').removeClass('jobs-east').removeAttr('id');

		qs.remove('filter');
		qs.remove('sort');
		qs.remove('desc');
		
		$('.jobs-table').html('<div class="loading"></div>');

		$.ajax({
			type: "GET",
			url: window.location.href,
			data: qs.toString(),
			success: function (res) {
				var html = $(res).find('.jobs-table').html();
				$('.jobs-table').html(html);
				paginate_jobs();
			}
		});

		return false;
	});
	
	var jobs_per_page = 20;
	
	$('.jobs-pagination a').live('click', function () {
		var parent = $(this).parents('.jobs-pagination:eq(0)');
		var idx = parent.find('a').index($(this));
		display_jobs_page(idx+1);
		return false;
	});
	
	//display specific jobs page
	function display_jobs_page(idx) {
		$('.jobs-table tr.ads').remove();
		$('.jobs-table tr:gt(0)').hide();
		$('.jobs-table tr:lt(' + (idx*jobs_per_page+1) + '):gt(' + ((idx-1)*jobs_per_page) + ')').show();
		var pidx = idx-1;
		$('.jobs-pagination').each(function () {
			$(this).find('a.active').removeClass('active');
			$(this).find('a:eq(' + pidx + ')').addClass('active');
			if (pidx == 0) {
				$(this).find('span.prevpage').hide();
			} else {
				$(this).find('span.prevpage').show();
			}
			if (pidx == $(this).find('a').length - 1) {
				$(this).find('span.nextpage').hide();
			} else {
				$(this).find('span.nextpage').show();
			}
		});
		
		add_ads_between_jobs();
		cut_jobs_paging();
		
		$(window).scrollTop(0);
		
		window.location.hash = '#page-' + idx;
	}
	
	//add pagination to jobs page
	function paginate_jobs() {
		$('.jobs-pagination, .jobs-table tr.ads').remove();
		var num_pages = Math.ceil($('.jobs-table tr:not(:first)').length/jobs_per_page);
		if (num_pages > 1) {
			var html = '<div class="jobs-pagination"><span class="prevpage"></span>';
			for(var i = 0; i < num_pages; i++) {
				var curr = i+1;
				html+= '<a href="#">' + curr + '</a>';
			}
			html += '<span class="nextpage"></span></div>';
			$('.jobs-table').append(html);
			$('.jobs-table').prepend(html);
			
			var hash = window.location.hash;
			var _page = parseInt(hash.replace('#page-', ''));
			if (isNaN(_page) || !_page || _page > num_pages) {
				_page = 1;
			}
			display_jobs_page(_page);
		}
		fix_table_tr_classes();
	}

	if (!$('.archived-jobs-template').length) {
		paginate_jobs();
	}
	
	$('span.prevpage, span.nextpage').live('click', function () {
		var parent = $(this).parents('.jobs-pagination:eq(0)');
		var idx = parent.find('a').index(parent.find('a.active'));
		var _next;
		if ($(this).hasClass('nextpage')) {
			_next = idx+2;
		} else {
			_next = idx;
		}
		display_jobs_page(_next);
	});

	//application request submission handling
	$('.send-to-friend-form').live('submit', function () {
		var th = $(this);
		var email_regex = "[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?";
		var has_error = false;
		
		var required = th.find('input[name="your_name"], input[name="your_email"], input[name="friends_name"], input[name="friends_email"], textarea[name="comments"]');
		
		required.each(function () {
			if ($(this).attr('name') == 'your_email' || $(this).attr('name') == 'friends_email') {
				if (!$(this).val().match(email_regex)) {
					alert('Please input ' + $(this).attr('title').toLowerCase().replace('*', '') + ' address.');
					$(this).focus();
					has_error = true;
					return false;
				}
			} else {
				if (!$(this).val() || $(this).val() == '') {
					alert('Please input ' + $(this).attr('title').toLowerCase().replace('*', '') + '.');
					$(this).focus();
					has_error = true;
					return false;
				}
			}
			
		});
		
		if (has_error) {
			return false;
		}
		
		$.ajax({  
			type: "POST",  
			url: $(this).attr('action'),
			data: "staf_form=yes" + 
				"&your_name=" + $(this).find('input[name="your_name"]').val() + 
				"&your_email=" + $(this).find('input[name="your_email"]').val() + 
				"&friends_name=" + $(this).find('input[name="friends_name"]').val() + 
				'&friends_email=' + $(this).find('input[name="friends_email"]').val() + 
				'&comments=' + $(this).find('textarea[name="practice_areas"]').val(),
			success: function (response) { 
				if (response.indexOf('error') > -1) {
					th.append(response);
				} else {
					th.html(response);
					if (th.parents('.popup').length) {
						setTimeout(function () {
							$.colorbox.close();
						}, 2000);
					}
				}
			}
		});
		return false;
	});
	
	$('.faq-question').live('click', function () {
		var item = $(this).parents('.faq-item:eq(0)');
		var answer = item.find('.faq-answer:eq(0)');
		if (!answer.is(':animated')) {
			answer.slideToggle("fast");
			item.toggleClass('box-closed box-open');
		}
	});
	
	//testimonials - fixing separators
	function fix_testimonials_separators() {
		var cont = $('#testimonials .links');
		var idx = cont.find('li').index(cont.find('li a.active').parent());
		var total = cont.find('li').length;
		var lc = 'remove-separator-left';
		var rc = 'remove-separator-right';
		var tc = 'remove-separator-this';
		cont.find('li').removeClass(lc + ' ' + rc + ' ' + tc);
		if (idx == 0) {
			cont.find('li:eq(1)').addClass(lc);
		} else if(idx == total - 1 && total > 1) {
			cont.find('li:eq(' + (total-2) + ')').addClass(rc);
		} else {
			cont.find('li:eq(' + (idx-1) + ')').addClass(rc);
			cont.find('li:eq(' + (idx+1) + ')').addClass(lc);
		}
		cont.find('li:eq(' + idx + ')').addClass(tc);
	}
	
	fix_testimonials_separators();
	
	//barton form specific scripts
	$('.gform_wrapper input[name="provider_type"]').live('change', function () {
		var form = $(this).parents('.gform_wrapper:eq(0)');
		var rectype = form.find('input[name="recordType"]');
		var wprt = form.find('input[name="00N60000001y0lM"]');
		
		if ($(this).val() == 'Get Started Physician') {
			rectype.val('01260000000Q2T2');
			wprt.val('Get Started Physician');
		} else if($(this).val() == 'Testimonials Physician') {
			rectype.val('01260000000Q2T2');
			wprt.val('Testimonials Physician');
		} else if ($(this).val() == 'Get Started NP') {
			rectype.val('01260000000Q2T2');
			wprt.val('Get Started NP');
		} else if ($(this).val() == 'Testimonials NP') {
			rectype.val('01260000000Q2T2');
			wprt.val('Testimonials NP');
		} else if ($(this).val() == 'Job Inquiry Physician') {
			rectype.val('01260000000Q2T2');
			wprt.val('Job Inquiry Physician');
		} else if ($(this).val() == 'Job Inquiry NP') {
			rectype.val('01260000000Q2T2');
			wprt.val('Job Inquiry NP');
		} else if ($(this).val() == 'Custom Job Search Physician') {
			rectype.val('01260000000Q2T2');
			wprt.val('Custom Job Search Physician');
		} else if ($(this).val() == 'Custom Job Search NP') {
			rectype.val('01260000000Q2T2');
			wprt.val('Custom Job Search NP');
		} else if ($(this).val() == 'Job Alert Physician') {
			rectype.val('01260000000Q2T2');
			wprt.val('Job Alert Physician');
		} else if ($(this).val() == 'Job Alert NP') {
			rectype.val('01260000000Q2T2');
			wprt.val('Job Alert NP');
		} else if($(this).val() == 'Get Started Facility' || $(this).val() == 'Testimonials Facility' || $(this).val() == 'Facility or Practice') {
			rectype.val('01260000000Q2Sz');
			wprt.val('Get Started Facility');
		}
		
		
	});
	
	//barton form specific scripts
	$('.lbform_wrapper input[name="provider_type"]').live('change', function () {
		var form = $(this).parents('.lbform_wrapper:eq(0)');
		var rectype = form.find('input[name="recordType"]');
		var wprt = form.find('input[name="00N60000001y0lM"]');
		
		if ($(this).val() == 'Get Started Physician') {
			rectype.val('01260000000Q2T2');
			wprt.val('Get Started Physician');
		} else if ($(this).val() == 'Get Started NP') {
			rectype.val('01260000000Q2T2');
			wprt.val('Get Started NP');
		} else if($(this).val() == 'Get Started Facility' || $(this).val() == 'Testimonials Facility' || $(this).val() == 'Facility or Practice') {
			rectype.val('01260000000Q2Sz');
			wprt.val('Get Started Facility');
		}
		
		
	});
	

});

function adscarousel_initCallback(carousel) {
	jQuery('#fader .ads .next').bind('click', function () {
        carousel.next();
        return false;
    });

    jQuery('#fader .ads .prev').bind('click', function () {
        carousel.prev();
        return false;
    });
};

function newscarousel_initCallback(carousel) {
	jQuery('#fader .blog-ticker .slider .next').bind('click', function () {
        carousel.next();
        return false;
    });
    
    jQuery('#fader .blog-ticker .slider .prev').bind('click', function () {
        carousel.prev();
        return false;
    });
};
