/******************************************************************************************************
*  GALLERY.JS - PHOTO SLIDESHOW
*
*  Written by Nicholas Slate - Property of Marshall University COSITC
*  Last modified: 11/3/2008
*
*  Depends on: JQuery 1.2 (www.jquery.com), JQuery Cycle Plugin (www.malsup.com/jquery/cycle/) 
*******************************************************************************************************/


// Specify the image files.... Extend or contract array as needed
//   Image in HTML is removed to provide a clean slate for the gallery
var fadeImages = new Array(
    //{filename: '/cos/r/i/feature-cos.jpg', caption: "The College of Science building features tributes to scientists that have personified the spirit of discovery."},
    //{filename: '/cos/r/i/', caption: "<h4>MU forensic science program gets major technology boost</h4><p></p><p><a href=\"http://www.herald-dispatch.com/news/marshall/x265527368/MU-forensic-science-program-gets-major-technology-boost?i=0\" title=\"Forensics\">Click to read full story.</a></p>"},
    {filename: '/cos/r/i/g/collierpic.jpg', caption: "<h4>Grant Funds Genetic Research into Cell Abnormalities</h4><p>Simon Collier has been awarded a three-year grant from the National Science Foundation (NSF) to study the role of genes in controlling animal development.</p><p><a href=\"http://www.herald-dispatch.com/news/marshall/x1517862651/Marshall-University-researcher-receives-genetics-grant?i=0\" title=\"Collier\">Click to read full story.</a></p>"},
    {filename: '/cos/r/i/g/chemcert.jpg', caption: "<h4>Local Teachers Participate in Chemistry Certification Training</h4><p>Seven teachers from Cabell and Wayne counties are participating in a three-year summer training that will get them certified to teach science classes up to Chemistry I.  Marshall professors Ken O'Conner and Edna Meiselle taught the week of June 27th.</p><p><a href=\"http://www.herald-dispatch.com/life/schools/x1517854115/No-Headline\" title=\"Chemistry\">Click to read full story.</a></p>"},
    {filename: '/cos/r/i/g/picopi.jpg', caption: "<p>Dr. Marcia A. Harrison is the principal investigator of a  $750,000 grant awarded by the National Science Foundation to continue an initiative aimed at increasing the number of women teaching science, technology, engineering and mathematics.  The funds will be used to support the ongoing Marshall University ADVANCE program, established in 2006 with a $1.2 million grant awarded through NSF's Advancement of Women in Academic Science and Engineering Careers (ADVANCE) program.  Harrison's co-investigators include Dr. Beverly C. Delidow, Patricia Y. Logan, Elizabeth E. Murray, and Judith A. Silver.</p>"}, 
    {filename: '/cos/r/i/g/tubes.jpg', caption: "<h4>Professor recieves Dreyfus Start-up Award</h4><p>Dr. Laura R. McCunn, an assistant professor in Marshall University’s Department of Chemistry, has been named one of eight recipients of a Camille and Henry Dreyfus Faculty Start-up Award. The unrestricted five-year grant provides $30,000 to begin her research program.</p><p><a href=\"http://www.wvresearch.org/index.php?option=com_content&task=view&id=119&Itemid=45\" title=\"StartUpAward\">Click to read full story.</a></p>"},
    
	{filename: '/cos/r/i/g/hsta2009.jpg', caption: "<h4>MU hosts \"Fun with Science\" Camp</h4><p>About 180 rising ninth- and 10th-grade students from throughout West Virginia visited Marshall University’s Huntington campus July 13-18 taking part in the Health Sciences and Technology Academy (HSTA)	Summer Institute with the emphais this year on Diabetes directed by David Cartwright.</p><p><a href=\"http://www.marshall.edu/www/pressrelease.asp?ID=1360/\" title=\"HSTA 2009\">Click to read full story.</a></p>"},
	{filename: '/cos/r/i/g/okeefepic.jpg', caption: "<h4>Dr. Frank O'Keefe discovers new dinosaur!</h4><p>Not many paleontologists can say they've discovered a new species of dinosaur. Only one in West Virginia can.</p><p><a href=\"http://www.wvgazette.com/News/200909090391\" title=\"New Dinosaur\">Click to read full story.</a></p>"},
	{filename: '/cos/r/i/g/lsamp.jpg', caption: "The National Science Foundation Kentucky-West Virginia Louis Stokes Alliance for Minority Participation(LSAMP) is a ten university alliance. The Marshall LSAMP wants to help students in Science, Technology, Engineering and Math (STEM) have a successful college education and rewarding career by promoting diverse campus environments where minority students can thrive."},
	{filename: '/cos/r/i/feature-cos.jpg', caption: "<h3>College of Science</h3><p>The College of Science is situated on the north side of the Marshall University campus and is contained in five buildings:  the Science Building, the Robert C. Byrd Biotechnology Center, the Morrow Library, Prichard Hall, and Smith Hall. Students in our college can choose from 18 undergraduate majors and 4 graduate degree programs. COS also services pre-professional students by providing advising and assistance with the professional school application process.</p>"},
    {filename: '/cos/r/i/g/1.jpg', caption: "<a href=\"http://www.marshall.edu/isat/\" title=\"Integrated Science and Technology\">IST</a> students diving with Manatees in Florida with the endangered species course."},
    {filename: '/cos/r/i/g/2.jpg', caption: "Fung is using the Atomic Force Microscope to write patterns of DNA on silicon substrates in Dr. Norton's lab."},
    {filename: '/cos/r/i/g/3.jpg', caption: "Marshall students learn methods in water quality assessment through hands-on experience."},
    {filename: '/cos/r/i/g/4.jpg', caption: "Integrated Science students use GIS software to map animal population density."},
    {filename: '/cos/r/i/g/6.jpg', caption: "<a href=\"http://www.marshall.edu/isat/\" title=\"Integrated Science and Technology\">IST</a> students and faculty survey an Appalachian stream prior to developing a HEC-RAS discharge model."},
    {filename: '/cos/r/i/g/7.jpg', caption: "Students in BSC 250, Microbiology, prepare to look at bacterial cultures."},
    {filename: '/cos/r/i/g/10.jpg', caption: "Geology students at an outcrop in Lavalette."},
    {filename: '/cos/r/i/g/11.jpg', caption: "Recipients of the Robert Fox Fieldcamp Scholarship."},   
    {filename: '/cos/r/i/g/13.jpg', caption: "Amanda is using an infrared spectrometer to study artificial amino acid dyes. These dyes are potentially useful for preparing fluorescent peptides and proteins."},
    {filename: '/cos/r/i/g/15.jpg', caption: "Kristen presenting her research on the characterization of structural properties of proteins encapsulated in nanoenvironment of reverse micelles to the WV state legislature."},
    {filename: '/cos/r/i/g/16.jpg', caption: "Students work in the mobile water quality laboratory aboard the Chattanooga Star."},
    {filename: '/cos/r/i/g/17.jpg', caption: "Pi Mu Epsilon went to a conference with several students: (l. to r.) Tue Ngoc Ly, Gustavo S&aacute, Wen Xue, John Stonestreet, Bonnie Shook, Shannon Miller, Elizabeth Duke, and Ashley Tucker."},
    {filename: '/cos/r/i/g/18.jpg', caption: "Undergraduate Mathematics major, Anthony Justice, begins construction of a mechanical integrator during the first phase of construction."},
    {filename: '/cos/r/i/g/21.jpg', caption: "Members of the Differential Analyzer Team, Stacy Scudder, Richard Merrit, and Dr. Bonita Lawrence work on the first phase of construction for the Marshall Differential Analyzer Project."},
    {filename: '/cos/r/i/g/22.jpg', caption: "Steven Taylor ('06 physics BS graduate and MUSOM student) and Dr. Thomas Wilson in the lab working on an American Foundation for the Blind TECH collaboration."},
    {filename: '/cos/r/i/g/23.jpg', caption: "The College of Science Undergraduate Ambassadors."}
    //{filename: '/cos/r/i/g/urawards.jpg', caption: "UNDERGRAD RESEARCH AWARDS NOW AVAILABLE!!! <a href=\"http://www.marshall.edu/cos/urawards.asp\">Click here</a> for more info!"}
);

