(function ($) {
// VERTICALLY ALIGN FUNCTION
$.fn.vAlign = function() {
	return this.each(function(i){
	var ah = $(this).height();
	var ph = $(this).parent().height();
	var mh = (ph - ah) / 2;
	$(this).css('margin-top', mh);
	});
};
})(jQuery);
$ = jQuery
function slideSwitch() {
    var $active = $('.gallery dl.active');
    if ( $active.length == 0 ) $active = $('.gallery dl:last');
    // use this to pull the images in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : $('.gallery dl:first');
    $active.fadeOut(1000).removeClass("active");
    $next.fadeIn(1000).addClass("active");
}
jQuery(document).ready(function($) {
    $(".horizontal-image .gallery img").each(function() {
        $(this).height(320);
    });
    $(".vertical-image .gallery img").each(function() {
        $(this).width(338)
            .parent().vAlign();
    });
    $('.gallery dl:first').show()
        .addClass('active');
    if ($(".gallery dl").length > 1) {
        setInterval( "slideSwitch()", 5000 );
    }
    $('.gallery').css("visibility", "visible");
});

