$(document).ready(function() {
	// submenu
	$('#nav li').hover(function(){
		$(this).find('.submenu').show();
	}, function(){
		$(this).find('.submenu').hide();
	});
	
	// calendar popup
	$('.calendar table tr td, table.calendar tr td').find('div').find('.info').hide();
	$('.calendar table tr td, table.calendar tr td').find('div').hover(function(){
		$(this).find('.info').show();
	},function(){
		$(this).find('.info').hide();
	});
	
	$('#hp_cal div.event').mouseenter(function() {
		$(this).find('.info').show();
	}).mouseleave(function() {
		$(this).find('.info').hide();
	});
	
	// month popup
	$('.calendar .monthSelect').find('.monthSelectList').hide();
	$('.archive').find('.monthList').hide();
	$('.archive').find('.yearList').hide();
	$('.calendar .monthSelect').find('a.more').click(function(e){
		$(this).parent().find('.monthSelectList').show();
		e.stopPropagation();
	});
	$('.archive').find('a.showMonths').click(function(e){
		$(this).parent().find('.monthList').show();
		e.stopPropagation();
		return false;
	});
	$('.archive').find('a.showYears').click(function(e){
		$(this).parent().find('.yearList').show();
		e.stopPropagation();
		return false;
	});
	// show month popup
	$('.calendar .monthSelect').find('.monthSelectList').click(function(e){
		e.stopPropagation();
	});
	$('.archive').find('.monthList').click(function(e){
		e.stopPropagation();
	});
	$('.archive').find('.yearList').click(function(e){
		e.stopPropagation();
	});
	// hide month popup
	$('body').click(function(){
		$('.calendar .monthSelect').find('.monthSelectList').hide();
		$('.archive').find('.monthList').hide();
		$('.archive').find('.yearList').hide();
	});
	
	// footer logos
	if ($('.sponsors li').length > 5){
		jQuery('.sponsors ul').jcarousel({
			scroll: 1,
			auto: 5,
			wrap: 'last'
		});
	}
	
	// gallery
	$('.galleryList a').click(function(){
		var img = new Image();
		var src = $(this).attr('href');
		
		$('#detailImage').html('').addClass('loading');
		
		$(img)
		.load(function () {
			$(this).hide();
			$('#detailImage')
				.removeClass('loading')
				.html(this);
			$(this).fadeIn();
		})
		.attr('src', src);

		return false;
	});
	
	// select
	$('.select select').selectbox();

	/* holes */
	$('#green > div').hover(function(){
		$(this).find('.popup').show();
	}, function(){
		$(this).find('.popup').hide();
	});
});

function mycarousel_initCallback(carousel) {
	jQuery('.gallerySlider .next').bind('click', function() {
		carousel.next();
		return false;
	});

	jQuery('.gallerySlider .prev').bind('click', function() {
		carousel.prev();
		return false;
	});
};

function swip (elementInput, swipFrom, swipTo) {
	if (elementInput.value == swipFrom) elementInput.value = swipTo;
}
