var gtwm_image_number = 0;

function next_slide() {
  var numSlideshowItems = $('.slideshow_item').size();
  if (numSlideshowItems < 2) {
  	// The first time we're called, load the slideshow items in
  	$.get('../static_features/slideshow_content.htm', function(data) {
      $('#slideshow').append(data);
    });
  } else {
  	  //rotate slideshow items
	  var imgSrc = $($('.slideshow_item').get(gtwm_image_number+1)).find("img").attr("src");
	  $('#slideshow').css('background','url(' + imgSrc + ')');
	  $('.slideshow_item').fadeOut(2000);
	  $($('.slideshow_item').get(gtwm_image_number+1)).fadeIn(2000);
	  if (gtwm_image_number >= ($('.slideshow_item').size() - 2)) {
	  	gtwm_image_number = -1;
	  } else {
	  	gtwm_image_number++;
	  }
  }
}

function show_all_news() {
  jQuery(".newsheadline").css('height','');
  jQuery(".newsheadline").show("fast");
  jQuery("#all_news").fadeOut("normal");
}

function formatPage() {
  var jqFirstArticle = $(".newsheadline:eq(0)");
  var jqSecondArticle = $(".newsheadline:eq(1)");
  // replace top left image with the image in the first article
  var jqSlideshowImage = jqFirstArticle.find("img");
  if (jqSlideshowImage.size() > 0) {
    $("#slideshow_image").replaceWith(jqSlideshowImage).addClass("rounded").attr("id","slideshow_image");
  }
  // set text over top left image
  $("#slideshow_caption").html(jqFirstArticle);
  // move second article to top right, unless there's an RSS feed already there
  if(jQuery("#video").find("#feedControl").size() == 0) {
    $("#video").html(jqSecondArticle);
  }
  // tidy up link separators
  $("img.section_separator").last().remove();
  // bottom section: remove columns if necessary
  if($("#bottom_half").find("iframe").size() > 0) {
    $("#bottom_half").css("column-count","1").css("-moz-column-count","1").css("-webkit-column-count","1");
  }
}

function fYouTube() {
	$('a').each(
			function() {
				var sHref = this.getAttribute('href');
				if ((sHref.indexOf('youtube.com') > -1)
						|| (sHref.indexOf('vimeo.com') > -1)) {
					var oContainer = document.createElement('div');
					oContainer = $(oContainer);
					oContainer.addClass('gtpb_youtube');
					$(this).replaceWith(oContainer);
					oContainer.oembed(sHref, 
					  {
					  	youtube: { maxWidth: 390 }
					  }
					);
				}
				// oContainer.find('embed').attr('rel',0);
			});
}

// pre-submit callback 
function ajaxFormValidate(formData, jqForm, options) { 
    if (jQuery("#enter_email").val().indexOf("@") == -1) {
      alert("Please enter an email address to sign up for special offers");
      return false;
    } else {
      return true;
    }
} 
 
// post-submit callback 
function ajaxFormShowResponse(responseText, statusText, xhr, $form)  { 
	alert("Thank you, your email address has been received");
}