// settings for the photo gallery
var imageWidth = 600;
var imageHeight = 275;
var imageIdPrefix = 'GalleryImage_'; // change if image IDs conflict with other page elements
var captionFadeDuration = 500;

// persistant storage for needed values
var captionElement;
var captionOpacity = 1;
var defaultImageCaption = '';
var firstTransition = true;

// dom ready event
$(document).ready(function(){                     
    
    // if there are images to display
    if (fadeImages && fadeImages.length && fadeImages.length > 0) {
    
        // collect some frequently used properties
        var imageContainer = $('#FeaturePictureContainer');
        imageContainer.empty();
        
        // create caption container
        captionElement = window.document.createElement('div');
        captionElement.id = 'FeaturePictureCaption';
        captionElement.innerHTML = $('#FeaturePicture').attr('alt');
        $('#PageFeatureInner').prepend(captionElement);
        
        // get opacity specified for caption in stylesheet
        if (jQuery.browser.msie) {
            captionOpacity = $(captionElement).css('filter'); // get value from filter property
            captionOpacity = captionOpacity.replace(/[^0-9\.]/g, ''); // replace anything but numbers and decimals (leave opacity value)
            captionOpacity = captionOpacity / 100; // put value in decimal form
        }
        else {
            captionOpacity = $(captionElement).css('opacity');
        }
        
        // hold created elements until they're placed
        var newImage;
        // create images for gallery
        for (var index in fadeImages) {
            if (!isNaN(index)) {
                newImage = window.document.createElement('img');
                newImage.id = imageIdPrefix + index;
                newImage.width = imageWidth;
                newImage.style.width = imageWidth + 'px'; // set width style too just to make IE gets it
                newImage.height = imageHeight;
                newImage.style.height = imageHeight + 'px'; // set height style too just to make IE gets it
                newImage.src = fadeImages[index].filename;
                imageContainer.append(newImage);
            }
        }
        
        // cycle through images placed in container
        imageContainer.cycle({ 
            fx:         'fade',                     // fade is the only transition available in this build (others available at www.malsup.com/jquery/cycle/)
            speed:      3000,                       // duration of transition
            timeout:    9000,                       // interval between transitions
            pause:      1,                          // pause on mouse over
            next:       '#FeaturePictureContainer', // clicking on this element will start transition
            before:     galleryBefore,              // actions performed before each transition
            after:      galleryAfter                // actions performed after each transition
        });
    }
});

// actions performed before each transition
function galleryBefore() {
    // prevent flicker on load
    if (!firstTransition) {
        // hide caption
        $(captionElement).fadeOut(captionFadeDuration);
    }
    firstTransition = false;
}
// actions performed after each transition
function galleryAfter() {
    var imageIndex = parseInt(this.id.substring(imageIdPrefix.length));
    // set caption text and display
    if (typeof(fadeImages[imageIndex]) != 'undefined' && typeof(fadeImages[imageIndex].caption) != 'undefined') {
        if (jQuery.browser.msie) {
            $(captionElement).css('opacity', captionOpacity); // set opacity again to remind IE
		    $(captionElement).css('filter', 'alpha(opacity=' + (captionOpacity*100) + ')');
		}
        $(captionElement).html(fadeImages[imageIndex].caption);
        $(captionElement).fadeIn(captionFadeDuration);
    }
}