function cycleImages(){
    var $active = $('#imgslides .active');
    var $next = ($('#imgslides .active').next().length > 0) ? $('#imgslides .active').next() : $('#imgslides img:first');
    $next.css('z-index',2);
	$active.fadeOut(2000,function(){
		$active.css('z-index',1).show().removeClass('active');
		$next.css('z-index',3).addClass('active');
	});
}

$(document).ready(function(){
	if ($("a[rel=lightbox]").length) {
		$("a[rel=lightbox]").fancybox({ 'zoomSpeedIn': 300, 'zoomSpeedOut': 300, 'transitionIn': 'elastic', 'transitionOut': 'elastic', 'overlayShow': true});
	}
	if ($("#imgslides").length) {
		//$('#imgslides').shuffle();
		if ($("#imgslides .active").length == 0) {
			$('#imgslides img:first').addClass('active');
		}
		setInterval('cycleImages()', 5500);
	}
	
	function check_h() {
		var rh = $('#main-right').height();
		var mh = $('#main-left').height();
		var mho = rh-93;
		if(mh<rh) {
			$('#main-left-bg').animate({ height: mho+'px'},500);
		}
	}
	check_h();
});

(function($){
  $.fn.shuffle = function() {
	return this.each(function(){
	  var items = $(this).children();
	  return (items.length)
		? $(this).html($.shuffle(items))
		: this;
	});
  }
  $.shuffle = function(arr) {
	for(
	  var j, x, i = arr.length; i;
	  j = parseInt(Math.random() * i),
	  x = arr[--i], arr[i] = arr[j], arr[j] = x
	);
	return arr;
  }
})(jQuery);
