$(document).ready(function(){
	
	$('a.photo').colorbox({
		maxWidth : '90%',
		maxHeight : '90%',
		minWidth : 630,
		minHeight : 660
	});
	
	$('a.modal').colorbox({
		width : 640,
		height : 480,
		iframe : true
	});
	
	$('a.out').click(function(){
		if ($(this).hasClass('photo') !== true) {
			window.open($(this).attr('href'));
			return false;
		}
	});
	
	if ($('#SLIDESHOW_ENABLED').val() == 'true') {
		
		goNextSlide = function() {
			if (parseInt($('#SLIDESHOW_TOTAL').val()) > 1) {
				var activeSlide = $('#slideshow img.active');
				if ($('#slideshow img[rel=' + (parseInt(activeSlide.attr('rel')) + 1) + ']').length > 0) {
					var nextSlide = $('#slideshow img[rel=' + (parseInt(activeSlide.attr('rel')) + 1) + ']');
				} else {
					var nextSlide = $('#slideshow img[rel=1]');
				}
				activeSlide.addClass('last-active');
				$('#SLIDESHOW_CURRENT').val(nextSlide.attr('rel'));
				nextSlide.css({ opacity : 0.0, top : 0 }).addClass('active').animate(
					{ opacity : 1.0 }, parseInt($('#SLIDESHOW_ANIMATE_SECS').val()), function() {
					activeSlide.removeClass('active last-active');
					if (nextSlide.height() > 190) {
						nextSlide.animate(
							{ top : '-' + (nextSlide.height() - 190) + 'px'},
							parseInt($('#SLIDESHOW_SCROLL_SECS').val()),
							goNextSlide
						);
					} else {
						setTimeout(goNextSlide, parseInt($('#SLIDESHOW_SCROLL_SECS').val()));
					}
				});
			}
		}
		
		setTimeout(goNextSlide, parseInt($('#SLIDESHOW_SCROLL_SECS').val()));
		
	}
	
});
