$(function() {
	if($('#cy-picture').length){
		var count = $("#cy-picture img").length;
		if(count > 1){
		    $('#cy-picture').cycle({
		        fx:     'fade',
		        speed:  'slow',
		        timeout: 5000,
		        pager:  '#real-nav',
		        before:  onBefore, 
		        after:   onAfter 
		    });
		    
		    $('.cy-stop').toggle(function () {
		        $('#cy-picture').cycle('pause');
		        $(".cy-stop").addClass("on");
		    }, function() {
		    	$(".cy-stop").removeClass("on");
		        $('#cy-picture').cycle('resume', true);
		    });
		} else {
			$('#cy-slide').css('height','330');
			$('#cy-stop').css('display','none');
			$('#cy-text').html('<h3>' + $("#cy-picture img").attr('title') + '</h3>' + $("#cy-picture img").attr('alt'));
			$('#cy-more-url > a').attr("href",$("#cy-picture img").attr('rel'));
		}
	}
});

function onBefore() {
	$('#cy-text').fadeOut('slow');	
}
function onAfter() {
	$('#cy-text').html('<h3>' + this.title + '</h3>' + this.alt);
	$('#cy-more-url > a').attr("href",$(this).attr('rel'));
	$('#cy-text').fadeIn('slow');

}
