jQuery.noConflict();
(function($, window, document, undefined){

$(function(){


	if ($.fn.slideshowFade)
	{
		$('#slideshow-fade1').slideshowFade({
			buttons: false
			//speed: 600, // default 600
			//auto: 5000 // default 5000
		});
	}


	if (window['DD_belatedPNG'] !== undefined)
		DD_belatedPNG.fix('img, #site-title a, #header');

});


// slideshowFade - jQuery plugin - creates a fading slideshow
$.fn.slideshowFade = function(args)
{
	if (!this.length)
		return this;

	var opts = $.extend({
		slides: '> ul > li',	// slides selector
		buttons: true,			// show buttons
		speed: 600,				// speed of transition
		auto: 5000				// speed of auto transition
	}, args);

	this.each(function(){
		var parent = $(this), slides = parent.find(opts.slides), buttons = $(), timer = null, n = 0, s = '';

		slides.each(function(){
			this.id = parent[0].id + '-' + (++n);
			s += '<a href="#' + this.id + '">' + n + '</a>';
		});

		if (opts.buttons)
		{
			buttons = parent.append('<div class="nav">' + s + '</div>').
				find('.nav a').click(function(){
					var hash = this.hash.substr(1);
					parent.triggerHandler('slideChange', [slides.filter('#' + hash)]);
					return false;
				});
		}

		if (!slides.filter('.active').length)
		{
			slides.eq(0).addClass('active');
			buttons.eq(0).addClass('active');
		}

		function change(next)
		{
			var active = slides.filter('.active');
			if (!next || !next.jquery)
				next = active.next();
			if (!next.length)
				next = slides.eq(0);

			parent.trigger('slideChanging', [parent, slides, active, next]);

			next.addClass('next');
			active.fadeOut(opts.speed, function(){
				next.addClass('active').removeClass('next');
				active.removeClass('active').show();
				buttons.removeClass('active').filter('[href="#' + next[0].id + '"]').addClass('active');
			});

			parent.trigger('slideChanged', [parent, slides, active, next]);
		}

		function auto()
		{
			if (opts.auto)
				timer = setInterval(change, opts.speed + opts.auto);
		}

		parent.bind('slideChange', function(ev, slide){
			clearInterval(timer);
			change(slide);
			auto();
		});

		auto();
	});

	return this;
};


})(jQuery, window, document);
