﻿//// <reference path="http://media.goodwillindy.org/js/jquery/1.4.1/jquery-1.4.1-vsdoc.js" /> // for our intellisense
$(document).ready(function () {
    //////////////////////////////SETTINGS//////////////////////////////////////////////////////////////////////////////////////////////
    var url = '/'; // set the ajax path for developing '/web/' or '/' for production
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    // we need to set which navigation to show, the commercial services or the GWCS Cleaning services//

    if ($('#window').length > 0) { // here we check if the #window div exists in the cc masterpage, its how we see if that master page is loaded
        $('#ccNav').show(); // the cc navigation
    } else {
        $('#mainNav').show(); // the main navigation
    }

    // end navigation display//
    // start our front page slide show
    $('.slideshow').cycle({ // lets start up the front page slideshow
        fx: 'fade', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
        timeout: '4000' // speed
    });

    /* our video player */

    $('.capabilitiesVideo').click(function () {
        $(this).gwVideoModal({
            url: 'http://media.goodwillindy.org/flash/goodwillBusiness/capabilities/video.swf',
            bgColor: '000',
            fadeTo: '0.4',
            width: '625',
            height: '355'
        });
    });

    /* end video player */
    /* video popout box */

    $('.news > a').delay(1500).animate({ // on the page load lets push it out so its visible
        width: '190',
        right: '0'
    }, 1000);

    $('.news > a').mouseover(function () {
        $(this).stop().animate({
            width: '390'
        }, 300);

    }).mouseout(function () {
        $(this).stop().animate({
            width: '190'
        }, 300);
    });

    /* end video info pop up */
    /* GW Video Modal plugin */
    $('.successStoryList > li > div > a.gwVideoModal').click(function () {
        var id = $(this).attr('id');
        $(this).gwVideoModal({
            url: 'http://media.goodwillindy.org/flash/goodwillBusiness/' + id + '/video.swf', // the url of the flash movie
            bgColor: '000',         // the background color of the background fade in
            fadeTo: '0.4',          // the amount to fade to 0.0 to 1.0. ex. 0.6
            width: '635',           // the width of the shadow box
            height: '365'          // the height of the shadow box        
        });
    });

    /* End plugin */
    /* request a quote page */

    if ($('#content .text .last-child input:checkbox').first().is(':checked')) { // lets check to see if the checkbox is checked on pageload and display the quote info accordingly
        $('#content > .text > #quoteInfo').show();
    } else {
        $('#content > .text > #quoteInfo').hide();
    }

    $('#content .text .last-child input:checkbox').first().change(function () { // if the quote checkbox is checked
        if (this.checked) {
            $('#content > .text > #quoteInfo').fadeIn(); // fade in the quote section
        } else {
            $('#content > .text > #quoteInfo').fadeOut(); // now we fade it out
        }
    });

    /* end request page */
    /* Supply Chain page */

    $('.supplyChain > div > p:eq(4)').show(); // lets show the default content first

    $('.supplyChain > div >ul > li').click(function () { // if we click on the selection
        var pid = ($('.supplyChain > div > p:visible').index() - 1); // get the index id of the content that is visible now
        var id = $(this).index(); // get the index id of the content we want to display

        $('.supplyChain > div > p:eq(' + pid + ')').slideUp('fast', function () { // slide the content up
            $('.supplyChain > div > p:eq(' + id + ')').slideDown('fast'); // slide down the selected content
        });

    });

    /* End Supply Chain */
    /* Success Stories */

    var count = $('.successStoryList > li').length; // how many stories do we have?
    var num = Math.floor(Math.random() * (count)); // lets take the amount of stories and generate a random number in that range

    $('.successStoryList > li:eq(' + num + ') > div').show(); // lets show the default content first which is randomly generated above

    $('.successStoryList li > span').click(function () { // lets show a story when the image is clicked

        var id = $($(this).parent()).index(); // get the index id of the content we want to display     
        var pid = $('.successStoryList > li > div:visible').parent().index();

        if (id != pid) {
            $('.successStoryList li > div').slideUp('slow'); // slide the content up
            $('.successStoryList li:eq(' + id + ') > div').slideDown('slow'); // slide down the selected content
        }
    });

    /* End Success Stories */
    /* Case Studies */

    $('.text > p > .more').click(function () { // click more to expose the content
        var id = $(this).parent().next('div'); // get the content div. this is the immediate div after the more link
        $(id).slideDown();
    });

    $('.text > div > .close').click(function () { // click to close the content
        var id = $(this).parent(); // get the content div. this is the div that the close link resides inside of
        $(id).slideUp();
    });

    /* End Studies */
    /* Begin Photo Gallery */

    $('div.photoGallery > p').imgRoll();

//    $('div.photoGallery > div > img').hover(function () {
//        $(this).stop().animate({
//            top: '-8',
//            left: '-8',
//            width: '210',
//            height: '160'
//        }, 100);
//        $(this).parent().css('z-index', '2');
//        $(this).css('border-color', 'fff');
//    }, function () {
//        $(this).stop().animate({
//            top: '0',
//            left: '0',
//            width: '192',
//            height: '144'
//        }, 100);
//        $(this).parent().css('z-index', '1');
//        $(this).css('border-color', '000');
//    });

    $('div.photoGallery > div > img').click(function () {
        var image = $(this).attr('class');
        $(this).gwImageModal({
            url: 'http://media.goodwillindy.org/images/goodwillBusiness/mod/photoGallery/' + image,
            bgColor: '000',
            fadeTo: '0.6',
            width: '600',
            height: '450'
        });
    });

    /* End Photo Gallery */

    /* footer popups */

    $('#footer a').click(function () { // open the popup

        var info = $(this).attr('id').split('-'); // split the string so we can get the height and page name seperated

        var page = info[0];
        var height = parseInt(info[1]);

        $('#footer #popup div').html('<img src="http://media.goodwillindy.org/images/goodwillBusiness/spinner.gif" />'); // show the preloader spinner while we wait for the data to load
        $('#footer #popup').show().animate({
            bottom: '0',
            height: (height)
        }, 200, function () {
            $.ajax({
                type: 'GET',
                url: url + 'mod/util/' + page + '.aspx',
                data: '',
                cache: false,
                success: function (data) {
                    $('#footer #popup div').html(data); // the page data
                }
            });
        });
    });
    $('#footer #popup span,#footer #popup').click(function () { // close the popup
        $('#footer #popup').animate({
            bottom: '0',
            height: '1'
        }, 200, function () {
            $(this).hide('fast', function () {
                $('#footer #popup div').html('');
            });
        });

    });
    /* end footer popups */
    /* Commercial Cleaning */

    /* the about us slide down elements */

    $('#content .text a').click(function () { $('#content .text #exp-' + $(this).attr('id')).toggle() });

    /* end about us */

    /* End cleaning */

    /* Lets filter our email addresses so those evil spammers don't grab them */
    $('.email').each(function () { $(this).html('<a href="mailto:' + $(this).attr('id').replace('-@-', '@') + '">' + $(this).attr('id').replace('-@-', '@') + '</a>') }); // we'll pull out the "-@-" and replace it with "@", losing the hyphens
    /* end email */

});





