/* Author: 

*/


$(function()
{
	$('#featured').hover(function()
	{
		$(this).find('.cover').stop(true,true).fadeOut();
	},function()
	{
		$(this).find('.cover').stop(true,true).fadeIn();
	});
	
	$('.bg').click(function()
	{
		var h = $(this).parent().find('a').first().attr('href');
		location = h;
	});
	
	if($('#map').length) init_map();
	
	// gallery
	init_gallery();
	
	equal_heights();
	
	if(!form_submitted)
	{
		$('#register-form input:not(.e),#register-form textarea').each(function()
		{
			$(this).data('def',$(this).val());
			$(this).focus(function()
			{
				if($(this).val() == $(this).data('def')) $(this).val('');
			}).blur(function()
			{
				if($(this).val() == '') $(this).val($(this).data('def'));
			});
		});
	}
	
	$('#subscribe-form input.text').each(function()
	{
		$(this).data('def',$(this).attr('title'));
		if($(this).val() == '') $(this).val($(this).attr('title'));
		$(this).focus(function()
		{
			if($(this).val() == $(this).data('def')) $(this).val('');
		}).blur(function()
		{
			if($(this).val() == '') $(this).val($(this).data('def'));
		});
	});
	
});

var check_form = function()
{
	$('#register-form input:not(.e),#register-form textarea').each(function()
	{
		if($(this).val() == $(this).data('def')) $(this).val('');
	});
	return true;
}

var check_subscribe = function()
{
	$('#subscribe-form input').each(function()
	{
		if($(this).val() == $(this).data('def')) $(this).val('');
	});
	return true;
}

var select_event = function(id)
{
	var $a = $('#box-'+id);
	if($a.hasClass('checked'))
	{
		$a.removeClass('checked');
		$a.find('img').attr('src','/images/checkbox.png');
		$('#event_'+id).val(0);
	} else
	{
		$a.addClass('checked');
		$a.find('img').attr('src','/images/checkbox-checked.png');
		$('#event_'+id).val(1);
	}
}

var init_gallery = function()
{
	var numImages = $('.images img').length;
	if(numImages > 1)
	{
		$current = $('.images img').first();
		$('.next').click(function()
		{
			$('.prev').fadeIn();
			var $n = $current.next('img');
			if($n.length)
			{
				
				$('p.caption').html($n.attr('alt'));
				$current.animate({'left':'-700px'},500,'easeInOutQuad');
				$n.css('left','700px').show().animate({'left':'0px'},500,'easeInOutQuad',function()
				{
					if($n.next('img').length < 1) $('.next').fadeOut();
					$current = $(this);
				});
				
			}
		});
		
		$('.prev').click(function()
		{
			$('.next').fadeIn();
			var $n = $current.prev('img');
			if($n.length)
			{
				
				$('p.caption').html($n.attr('alt'));
				$current.animate({'left':'700px'},500,'easeInOutQuad');
				$n.css('left','-700px').show().animate({'left':'0px'},500,'easeInOutQuad',function()
				{
					if($n.prev('img').length < 1) $('.prev').fadeOut();
					$current = $(this);
				});
				
			}
		});
		
		$('.next').fadeIn();
		
		
	}
}

var equal_heights = function()
{
	var max = 0;
	$('.equal').each(function()
	{
		var h = $(this).height();
		max = Math.max(h,max);
	});
	
	$('.equal').height(max);
	
	// footer specific
	
	var max = 0;
	$('footer .col4').each(function()
	{
		var h = $(this).outerHeight();
		max = Math.max(h,max);
	});
	max += 40;
	$('footer .col4:not(#contact)').height(max - 40);
	$('footer').height(max);
	
	
}
