function slideShow(speed) {

	//Call the gallery function to run the slideshow

//	$('ul.slideshow li').each(function(e){
//		var x = setTimeout('gallery()',speed);
//		console.log($(this).attr('class'));
//	});

	var timer = setInterval(function(){
		//if no IMGs have the show class, grab the first image
		var current = ($('ul.slideshow li.show')?  $('ul.slideshow li.show') : $('#ul.slideshow li:first'));

		//Get next image, if it reached the end of the slideshow, rotate it back to the first image
		var next = ((current.next().length) ? ((current.next().attr('id') == 'slideshow-caption')? $('ul.slideshow li:first') :current.next()) : $('ul.slideshow li:first'));

		if(next.attr('class').indexOf('stop')!=-1)
		{
			next.css({opacity: 0.0}).addClass('show').animate({opacity: 1.0}, 3000)
/** Uncomment to activate			$('#slideshow-caption').animate({bottom:-80}, 300);  */
			next.css('background-image', 'url(' + $('#bb-meta-background-image').attr('class') + ')');
			next.html($('#billboard-form').html());

			current.animate({opacity: 0.0}, 3000).removeClass('show');

			clearInterval(timer);
			
			$('ul.slideshow').children('li').each(function(){
				if($(this).attr('class').indexOf('stop')==-1)
				{
					$(this).remove();
				} else {
					$(this).css({'position':'','z-index':'100'});
				}
			});

			var toppos = parseInt($('#bb-meta-y').attr('class'));

			if($('#bb-meta-user-title-size').length > 0 && $('#bb-meta-user-title-size').attr('class').length > 0)
			{
				toppos = parseInt($('#bb-meta-user-title-size').attr('class')) + parseInt($('#bb-meta-y').attr('class'));
			}

			$('#billboard-form-render').css({'left': parseInt($('#bb-meta-x').attr('class')), 'top': toppos, 'margin-top': 0});
			$('#billboard-form-render').width(parseInt($('#bb-meta-w').attr('class')));
			$('#billboard-form-render').height(parseInt($('#bb-meta-h').attr('class')));

			if($('#bb-meta-background-color').length > 0 && $('#bb-meta-background-color').attr('class').length > 0)
			{
				$('#billboard-form-render').css('background-color', $('#bb-meta-background-color').attr('class'));
			}

			if($('#bb-meta-label-color').length > 0 && $('#bb-meta-label-color').attr('class').length > 0)
			{
				$('#bb-signupform label').css('color', $('#bb-meta-label-color').attr('class'));
			}
			

			if($('#user-title-text').length > 0)
			{
			
				$('#user-title-text').css('margin-top',0);
		
				if($('#bb-meta-user-title-font').length > 0 && $('#bb-meta-user-title-font').attr('class').length > 0 )
				{
					$('#user-title-text').css('font-family', $('#bb-meta-user-title-font').attr('class'));
				}

				if($('#bb-meta-user-title-weight').length > 0 && $('#bb-meta-user-title-weight').attr('class').length > 0)
				{
					$('#user-title-text').css('font-weight', $('#bb-meta-user-title-weight').attr('class'));
				}

				if($('#bb-meta-user-title-size').length > 0 && $('#bb-meta-user-title-size').attr('class').length > 0)
				{
					$('#user-title-text').css('font-size', $('#bb-meta-user-title-size').attr('class') + 'px');
				}

				if($('#bb-meta-user-title-style').length > 0 && $('#bb-meta-user-title-style').attr('class').length > 0)
				{
					$('#user-title-text').css('font-style', $('#bb-meta-user-title-style').attr('class'));
				}

				if($('#bb-meta-user-title-color').length > 0 && $('#bb-meta-user-title-color').attr('class').length > 0)
				{
					$('#user-title-text').css('color', $('#bb-meta-user-title-color').attr('class'));
				}

				if( ($('#bb-meta-user-title-x').length > 0 && $('#bb-meta-user-title-x').attr('class').length > 0 ) &&
					($('#bb-meta-user-title-y').length > 0 && $('#bb-meta-user-title-y').attr('class').length > 0 ))
				{
					$('#user-title-text').css({'top': (parseInt($('#bb-meta-user-title-y').attr('class')))});

				}
			}

			if( $('#groupid').length > 0 && $('#bb-meta-groupid').attr('class').length > 0)
			{
				$('#groupid').val($('#bb-meta-groupid').val());
			}

			// bless the form

			blessform();

		} else {

			//Get next image caption
			/** Uncomment to turn back on
			var title = next.find('img').attr('title');
			var desc = next.find('img').attr('alt');
			*/

			//Set the fade in effect for the next image, show class has higher z-index
			next.css({opacity: 0.0}).addClass('show').animate({opacity: 1.0}, 3000)

			//Hide the caption first, and then set and display the caption

/** Uncomment to turn back on
			$('#slideshow-caption h3').html(title);
			$('#slideshow-caption p').html(desc);

			$('#slideshow-caption').animate({bottom:-80}, 300, function () {
					//Display the content
					$('#slideshow-caption h3').html(title);
					$('#slideshow-caption p').html(desc);
					$('#slideshow-caption').animate({bottom:0}, 500);
			});
*/
			//Hide the current image
			current.animate({opacity: 0.0}, 3000).removeClass('show');
		}
	},speed);
}

function blessform()
{
	if($('#bb-signupform').length > 0)
	{
		$('#billboard-submit-img').attr('alt','');
		$('#billboard-submit-img').html('');
		
		$('#billboard-submit-img').click(function(e){
			e.preventDefault();
			doAjaxStuff();
		});
		
		$('#bb-signupform').submit(function(e){
			e.preventDefault();
			doAjaxStuff();
		});

	}

}

function doAjaxStuff()
{
	$.ajax({
		type: 'POST',
		url: '/billboard/',
		data: $('#bb-signupform').serialize() + '&groupid=' + $('#bb-meta-groupid').attr('class') + '&bb-meta-link=' + $('#bb-meta-link').attr('class') + '&bb-meta-thankyou=' + $('#bb-meta-thankyou').attr('class'),
		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()
				{
					if($(this).length > 0)
					{
						$(this).css('color','#f00');
					}
				});

			} else {
				window.open($('#bb-meta-thankyou').attr('class'), '_self');
			}
		}
	});
}
