﻿// js file for navigation
// Get what page we are on
var sPath = window.location.pathname;
var currentPage = sPath.substring(sPath.lastIndexOf('/') + 1);
if (currentPage == "") {
    document.location = "/Default.aspx";
}

function getFlashMovie(movieName) {
    var isIE = navigator.appName.indexOf("Microsoft") != -1;
    return (isIE) ? document.getElementById(movieName) : document[movieName];
}
function loadNavPage(str) {
    if (currentPage == "Default.aspx") {
        var movie = getFlashMovie('swfReq');
        movie.popUpWin(str);
    } else {
        document.location = "/Default.aspx?showPopup=" + str
    }
}

function loadVideo(vFile, vTitle) {
    var movie = getFlashMovie('swfVideo');
    movie.loadNewVideo(vFile);
    $('#video_name').html(vTitle);
}

function getQuerystring(key, default_) {
    if (default_ == null) default_ = "";
    key = key.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
    var regex = new RegExp("[\\?&]" + key + "=([^&#]*)");
    var qs = regex.exec(window.location.href);
    if (qs == null)
        return default_;
    else
        return qs[1];
}

var showPopup = getQuerystring('showPopup');

$(document).ready(function () {
    // fix transparent PNGs for older IE browsers
    if ($.browser.msie && $.browser.version.substr(0, 1) < 7) {
        $(document).pngFix();
        //stupid IE6 can't do direct-descendant
        $('div#quiz > ol li').css('list-style-type', 'none');
        //dummy IE6 can't do hover pseudoclass on li
        $('div#quiz li.a').mouseover(function () {
            $(this).css('color', '#70bf54');
            $(this).css('cursor', 'pointer');
        });
        $('li.a').mouseout(function () {
            $(this).css('color', '#00aeef');
            $(this).css('cursor', 'default');
        });
    }

    // Hide little plane for Learn More page
    if (currentPage == "learn_more.aspx") {
        $('#adplane').hide();
    }

    var speed = "slow";

    if ($.browser.msie) speed = '';
    // Show bio for Learn More page
    $('#bio').click(function () {
        $('#michele_bio').show(speed);
    });

    // Hide bio for Learn More page
    $('#bio_close').click(function () {
        $('#michele_bio').hide(speed);
    });


    // navigation rollovers
    $('div#main div#navigation .navlinks a').hover(function () {
        // on
        $('img', this).attr('src', $('img', this).attr('src').replace('.gif', '_over.gif'));
    }, function () {
        // off
        $('img', this).attr('src', $('img', this).attr('src').replace('_over.gif', '.gif'));
    });

    // show first question in the quiz
    $('div#quiz ol li.q:eq(0)').show();

    // event handler for selecting answers to questions
    $('div#quiz li.a').click(function () {
        //change the font-color
        $(this).toggleClass('ans-yes');
        if ($('div.ck img', this).is(":visible")) {
            $('div.ck img', this).hide();
        } else {
            $('div.ck img', this).css('display', 'inline');
            //$('div.ck img',this).show();
        }
    });

    // event handler for buttons to show next question in quiz
    $('div#quiz div.next-q').click(function () {
        if (hasCheckedOne(this)) {
            //hide current question
            $(this).parent().hide();
            //show next question
            $(this).parent().next().show();
        } else {
            $('.err-msg', $(this).parent()).show();
        }
    });

    // event handler for button on final question
    $('div#quiz div.last-q').click(function () {
        if (hasCheckedOne(this)) {
            var result = scoreQuiz();
            showResult(result);
        } else {
            $('.err-msg', $(this).parent()).show();
        }
    });

    // event handler for the Take the quiz button on pr-intro
    $('div#pr-intro img.btn-quiz').click(function () {
        $('div#pr-intro').hide();
        $('div#quiz').show();
    });
});

