$(document).ready(function()
{
	var shadowbox_options = ''; // Will be appended to rel attribute for images and media
	
	//---------------------------------------------START CUSTOM JS//
	if(navigator.appVersion.indexOf("Mac")!=-1) // Sort out silly mac fat fonts
	{
		$('body').css('fontSize','64%');
	}
	
	if($('div.column').length > 0)
	{
		if($('div.page').height() > $('div.column').height()+20)
		{
			$('div.column').css('height',$('div.page').height()+'px');
			$('a.donate_link').css('position','absolute');
			$('a.donate_link').css('bottom','150px');
			$('a.donate_link').css('left','20px');
			$('a.parent_champion').css('position','absolute');
			$('a.parent_champion').css('bottom','20px');
			$('a.parent_champion').css('left','20px');			
			
		}
		else
		{
					
		}
		$('div.column div.item').each(function() 
		{
			if($(this).find('img').length > 0)
			{
				$(this).find('a.read_more').css('display','block');
			}
		});	
	}

		if($("form.search").length > 0)
		{
			$("input[name='keywords']").focus(function()
			{
				$(this).val('');
			});
		}
	
	if($('form#enquiry_form').length > 0)
	{
		$('textarea.enquiry').parent().css('display','none');
	}
	
	$('select#enquiry_subject').change(function() {
		if($('select#enquiry_subject').val() == 'General Enquiries')
		{
			$('textarea.enquiry').parent().css('display','inline');
		}
		else
		{
			$('textarea.enquiry').parent().css('display','none');
		}
	});
	
	// don't have divider on last menu object...
	$("ul#nav li.subnav ul li:last-child").css('background','none');
	
	// make nice roundy corners on stuff...
	if(!$.browser.msie || $.browser.version > 6)
	{
		$.getScript(_root+'media/js/jquery-corner.js', function()
		{
			$('body#survey div.page fieldset').corner('12px');		
			$('body#survey div.page input').corner('4px');					
			$('body#survey div.page select').corner('4px');		
			$('body#survey div.page dl.inputgroup').corner('4px');
		});
	}
	
	
	//---------------------------------------------END CUSTOM JS//
	
	$("li.subnav").hover(function()
	{
		$(this).addClass("active");
		
		if($("a.nav_search").hasClass("active"))
		{
			$("a.nav_search").removeClass("active");
			$("form.search").animate({ opacity: 0 }, 250);
			
			search_height_timeout = setTimeout(function()
			{
				$("form.search").css("height","0");
			}, 1000);
		}
	},
	function()
	{
		$(this).removeClass("active");
	});
	
	$('a[rel*="external"]').click(function()
	{
		open($(this).attr('href'));
		return false;
	});
	
	$('a[rel*="shadowbox"]').each(function()
	{
		if(!$(this).hasClass('page_media'))
		{
			var enlarge_img = $(this).attr('rel').split(' ');
			
			if(enlarge_img != 'undefined' && enlarge_img != '')
			{
				$(this).removeAttr('rel');
				
				if(enlarge_img[1] != undefined)
				{
					$(this).attr('rel', enlarge_img[1]+shadowbox_options);
				}
				else
				{
					$(this).attr('rel', enlarge_img[0]+shadowbox_options);
				}
			}
		}
		else
		{
			var media_rel = $(this).attr('rel');
			
			$(this).removeAttr('rel');
			
			$(this).attr('rel', media_rel+shadowbox_options);
		}
	});
	
	$("ul.thumbs li a img").each(function()
	{
		$.preloadImages.add($(this).attr("src").replace("thumb", "mid"));
	});
	
	$("ul.thumbs li a").mouseover(function()
	{
		$("img#full").attr("src", ($(this).attr('href')).replace("full", "mid"));
		$("img#full").attr("alt", ($(this).attr('alt')));
		$("a#enlarge").attr("href", ($(this).attr('href')).replace("thumb", "full"));
		$("a#enlarge").attr("title", ($(this).attr('title')));
	});
	
	$("ul.thumbs li:first a").click(function()
	{
		$("a#enlarge").click();
	});
	
	$("ul.thumbs li a").click(function()
	{
		$("img#full").attr("src", ($(this).attr('href')).replace("full", "mid"));
		$("img#full").attr("alt", ($(this).attr('alt')));
		$("a#enlarge").attr("href", ($(this).attr('href')).replace("thumb", "full"));
		$("a#enlarge").attr("title", ($(this).attr('title')));
		return false;
	});
	
	if($('a.page_media').length > 0)
	{
		var page_media = $('a.page_media').attr('rel').split(' ');
		
		if(page_media != 'undefined' && page_media != '')
		{
			$('a.page_media').removeAttr('rel');
			$('a.page_media').attr('rel', page_media[1]);
		}
	}
	
	if($("li.help a").length > 0)
	{
		$("li.help a").click(function()
		{
			return false;
		});
		
		var help_timeout = 'undefined';
		
		$("li.help a").bind("mouseenter",function()
		{
			if(help_timeout != 'undefined')
			{
				clearTimeout(help_timeout);
			}
			$("li.help div").fadeOut();
			$(this).next().addClass('active').fadeIn();
		}).bind("mouseleave",function()
		{
			help_timeout = setTimeout(function()
			{
				$('li.help div.active').removeClass('active').fadeOut();
			},2000);
		});
		
		$('input').focus(function()
		{
			$('li.help div.active').removeClass('active').fadeOut();
		});
		
		$('select').focus(function()
		{
			$('li.help div.active').removeClass('active').fadeOut();
		});
		
		$('textarea').focus(function()
		{
			$('li.help div.active').removeClass('active').fadeOut();
		});
	}
	
	if($('a[rel*="shadowbox"]').length > 0)
	{
		if($('a.page_audio').length > 0 || $('a.page_video').length > 0)
		{
			Shadowbox.init({
								continuous		:	true,
								ext				: 	{
										                img		:	['png', 'jpg', 'jpeg', 'gif', 'bmp'],
										                swf		:	['swf'],
										                flv		:	['flv', 'm4v', 'mp4', 'mp3'],
										                qt		:	['dv', 'mov', 'moov', 'movie'],
										                wmp		:	['asf', 'wm', 'wmv'],
										                qtwmp	:	['avi', 'mpg', 'mpeg']
										            },
								players			: 	['img', 'flv', 'iframe'],
								useSizzle		: 	false
							});
		}
		else
		{
			Shadowbox.init({
								continuous		: 	true,
								players			: 	['img'],
								useSizzle		: 	false
							});
		}
	}
});
