

function SiteFramework() {
	this.init = function() {
		$(function() {
			$('.searchBox input:first').focusin(function() {
				$('.searchBox').stop().animate({width:'343px'}, 500).queue(function(){$('.searchBox input:first').stop().animate({width:'256px'}, 100);});
			}).focusout(function() {
				$('.searchBox input:first').stop().animate({width:'56px'}, 100).queue(function(){$('.searchBox').stop().animate({width:'143px'}, 500);});
			});
			$('.nav li a').hover(function() {$(this).parent().addClass('hover');},function() {$(this).parent().removeClass('hover');});
			//handle twisty menus
			$('ul.twisty').hide();
			$('h3.twisty a').click(function(){$('html,body').animate({'scrollTop':$(this).offset().top},500);$(this).parent().next().slideToggle(500);return false;});
			$('a.twisty').click(function() {$('html,body').animate({'scrollTop':$(this).offset().top},500);$(this).next().slideToggle(500);return false; });
			$('.link-new-window a, a.link-new-window').attr('target', '_blank');
		});
	};
	this.Forms = {
		CalendarPicker : function() {
			$(function() {
				$('div.calendarMonthPicker, ul.calendarMonthPicker').show();
				$('select.calendarMonthPicker').hide();
				$('ul.calendarMonthPicker li').click(function() {
					var i = $(this).index()+1;
					$('ul.calendarMonthPicker li').removeClass('active');
					$(this).addClass('active');
					$('select.calendarMonthPicker').attr("selectedIndex", i);
				});
			});
		},
		Validation : function() {
			$(function() {
				$('.webForm').nextVal({useInline:false,useSummary:true,useTitles:true,
				    customRules:['date-opt', function($o){return !$o.val().match(/^((((((((0?[13578])|(1[02]))[\.\-/]?((0?[1-9])|([12]\d)|(3[01])))|(((0?[469])|(11))[\.\-/]?((0?[1-9])|([12]\d)|(30)))|((0?2)[\.\-/]?((0?[1-9])|(1\d)|(2[0-8]))))[\.\-/]?(((19)|(20))?([\d][\d]))))|((0?2)[\.\-/]?(29)[\.\-/]?(((19)|(20))?(([02468][048])|([13579][26]))))))*$/);}, 'Please enter a valid date. For example 7/3/1987.'] });
			});
		}
	};
	this.Event = function() {
		$(function() {
			$('.eventFormButtons').show();
			$('.eventForm').hide();
			$('.showForm').click(function() {$('.eventFormButtons').slideUp();$('.eventForm').slideDown();});
			$('[name=BackToResults]').click(function() { history.go(-1) });
			$('[name=CancelBackToResults]').click(function() { history.go(-1) });
		});
	};
	this.Doc = function() {
	    $(function() {
	        //asset sliders
	        $('.docAssetCase ul').each(function() {
	            var liCount = $(this).children('li').length;
    	        if (liCount > 0)
	                $(this).bxCarousel({
	                    display_num: (liCount < 4 ? liCount : 4),
	                    move: 1,
	                    prev_image: '/CMSTemplates/ECHN/styles/images/docAssetPrev.jpg',
	                    next_image: '/CMSTemplates/ECHN/styles/images/docAssetNext.jpg',
	                    margin: 20,
	                    controls: (liCount > 4 ? true : false)
	                });
	        });
	        $('.docAssetCase').hide();
	        $('.docControl').click(function() { $(this).next('.docAssetCase').slideToggle(500); return false; });
	    });
	};
	this.Services = function() {
		$(function(){
			$('.servicesNav > li > a').hover(function(){
				$('.servicesNav > li > ul').css({top:'-5000px'});
				var $t = $(this).parent();
				$('ul', $t).css({top:$t.position().top});
				return false;
			});
		});
	};
	this.Home = function() {
		var anmbettertogether = function(){
			$('.bettertogether .bannerText, .bettertogether img.anm1, .bettertogether img.anm2, .bettertogether img.anm3, .bettertogether img.anm4').hide();
			$('.bettertogether').parent().show();
			$('.bettertogether .bannerText').delay('1000').fadeIn(700).queue(function(){
				$('.bettertogether img.anm1').fadeIn(700).queue(function(){
					$('.bettertogether img.anm2').fadeIn(700).queue(function(){
						$('.bettertogether img.anm3').fadeIn(700).queue(function(){
							$('.bettertogether img.anm4').fadeIn(700);
							$(this).dequeue();
						});
						$(this).dequeue();
					});
					$(this).dequeue();
				});
				$(this).dequeue();
			});
			return 3500;
		};
		var anmworldclass = function(){
			$('.worldclass .bannerText, .worldclass img.anm1, .worldclass img.anm2, .worldclass img.anm3').hide();
			$('.worldclass').parent().show();
			$('.worldclass .bannerText').delay('1000').fadeIn(700).queue(function(){
				$('.worldclass img.anm1').fadeIn(700).queue(function(){
					$('.worldclass img.anm2').fadeIn(700).queue(function(){
						$('.worldclass img.anm3').fadeIn(700);
						$(this).dequeue();
					});
					$(this).dequeue();
				});
				$(this).dequeue();
			});
			return 2800;
		};
		var anmhealthgrade = function(){
			$('.healthgrade .bannerText, .healthgrade img.anm1, .healthgrade img.anm2, .healthgrade img.anm3, .healthgrade img.star1, .healthgrade img.star2, .healthgrade img.star3, .healthgrade img.star4, .healthgrade img.star5, .healthgrade img.tehrating').hide();
			$('.healthgrade').parent().show();
			$('.healthgrade .bannerText').delay('1000').fadeIn(700).queue(function(){
				$('.healthgrade img.anm1').fadeIn(700).queue(function(){
					$('.healthgrade img.anm2').fadeIn(700).queue(function(){
						$('.healthgrade img.anm3').fadeIn(700).queue(function(){
							
											
					
								$('.healthgrade img.star1').fadeIn(700);
									$(this).dequeue();
								$('.healthgrade img.star2').delay(350).fadeIn(700);
								$('.healthgrade img.star3').delay(700).fadeIn(700);
								$('.healthgrade img.star4').delay(1050).fadeIn(700);
								$('.healthgrade img.star5').delay(1400).fadeIn(700);
						
						});
						$(this).dequeue();
					});
					$(this).dequeue();
				
				});
				$(this).dequeue();
			});
			return 5550;
		};
		var anmcancer = function(){
			$('.cancer .bannerText, .cancer img.anm1, .cancer img.anm2, .cancer img.anm3, .cancer img.anm4').hide();
			$('.cancer').parent().show();
			$('.cancer .bannerText').delay('1000').fadeIn(700).queue(function(){
				$('.cancer img.anm1').fadeIn(700).queue(function(){
					$('.cancer img.anm2').fadeIn(700).queue(function(){
						$('.cancer img.anm3').fadeIn(700).queue(function(){
							$('.cancer img.anm4').fadeIn(700);
							$(this).dequeue();
						});
						$(this).dequeue();
					});
					$(this).dequeue();
				});
				$(this).dequeue();
			});
			return 3500;
		};
		
		
		$(function() {
			var anms = [ function(){return anmbettertogether();}, function(){return anmworldclass();}, function(){return anmhealthgrade();}, function(){return anmcancer();}];
			$('.banner ul').afCarousel({animation: anms, auto:true, showArrows:false});
		});
		
	};
	
	this.init();
};

var siteFramework = new SiteFramework();
