$(document).ready(function(){

	function blessform()
	{
		if($('#closegsl').length > 0)
		{
			$('#closegsl').submit(function(e){

				e.preventDefault();

				$.ajax({
					type: 'POST',
					url: $('#closegsl').attr('action'),
					data: $('#closegsl').serialize(),
					async: true,
					complete: function(msg){
						var response = msg.responseText;

						if(response.indexOf(':ERR:')!=-1)
						{
							var errmsg = response.split(":ERR:\n");
							JQAlertBox.alert(errmsg[1]);

							$('label.required').each(function()
							{
								$(this).css('color','#f00');
							});
						}

						if(response.indexOf('-_-')!=-1)
						{
							var resptext = response.split("\n-_-\n");

							$('#video').css('display','none');

							$('#splash-left').css('background-image', "url('/images/splash/bg-left-taf.gif')");
							$('#alttext_line2').html(resptext[0]);
							$('#splash-right').css('background-image', "url('/images/splash/bg-right-taf.gif')");
							$('#right-render').html(resptext[1]);
							$('#right-render').css('margin-top','149px');
							$('#right-render').css('margin-left','23px');

							blessform();
						}
					}
				});

			});
		}

		if($('#tellafriend').length > 0)
		{
			$("#tellafriend").bind("submit", function() { return false; })

			$('#tellafriend').submit(function(e){
				e.preventDefault();

				var post = $('#tellafriend').serialize();

				$.ajax({
					type: 'POST',
					url: '/colin/tellafriend/',
					data: $('#tellafriend').serialize(),
					async: true,
					complete: function(msg){
						var response = msg.responseText;

						$('#right-render').html(response);

						if(response.indexOf('form')!=-1)
						{
							blessform();
						} else {
							$('#right-render').html(response);
							window.setTimeout(function(){window.open('http://www.bradycampaign.org/','_self');}, 3000);
						}
					}
				});

			});
		}

	}

	blessform();

	

	function swapvideo()
	{
		$('#wantmore').click(function(e){
			e.preventDefault();

			var bgimg = $('#splash-left').css('background-image');

			if($('#splash-left').css('background-image').indexOf('bg-left.gif')!=-1)
			{
				$('#splashvideo').css('display','none');
				$('#gunshopvideo').css('display','block');
				$('#splash-left').css('background-image','url(/images/splash/bg-left-colin.gif)');
			} else {

				$('#splashvideo').css('display','block');
				$('#gunshopvideo').css('display','none');
				$('#splash-left').css('background-image','url(/images/splash/bg-left.gif)');
			}

		});
	}

	swapvideo();

});
