$(document).ready(function(){
  //$('ul.dbem_events_list li:not(.dbem_period):even').addClass('alternate');
  
  $('#menu li a').wrapInner('<span />');
  
  add_menu_animation();
  
	$("a[rel=fancygallery]").fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'easingIn'		:	'easeOutExpo',
		'easingOut'		:	'easeInExpo',
		'speedIn'		:	600, 
		'speedOut'		:	400, 
		'overlayShow'	:	true
	});
  
  $('#header-image img:random').addClass('active');
  
	$('.past').animate({
		opacity: 0.3
	},{
		queue:false,
		duration:1000
	});
  
});

jQuery.jQueryRandom = 0;
jQuery.extend(jQuery.expr[":"],
{
    random: function(a, i, m, r) {
        if (i == 0) {
            jQuery.jQueryRandom = Math.floor(Math.random() * r.length);
        };
        return i == jQuery.jQueryRandom;
    }
});

function add_menu_animation() {
	$('#menu ul li a').hover(
		function () {
			var paddingRight = 130 - $(this).children().innerWidth();
		  $(this).children().animate({
		      paddingRight: paddingRight+"px"
		    },{
		      queue:false,
		      duration:300,
		      easing: 'easeOutExpo'
		    });
		}, 
		function () {
		  $(this).children().animate({
				paddingRight: "0px"
		    },{
		      queue:false,
		      duration:300,
		      easing: 'easeOutExpo'
		    });
		}
	);
	
	$('#menu ul li a').click(function(){
		$(this).css('textAlign','left');
	});
	
}

function slideSwitch() {
    var $active = $('#header-image img.active');

    if ( $active.length == 0 ) $active = $('#header-image img:last');

    // use this to pull the images in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : $('#header-image img:first');

    // uncomment the 3 lines below to pull the images in random order
    
    // var $sibs  = $active.siblings();
    // var rndNum = Math.floor(Math.random() * $sibs.length );
    // var $next  = $( $sibs[ rndNum ] );


    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}

$(function() {
    setInterval( "slideSwitch()", 5000 );
});





