// JavaScript Document

$(document).ready(function(){
	
	$('img[src$=.png]').ifixpng();
	
	$("body").rightClick( function(e) {
        // Do something
    });

	$('#fotoshow1').cycle({
		fx: 'fade',
		random: 1,
		delay: -1500,
		speed: 1000, 
		timeout: 4000
	});
	$('#fotoshow2').cycle({
		fx: 'fade',
		random: 1,
		delay: -1000,
		speed: 1000, 
		timeout: 4000
	});
	$('#fotoshow3').cycle({
		fx: 'fade',
		random: 1,
		delay: -500,
		speed: 1000, 
		timeout: 4000
	});
	$('#fotoshow4').cycle({
		fx: 'fade',
		random: 1,
		delay: 0,
		speed: 1000, 
		timeout: 4000
	});
	$('#fotoshow5').cycle({
		fx: 'fade',
		random: 1,
		delay: 500,
		speed: 1000, 
		timeout: 4000
	});
	$('#fotoshow6').cycle({
		fx: 'fade',
		random: 1,
		delay: 1000,
		speed: 1000, 
		timeout: 4000
	});
	
	
	// Initially set opacity on thumbs and add
	// additional styling for hover effect on thumbs
	var onMouseOutOpacity = 1;
	$('#thumbs-adv ul.thumbs li').css('opacity', onMouseOutOpacity)
		.hover(
			function () {
				$(this).not('.selected').fadeTo('fast', 1.0);
			}, 
			function () {
				$(this).not('.selected').fadeTo('fast', onMouseOutOpacity);
			}
	);

	// Initialize Advanced Galleriffic Gallery
	var galleryAdv = $('#gallery-adv').galleriffic('#thumbs-adv', {
		delay:                  2000,
		numThumbs:              8,
		preloadAhead:           6,
		enableTopPager:         true,
		enableBottomPager:      true,
		imageContainerSel:      '#slideshow-adv',
		controlsContainerSel:   '#controls-adv',
		captionContainerSel:    '#caption-adv',
		loadingContainerSel:    '#loading-adv',
		renderSSControls:       false,
		renderNavControls:      false,
		playLinkText:           'Play Slideshow',
		pauseLinkText:          'Pause Slideshow',
		prevLinkText:           '&lsaquo; Previous Photo',
		nextLinkText:           'Next Photo &rsaquo;',
		nextPageLinkText:       'Next &rsaquo;',
		prevPageLinkText:       '&lsaquo; Prev',
		enableHistory:          true,
		autoStart:              false,
		onChange:               function(prevIndex, nextIndex) {
			$('#thumbs-adv ul.thumbs').children()
				.eq(prevIndex).fadeTo('fast', onMouseOutOpacity).end()
				.eq(nextIndex).fadeTo('fast', 1.0);
		},
		onTransitionOut:        function(callback) {
			$('#slideshow-adv, #caption-adv').fadeOut('fast', callback);
		},
		onTransitionIn:         function() {
			$('#slideshow-adv, #caption-adv').fadeIn('fast');
		},
		onPageTransitionOut:    function(callback) {
			$('#thumbs-adv ul.thumbs').fadeOut('fast', callback);
		},
		onPageTransitionIn:     function() {
			$('#thumbs-adv ul.thumbs').fadeIn('fast');
		}
	});
	
	// Initialize Minimal Galleriffic Gallery
	var galleryMin = $('#gallery-min').galleriffic('#thumbs-min', {
		imageContainerSel:      '#slideshow-min',
		controlsContainerSel:   '#controls-min'
	});
	
	$('.twocolumns').columns({columns: 2});

	$('a.email').each(function(){
		e = this.rel;
		e = splitext = e.split("");
		revertext = splitext.reverse();
		reversed = revertext.join("");
		reversed = reversed.replace('[a]','@');
		reversed = reversed.replace(/\[\!\]/g,'.');
		this.href = 'mailto:' + reversed + '?subject=' + $(this).attr('subject');
		$(this).text(reversed);
	});
	
	$('.hoverflag').hover(
		function () {
			$(this).attr('src',$(this).attr('src').replace('_bw.png','.png'));
		}, 
		function () {
			$(this).attr('src',$(this).attr('src').replace('.png','_bw.png'));
		}
	);

});

