﻿/// <reference path="jquery-1.4.1-vsdoc.js" />
//The following snippet adds the indexOf function to the array object for IE which does not support this by default
//This prototype is provided by the Mozilla foundation and
//is distributed under the MIT license.//http://www.ibiblio.org/pub/Linux/LICENSES/mit.license
if (!Array.prototype.indexOf) {
    Array.prototype.indexOf = function (elt /*, from*/) {
        var len = this.length, from = Number(arguments[1]) || 0;
        from = (from < 0) ? Math.ceil(from) : Math.floor(from);
        if (from < 0) {
            from += len;
        }
        for (; from < len; from++) {
            if (from in this && this[from] === elt)
                return from;
        }
        return -1;
    };
}

/* Site.Master ***********************************************************************************/

var currentCaption = 0,
    rotatorImages = [{ Name: 'One.jpg', Caption: 'Special Kids Fund', Text: 'Parent organization for CharityChoice Gift Cards. Benefits special needs children.' },
        { Name: 'Three.jpg', Caption: 'Special Kids Fund', Text: 'Parent organization for CharityChoice Gift Cards. Benefits special needs children.' },
        { Name: 'Alex_001.jpg', Caption: 'Alex\'s Lemonade Stand', Text: 'Alex\'s "Original" Lemonade Stand 2008' },
        { Name: 'Alex_003.jpg', Caption: 'Alex\'s Lemonade Stand', Text: 'Rita\'s Water Ice Representatives' },
        { Name: 'Nurse001.jpg', Caption: 'Nurse-Family Partnership', Text: 'Maternal and early childhood health program, fosters long-term success for first-time moms, their babies, and society.' },
        { Name: 'Nurse002.jpg', Caption: 'Nurse-Family Partnership', Text: 'Maternal and early childhood health program, fosters long-term success for first-time moms, their babies, and society.', Caption: 'Nurse-Family Partnership' },
        { Name: '628.3.jpg', Caption: 'Michigan Coonhound Rescue, Inc.', Text: 'Purple Puppy, Treeing Walker Coonhound' },
        { Name: '645.3.jpg', Caption: 'Seeing Eye, Inc.', Text: 'Seeing Eye® dogs being recognized for their wonderful work.' },
        { Name: '652.1.jpg', Caption: 'Center for Ecosystem Management and Restoration', Text: 'A steelhead is released to continue its migration' },
        { Name: '652.3.jpg', Caption: 'Center for Ecosystem Management and Restoration', Text: 'Fan allows for frost protection for grapes without pumping water from streams' },
        { Name: '656.1.png', Caption: 'Caring for Carcinoid Foundation', Text: '' },
        { Name: '665.1.jpg', Caption: 'Neighborhood Centers Inc.', Text: 'Neighborhood Centers offers programs and services for youth designed to enhance their social, educational and personal development.' },
        { Name: '665.3.jpg', Caption: 'Neighborhood Centers Inc.', Text: 'Aging in place enables remaining independent in one\'s home and neighborhood, in familiar surroundings and near friends and family.' },
        { Name: '673.1.jpg', Caption: 'Water Missions International', Text: 'Haitians receiving purified safe water after earthquake' },
        { Name: '695.1.jpg', Caption: 'Crime Survivors, Inc.', Text: 'Awareness * Prevention * Survival' },
        { Name: '717.3.jpg', Caption: 'Worldreader.org', Text: 'Ayenyah, Ghana primary-school students reading Curious George'}],
    captionStrings = ['Corporate affinity with charitable giving',
        'Corporate promotions',
        'Business gifts',
        'Robust customization suite',
        'CSR at its best',
        'Incentives and employee rewards',
        'Birthday presents and gifts',
        'Give the gift that keeps on giving'],
    linksList = [] //any page that has a list of links to display will fill the list as needed;

        $(document).ready(function () {
            var imageList = [],
        index = -1,
        i,
        html = '',
        image,
        innerDiv;
            for (i = 0; i < 5; i++) {
                index = Math.floor(Math.random() * rotatorImages.length);
                imageList[imageList.length] = index;
                image = rotatorImages[index];
                html += '<div class="rotatorContainer"><div class="rotatorImageSec"><div class="imageHeader">' +
                    image.Caption + '</div><img src="/Images/RotatorImages/' + image.Name + '" alt="' +
                    (image.Text || image.Caption) + '" /></div>' +
                    '<div class="imageText">' + (image.Text || image.Caption) + '</div></div>';
            }
            $('#divImageRotator').html(html);
            innerDiv = $('#divImageRotator div.rotatorContainer');
            innerDiv.css('opacity', 0.0);
            innerDiv.first().addClass('show').css('opacity', 1.0);

            window.setInterval(function () {
                var outer = '#divImageRotator',
                inner = 'div.rotatorContainer',
                current = $(outer + ' div.show'),
                next = ((current.next().length) ?
                    ((current.next().hasClass('show')) ?
                        $(outer + ' ' + inner + ':first') :
                        current.next()) :
                    $(outer + ' ' + inner + ':first'));
                next.css({ opacity: 0.0, display: '' }).addClass('show').animate({ opacity: 1.0 }, 1000);
                current.animate({ opacity: 0.0 }, 1000).removeClass('show').hide('slow');
            }, 6000);

            window.setInterval(function () {
                $('.headerTextSection div')
            .removeClass('active')
            .after('<div class="active">' + captionStrings[currentCaption] + '</div>')
            .animate({ opacity: 0.0 }, 2000, function () {
                $(this).remove();
            });
                $('.headerTextSection div.active').css('opacity', 0.0).animate({ opacity: 1.0 }, 2000);
                currentCaption = (currentCaption == (captionStrings.length - 1) ? 0 : (currentCaption + 1));
            }, 4000);           
        });

/*************************************************************************************************/
