﻿$(document).ready(function () {
    //SetHeader();

    $(".rollover").hover(
        function () { $(this).attr("src", $(this).attr("src").replace("-off", "-on")); },
        function () { $(this).attr("src", $(this).attr("src").replace("-on", "-off")); }
    );
    

    $(".topImg").hover(
    function () {
        var submenu = $(".topNav .dropDown");

        $(".topNav").children(".active").children(".dropDown").hide();
        $(this).addClass("on");

        var el = $(".dropDown", this);

        el.show();

    },

    function () {
        var el = $(".dropDown", this);

        $(this).removeClass("on");

        if (!el.hasClass("active")) {
            el.hide();
        }

        //$(".topNav").children(".active").children(".dropDown").show();
    }
    );

    var navID = "#nav" + $(".navName").attr("id");
    navigation(navID);

    var myClose = function () {
        $('.jqmWindow').hide();
        $('.jqmOverlay').hide();
        $('#homeVideoContainer').show();
    };
    $('#dialog').jqm({ onHide: myClose });

    /***** Leavign site popup **********/

    //leaving site popup
    $('#leavingSite').jqm();

    $('.leavingSite').bind('click', function (event) {

        event.preventDefault();
        $('#btn_ok').attr("href", this.href);
        $('#btn_ok').attr("target", "_blank");
        $('#leavingSite').jqmShow();
        $('body').prepend($('#leavingSite')); //fix IE layer problem
    });

    $('#btn_ok').bind('click', function () {
        parent.$("#leavingSite").jqmHide();
    })

    $('#btn_cancel').bind('click', function (event) {
        event.preventDefault();
        $("#leavingSite").jqmHide();
    })

    function preload(arrayOfImages) {
        $(arrayOfImages).each(function () {
            //$('<img/>')[0].src = this;
            // Alternatively you could use:
            (new Image()).src = this;
        });
    }
    

});

function getQueryString() {
    var result = {}, queryString = location.search.substring(1),
      re = /([^&=]+)=([^&]*)/g, m;

    while (m = re.exec(queryString)) {
        result[decodeURIComponent(m[1])] = decodeURIComponent(m[2]);
    }

    return result;
}


function displayFAQ(FAQNum) {
    $(".FAQ").hide();
    $(".FAQ:eq("+FAQNum+")").show();
}

function navigation(navID) {
    if ($(navID).length > 0) {
        var topNav = $(navID);
        $(navID + " a:first").addClass("active");
        while (!topNav.hasClass("topNav")) {
        	
            topNav.addClass("active");
            topNav = topNav.parent();
        }
        topNav.addClass("active");
    }
    if ($("#subNavigation").length > 0) {
        if ($(".active .specialSubNav").length > 0) {
            $(".active .specialSubNav").appendTo($("#subNavigation"));
            var title = $(".specialSubNav p").text();
        }
        else {
            $(".dropDownItem.active .subNav").appendTo($("#subNavigation"));
            var title = $(".dropDownItem.active a").text();
        }

        $("#subNavigation .subNav").css("display", "block");
        $("#subTitle").html(title);        
    }
   }
   function popReg() {
   	$('#dialog').jqmShow();
}

//function SetHeader() {

//    var story = getQueryString()["story"];    
//    if (story != null && (story == "claudia" || story == "donnette" || story == "ralph")) {
//        if (story == "claudia") {
//            SetHeaderClaudia();
//        }
//        else if (story == "donnette") {
//            SetHeaderDonnette();
//        }
//        else if (story == "ralph") {
//            SetHeaderRalph();
//        }
//    }
//    else {
//        RandomizeHeader();
//    }
//}

function RandomizeHeader() {

    var mod = Math.floor(Math.random() * 3);             
    
    if (mod == 0) {
        SetHeaderClaudia();
    }
    else if (mod == 1) {
        SetHeaderDonnette();
    }
    else {
        SetHeaderRalph();
    }
}

function SetHeaderDonnette() {
    $('#staticDonnette').show();
    $('#thumbClaudia').insertAfter('#thumbDonnette');
    $('#thumbRalph').insertAfter('#thumbClaudia');
    $('#homeVideos').attr('src', 'http://sfth1.healththeater.com//video/Meet_Donnette_and_Ralph_id528.html');
}

function SetHeaderClaudia() {
    $('#staticClaudia').show();
    $('#thumbDonnette').insertAfter('#thumbClaudia');
    $('#thumbRalph').insertAfter('#thumbDonnette');
    $('#homeVideos').attr('src', 'http://sfth1.healththeater.com//video/Meet_Claudia_id954.html');
}

function SetHeaderRalph() {
    $('#staticRalph').show();
    $('#thumbDonnette').insertAfter('#thumbRalph');
    $('#thumbClaudia').insertAfter('#thumbDonnette');
    $('#homeVideos').attr('src', 'http://sfth1.healththeater.com//video/Meet_Donnette_and_Ralph_id528.html');
}

function HideVideo() {
    $('#homeVideos').attr('src', '');
}

function ShowVideo() {
    $('#homeVideos').attr('src', '');
}



