// how many images are there?
photoNumber = 825;


$(document).ready(function(){

	$("h3").click(function(){
		$(this).parent().toggleClass("closed");
		return false;
	});

	$("#alertBG,#alertCloser").click(function(){
		$("#alertBG").fadeOut("fast");
		$("#alertContent").fadeOut("fast");
		return false;
	});
	
	setTimeout(function(){
		swapTimer();
	},5000);

	$("#mainContent #photo img").live('click',function(){
		swapSlide();
	});

	$("#twitter_update_list a").live('click',function(){

		$(this).attr('target','_blank');

	});
	
	var tweetText = "RT @The_National " + $("#twitter_update_list li span").html().replace(/<[^>]+>/g, " ").replace(/<\/[^>]+>/g, " ")

	$("a#retweeter").attr('href','http://twitter.com/?status=' + tweetText);

});

function swapSlide() {

	randomNum = Math.ceil(Math.random()*photoNumber);
	
	if ($(".bigBoy").length == 0) {
		newPhoto = '<img src="-/img/imgs_580x330px/' + randomNum + '.jpg" alt="" width="580" height="330" />';
	} else {
		newPhoto = '<img src="-/img/imgs_880x500px/' + randomNum + '.jpg" alt="" width="880" height="500" />';
	}

	$('#mainContent #photo').append(newPhoto);

	$('#mainContent #photo img:eq(0)').fadeOut('fast')
	$('#mainContent #photo img:eq(1)').fadeIn('', function(){
		$('#mainContent #photo img:eq(0)').remove();
	});

};

function swapTimer() {

	swapSlide();
	
	setTimeout(function(){
		swapTimer();
	},8000);
	
};
