// remove the "$" namespace from jQuery, avoids conflicts with other libraries
jQuery.noConflict();

// closure, mapping jQuery to $, window, document and undefined - useful for minifing tools
(function($, window, document, undefined){

// document ready method
$(function(){

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



	if ($.fn.equalHeights)
	{
		$('#menu-footer > li').equalHeights();
		$('.box-f, #separator-f1').equalHeights();
		$('.big-box').equalHeights();
	}


});

// plugins

// slideshowFade - jQuery plugin - creates a fading slideshow - by Valentin Agachi http://agachi.name
$.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 || {});

	return 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 += '<li><a href="#' + this.id + '">' + n + '</a></li>';
		});

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

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

			var stop = parent.triggerHandler('slideChanging', [parent, slides, opts, active, next]);
			if (!stop)
			{
				next.addClass('next');
				active.fadeOut(opts.speed, function(){
					next.addClass('active').removeClass('next');
					active.removeClass('active').show();
					$('.buttons').find('.active').removeClass('active');
					buttons.filter('[href="#' + next[0].id + '"]').parent('li').addClass('active');
				});
			}
			else
			{
				$('.buttons').find('.active').removeClass('active');
				buttons.filter('[href="#' + next[0].id + '"]').parent('li').addClass('active');
			}

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

		function changeNow(next)
		{
			slides.removeClass('active');
			next.addClass('active').show();
			$('.buttons').find('.active').removeClass('active');
			buttons.filter('[href="#' + next[0].id + '"]').parent('li').addClass('active');

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

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

		parent.bind('slideChange', function(ev, slide, now){
			clearInterval(timer);
			now ? changeNow(slide) : change(slide);
			auto();
		});
		parent.bind('slideAdvance', function(ev, delta){
			var dir = (delta > 0), cnt = Math.abs(delta),
				active = slides.filter('.active'), next = active;
			while (cnt--)
			{
				next = active[(dir ? 'next' : 'prev')]();
				if (!next.length)
					next = slides.eq(dir ? 0 : slides.length - 1);
			}
			parent.trigger('slideChange', [next]);
		});
		parent.bind('changeAuto', function(ev, time){
			clearInterval(timer);
			opts.auto = time;
			auto();
		});

		if ((a = slides.filter('.active')) && !a.length)
			changeNow(slides.eq(0));
		else
			changeNow(a);

		auto();
	});
};


// equalHeights - jQuery plugin - forces elements to have the same height (maximum)
$.fn.equalHeights = function(add)
{
	var m = 0;
	this.each(function(){
		m = Math.max(m, $(this).outerHeight());
	});
	return this.each(function(){
		var t = $(this), p = 0;
		$.each(['borderTopWidth', 'paddingTop', 'paddingBottom', 'borderBottomWidth'], function(i,n){
			var v = parseInt(t.css(n));
			p += (isNaN(v) ? 0 : v);
		});
		var h = m - p;
		if (add && add[this.id])
			h += add[this.id];
		if ($.browser.msie && $.browser.version <= 6) 
			t.css('height', h);
		t.css('min-height', h); 
	});
};



})(jQuery, window, document);