function hasCheckedOne(elem) {
    var qq = $('ol li.ans-yes', $(elem).parent());
    if (qq.length > 0) {
        return true;
    } else {
        return false;
    }
}

function showResult(rr) {
    switch (rr) {
        case 'do-good':
            $('#result-string').text('Global Do-Gooder');
            $('#guide-link').attr('href', 'pdf/wingive-parentingguide_DoGooders.pdf'); //do-gooders is 1
            $('#guide-link').attr('onclick', "dcsMultiTrack('DCS.dcssip','www.winonegiveone.com','DCS.dcsuri','/for_moms/tell_your_friends.aspx','WT.ti','Do-Gooder PDF Clicked');");
            break;
        case 'helper':
            $('#result-string').text('Neighborhood Helper');
            $('#guide-link').attr('href', 'pdf/wingive-parentingguide_NeighborhoodHelpers.pdf'); //helpers
            $('#guide-link').attr('onclick', "dcsMultiTrack('DCS.dcssip','www.winonegiveone.com','DCS.dcsuri','/for_moms/tell_your_friends.aspx','WT.ti','Helpers PDF Clicked');");
            break;
        case 'seeker':
            $('#result-string').text('Project Seeker');
            $('#guide-link').attr('href', 'pdf/wingive-parentingguide_ProjectSeekers.pdf');
            $('#guide-link').attr('onclick', "dcsMultiTrack('DCS.dcssip','www.winonegiveone.com','DCS.dcsuri','/for_moms/tell_your_friends.aspx','WT.ti','Seekers PDF Clicked');");
            break;
        default:
            $('#result-string').text('Global Do-Gooder');
            $('#guide-link').attr('href', 'pdf/wingive-parentingguide_DoGooders.pdf');
            $('#guide-link').attr('onclick', "dcsMultiTrack('DCS.dcssip','www.winonegiveone.com','DCS.dcsuri','/for_moms/tell_your_friends.aspx','WT.ti','Do-Gooder Clicked');");
            break;
    }
    $('#quiz').hide();
    $('#quiz-results').show();
}

function scoreQuiz() {
    //this will calculate a score and show a link to the right PDF
    var ptsDoGooder = 0, ptsHelper = 0, ptsSeeker = 0;
    $('div#quiz li.a').each(function () {
        if ($(this).hasClass('ans-yes')) {
            //if do-good is in array, 1 pt for ptsDoGooder
            if ($(this).hasClass('do-good'))
                ptsDoGooder++;
            //if helper is in array, 1 pt for ptsHelper
            if ($(this).hasClass('helper'))
                ptsHelper++;
            //if seeker is in array, 1 pt for ptsSeeker
            if ($(this).hasClass('seeker'))
                ptsSeeker++;
        }
    });
    var result = Math.max(ptsDoGooder, ptsHelper, ptsSeeker);
    if (result == ptsDoGooder) {
        return 'do-good';
    } else if (result == ptsHelper) {
        return 'helper';
    } else if (result == ptsSeeker) {
        return 'seeker';
    }
    return 'do-good'; //returns do-good if something went wrong
}

function scrollMomPage(val) {
    $('html, body').animate({ scrollTop: val }, 1000);
}

// Spotlight Tags


// Learn More - Clicked
function spotlight_SNK_BCFS_MEGA_KidLearn() {
    var axel = Math.random() + "";
    var a = axel * 10000000000000;
    var spotpix = new Image(1, 1);
    spotpix.src = 'http://ad.doubleclick.net/activity;src=1869704;type=snack771;cat=snk_b557;ord=1;num=' + a + '?';
}



// Donate - Donated Laptop
function spotlight_SNK_BCFS_MEGA_KidDonate() {
    var axel = Math.random() + "";
    var a = axel * 10000000000000;
    var spotpix = new Image(1, 1);
    spotpix.src = 'http://fls.doubleclick.net/activityi;src=1869704;type=snack771;cat=snk_b162;ord=1;num=' + a + '?';
}
