//Cufon Text
if (!jQuery.browser.msie) {
	Cufon.replace('.callUs',{fontFamily:'Franklin Gothic Book Regular', textShadow: '0 1px #184c63'});
	Cufon.replace('#navigation ul li a',{fontFamily:'Perpetua Bold', hover: true, textShadow: '0 1px #fbfbfb'});
	Cufon.replace('.sub-nav ul li a span, .catalogDownload p, .contactInfo p, #content h4, #content h3, .col h2 , .medical_assistant .requirements, ',{fontFamily:'Arial Rounded'});
	Cufon.replace('.sidebarNav ul li a, #content .homeTabs .tab .text-holder h3, .sidebarNews p, .theme-widget-vertical-marquee h2.widgettitle',{fontFamily:'Arial Rounded'});
	Cufon.replace('.sub-nav ul li a strong, .sidebarNews h3',{fontFamily:'Arial Rounded Bold'});
	Cufon.replace('#gform_wrapper_1 .gform_title, .creditsHolder .item h3',{fontFamily:'Franklin Gothic Heavy'});
	Cufon.replace('.calendar-box .tabNav ul li a',{fontFamily:'Franklin Gothic Medium'});
	Cufon.replace('.calendar-box .tabNav ul li a strong',{fontFamily:'Franklin Gothic Heavy', hover: true});
	Cufon.replace('#breadcrumbs h2, #breadcrumbs h3, #breadcrumbs h4, .slogan h2, .slogan h3, .slogan h4',{fontFamily:'Franklin Gothic Demi', textShadow: '0 2px #fff'});
	Cufon.replace('.homeTablinks a span strong',{fontFamily:'Arial Rounded Bold'});
	Cufon.replace('.homeTablinks a span em',{fontFamily:'Arial Rounded' });
}


//jQuery Func
jQuery(function($) { 
	
	$('#navigation > div > ul > li:last').addClass('last');
	$('p').each(function() {
		var node_text = $(this).text();
		if (node_text.match(/^[\s]*$/)) {
			$(this).remove();
		}
	})
	
	//PNG fix
	if($.browser.msie && $.browser.version.substr(0,1) == 6){
		DD_belatedPNG.fix('.callUs, h1#logo a, #navigation, .slider ul li img, .slider .curves, .sub-nav li a, #gform_wrapper_1, .read-more, .stories .item, .content-box_2-b');
	}
	
	//Slider init	
	// $('.slider ul').jcarousel({
	// 	auto: 4,
	// 	scroll: 1,
	// 	visible: 1,
	// 	wrap: 'both',
	// 	animation: 750,
	// 	buttonNextHTML: null,
	// 	buttonPrevHTML: null
	// });
	var fader_items = $('#slider_wrapper .slider li');
	if (fader_items.length) {
		var current_item = fader_items.length - 1;
		var duration = 800;
		var pause = 5000;
		
		fader_items.hide();
		$(fader_items[current_item]).show();
		
		setInterval(function() {
			$(fader_items[current_item]).fadeOut(duration);
			current_item = (current_item > 0) ? (current_item - 1) : (fader_items.length - 1);
			$(fader_items[current_item]).fadeIn(duration);
		}, pause);
	}
	
	$('#sidebar .widget marquee').each(function() {
		var parent = $(this).parent();
		$(this).parent().html('<div class="marquee">' + $(this).html() + '</div>');
		var marquee = parent.find('> .marquee');
		setInterval(function() {
			if (parseInt(marquee.css('top')) > -(marquee.height() - 30)) {
				marquee.animate({ top: '-=1px' }, 50);
			} else {
				marquee.css('top', '75px');
			}
		}, 50);
	});
	
	//Calendar tabs
	$(".calendar-box .tabNav a").click(function(){ 
		var a_idx = $(this).parent().index();
		$('.calendar-box .tabNav a').removeClass('current_tab');
		$(this).addClass('current_tab');
		$('.calendar-box .tabContent .item').removeClass('item_current');
		$('.calendar-box .tabContent .item').eq(a_idx).addClass('item_current');
		return false;
	});
	
	$('.calendar-box .tabNav a:first').click();
	
	//Home Tabs Hover
	$('.homeTablinks li').hover(function(){ 
		$(this).find('a').addClass('hover');
		if (!$browser.msie) {
			Cufon.refresh('.homeTablinks a span strong');
			Cufon.refresh('.homeTablinks a span em');
		}
	},function(){ 
		$(this).find('a').removeClass('hover');
		if (!$browser.msie) {
	 		Cufon.refresh('.homeTablinks a span strong');
			Cufon.refresh('.homeTablinks a span em');
		}
	});
    
    //Home Tabs Click
	$('.homeTablinks li a').click(function(){ 
		var a_idx = $(this).parent().index();
		$('.homeTablinks li a').removeClass('active_tab');
		$(this).addClass('active_tab');
		$('.homeTabs .tab-holder').hide();
		$('.homeTabs .tab-holder').eq(a_idx).show();
		if (!$.browser.msie) {
			Cufon.refresh();
			Cufon.refresh();
		}
		return false;
    });
    
    $('.homeTablinks li a:first').click();
	
	$('#mandl_home_form').submit(function() {
		var valid = true;
		var errors = '';
		
		$(this).find('.required').each(function() {
			if ($(this).val() == '') {
				$(this).addClass('field-error');
				errors += 'The "' + $(this).attr('title') + '" field is required\n';
				if (valid) {
					$(this).focus();
				}
				valid = false;
			} else {
				$(this).removeClass('field-error');
			}
		});
		
		$(this).find('.email').each(function() {
			var pattern=/^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/;
			
			if (!pattern.test($(this).val())) {
				$(this).addClass('field-error');
				errors += 'The email address you entered is not valid\n';
				if (valid) {
					$(this).focus();
				}
				valid = false;
			} else {
				$(this).removeClass('field-error');
			}
		});
		
		if (!valid) {
			alert(errors);
		}
		
		return valid;
	});
	
	$('.widget_contact_form').submit(function() {
		var valid = true;
		var errors = '';
		
		$(this).find('.required').each(function() {
			if ($(this).val() == '') {
				$(this).addClass('field-error');
				errors += 'The "' + $(this).attr('title') + '" field is required\n';
				if (valid) {
					$(this).focus();
				}
				valid = false;
			} else {
				$(this).removeClass('field-error');
			}
		});
		
		$(this).find('.email').each(function() {
			var pattern=/^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/;
			
			if (!pattern.test($(this).val())) {
				$(this).addClass('field-error');
				errors += 'The email address you entered is not valid\n';
				if (valid) {
					$(this).focus();
				}
				valid = false;
			} else {
				$(this).removeClass('field-error');
			}
		});
		
		if (!valid) {
			alert(errors);
		}
		
		return valid;
	});

	$('#slider_wrapper .sub-nav a.popup_image_link').click(function() {
		$(this).find('> img').addClass('visible');
		return false;
	}).hover(function() {},
	function() {
		$(this).find('> img.visible').removeClass('visible');
	});
});
