﻿$(document).ready(function () {

    $(".facebook-popup a").hover(function () {
        $(this).next("em").stop(true, true).animate({ opacity: "show", top: "-60" }, "slow");
    }, function () {
        $(this).next("em").animate({ opacity: "hide", top: "-70" }, "fast");
    });

    // the photos page//
    $().piroBox({
        my_speed: 300, //animation speed
        bg_alpha: 0.5, //background opacity
        slideShow: 'true', // true == slideshow on, false == slideshow off
        slideSpeed: 3, //slideshow 
        close_all: '.piro_close' // add class .piro_overlay(with comma)if you want overlay click close piroBox
    });
    //For our meet the staff page and the pop up bio//
    $(".StaffBio").fancybox({
        'titlePosition': 'inside',
        'transitionIn': 'none',
        'transitionOut': 'none'
    });
    // lets load the front page video
    $("#Video").flashembed({ src: 'http://media.goodwillindy.org/flash/theExcelCenter/FrontPage/Video.swf', wmode: 'opaque' });

    // our Student Profiles page //
    $.extend({
        getUrlVars: function () { // function that parses the url and gets us the variable value
            var vars = [], hash;
            var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
            for (var i = 0; i < hashes.length; i++) {
                hash = hashes[i].split('=');
                vars.push(hash[0]);
                vars[hash[0]] = hash[1];
            }
            return vars;
        },
        getUrlVar: function (name) {
            return $.getUrlVars()[name];
        }
    });

    if ($('#studentProfiles').size && $.getUrlVar('profile') > 0) { // if the viewer comes via a preselected profile from an external link lets display that profile "?profile=##"
        var id = $.getUrlVar('profile');
        getPopup(id);
    }

    $('.studentProfiles img').click(function () {

        var id = $(this).attr('id');

        if ($('#profilePopup').is(':visible')) {

            $('#profilePopup').fadeOut(function () {
                $(this).empty();
                getPopup(id);
            });

        } else {
            getPopup(id);
        }
        return false;
    });
    /**** headline *****/
    if (($('headline').size && $.getUrlVar('headline') > 0)) { // if the viewer comes via a preselected headline from an external link lets display that headline "?headline=1"
        getHeadline('.headline');
    }

    $('.headline .gwVideoModal').click(function () { // for our headline video on the student profiles page
        getHeadline('.headline');
    });
    /***** end headline *******/
    /***** Front page slidedown banner ******/

    $('div.slidedown').delay(1000).animate({
        top: '0'
    }, 500);

    $('div.slidedown > a').click(function () {

        $('div.slidedown').animate({
            top: '-205'
        }, 500);
        return false;
    });

    /***** End slidedown*******/

});

///////functions/////////
/////////////////////////
function getHeadline(id) { // lets get and play the headline video // id is the name of the class for the video button *

    $(id).gwVideoModal({
        url: 'http://media.goodwillindy.org/flash/theExcelCenter/studentProfiles/headline/profilesHeadline.swf',
        bgColor: '000',
        fadeTo: '0.4',
        width: '510',
        height: '292'
    });
    return false;

}

function getPopup(id) { // lets get the popup profile and its data
    $('#profilePopup').fadeIn(function () {
                $.ajax({
                    url: "data/Profiles/" + id + "/" + id + ".txt",
                    success: function (data) {
                        $('#profilePopup').html("<img src='http://media.goodwillindy.org/images/theExcelCenter/Profiles/" + id + "/" + id + ".jpg' alt='' />" + data.replace(/\n/g, "<br />") + "<br /><a href='javascript:closeWindow();' id='profileClose'>Close Window</a>");
                        $('#profilePopup img').css('cursor', 'default');
                    }
                });

                $(this).ajaxError(function () {
                    $(this).html("<h4>Sorry</h4>No such profile available<br /><a href='javascript:closeWindow();' id='profileClose'>Close Window</a>");
                });

    });
}

function closeWindow() {
    $('#profilePopup').fadeOut(function () {
        $(this).empty();
    });
}
