jQuery(document).ready(function() {
		/*$(".container").equalHeights();*/
		$("#locations_menu").bind("mouseover", function(){
		$("#locations_menu").toggleClass("collapsed");
		$("#locations_menu").toggleClass("expanded");
		$("#other_locations").show();
});
	$("#locations_menu").bind("mouseout", function(){
   		$("#other_locations").hide();
		$("#locations_menu").toggleClass("collapsed");
		$("#locations_menu").toggleClass("expanded");
});

   // set up of slide show gallery
   	$('.mod-gallery954').fadeIn(200);
    $('.mod-gallery954 .jcarousel-skin-gallery').addClass('gallery_show'); // adds new class name to 33 maintain degradability
    $('.mod-gallery954 ul.gallery_show').galleria({
        history: false, // controls the history object for bookmarking, back-button etc.
        clickNext: true, // helper for making the image clickable
        insert: '#main_image', // the containing selector for our main image
        onImage: function(image, caption, description, tracker, thumb) { 
			// let's add some image effects for demonstration purposes
            // fade in the image & caption
            image.css('display', 'none').fadeIn(200);
            caption.css('display', 'none').fadeIn(200);
            description.css('display', 'none').fadeIn(200);
            tracker.css('display', 'none').fadeIn(200);
			tracker.css('display', 'none');
            // fetch the thumbnail container
            var _li = thumb.parents('li');
            // fade out inactive thumbnail
            _li.siblings().children('img.selected').fadeTo(100, 0.5);
            // fade in active thumbnail
            thumb.fadeTo('fast', 1).addClass('selected');
            // add a title for the clickable image
            image.attr('title', 'Next image >>');
            $('#main_image').trigger('img_change');
        },
        onThumb: function(thumb) { // thumbnail effects goes here
            // fetch the thumbnail container
            var _li = thumb.parents('li');
            // if thumbnail is active, fade all the way.
            var _fadeTo = _li.is('.active') ? '1' : '0.5';
            // fade in the thumbnail when finished loading
            thumb.css({ display: 'none', opacity: 0 })
            thumb.css({ display: 'block' }).fadeTo(500, _fadeTo);
            // hover effects
            thumb.hover(
				function() { thumb.fadeTo('fast', 1); },
				function() { _li.not('.active').children('img').fadeTo('fast', 0.5); } // don't fade out if the parent is active
			)
        }
    });

    $('.mod-gallery954').prepend("<div class='autoControl'>Pause</div>");
		var active = true;
		var gal = jQuery('.mod-gallery954');
		var ctrl = gal.find('.autoControl')

    $(function() {
        //var slideshow = $("gallerytitle");

        if (active) {
            ctrl.css("background-position", "0 0");
            gal.everyTime('10s', 'slideshow', function() {
                $.galleria.next();
            });
        } if (!active) {
            ctrl.css("background-position", "0 -23px");
        };

        ctrl.css("cursor", "pointer").click(function() {
            if (!active) {
                active = true;
                $.galleria.next();
                ctrl.css("background-position", "0 0").html("Pause");
                gal.everyTime('10s', 'slideshow', function() {
                    $.galleria.next();
                });
            } else if (active) {
                active = !active;
                ctrl.css("background-position", "0 -23px").html("Play");
                gal.stopTime('slideshow');
            }
        });

    });

	jQuery('.mod-gallery954 #gallery').jcarousel({
		scroll: 5,
		  initCallback: gallery_initCallback
	 });

	 $.hotkeys.add('left', function(){$.galleria.prev();});
	 $.hotkeys.add('right', function(){$.galleria.next();});


	$('.mod-gallery954 .main_image_wrapper').append("<a class='prevImg' href='#'>Previous Image</a>");
	$('.mod-gallery954 .main_image_wrapper').append("<a class='nextImg' href='#'>Next Image</a>");

	$('.mod-gallery954 .prevImg').click(function(){
		$.galleria.prev();
		if (active) {
			active = !active;
			ctrl.css("background-position", "0 -23px").html("Play");
			gal.stopTime('slideshow');
		}
		return false;
	});
	$('.mod-gallery954 .nextImg').click(function(){
		$.galleria.next();
		if (active) {
			active = !active;
			ctrl.css("background-position", "0 -23px").html("Play");
			gal.stopTime('slideshow');
		}
		return false;
	});
		
	$('.mod-gallery954 .galleria_wrapper, .mod-gallery954 .jcarousel-item, .mod-gallery954 .jcarousel-prev, .mod-gallery954 .jcarousel-next').click(function(){
		if (active) {
			active = !active;
			ctrl.css("background-position", "0 -23px").html("Play");
			gal.stopTime('slideshow');
		}
	});

	$('.mod-gallery954 .gallery_info').hide();

	$('.mod-gallery954 .ssInfoLink').toggle(
		function () {
		  $('.mod-gallery954 .gallery_info').slideDown('fast');
		  $(this).html("hide slideshow info");
		  return false;
		},
		function () {
		  $('.mod-gallery954 .gallery_info').slideUp('fast');
		  $(this).html("slideshow info");
		  return false;
		}
	);



    //end setup of slideshow gallery

});

$.fn.cycle.updateActivePagerLink = function(pager, currSlideIndex) {
    $(pager).find('div').removeClass('stgbtnon')
        .filter('div:eq(' + currSlideIndex + ')').addClass('stgbtnon');
};

function gallery_initCallback(carousel) {
	var listTotal = jQuery('#gallery li').length;

	jQuery('.mod-gallery954 #main_image').bind('img_change', function() {
	    var num = parseInt((jQuery('.mod-gallery954 .caption').text()).split(";", 1)[0]) - 3;
	    var location = parseInt(jQuery('.mod-gallery954 .caption').text().split(";", 2)[0]) + 1;

	    jQuery('.mod-gallery954 .caption').html(jQuery('.caption').text().split(";", 2)[1]);
	    jQuery('.mod-gallery954 .tracker').html(location + " of " + listTotal);

	    carousel.scroll(num);
	    return false;
	});
};

function onBefore() {
	$('.stghrimg').html($('.stgslideheading', this).html());
	$('.stghrtxt').html($('.stgslidecontent', this).html());
	$('.stgcredit').html($('.stgslidecredit', this).html());
}

jQuery(function($) {

	//tabs
	$('.tabWidget > ul').tabs();

});