function autoSlider() {
	$active = $('.slider-box.active');
	if ($active.length == 0) {
		$active = $('.slider-box:first');
	}
	
	$next = $active.next('.slider-box');
	if ($next.length == 0) {
		$next = $('.slider-box:first');
	}

	activateSliderBox($next);
}

function activateSliderBox($box) {
	if ($('.slider-box.active').attr('data') == $box.attr('data'))
		return;
	$('.slider-images img').css('opacity', 1);
	$('.slider-images img:visible').stop().show().fadeOut();
	$('.slider-images img[data="' + $box.attr('data') + '"]').stop().hide().fadeIn();

	$('.slider-box.active').removeClass('active');
	$box.addClass('active');
}

var sliderInterval = null;
function runSlider() {
	stopSlider();
	sliderInterval = setInterval('autoSlider()', 3000);
}
function stopSlider() {
	clearInterval(sliderInterval);
}
$(function(){
	$imageBox = $('<div />')
		.addClass('slider-images')
		.addClass('corners')
		.prependTo('.content-wrapper')
	;
	$('<div class="lt" />').appendTo($imageBox);
	$('<div class="rt" />').appendTo($imageBox);
	$('<div class="lb" />').appendTo($imageBox);
	$('<div class="rb" />').appendTo($imageBox);
	var id = 1;
	$('.slider-box').each(function(){
		$('<span class="slider-box-indicator" />').appendTo($(this));
		$(this)
			.attr('data', id)
			.mouseover(function(){
				stopSlider();
				activateSliderBox($(this));
			})
		;
		$image = $(this).find('img:first');
		$image.attr('data', id);
		$image.appendTo($imageBox);
		if (id != 1)
			$image.hide();
		else
			$(this).addClass('active');
		id++;
	});
	$('.sliders').mouseout(runSlider);
	runSlider();

	$('.navigation .left, .navigation .right').height(($('.navigation .left').height() > $('.navigation .right').height()) ? $('.navigation .left').height() : $('.navigation .right').height() );
});

