var ROOT_DIR = '/';

$(function() {
	
	$('input[type=text],textarea').defaultText();

	$('a.lightbox').lightBox();
	$('a.facebox').facebox();
	
	$('.slideshow').cycle({
		fx : 'fade'
	});
	
	$('#message').live('click',function() {
		$(this).slideUp();
	}).live('mouseover',function() {
		$(this).css('cursor','pointer');
	}).live('mouseout',function() {
		$(this).css('cursor','default');
	});

	$('#captions > li').click(function() {
		if($(this).attr('link')) {
			window.location.href = $(this).attr('link');
		} else {
			window.parent.location = $(this).attr('file');
		}
	}).hover(function() {
		$(this).css('cursor','pointer');
	},function() {
		$(this).css('cursor','default');
	});

	$('form.ajax').submit(function() {
		var thisForm = $(this);
		var data = {
			ajax : 1,
			_submit_ : 1,
			name : $('input[name=name]',thisForm).val(),
			email : $('input[name=email]',thisForm).val(),
			phone : $('input[name=phone]',thisForm).val(),
			comments : $('textarea[name=comments]',thisForm).val()
		};
		$.post(thisForm.attr('action'),data,function(ret) {
			if(ret) {
				$('html,body').animate({scrollTop:0},'fast');
				var html_body = $('body');
				var img = $("<img />")
					.attr('src','/~shadow/skin/shadow/images/click-to-close.png');
				var msg = $("<p />")
					.html('Thank you for contacting us. A representative from Shadow Mountain Recovery will contact you shortly.');
				var divMessage = $('<div />')
					.attr('id','message')
					.append(msg)
					.append(img)
					.prependTo(html_body);
				$('input[name=name]',thisForm).val('name');
				$('input[name=email]',thisForm).val('email');
				$('input[name=phone]',thisForm).val('phone');
				$('textarea[name=comments]',thisForm).val('comments');
			}
		});
		return false;
	});

	var h = $('#end').height();
	var ah = Math.floor($(document).height() - ($('#end').position().top+h));
	$('#end').height(h+ah);
	
	/*$('#get-help-for').click(function() {
		window.location.href = ROOT_DIR + 'program';
	}).hover(function() {
		$(this).css('cursor','pointer');
	},function() {
		$(this).css('cursor','default');
	});*/

});
