﻿function positionFooter()
{
	$.browser.msie6 = $.browser.msie && /MSIE 6\.0/i.test(window.navigator.userAgent) && !/MSIE 7\.0/i.test(window.navigator.userAgent);
	var winHeight = $(window).height();
	var bodyHeight = $('body').height();
	
	if($.browser.safari)
		bodyHeight+=244;
	
	if (bodyHeight < winHeight)
		$('body').css('position','static');
	else
	{
		if($.browser.msie6)
		{
			$('body').css('position','absolute');
		}
		else
		{
			$('body').css('position','relative');
		}
	}
}

function expandableForms()
{
	$('.expand-form').css('display','none');
	
	$('a.expand').click(function()
	{
		$(this).parent().css({height:'auto'});
		var element = $(this).parent().find('.expand-form');
		
		if(element.is(':hidden'))
		{
			element.animate(
			{
				height: 'show'
			}, 200, 'swing', function() 
			{
				element.animate(
				{
					height: '+=4px'
				}, 100, 'swing', function()
				{
					element.animate({height: '-=4px'}, 35, 'swing');
				});
			});
		}
		else
		{
			element.animate(
			{
				height: '+=4px'
			}, 150, 'swing', function()
			{
				element.animate({height: '-=4px'}, 50, 'swing', function()
				{
					element.animate(
					{
						height: 'hide'
					}, 200, 'swing');
				});
			});
		}
		
		return false;
	});
}

function expandableText()
{
	$('h3 a').each(function()
	{
		rel = $(this).attr('rel');
		if(rel != 'visible')
		{
			$(this).parent().next().css('display','none');	
		}
	});
	
	$('h3 a').click(function()
	{
		$(this).parent().next().css({height:'auto'});
		var element = $(this).parent().next();
		
		if(element.is(':hidden'))
		{
			element.animate({height: 'show'}, 200, positionFooter);
		}
		else
		{
			element.animate({height: 'hide'}, 200, positionFooter);
		}
		
		return false;
	});
}

function enablePrintLinks(elementArray)
{
	elementArray.each(function()
	{
		$(this).attr('href','javascript:window.print()');
	});
}

function roundBox(elementArray)
{
	elementArray.each(function()
	{
		$(this).append('<div class="corner tl"></div><div class="corner tr"></div><div class="corner br"></div><div class="corner bl"></div>');
	});
}

function addHoverClass(element)
{
	$.browser.msie6 = $.browser.msie && /MSIE 6\.0/i.test(window.navigator.userAgent) && !/MSIE 7\.0/i.test(window.navigator.userAgent);
	
	if(!$.browser.msie6)
	{
		element.hover(function()
		{
			$(this).addClass('hover');
		},
		function()
		{
			$(this).removeClass('hover');
		});
	}
}

$(function() {
	positionFooter();
	$(window).resize(positionFooter);
	expandableForms();
	expandableText();
	enablePrintLinks($('.print-page'));
	roundBox($('.note'));
	addHoverClass($('.residence-item'));
});