$(document).ready(function() {
	$('body').removeClass('no-js').addClass('js');
	
	var init = {
		slider : function() {
			$('div.slider').nivoSlider({
				 slices : 1,
				 effect:'fade',
			     directionNav:true,
			     directionNavHide:false,
			     pauseTime: 6000
			});
		},
		
		subscribe : function() {
			var form = $('form.subscribe');
			var label = $('label.subscribe',form);
			var input = $('input#subscribe_email',form);
			
			label.css({
				position : 'absolute'
			});
			
			label.css({
				left : input.position().left,
				top : input.position().top + 2
			});
			
			input.focus(function() {
				label.css({'z-index':-1});
			});
			
			input.blur(function() {
				if(input.val()==='') {
					label.css({'z-index':1});
				}
			});
			
			if(input.val()!=='') {
				label.css({'z-index':-1});
			}

		},
		
		topmenu : function() {
			doMagicLine($('#nav ul.menu'));
		},
		
		googlemap : function() {
			$.getScript('http://maps.google.com/maps/api/js?sensor=false&callback=init_map');
		},
		
		dropdown : function() {
			$('.shower').click(function() {
				$('.hider',$(this).parent()).slideToggle(300);
				return false;
			});
		},		
		
		managedHeight : function() {
			$(window).load(function() {
				var $content = $('.managed_contentContainer .content');
				var $embed = $('.managed_contentContainer .embed');
				if($content.length>0 && $embed.length>0) {
					var height = $embed.height() - $content.position().top - ($content.innerHeight() - $content.height());
					if($content.height()<height) {
						$content.height(height);
					}
				}
			});
		},
		
		snippetHeight : function() {
			$(window).load(function() {
				var $content = $('.snippets .content');
				if($content.length>0) {
					var height = 0;
					$content.each(function() { height = Math.max(height,$(this).height());});
					$content.height(height);
				}
			});
		},
		
		treatmentList : function() {
			var lis = $('ul.treatment_category_list li');
			lis.hover(
				function() {
					$('> a',lis.not(this)).stop(true).fadeTo(200,0.8);
					$(this).stop(true).fadeTo(50,1);
				},
				function() {
					$('> a',lis).stop(true).fadeTo(200,1);
				}
			);
		}
	};
	
	$.each(modules,function(i,m) {
		if(m && typeof(init[i])==='function') {
			init[i]();
		}
	});
});
