$(document).ready(function(){
	
	$('a.photo').colorbox({
		maxWidth : '90%',
		maxHeight : '90%',
		minWidth : 630,
		minHeight : 660
	});
	
	$('a.modal').colorbox({
		width : 640,
		height : 480,
		iframe : true
	});
	
	$('a.inlinemodal').colorbox({
		width : 750,
		height : 600,
		iframe : false
	});
	
	$('a.out').click(function(){
		if ($(this).hasClass('photo') !== true) {
			window.open($(this).attr('href'));
			return false;
		}
	});
	
	$('#e-address').focus(function() {
		$(this).val('');
	});
	
	// SLIDESHOW
	
	var slideBlocked = false;
	
	slideshowSet = function(n) {
		slideBlocked = true;
		var activeSlide = $('#slideshow img.active');
		var nextSlide = $('#slideshow img[rel=' + n + ']');
		activeSlide.addClass('last-active');
		$('#SSHOW_CURRENT').val(n);
		$('#slideshow_paging a').removeClass('active');
		$('#slideshow_paging a[rel=' + n + ']').addClass('active');
		$('#slideshow_contents').html(' &nbsp; ');
		nextSlide.css({ opacity : 0.0 }).addClass('active').animate(
			{ opacity : 1.0 }, 300, function(){
			activeSlide.removeClass('active last-active');
			$('#slideshow_contents').html($('#SSHOW_CONTENT_' + n).val());
			slideBlocked = false;
		});
	}
	
	if (parseInt($('#SSHOW_TOTAL').val()) > 1) {
		var slideInterval = setInterval(function(){
			var currentSlide = parseInt($('#SSHOW_CURRENT').val());
			var nextSlide = (1 + currentSlide);
			if ($('#slideshow img[rel=' + nextSlide + ']').length > 0) {
				slideshowSet(nextSlide);
			} else {
				slideshowSet(1);
			}
		}, $('#SSHOW_SECS').val());
	}
	
	$('#slideshow_paging a').click(function(){
		if ($(this).hasClass('active') || slideBlocked == true) {
			return false;
		} else {
			slideshowSet($(this).attr('rel'));
			clearInterval(slideInterval);
			return false;
		}
	});
	
});
