$(document).ready(function() {
/* 	$('#slideshow ul').reorder(); */
	$('#slideshow').css({'visibility':'visible'});
	var newText = $('#slideshow ul li:first-child a img').attr("alt");
	var newLink = $('#slideshow ul li:first-child a').attr("href");
	$('#slideshow-overlay').attr("href", newLink);
	$('#slideshow-overlay p').html(newText);
	/* if (newText == 'No. 1 Martin Place') { $("#slideshow-overlay").css({"width":"270px"}); }  */
	
	$('#slideshow-overlay').hover(
	  function () {
	  	if (transitioning == false) {
	      $(this).stop().animate({height:'46px', opacity:'0.8'}, 300, function() { transitioning = false; });
	    }
	  }, 
	  function () {
	    if (transitioning == false) {
	      $(this).stop().animate({height:'26px', opacity:'0.8'}, 300, function() { transitioning = false; });
	    }
	  }
	);

});

$(window).bind("load", function(){
    $('#slideshow ul').cycle({
		fx: 'fade',
		timeout: 9000,
		speed: 1500,
		cleartype: 1,
		pause: 1,
		before: onBefore,
		after: onAfter
	});
});


var transitioning = false;
var firstRun = true;

function onBefore(curr, next, options, f) {
	transitioning = true;
	$('#slideshow-overlay').stop(true, true).animate({height:'26px'});
	if (firstRun == true) {
		firstRun = false;
		transitioning = false;
	} else {
		$('#slideshow-overlay').stop(true, true).animate({opacity:'0'});
	}
}

function onAfter() {
	//animation end callback
	var newText = $('img', this).attr("alt");
	$('#slideshow-overlay').attr("href", $('a', this).attr("href"));
	$('#slideshow-overlay p').html(newText);

	if ($('img', this).attr("alt") !== "") {
		$("#slideshow-overlay").fadeTo("slow", 0.8, function() { transitioning = false; });
	} else {
		$("#slideshow-overlay").fadeOut("slow");
	}
}

