$(document).ready(function(){
	/* Create inner input labels */
	$('form').formlabel();
	
	/* Setup Lightbox and Photo Gallery */
	var lbimages = lightbox_images,
		$lbimages_dom = $('<div id="lightbox_images">');
	
	$.each(lbimages, function(i, val){
		if(val)
		{
			var string = '<a class="lightbox"';
					
			if(val.length > 2)
			{
				string += ' title="' + val[2] + '"';
			}
	
			string += ' href="' + val[1] + '">';
			string += '<img src="' + val[0] + '" width="270" height="180" alt="" /></a>';		
	
			$lbimages_dom.append($(string));
		}
	});
	
	$('#photogallery_image').html($lbimages_dom.css('width', $lbimages_dom.find('a').length * 270 + 'px'));

	$('#lightbox_images a').lightBox({
		'imageLoading': 'http://studentorgs.utexas.edu/swheart/media/img/lightbox/lightbox-ico-loading.gif',
		'imageBtnPrev': 'http://studentorgs.utexas.edu/swheart/media/img/lightbox/lightbox-btn-prev.gif',	
		'imageBtnNext': 'http://studentorgs.utexas.edu/swheart/media/img/lightbox/lightbox-btn-next.gif',			
		'imageBtnClose': 'http://studentorgs.utexas.edu/swheart/media/img/lightbox/lightbox-btn-close.gif',		
		'imageBlank': 'http://studentorgs.utexas.edu/swheart/media/img/lightbox/lightbox-blank.gif'
	}); 	
	
	var index = -1,
		$photogallery = $('#lightbox_images a'),
		$photogallery_comment = $('#photogallery_comment');
	
	$('#photogallery_nav_right').click(function(){
		if(index < $photogallery.length-1)
		{
			var $image = $($photogallery[++index]);
			$lbimages_dom.animate({'left': '-=270px'}, 'slow');
			$photogallery_comment.html($image.attr('title'));
		}
	});
	
	$('#photogallery_nav_left').click(function(){
		if(index > 0)
		{
			var $image = $($photogallery[--index]);
			$lbimages_dom.animate({'left': '+=270px'}, 'slow');
			$photogallery_comment.html($image.attr('title'));
		}
	});
	
	$photogallery_comment.html($($photogallery[++index]).attr('title'));
	
	/* Custom Checkbox */
	$('form div.checkbox').click(function(){
		var $newsletter = $('input[name=newsletter]');
		if($newsletter.val() == 'false' || $newsletter.val() == 'NEWSLETTER')
		{
			$newsletter.val('true');
			$('form div.checkbox').html('y');
		}
		else if($newsletter.val() == 'true')
		{
			$newsletter.val('false');
			$('form div.checkbox').html('&nbsp;');
		}		
	});
	
	/* Nav Hovers */
	$('div#nav ul li img').mouseover(function(){
		$this = $(this);
		
		$(this).attr('src', $this.attr('src').substr(0, $this.attr('src').length-4) + '_active.gif');
	});
	
	$('div#nav ul li img').mouseout(function(){
		$this = $(this);
		
		$(this).attr('src', $this.attr('src').substr(0, $this.attr('src').length-11) + '.gif');
	});
});