﻿(function($) {
    $.fn.ImageGallery = function() {
        this.each(function() {
            var $element = jQuery(this)
            $element.find(".image_thumb ul li:first").addClass('active'); //Add the active class (highlights the very first list item by default)
            $element.find(".image_thumb ul li").click(function() {
                //Set Variables
                var imgAlt = $(this).find('img').attr("alt"); //Get Alt Tag of Image
                var imgTitle = $(this).find('a').attr("href"); //Get Main Image URL

                if ($(this).is(".active")) {  //If the list item is active/selected, then...
                    return false; // Don't click through - Prevents repetitive animations on active/selected list-item
                } else { //If not active then...
                    $element.find(".main_image img").attr({ src: imgTitle, alt: imgAlt }); //Switch the main image (URL + alt tag)
                }
                //Show active list-item
                $element.find(".image_thumb ul li").removeClass('active'); //Remove class of 'active' on all list-items
                $(this).addClass('active');  //Add class of 'active' on the selected list
                return false;
            });
        });
    }
})(jQuery);
